Commit 6f03bd17 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

cleanup of source code

parent 12eebf7a
...@@ -28,9 +28,7 @@ namespace Dune { namespace experimental ...@@ -28,9 +28,7 @@ namespace Dune { namespace experimental
std::size_t idx = 0; std::size_t idx = 0;
for (std::size_t i = 0; i < types.size(); ++i) { for (std::size_t i = 0; i < types.size(); ++i) {
if (Vtk::Map::from_type.count(types[i]) == 0) auto type = Vtk::to_geometry(types[i]);
DUNE_THROW(Exception, "Unknown ElementType: " << types[i]);
auto type = Vtk::Map::from_type[types[i]];
Vtk::CellType cellType{type}; Vtk::CellType cellType{type};
auto refElem = referenceElement<double,Grid::dimension>(type); auto refElem = referenceElement<double,Grid::dimension>(type);
...@@ -92,9 +90,7 @@ namespace Dune { namespace experimental ...@@ -92,9 +90,7 @@ namespace Dune { namespace experimental
idx = 0; idx = 0;
for (std::size_t i = 0; i < types.size(); ++i) { for (std::size_t i = 0; i < types.size(); ++i) {
if (Vtk::Map::from_type.count(types[i]) == 0) auto type = Vtk::to_geometry(types[i]);
DUNE_THROW(Exception, "Unknown ElementType: " << types[i]);
auto type = Vtk::Map::from_type[types[i]];
Vtk::CellType cellType{type}; Vtk::CellType cellType{type};
std::size_t nNodes = offsets[i] - (i == 0 ? 0 : offsets[i-1]); std::size_t nNodes = offsets[i] - (i == 0 ? 0 : offsets[i-1]);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <locale> #include <locale>
#include <sstream>
#include <string> #include <string>
namespace Dune namespace Dune
...@@ -74,8 +75,8 @@ namespace Dune ...@@ -74,8 +75,8 @@ namespace Dune
} }
} }
template <class InputIter, class SeparaterIter, class Func> template <class InputIter, class SeparatorIter, class Func>
void split(InputIter first, InputIter end, SeparaterIter s_first, SeparaterIter s_end, Func f) void split(InputIter first, InputIter end, SeparatorIter s_first, SeparatorIter s_end, Func f)
{ {
if (first == end) if (first == end)
return; return;
...@@ -102,4 +103,18 @@ namespace Dune ...@@ -102,4 +103,18 @@ namespace Dune
} }
} }
template <class InputIter>
std::string join (InputIter first, InputIter end, std::string sep = " ")
{
if (first == end)
return "";
std::ostringstream os;
os << *first++;
while (first != end)
os << sep << *first++;
return os.str();
}
} // end namspace Dune } // end namspace Dune
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <type_traits> #include <type_traits>
#include <dune/common/std/type_traits.hh> #include <dune/common/std/type_traits.hh>
#include <dune/functions/common/signature.hh>
#include <dune/functions/common/typeerasure.hh> #include <dune/functions/common/typeerasure.hh>
namespace Dune { namespace experimental namespace Dune { namespace experimental
...@@ -162,14 +163,32 @@ namespace Dune { namespace experimental ...@@ -162,14 +163,32 @@ namespace Dune { namespace experimental
template <class F> template <class F>
using HasLocalFunction = decltype(localFunction(std::declval<F>())); using HasLocalFunction = decltype(localFunction(std::declval<F>()));
public:
template <class F> template <class F>
VTKFunction (F&& f, std::string name, int ncomps = 1) using Signature = typename std::decay_t<F>::Signature;
public:
template <class F,
class Range = typename Functions::SignatureTraits<Signature<F>>::Range>
VTKFunction (F&& f, std::string name, int ncomps = 1,
Vtk::DataTypes type = Vtk::Map::type<Range>)
: Super(std::forward<F>(f))
, name_(std::move(name))
, ncomps_(ncomps > 3 ? 9 : ncomps > 1 ? 3 : 1) // tensor, vector, or scalar
, type_(type)
{
static_assert(Std::is_detected<HasLocalFunction,F>::value,
"Requires A GridFunction to be passed to the VTKFunction.");
}
template <class F,
std::enable_if_t<not Std::is_detected<Signature,F>::value,int> = 0>
VTKFunction (F&& f, std::string name, int ncomps = 1,
Vtk::DataTypes type = Vtk::FLOAT32)
: Super(std::forward<F>(f)) : Super(std::forward<F>(f))
, name_(std::move(name)) , name_(std::move(name))
, ncomps_(ncomps > 1 ? 3 : 1) , ncomps_(ncomps > 3 ? 9 : ncomps > 1 ? 3 : 1) // tensor, vector, or scalar
, type_(type)
{ {
assert(1 <= ncomps && ncomps <= 3);
static_assert(Std::is_detected<HasLocalFunction,F>::value, static_assert(Std::is_detected<HasLocalFunction,F>::value,
"Requires A GridFunction to be passed to the VTKFunction."); "Requires A GridFunction to be passed to the VTKFunction.");
} }
...@@ -194,10 +213,16 @@ namespace Dune { namespace experimental ...@@ -194,10 +213,16 @@ namespace Dune { namespace experimental
return ncomps_; return ncomps_;
} }
/// Return the VTK Datatype associated with the functions range type
Vtk::DataTypes type () const
{
return type_;
}
private: private:
std::string name_; std::string name_;
int ncomps_ = 1; int ncomps_ = 1;
Vtk::DataTypes type_;
}; };
}} // end namespace Dune::experimental }} // end namespace Dune::experimental
...@@ -29,56 +29,39 @@ void VtkImageDataWriter<GV,DC> ...@@ -29,56 +29,39 @@ void VtkImageDataWriter<GV,DC>
} }
std::vector<pos_type> offsets; // pos => offset std::vector<pos_type> offsets; // pos => offset
out << "<VTKFile type=\"ImageData\" version=\"1.0\" " out << "<VTKFile"
<< "byte_order=\"" << this->getEndian() << "\" header_type=\"UInt64\"" << " type=\"StructuredGrid\""
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\">\n" : ">\n"); << " version=\"1.0\""
out << "<ImageData WholeExtent=\""; << " byte_order=\"" << this->getEndian() << "\""
<< " header_type=\"UInt64\""
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\"" : "")
<< ">\n";
auto const& wholeExtent = dataCollector_.wholeExtent(); auto const& wholeExtent = dataCollector_.wholeExtent();
for (int i = 0; i < 3; ++i) {
out << (i == 0 ? "" : " ") << wholeExtent[2*i] << " " << wholeExtent[2*i+1];
}
out << "\" Origin=\"";
auto const& origin = dataCollector_.origin(); auto const& origin = dataCollector_.origin();
for (int i = 0; i < 3; ++i) {
out << (i == 0 ? "" : " ") << origin[i];
}
out << "\" Spacing=\"";
auto const& spacing = dataCollector_.spacing(); auto const& spacing = dataCollector_.spacing();
for (int i = 0; i < 3; ++i) { out << "<ImageData"
out << (i == 0 ? "" : " ") << spacing[i]; << " WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\""
} << " Origin=\"" << join(origin.begin(), origin.end()) << "\""
out << "\">\n"; << " Spacing=\"" << join(spacing.begin(), spacing.end()) << "\""
<< ">\n";
dataCollector_.writeLocalPiece([&out](std::array<int,6> const& extent)
{ dataCollector_.writeLocalPiece([&out](auto const& extent) {
out << "<Piece Extent=\""; out << "<Piece Extent=\"" << join(extent.begin(), extent.end()) << "\">\n";
for (int i = 0; i < 3; ++i) {
out << (i == 0 ? "" : " ") << extent[2*i] << " " << extent[2*i+1];
}
out << "\">\n";
}); });
{ // Write data associated with grid points // Write data associated with grid points
auto scalar = std::find_if(pointData_.begin(), pointData_.end(), [](auto const& v) { return v.ncomps() == 1; }); out << "<PointData" << this->getNames(pointData_) << ">\n";
auto vector = std::find_if(pointData_.begin(), pointData_.end(), [](auto const& v) { return v.ncomps() > 1; }); for (auto const& v : pointData_)
out << "<PointData" << (scalar != pointData_.end() ? " Scalars=\"" + scalar->name() + "\"" : "") this->writeData(out, offsets, v, Super::POINT_DATA);
<< (vector != pointData_.end() ? " Vectors=\"" + vector->name() + "\"" : "") out << "</PointData>\n";
<< ">\n";
for (auto const& v : pointData_) // Write data associated with grid cells
this->writeData(out, offsets, v, Super::POINT_DATA); out << "<CellData" << this->getNames(cellData_) << ">\n";
out << "</PointData>\n"; for (auto const& v : cellData_)
} this->writeData(out, offsets, v, Super::CELL_DATA);
out << "</CellData>\n";
{ // Write data associated with grid cells
auto scalar = std::find_if(cellData_.begin(), cellData_.end(), [](auto const& v) { return v.ncomps() == 1; });
auto vector = std::find_if(cellData_.begin(), cellData_.end(), [](auto const& v) { return v.ncomps() > 1; });
out << "<CellData" << (scalar != cellData_.end() ? " Scalars=\"" + scalar->name() + "\"" : "")
<< (vector != cellData_.end() ? " Vectors=\"" + vector->name() + "\"" : "")
<< ">\n";
for (auto const& v : cellData_)
this->writeData(out, offsets, v, Super::CELL_DATA);
out << "</CellData>\n";
}
out << "</Piece>\n"; out << "</Piece>\n";
out << "</ImageData>\n"; out << "</ImageData>\n";
...@@ -88,13 +71,13 @@ void VtkImageDataWriter<GV,DC> ...@@ -88,13 +71,13 @@ void VtkImageDataWriter<GV,DC>
out << "<AppendedData encoding=\"raw\">\n_"; out << "<AppendedData encoding=\"raw\">\n_";
appended_pos = out.tellp(); appended_pos = out.tellp();
for (auto const& v : pointData_) { for (auto const& v : pointData_) {
if (datatype_ == Vtk::FLOAT32) if (v.type() == Vtk::FLOAT32)
blocks.push_back( this->template writeDataAppended<float>(out, v, Super::POINT_DATA) ); blocks.push_back( this->template writeDataAppended<float>(out, v, Super::POINT_DATA) );
else else
blocks.push_back( this->template writeDataAppended<double>(out, v, Super::POINT_DATA) ); blocks.push_back( this->template writeDataAppended<double>(out, v, Super::POINT_DATA) );
} }
for (auto const& v : cellData_) { for (auto const& v : cellData_) {
if (datatype_ == Vtk::FLOAT32) if (v.type() == Vtk::FLOAT32)
blocks.push_back( this->template writeDataAppended<float>(out, v, Super::CELL_DATA) ); blocks.push_back( this->template writeDataAppended<float>(out, v, Super::CELL_DATA) );
else else
blocks.push_back( this->template writeDataAppended<double>(out, v, Super::CELL_DATA) ); blocks.push_back( this->template writeDataAppended<double>(out, v, Super::CELL_DATA) );
...@@ -123,63 +106,53 @@ void VtkImageDataWriter<GV,DC> ...@@ -123,63 +106,53 @@ void VtkImageDataWriter<GV,DC>
std::string filename = pfilename + ".p" + this->fileExtension(); std::string filename = pfilename + ".p" + this->fileExtension();
std::ofstream out(filename, std::ios_base::ate | std::ios::binary); std::ofstream out(filename, std::ios_base::ate | std::ios::binary);
out << "<VTKFile type=\"PImageData\" version=\"1.0\" " out << "<VTKFile"
<< "byte_order=\"" << this->getEndian() << "\" header_type=\"UInt64\"" << " type=\"StructuredGrid\""
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\">\n" : ">\n"); << " version=\"1.0\""
out << "<PImageData GhostLevel=\"0\" WholeExtent=\""; << " byte_order=\"" << this->getEndian() << "\""
<< " header_type=\"UInt64\""
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\"" : "")
<< ">\n";
auto const& wholeExtent = dataCollector_.wholeExtent(); auto const& wholeExtent = dataCollector_.wholeExtent();
for (int i = 0; i < 3; ++i) {
out << (i == 0 ? "" : " ") << wholeExtent[2*i] << " " << wholeExtent[2*i+1];
}
out << "\" Origin=\"";
auto const& origin = dataCollector_.origin(); auto const& origin = dataCollector_.origin();
for (int i = 0; i < 3; ++i) {
out << (i == 0 ? "" : " ") << origin[i];
}
out << "\" Spacing=\"";
auto const& spacing = dataCollector_.spacing(); auto const& spacing = dataCollector_.spacing();
for (int i = 0; i < 3; ++i) { out << "<PImageData"
out << (i == 0 ? "" : " ") << spacing[i]; << " GhostLevel=\"0\""
<< " WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\""
<< " Origin=\"" << join(origin.begin(), origin.end()) << "\""
<< " Spacing=\"" << join(spacing.begin(), spacing.end()) << "\""
<< ">\n";
// Write data associated with grid points
out << "<PPointData" << this->getNames(pointData_) << ">\n";
for (auto const& v : pointData_) {
out << "<PDataArray"
<< " Name=\"" << v.name() << "\""
<< " type=\"" << to_string(v.type()) << "\""
<< " NumberOfComponents=\"" << v.ncomps() << "\""
<< " />\n";
} }
out << "\">\n"; out << "</PPointData>\n";
{ // Write data associated with grid points // Write data associated with grid cells
auto scalar = std::find_if(pointData_.begin(), pointData_.end(), [](auto const& v) { return v.ncomps() == 1; }); out << "<PCellData" << this->getNames(cellData_) << ">\n";
auto vector = std::find_if(pointData_.begin(), pointData_.end(), [](auto const& v) { return v.ncomps() > 1; }); for (auto const& v : cellData_) {
out << "<PPointData" << (scalar != pointData_.end() ? " Scalars=\"" + scalar->name() + "\"" : "") out << "<PDataArray"
<< (vector != pointData_.end() ? " Vectors=\"" + vector->name() + "\"" : "") << " Name=\"" << v.name() << "\""
<< ">\n"; << " type=\"" << to_string(v.type()) << "\""
for (auto const& v : pointData_) { << " NumberOfComponents=\"" << v.ncomps() << "\""
out << "<PDataArray Name=\"" << v.name() << "\" type=\"" << Vtk::Map::from_datatype[datatype_] << "\"" << " />\n";
<< " NumberOfComponents=\"" << v.ncomps() << "\" />\n";
}
out << "</PPointData>\n";
}
{ // Write data associated with grid cells
auto scalar = std::find_if(cellData_.begin(), cellData_.end(), [](auto const& v) { return v.ncomps() == 1; });
auto vector = std::find_if(cellData_.begin(), cellData_.end(), [](auto const& v) { return v.ncomps() > 1; });
out << "<PCellData" << (scalar != cellData_.end() ? " Scalars=\"" + scalar->name() + "\"" : "")
<< (vector != cellData_.end() ? " Vectors=\"" + vector->name() + "\"" : "")
<< ">\n";
for (auto const& v : cellData_) {
out << "<PDataArray Name=\"" << v.name() << "\" type=\"" << Vtk::Map::from_datatype[datatype_] << "\""
<< " NumberOfComponents=\"" << v.ncomps() << "\" />\n";
}
out << "</PCellData>\n";
} }
out << "</PCellData>\n";
// Write piece file references // Write piece file references
dataCollector_.writePieces([&out,pfilename,ext=this->fileExtension()](int p, std::array<int,6> const& extent, bool write_extent) dataCollector_.writePieces([&out,pfilename,ext=this->fileExtension()](int p, auto const& extent, bool write_extent)
{ {
out << "<Piece Source=\"" << pfilename << "_p" << std::to_string(p) << "." << ext << "\""; std::string piece_source = pfilename + "_p" + std::to_string(p) + "." + ext;
if (write_extent) { out << "<Piece Source=\"" << piece_source << "\"";
out << " Extent=\""; if (write_extent)
for (int i = 0; i < 3; ++i) { out << " Extent=\"" << join(extent.begin(), extent.end()) << "\"";
out << (i == 0 ? "" : " ") << extent[2*i] << " " << extent[2*i+1];
}
out << "\"";
}
out << " />\n"; out << " />\n";
}); });
......
...@@ -29,46 +29,32 @@ void VtkStructuredGridWriter<GV,DC> ...@@ -29,46 +29,32 @@ void VtkStructuredGridWriter<GV,DC>
} }
std::vector<pos_type> offsets; // pos => offset std::vector<pos_type> offsets; // pos => offset
out << "<VTKFile type=\"StructuredGrid\" version=\"1.0\" " out << "<VTKFile"
<< "byte_order=\"" << this->getEndian() << "\" header_type=\"UInt64\"" << " type=\"StructuredGrid\""
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\">\n" : ">\n"); << " version=\"1.0\""
out << "<StructuredGrid WholeExtent=\""; << " byte_order=\"" << this->getEndian() << "\""
<< " header_type=\"UInt64\""
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\"" : "")
<< ">\n";
auto const& wholeExtent = dataCollector_.wholeExtent(); auto const& wholeExtent = dataCollector_.wholeExtent();
for (int i = 0; i < 3; ++i) { out << "<StructuredGrid WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\">\n";
out << (i == 0 ? "" : " ") << wholeExtent[2*i] << " " << wholeExtent[2*i+1];
}
out << "\">\n";
dataCollector_.writeLocalPiece([&out](std::array<int,6> const& extent) dataCollector_.writeLocalPiece([&out](auto const& extent) {
{ out << "<Piece Extent=\"" << join(extent.begin(), extent.end()) << "\">\n";
out << "<Piece Extent=\"";
for (int i = 0; i < 3; ++i) {
out << (i == 0 ? "" : " ") << extent[2*i] << " " << extent[2*i+1];
}
out << "\">\n";
}); });
{ // Write data associated with grid points // Write data associated with grid points
auto scalar = std::find_if(pointData_.begin(), pointData_.end(), [](auto const& v) { return v.ncomps() == 1; }); out << "<PointData" << this->getNames(pointData_) << ">\n";
auto vector = std::find_if(pointData_.begin(), pointData_.end(), [](auto const& v) { return v.ncomps() > 1; }); for (auto const& v : pointData_)
out << "<PointData" << (scalar != pointData_.end() ? " Scalars=\"" + scalar->name() + "\"" : "") this->writeData(out, offsets, v, Super::POINT_DATA);
<< (vector != pointData_.end() ? " Vectors=\"" + vector->name() + "\"" : "") out << "</PointData>\n";
<< ">\n";
for (auto const& v : pointData_)
this->writeData(out, offsets, v, Super::POINT_DATA);
out << "</PointData>\n";
}
{ // Write data associated with grid cells // Write data associated with grid cells
auto scalar = std::find_if(cellData_.begin(), cellData_.end(), [](auto const& v) { return v.ncomps() == 1; }); out << "<CellData" << this->getNames(cellData_) << ">\n";
auto vector = std::find_if(cellData_.begin(), cellData_.end(), [](auto const& v) { return v.ncomps() > 1; }); for (auto const& v : cellData_)
out << "<CellData" << (scalar != cellData_.end() ? " Scalars=\"" + scalar->name() + "\"" : "") this->writeData(out, offsets, v, Super::CELL_DATA);
<< (vector != cellData_.end() ? " Vectors=\"" + vector->name() + "\"" : "") out << "</CellData>\n";
<< ">\n";
for (auto const& v : cellData_)
this->writeData(out, offsets, v, Super::CELL_DATA);
out << "</CellData>\n";
}
// Write point coordinates // Write point coordinates
out << "<Points>\n"; out << "<Points>\n";
...@@ -84,17 +70,18 @@ void VtkStructuredGridWriter<GV,DC> ...@@ -84,17 +70,18 @@ void VtkStructuredGridWriter<GV,DC>
out << "<AppendedData encoding=\"raw\">\n_"; out << "<AppendedData encoding=\"raw\">\n_";
appended_pos = out.tellp(); appended_pos = out.tellp();
for (auto const& v : pointData_) { for (auto const& v : pointData_) {
if (datatype_ == Vtk::FLOAT32) if (v.type() == Vtk::FLOAT32)
blocks.push_back( this->template writeDataAppended<float>(out, v, Super::POINT_DATA) ); blocks.push_back( this->template writeDataAppended<float>(out, v, Super::POINT_DATA) );
else else
blocks.push_back( this->template writeDataAppended<double>(out, v, Super::POINT_DATA) ); blocks.push_back( this->template writeDataAppended<double>(out, v, Super::POINT_DATA) );
} }
for (auto const& v : cellData_) { for (auto const& v : cellData_) {
if (datatype_ == Vtk::FLOAT32) if (v.type() == Vtk::FLOAT32)
blocks.push_back( this->template writeDataAppended<float>(out, v, Super::CELL_DATA) ); blocks.push_back( this->template writeDataAppended<float>(out, v, Super::CELL_DATA) );
else else
blocks.push_back( this->template writeDataAppended<double>(out, v, Super::CELL_DATA) ); blocks.push_back( this->template writeDataAppended<double>(out, v, Super::CELL_DATA) );
} }
if (datatype_ == Vtk::FLOAT32) if (datatype_ == Vtk::FLOAT32)
blocks.push_back( this->template writePointsAppended<float>(out) ); blocks.push_back( this->template writePointsAppended<float>(out) );
else else
...@@ -123,58 +110,57 @@ void VtkStructuredGridWriter<GV,DC> ...@@ -123,58 +110,57 @@ void VtkStructuredGridWriter<GV,DC>
std::string filename = pfilename + ".p" + this->fileExtension(); std::string filename = pfilename + ".p" + this->fileExtension();
std::ofstream out(filename, std::ios_base::ate | std::ios::binary); std::ofstream out(filename, std::ios_base::ate | std::ios::binary);
out << "<VTKFile type=\"PStructuredGrid\" version=\"1.0\" " out << "<VTKFile"
<< "byte_order=\"" << this->getEndian() << "\" header_type=\"UInt64\"" << " type=\"PStructuredGrid\""
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\">\n" : ">\n"); << " version=\"1.0\""
out << "<PStructuredGrid GhostLevel=\"0\" WholeExtent=\""; << " byte_order=\"" << this->getEndian() << "\""
<< " header_type=\"UInt64\""
<< (format_ == Vtk::COMPRESSED ? " compressor=\"vtkZLibDataCompressor\"" : "")
<< ">\n";
auto const& wholeExtent = dataCollector_.wholeExtent(); auto const& wholeExtent = dataCollector_.wholeExtent();
for (int i = 0; i < 3; ++i) { out << "<PStructuredGrid"
out << (i == 0 ? "" : " ") << wholeExtent[2*i] << " " << wholeExtent[2*i+1]; << " GhostLevel=\"0\""
<< " WholeExtent=\"" << join(wholeExtent.begin(), wholeExtent.end()) << "\""
<< ">\n";
// Write data associated with grid points
out << "<PPointData" << this->getNames(pointData_) << ">\n";
for (auto const& v : pointData_) {
out << "<PDataArray"
<< " Name=\"" << v.name() << "\""
<< " type=\"" << to_string(v.type()) << "\""
<< " NumberOfComponents=\"" << v.ncomps() << "\""
<< " />\n";
} }
out << "\">\n"; out << "</PPointData>\n";
{ // Write data associated with grid points // Write data associated with grid cells
auto scalar = std::find_if(pointData_.begin(), pointData_.end(), [](auto const& v) { return v.ncomps() == 1; }); out << "<PCellData" << this->getNames(cellData_) << ">\n";
auto vector = std::find_if(pointData_.begin(), pointData_.end(), [](auto const& v) { return v.ncomps() > 1; }); for (auto const& v : cellData_) {
out << "<PPointData" << (scalar != pointData_.end() ? " Scalars=\"" + scalar->name() + "\"" : "") out << "<PDataArray"
<< (vector != pointData_.end() ? " Vectors=\"" + vector->name() + "\"" : "") << " Name=\"" << v.name() << "\""
<< ">\n"; << " type=\"" << to_string(v.type()) << "\""
for (auto const& v : pointData_) { << " NumberOfComponents=\"" << v.ncomps() << "\""
out << "<PDataArray Name=\"" << v.name() << "\" type=\"" << Vtk::Map::from_datatype[datatype_] << "\"" << " />\n";
<< " NumberOfComponents=\"" << v.ncomps() << "\" />\n";
}
out << "</PPointData>\n";
}
{ // Write data associated with grid cells
auto scalar = std::find_if(cellData_.begin(), cellData_.end(), [](auto const& v) { return v.ncomps() == 1; });
auto vector = std::find_if(cellData_.begin(), cellData_.end(), [](auto const& v) { return v.ncomps() > 1; });
out << "<PCellData" << (scalar != cellData_.end() ? " Scalars=\"" + scalar->name() + "\"" : "")
<< (vector != cellData_.end() ? " Vectors=\"" + vector->name() + "\"" : "")
<< ">\n";
for (auto const& v : cellData_) {
out << "<PDataArray Name=\"" << v.name() << "\" type=\"" << Vtk::Map::from_datatype[datatype_] << "\""
<< " NumberOfComponents=\"" << v.ncomps() << "\" />\n";
}
out << "</PCellData>\n";
} }
out << "</PCellData>\n";
// Write points // Write points
out << "<PPoints>\n";