10 #include <dune/geometry/referenceelements.hh>
11 #include <dune/geometry/type.hh>
19 template <
class GV,
class DC>
20 void VtkStructuredGridWriter<GV,DC>
21 ::writeSerialFile (std::ofstream& out)
const
23 std::vector<pos_type> offsets;
24 this->writeHeader(out,
"StructuredGrid");
26 auto const& wholeExtent = dataCollector_->wholeExtent();
27 out <<
"<StructuredGrid WholeExtent=\"" <<
Vtk::join(wholeExtent.begin(), wholeExtent.end()) <<
"\">\n";
29 dataCollector_->writeLocalPiece([&out](
auto const& extent) {
30 out <<
"<Piece Extent=\"" <<
Vtk::join(extent.begin(), extent.end()) <<
"\">\n";
35 this->writePoints(out, offsets);
39 out <<
"<PointData" << this->getNames(pointData_) <<
">\n";
40 for (
auto const& v : pointData_)
41 this->writeData(out, offsets, v, Super::POINT_DATA);
42 out <<
"</PointData>\n";
45 out <<
"<CellData" << this->getNames(cellData_) <<
">\n";
46 for (
auto const& v : cellData_)
47 this->writeData(out, offsets, v, Super::CELL_DATA);
48 out <<
"</CellData>\n";
51 out <<
"</StructuredGrid>\n";
53 this->writeAppended(out, offsets);
58 template <
class GV,
class DC>
59 void VtkStructuredGridWriter<GV,DC>
60 ::writeParallelFile (std::ofstream& out, std::string
const& pfilename,
int )
const
62 this->writeHeader(out,
"PStructuredGrid");
64 auto const& wholeExtent = dataCollector_->wholeExtent();
65 out <<
"<PStructuredGrid"
66 <<
" GhostLevel=\"" << dataCollector_->ghostLevel() <<
"\""
67 <<
" WholeExtent=\"" <<
Vtk::join(wholeExtent.begin(), wholeExtent.end()) <<
"\""
73 <<
" type=\"" <<
to_string(datatype_) <<
"\""
74 <<
" NumberOfComponents=\"3\""
76 out <<
"</PPoints>\n";
79 out <<
"<PPointData" << this->getNames(pointData_) <<
">\n";
80 for (
auto const& v : pointData_) {
82 <<
" Name=\"" << v.name() <<
"\""
83 <<
" type=\"" <<
to_string(v.dataType()) <<
"\""
84 <<
" NumberOfComponents=\"" << v.numComponents() <<
"\""
87 out <<
"</PPointData>\n";
90 out <<
"<PCellData" << this->getNames(cellData_) <<
">\n";
91 for (
auto const& v : cellData_) {
93 <<
" Name=\"" << v.name() <<
"\""
94 <<
" type=\"" <<
to_string(v.dataType()) <<
"\""
95 <<
" NumberOfComponents=\"" << v.numComponents() <<
"\""
98 out <<
"</PCellData>\n";
101 dataCollector_->writePieces([&out,pfilename,ext=this->fileExtension()](
int p,
auto const& extent,
bool write_extent)
103 std::string piece_source = pfilename +
"_p" +
std::to_string(p) +
"." + ext;
104 out <<
"<Piece Source=\"" << piece_source <<
"\"";
106 out <<
" Extent=\"" <<
Vtk::join(extent.begin(), extent.end()) <<
"\"";
110 out <<
"</PStructuredGrid>\n";
115 template <
class GV,
class DC>
116 void VtkStructuredGridWriter<GV,DC>
117 ::writeGridAppended (std::ofstream& out, std::vector<std::uint64_t>& blocks)
const
122 Vtk::mapDataTypes<std::is_floating_point, std::is_integral>(datatype_, headertype_,
123 [&](
auto f,
auto h) {
124 using F =
typename decltype(f)::type;
125 using H =
typename decltype(h)::type;
126 blocks.push_back(this->
template writeValuesAppended<H>(out, dataCollector_->template points<F>()));
std::string to_string(Vtk::FormatTypes type)
Definition: types.cc:12
constexpr bool is_a(E a, Integer b)
Definition: enum.hh:12
std::string join(InputIter first, InputIter end, std::string sep=" ")
Definition: string.hh:110