Dune Core Modules (2.9.1)

pvtuwriter.hh
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
7#define DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
8
9#include <ostream>
10#include <string>
11
13#include <dune/common/indent.hh>
14
16
17namespace Dune {
18
21
22 namespace VTK {
23
25
62 class PVTUWriter {
63 std::ostream& stream;
64
65 std::string fileType;
66
67 Indent indent;
68
69 public:
71
78 inline PVTUWriter(std::ostream& stream_, FileType fileType_)
79 : stream(stream_)
80 {
81 switch(fileType_) {
82 case polyData :
83 fileType = "PPolyData";
84 break;
85 case unstructuredGrid :
86 fileType = "PUnstructuredGrid";
87 break;
88 default :
89 DUNE_THROW(IOError, "PVTUWriter: Unknown fileType: " << fileType_);
90 }
91 const std::string& byteOrder = getEndiannessString();
92
93 stream << indent << "<?xml version=\"1.0\"?>\n";
94 stream << indent << "<VTKFile"
95 << " type=\"" << fileType << "\""
96 << " version=\"0.1\""
97 << " byte_order=\"" << byteOrder << "\">\n";
98 ++indent;
99 }
100
102 inline ~PVTUWriter() {
103 --indent;
104 stream << indent << "</VTKFile>\n"
105 << std::flush;
106 }
107
109
120 inline void beginPointData(const std::string& scalars = "",
121 const std::string& vectors = "") {
122 stream << indent << "<PPointData";
123 if(scalars != "") stream << " Scalars=\"" << scalars << "\"";
124 if(vectors != "") stream << " Vectors=\"" << vectors << "\"";
125 stream << ">\n";
126 ++indent;
127 }
129 inline void endPointData() {
130 --indent;
131 stream << indent << "</PPointData>\n";
132 }
133
135
146 inline void beginCellData(const std::string& scalars = "",
147 const std::string& vectors = "") {
148 stream << indent << "<PCellData";
149 if(scalars != "") stream << " Scalars=\"" << scalars << "\"";
150 if(vectors != "") stream << " Vectors=\"" << vectors << "\"";
151 stream << ">\n";
152 ++indent;
153 }
155 inline void endCellData() {
156 --indent;
157 stream << indent << "</PCellData>\n";
158 }
159
161
166 inline void beginPoints() {
167 stream << indent << "<PPoints>\n";
168 ++indent;
169 }
171 inline void endPoints() {
172 --indent;
173 stream << indent << "</PPoints>\n";
174 }
175
177
189 inline void beginMain(unsigned ghostLevel = 0) {
190 stream << indent << "<" << fileType
191 << " GhostLevel=\"" << ghostLevel << "\">\n";
192 ++indent;
193 }
195 inline void endMain() {
196 --indent;
197 stream << indent << "</" << fileType << ">\n";
198 }
199
201
207 void addArray(const std::string& name, unsigned ncomps, Precision prec) {
208 stream << indent << "<PDataArray"
209 << " type=\"" << toString(prec) << "\""
210 << " Name=\"" << name << "\""
211 << " NumberOfComponents=\"" << ncomps << "\"/>\n";
212 }
213
215 inline void addPiece(const std::string& filename) {
216 stream << indent << "<Piece "
217 << " Source=\"" << filename << "\"/>\n";
218 }
219 };
220
221 } // namespace VTK
222
224
225} // namespace Dune
226
227#endif // DUNE_GRID_IO_FILE_VTK_PVTUWRITER_HH
Default exception class for I/O errors.
Definition: exceptions.hh:231
Utility class for handling nested indentation in output.
Definition: indent.hh:53
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:62
~PVTUWriter()
write footer
Definition: pvtuwriter.hh:102
void endMain()
finish the main PolyData/UnstructuredGrid section
Definition: pvtuwriter.hh:195
void endCellData()
finish CellData section
Definition: pvtuwriter.hh:155
void addArray(const std::string &name, unsigned ncomps, Precision prec)
Add an array to the output file.
Definition: pvtuwriter.hh:207
void beginMain(unsigned ghostLevel=0)
start the main PPolyData/PUnstructuredGrid section
Definition: pvtuwriter.hh:189
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: pvtuwriter.hh:146
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: pvtuwriter.hh:120
void addPiece(const std::string &filename)
Add a serial piece to the output file.
Definition: pvtuwriter.hh:215
PVTUWriter(std::ostream &stream_, FileType fileType_)
create a PVTUWriter object
Definition: pvtuwriter.hh:78
void endPointData()
finish PointData section
Definition: pvtuwriter.hh:129
void endPoints()
finish section for the point coordinates
Definition: pvtuwriter.hh:171
void beginPoints()
start section for the point coordinates
Definition: pvtuwriter.hh:166
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:271
FileType
which type of VTK file to write
Definition: common.hh:252
@ polyData
for .vtp files (PolyData)
Definition: common.hh:254
@ unstructuredGrid
for .vtu files (UnstructuredGrid)
Definition: common.hh:256
std::string toString(Precision p)
map precision to VTK type name
Definition: common.hh:280
std::string getEndiannessString()
determine endianness of this C++ implementation
Definition: common.hh:232
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Utility class for handling nested indentation in output.
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)