foamVtkPolyWriter.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::vtk::polyWriter
28 
29 Description
30  Write faces/points (optionally with fields)
31  as a vtp file or a legacy vtk file.
32 
33  The file output states are managed by the Foam::vtk::fileWriter class.
34  FieldData (eg, TimeValue) must appear before any geometry pieces.
35 
36 Note
37  Parallel output is combined into a single Piece without point merging,
38  which is similar to using multi-piece data sets, but allows more
39  convenient creation as a streaming process.
40  In the future, the duplicate points at processor connections
41  may be addressed using ghost points.
42 
43 SourceFiles
44  foamVtkPolyWriter.C
45  foamVtkPolyWriterTemplates.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef Foam_vtk_polyWriter_H
50 #define Foam_vtk_polyWriter_H
51 
52 #include "foamVtkFileWriter.H"
53 #include "pointField.H"
54 #include "edgeList.H"
55 #include "faceList.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 namespace vtk
62 {
63 
64 /*---------------------------------------------------------------------------*\
65  Class vtk::polyWriter Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class polyWriter
69 :
70  public vtk::fileWriter
71 {
72 protected:
73 
74  // Protected Data
75 
76  //- The number of field points for the current Piece
77  label numberOfPoints_;
78 
79  //- The number of field cells (edges or faces) for the current Piece
80  label numberOfCells_;
81 
82  //- Local number of points
83  label nLocalPoints_;
84 
85  //- Local number of vertices (points)
86  label nLocalVerts_;
87 
88  //- Local number of lines (edges)
89  label nLocalLines_;
90 
91  //- Local number of polys (faces)
92  label nLocalPolys_;
93 
94 
95  // Protected Member Functions
96 
97  //- Write a uniform field of Cell (Poly or Line) or Point values
98  template<class Type>
100  (
101  const label nCellValues, // Could be Poly or Line!
102  const word& fieldName,
103  const Type& val
104  );
105 
106 private:
107 
108  // Private Member Functions
109 
110  //- Determine sizes (nLocalPoints_, nLocalLines_),
111  //- and begin piece
112  void beginPiece(const pointField& points, const edgeList& edges);
113 
114  //- Determine sizes (nLocalPoints_, nLocalPolys_),
115  //- and begin piece
116  void beginPiece(const pointField& points, const faceList& faces);
117 
118  //- Write points
119  void writePoints(const pointField& points);
120 
121  //- Write lines, legacy format
122  // \param pointOffset processor-local point offset
123  void writeLinesLegacy(const edgeList& edges, const label pointOffset);
124 
125  //- Write lines
126  // \param pointOffset processor-local point offset
127  void writeLines(const edgeList& edges, const label pointOffset);
128 
129  //- Write faces, legacy format
130  // \param pointOffset processor-local point offset
131  void writePolysLegacy(const faceList& faces, const label pointOffset);
132 
133  //- Write faces
134  // \param pointOffset processor-local point offset
135  void writePolys(const faceList& faces, const label pointOffset);
136 
137  //- No copy construct
138  polyWriter(const polyWriter&) = delete;
139 
140  //- No copy assignment
141  void operator=(const polyWriter&) = delete;
142 
143 
144 public:
145 
146  // Constructors
147 
148  //- Construct from components (default format INLINE_BASE64)
149  explicit polyWriter
150  (
152  );
153 
154  //- Construct from components (default format INLINE_BASE64),
155  //- and open the file for writing.
156  // The file name is with/without an extension.
157  explicit polyWriter
158  (
159  const fileName& file,
160  bool parallel = Pstream::parRun()
161  );
162 
163  //- Construct from components and open the file for writing.
164  // The file name is with/without an extension.
165  polyWriter
166  (
167  const vtk::outputOptions opts,
168  const fileName& file,
169  bool parallel = Pstream::parRun()
170  );
171 
172 
173  //- Destructor
174  virtual ~polyWriter() = default;
175 
176 
177  // Member Functions
178 
179  //- File extension for current format type.
180  using vtk::fileWriter::ext;
181 
182  //- File extension for given output type
184  {
186  }
187 
188  //- Dummy write mesh topology method - Fatal if called
189  // Provided for special-purpose writers that do not hold
190  // their own geomety, but use writePolyGeometry() directly
191  virtual bool writeGeometry();
192 
193  //- Low-level write edge/point topology.
194  //- Normally used by writeGeometry() in a derived class
195  // Also writes the file header if not previously written.
196  // \note Must be called prior to writing CellData or PointData
197  bool writeLineGeometry
198  (
199  const pointField& points,
200  const edgeList& edges
201  );
202 
203  //- Low-level write face/point topology.
204  //- Normally used by writeGeometry() in a derived class
205  // Also writes the file header if not previously written.
206  // \note Must be called prior to writing CellData or PointData
207  bool writePolyGeometry
208  (
209  const pointField& points,
210  const faceList& faces
211  );
212 
213  //- Begin CellData output section for specified number of fields.
214  // Must be called prior to writing any cell data fields.
215  // \param nFields is for legacy format only.
216  // When nFields=0, this a no-op for legacy format.
217  // \note Expected calling states: (PIECE | POINT_DATA).
218  //
219  // \return True if the state changed
220  virtual bool beginCellData(label nFields = 0);
221 
222  //- Begin PointData for specified number of fields.
223  // Must be called prior to writing any point data fields.
224  // \param nFields is for legacy format only.
225  // When nFields=0, this a no-op for legacy format.
226  // \note Expected calling states: (PIECE | CELL_DATA).
227  //
228  // \return True if the state changed
229  virtual bool beginPointData(label nFields = 0);
230 
231 
232  // Write
233 
234  //- Write primitive field of CellData (Poly or Line) or PointData values
235  template<class Type>
236  void write(const word& fieldName, const UList<Type>& field);
237 
238  //- Write primitive field of CellData
239  template<class Type>
240  void writeCellData(const word& fieldName, const UList<Type>& field);
241 
242  //- Write primitive field of PointData
243  template<class Type>
244  void writePointData(const word& fieldName, const UList<Type>& field);
245 };
246 
247 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 
250 } // End namespace vtk
251 } // End namespace Foam
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 #ifdef NoRepository
257 #endif
258 
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 #endif
263 
264 // ************************************************************************* //
bool parallel() const noexcept
Parallel output requested?
rDeltaTY field()
A class for handling file names.
Definition: fileName.H:72
label nLocalVerts_
Local number of vertices (points)
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data). These output formats are structured as DECLARED, FIELD_DATA, PIECE followed by any CELL_DATA or POINT_DATA.
void writePointData(const word &fieldName, const UList< Type > &field)
Write primitive field of PointData.
virtual bool writeGeometry()
Dummy write mesh topology method - Fatal if called.
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
vtk::outputOptions opts() const noexcept
The output options in use.
label numberOfPoints_
The number of field points for the current Piece.
void write(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData (Poly or Line) or PointData values.
void writeCellData(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
label nLocalLines_
Local number of lines (edges)
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
const pointField & points
word ext() const
File extension for current format type.
A class for handling words, derived from Foam::string.
Definition: word.H:63
label nLocalPoints_
Local number of points.
void writeUniformValue(const label nCellValues, const word &fieldName, const Type &val)
Write a uniform field of Cell (Poly or Line) or Point values.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
virtual ~polyWriter()=default
Destructor.
bool writePolyGeometry(const pointField &points, const faceList &faces)
Low-level write face/point topology. Normally used by writeGeometry() in a derived class...
label nLocalPolys_
Local number of polys (faces)
word ext(vtk::fileTag contentType) const
The file extension (legacy or xml) for the given content-type.
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
XML inline base64, base64Formatter.
bool writeLineGeometry(const pointField &points, const edgeList &edges)
Low-level write edge/point topology. Normally used by writeGeometry() in a derived class...
label numberOfCells_
The number of field cells (edges or faces) for the current Piece.
Namespace for OpenFOAM.