DUNE PDELab (2.8)

pvtuwriter.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
5#define DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
6
7#include <ostream>
8#include <string>
9
11#include <dune/common/indent.hh>
12
14
15namespace Dune {
16
19
20 namespace VTK {
21
23
60 class PVTUWriter {
61 std::ostream& stream;
62
63 std::string fileType;
64
65 Indent indent;
66
67 public:
69
76 inline PVTUWriter(std::ostream& stream_, FileType fileType_)
77 : stream(stream_)
78 {
79 switch(fileType_) {
80 case polyData :
81 fileType = "PPolyData";
82 break;
83 case unstructuredGrid :
84 fileType = "PUnstructuredGrid";
85 break;
86 default :
87 DUNE_THROW(IOError, "PVTUWriter: Unknown fileType: " << fileType_);
88 }
89 const std::string& byteOrder = getEndiannessString();
90
91 stream << indent << "<?xml version=\"1.0\"?>\n";
92 stream << indent << "<VTKFile"
93 << " type=\"" << fileType << "\""
94 << " version=\"0.1\""
95 << " byte_order=\"" << byteOrder << "\">\n";
96 ++indent;
97 }
98
100 inline ~PVTUWriter() {
101 --indent;
102 stream << indent << "</VTKFile>\n"
103 << std::flush;
104 }
105
107
118 inline void beginPointData(const std::string& scalars = "",
119 const std::string& vectors = "") {
120 stream << indent << "<PPointData";
121 if(scalars != "") stream << " Scalars=\"" << scalars << "\"";
122 if(vectors != "") stream << " Vectors=\"" << vectors << "\"";
123 stream << ">\n";
124 ++indent;
125 }
127 inline void endPointData() {
128 --indent;
129 stream << indent << "</PPointData>\n";
130 }
131
133
144 inline void beginCellData(const std::string& scalars = "",
145 const std::string& vectors = "") {
146 stream << indent << "<PCellData";
147 if(scalars != "") stream << " Scalars=\"" << scalars << "\"";
148 if(vectors != "") stream << " Vectors=\"" << vectors << "\"";
149 stream << ">\n";
150 ++indent;
151 }
153 inline void endCellData() {
154 --indent;
155 stream << indent << "</PCellData>\n";
156 }
157
159
164 inline void beginPoints() {
165 stream << indent << "<PPoints>\n";
166 ++indent;
167 }
169 inline void endPoints() {
170 --indent;
171 stream << indent << "</PPoints>\n";
172 }
173
175
187 inline void beginMain(unsigned ghostLevel = 0) {
188 stream << indent << "<" << fileType
189 << " GhostLevel=\"" << ghostLevel << "\">\n";
190 ++indent;
191 }
193 inline void endMain() {
194 --indent;
195 stream << indent << "</" << fileType << ">\n";
196 }
197
199
205 void addArray(const std::string& name, unsigned ncomps, Precision prec) {
206 stream << indent << "<PDataArray"
207 << " type=\"" << toString(prec) << "\""
208 << " Name=\"" << name << "\""
209 << " NumberOfComponents=\"" << ncomps << "\"/>\n";
210 }
211
213 inline void addPiece(const std::string& filename) {
214 stream << indent << "<Piece "
215 << " Source=\"" << filename << "\"/>\n";
216 }
217 };
218
219 } // namespace VTK
220
222
223} // namespace Dune
224
225#endif // DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
Default exception class for I/O errors.
Definition: exceptions.hh:229
Utility class for handling nested indentation in output.
Definition: indent.hh:51
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:60
~PVTUWriter()
write footer
Definition: pvtuwriter.hh:100
void endMain()
finish the main PolyData/UnstructuredGrid section
Definition: pvtuwriter.hh:193
void endCellData()
finish CellData section
Definition: pvtuwriter.hh:153
void addArray(const std::string &name, unsigned ncomps, Precision prec)
Add an array to the output file.
Definition: pvtuwriter.hh:205
void beginMain(unsigned ghostLevel=0)
start the main PPolyData/PUnstructuredGrid section
Definition: pvtuwriter.hh:187
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: pvtuwriter.hh:144
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: pvtuwriter.hh:118
void addPiece(const std::string &filename)
Add a serial piece to the output file.
Definition: pvtuwriter.hh:213
PVTUWriter(std::ostream &stream_, FileType fileType_)
create a PVTUWriter object
Definition: pvtuwriter.hh:76
void endPointData()
finish PointData section
Definition: pvtuwriter.hh:127
void endPoints()
finish section for the point coordinates
Definition: pvtuwriter.hh:169
void beginPoints()
start section for the point coordinates
Definition: pvtuwriter.hh:164
A few common exception classes.
Common stuff for the VTKWriter.
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:269
FileType
which type of VTK file to write
Definition: common.hh:250
@ polyData
for .vtp files (PolyData)
Definition: common.hh:252
@ unstructuredGrid
for .vtu files (UnstructuredGrid)
Definition: common.hh:254
std::string toString(Precision p)
map precision to VTK type name
Definition: common.hh:278
std::string getEndiannessString()
determine endianness of this C++ implementation
Definition: common.hh:230
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Utility class for handling nested indentation in output.
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)