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-2021 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 lines (edges)
86  label nLocalLines_;
87 
88  //- Local number of polys (faces)
89  label nLocalPolys_;
90 
91 
92  // Protected Member Functions
93 
94  //- Write a uniform field of Cell (Poly or Line) or Point values
95  template<class Type>
97  (
98  const label nCellValues, // Could be Poly or Line!
99  const word& fieldName,
100  const Type& val
101  );
102 
103 private:
104 
105  // Private Member Functions
106 
107  //- Determine sizes (nLocalPoints_, nLocalLines_),
108  //- and begin piece
109  void beginPiece(const pointField& points, const edgeList& edges);
110 
111  //- Determine sizes (nLocalPoints_, nLocalPolys_),
112  //- and begin piece
113  void beginPiece(const pointField& points, const faceList& faces);
114 
115  //- Write points
116  void writePoints(const pointField& points);
117 
118  //- Write lines, legacy format
119  // \param pointOffset processor-local point offset
120  void writeLinesLegacy(const edgeList& edges, const label pointOffset);
121 
122  //- Write lines
123  // \param pointOffset processor-local point offset
124  void writeLines(const edgeList& edges, const label pointOffset);
125 
126  //- Write faces, legacy format
127  // \param pointOffset processor-local point offset
128  void writePolysLegacy(const faceList& faces, const label pointOffset);
129 
130  //- Write faces
131  // \param pointOffset processor-local point offset
132  void writePolys(const faceList& faces, const label pointOffset);
133 
134  //- No copy construct
135  polyWriter(const polyWriter&) = delete;
136 
137  //- No copy assignment
138  void operator=(const polyWriter&) = delete;
139 
140 
141 public:
142 
143  // Constructors
144 
145  //- Construct from components (default format INLINE_BASE64)
146  explicit polyWriter
147  (
149  );
150 
151  //- Construct from components (default format INLINE_BASE64),
152  //- and open the file for writing.
153  // The file name is with/without an extension.
154  explicit polyWriter
155  (
156  const fileName& file,
157  bool parallel = Pstream::parRun()
158  );
159 
160  //- Construct from components and open the file for writing.
161  // The file name is with/without an extension.
162  polyWriter
163  (
164  const vtk::outputOptions opts,
165  const fileName& file,
166  bool parallel = Pstream::parRun()
167  );
168 
169 
170  //- Destructor
171  virtual ~polyWriter() = default;
172 
173 
174  // Member Functions
175 
176  //- File extension for current format type.
177  using vtk::fileWriter::ext;
178 
179  //- File extension for given output type
181  {
183  }
184 
185  //- Dummy write mesh topology method - Fatal if called
186  // Provided for special-purpose writers that do not hold
187  // their own geomety, but use writePolyGeometry() directly
188  virtual bool writeGeometry();
189 
190  //- Low-level write edge/point topology.
191  //- Normally used by writeGeometry() in a derived class
192  // Also writes the file header if not previously written.
193  // \note Must be called prior to writing CellData or PointData
194  bool writeLineGeometry
195  (
196  const pointField& points,
197  const edgeList& edges
198  );
199 
200  //- Low-level write face/point topology.
201  //- Normally used by writeGeometry() in a derived class
202  // Also writes the file header if not previously written.
203  // \note Must be called prior to writing CellData or PointData
204  bool writePolyGeometry
205  (
206  const pointField& points,
207  const faceList& faces
208  );
209 
210  //- Begin CellData output section for specified number of fields.
211  // Must be called prior to writing any cell data fields.
212  // \param nFields is for legacy format only.
213  // When nFields=0, this a no-op for legacy format.
214  // \note Expected calling states: (PIECE | POINT_DATA).
215  //
216  // \return True if the state changed
217  virtual bool beginCellData(label nFields = 0);
218 
219  //- Begin PointData for specified number of fields.
220  // Must be called prior to writing any point data fields.
221  // \param nFields is for legacy format only.
222  // When nFields=0, this a no-op for legacy format.
223  // \note Expected calling states: (PIECE | CELL_DATA).
224  //
225  // \return True if the state changed
226  virtual bool beginPointData(label nFields = 0);
227 
228 
229  // Write
230 
231  //- Write primitive field of CellData (Poly or Line) or PointData values
232  template<class Type>
233  void write(const word& fieldName, const UList<Type>& field);
234 
235  //- Write primitive field of CellData
236  template<class Type>
237  void writeCellData(const word& fieldName, const UList<Type>& field);
238 
239  //- Write primitive field of PointData
240  template<class Type>
241  void writePointData(const word& fieldName, const UList<Type>& field);
242 };
243 
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 } // End namespace vtk
248 } // End namespace Foam
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 #ifdef NoRepository
254 #endif
255 
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 #endif
260 
261 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::vtk::fileWriter
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
Definition: foamVtkFileWriter.H:66
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::vtk::fileWriter::opts
vtk::outputOptions opts() const
The output options in use.
Definition: foamVtkFileWriterI.H:62
Foam::vtk::polyWriter::writePointData
void writePointData(const word &fieldName, const UList< Type > &field)
Write primitive field of PointData.
Definition: foamVtkPolyWriterTemplates.C:136
Foam::vtk::polyWriter::numberOfPoints_
label numberOfPoints_
The number of field points for the current Piece.
Definition: foamVtkPolyWriter.H:76
foamVtkPolyWriterTemplates.C
Foam::vtk::polyWriter::writeLineGeometry
bool writeLineGeometry(const pointField &points, const edgeList &edges)
Definition: foamVtkPolyWriter.C:619
Foam::vtk::fileTag::POLY_DATA
"PolyData"
foamVtkFileWriter.H
Foam::vtk::polyWriter::ext
static word ext(vtk::outputOptions opts)
File extension for given output type.
Definition: foamVtkPolyWriter.H:179
Foam::vtk::polyWriter::writePolyGeometry
bool writePolyGeometry(const pointField &points, const faceList &faces)
Definition: foamVtkPolyWriter.C:649
Foam::vtk::polyWriter::~polyWriter
virtual ~polyWriter()=default
Destructor.
faceList.H
Foam::vtk::fileWriter::parallel
bool parallel() const noexcept
Parallel output requested?
Definition: foamVtkFileWriterI.H:80
Foam::vtk::polyWriter::numberOfCells_
label numberOfCells_
The number of field cells (edges or faces) for the current Piece.
Definition: foamVtkPolyWriter.H:79
Foam::Field< vector >
field
rDeltaTY field()
Foam::vtk::polyWriter::writeCellData
void writeCellData(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData.
Definition: foamVtkPolyWriterTemplates.C:109
edgeList.H
Foam::vtk::formatType::INLINE_BASE64
XML inline base64, base64Formatter.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::polyWriter::nLocalPoints_
label nLocalPoints_
Local number of points.
Definition: foamVtkPolyWriter.H:82
pointField.H
Foam::vtk::polyWriter::writeGeometry
virtual bool writeGeometry()
Dummy write mesh topology method - Fatal if called.
Definition: foamVtkPolyWriter.C:607
Foam::vtk::polyWriter::nLocalLines_
label nLocalLines_
Local number of lines (edges)
Definition: foamVtkPolyWriter.H:85
Foam::vtk::polyWriter::writeUniformValue
void writeUniformValue(const label nCellValues, const word &fieldName, const Type &val)
Write a uniform field of Cell (Poly or Line) or Point values.
Definition: foamVtkPolyWriterTemplates.C:32
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< edge >
Foam::UList< Type >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::vtk::outputOptions::ext
word ext(vtk::fileTag contentType) const
The file extension (legacy or xml) for the given content-type.
Definition: foamVtkOutputOptionsI.H:77
Foam::vtk::polyWriter::nLocalPolys_
label nLocalPolys_
Local number of polys (faces)
Definition: foamVtkPolyWriter.H:88
Foam::vtk::polyWriter
Write faces/points (optionally with fields) as a vtp file or a legacy vtk file.
Definition: foamVtkPolyWriter.H:67
Foam::vtk::polyWriter::beginPointData
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
Definition: foamVtkPolyWriter.C:684
Foam::vtk::polyWriter::write
void write(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData (Poly or Line) or PointData values.
Definition: foamVtkPolyWriterTemplates.C:72
Foam::vtk::polyWriter::beginCellData
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Definition: foamVtkPolyWriter.C:678
Foam::vtk::fileWriter::ext
word ext() const
File extension for current format type.
Definition: foamVtkFileWriterI.H:68