10#include <dune/geometry/referenceelements.hh>
11#include <dune/geometry/type.hh>
19template <
class GV,
class DC>
20void VtkRectilinearGridWriter<GV,DC>
21 ::writeSerialFile (std::ofstream& out)
const
23 std::vector<pos_type> offsets;
24 this->writeHeader(out,
"RectilinearGrid");
26 auto const& wholeExtent = dataCollector_->wholeExtent();
27 out <<
"<RectilinearGrid"
28 <<
" WholeExtent=\"" <<
Vtk::join(wholeExtent.begin(), wholeExtent.end()) <<
"\""
31 dataCollector_->writeLocalPiece([&out](
auto const& extent) {
32 out <<
"<Piece Extent=\"" <<
Vtk::join(extent.begin(), extent.end()) <<
"\">\n";
36 out <<
"<Coordinates>\n";
37 writeCoordinates(out, offsets);
38 out <<
"</Coordinates>\n";
41 out <<
"<PointData" << this->getNames(pointData_) <<
">\n";
42 for (
auto const& v : pointData_)
43 this->writeData(out, offsets, v, Super::POINT_DATA);
44 out <<
"</PointData>\n";
47 out <<
"<CellData" << this->getNames(cellData_) <<
">\n";
48 for (
auto const& v : cellData_)
49 this->writeData(out, offsets, v, Super::CELL_DATA);
50 out <<
"</CellData>\n";
53 out <<
"</RectilinearGrid>\n";
55 this->writeAppended(out, offsets);
60template <
class GV,
class DC>
61void VtkRectilinearGridWriter<GV,DC>
62 ::writeParallelFile (std::ofstream& out, std::string
const& pfilename,
int )
const
64 this->writeHeader(out,
"PRectilinearGrid");
66 auto const& wholeExtent = dataCollector_->wholeExtent();
67 out <<
"<PRectilinearGrid"
68 <<
" GhostLevel=\"" << dataCollector_->ghostLevel() <<
"\""
69 <<
" WholeExtent=\"" <<
Vtk::join(wholeExtent.begin(), wholeExtent.end()) <<
"\""
73 out <<
"<PCoordinates>\n";
74 out <<
"<PDataArray Name=\"x\" type=\"" <<
to_string(datatype_) <<
"\" />\n";
75 out <<
"<PDataArray Name=\"y\" type=\"" <<
to_string(datatype_) <<
"\" />\n";
76 out <<
"<PDataArray Name=\"z\" type=\"" <<
to_string(datatype_) <<
"\" />\n";
77 out <<
"</PCoordinates>\n";
80 out <<
"<PPointData" << this->getNames(pointData_) <<
">\n";
81 for (
auto const& v : pointData_) {
83 <<
" Name=\"" << v.name() <<
"\""
84 <<
" type=\"" <<
to_string(v.dataType()) <<
"\""
85 <<
" NumberOfComponents=\"" << v.numComponents() <<
"\""
88 out <<
"</PPointData>\n";
91 out <<
"<PCellData" << this->getNames(cellData_) <<
">\n";
92 for (
auto const& v : cellData_) {
94 <<
" Name=\"" << v.name() <<
"\""
95 <<
" type=\"" <<
to_string(v.dataType()) <<
"\""
96 <<
" NumberOfComponents=\"" << v.numComponents() <<
"\""
99 out <<
"</PCellData>\n";
102 dataCollector_->writePieces([&out,pfilename,ext=this->fileExtension()](
int p,
auto const& extent,
bool write_extent)
104 std::string piece_source = pfilename +
"_p" + std::to_string(p) +
"." + ext;
105 out <<
"<Piece Source=\"" << piece_source <<
"\"";
107 out <<
" Extent=\"" <<
Vtk::join(extent.begin(), extent.end()) <<
"\"";
111 out <<
"</PRectilinearGrid>\n";
116template <
class GV,
class DC>
117void VtkRectilinearGridWriter<GV,DC>
118 ::writeCoordinates (std::ofstream& out, std::vector<pos_type>& offsets,
119 std::optional<std::size_t> timestep)
const
121 std::string names =
"xyz";
123 auto coordinates = dataCollector_->template coordinates<double>();
124 for (std::size_t d = 0; d < 3; ++d) {
125 out <<
"<DataArray type=\"" <<
to_string(datatype_) <<
"\" Name=\"" << names[d] <<
"\" format=\"ascii\"";
127 out <<
" TimeStep=\"" << *timestep <<
"\"";
129 this->writeValuesAscii(out, coordinates[d]);
130 out <<
"</DataArray>\n";
134 for (std::size_t j = 0; j < 3; ++j) {
135 out <<
"<DataArray type=\"" <<
to_string(datatype_) <<
"\" Name=\"" << names[j] <<
"\" format=\"appended\"";
137 out <<
" TimeStep=\"" << *timestep <<
"\"";
139 offsets.push_back(out.tellp());
140 out << std::string(std::numeric_limits<std::uint64_t>::digits10 + 2,
' ');
147template <
class GV,
class DC>
148void VtkRectilinearGridWriter<GV,DC>
149 ::writeGridAppended (std::ofstream& out, std::vector<std::uint64_t>& blocks)
const
154 Vtk::mapDataTypes<std::is_floating_point, std::is_integral>(datatype_, headertype_,
155 [&](
auto f,
auto h) {
156 using F =
typename decltype(f)::type;
157 using H =
typename decltype(h)::type;
158 auto coordinates = dataCollector_->template coordinates<F>();
159 blocks.push_back(this->
template writeValuesAppended<H>(out, coordinates[0]));
160 blocks.push_back(this->
template writeValuesAppended<H>(out, coordinates[1]));
161 blocks.push_back(this->
template writeValuesAppended<H>(out, coordinates[2]));
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