foamVtkPatchMeshWriter.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) 2016-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::vtk::patchMeshWriter
28
29Description
30 Write OpenFOAM patches and patch fields in VTP or legacy vtk format.
31
32 The file output states are managed by the Foam::vtk::fileWriter class.
33 FieldData (eg, TimeValue) must appear before any geometry pieces.
34
35Note
36 Parallel output is combined into a single Piece without point merging,
37 which is similar to using multi-piece data sets, but allows more
38 convenient creation as a streaming process.
39 In the future, the duplicate points at processor connections
40 may be addressed using ghost points.
41
42See Also
43 Foam::vtk::patchWriter
44
45SourceFiles
46 foamVtkPatchMeshWriter.C
47 foamVtkPatchMeshWriterTemplates.C
48
49\*---------------------------------------------------------------------------*/
50
51#ifndef Foam_vtk_PatchMeshWriter_H
52#define Foam_vtk_PatchMeshWriter_H
53
54#include "foamVtkFileWriter.H"
55#include "polyMesh.H"
56
57// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58
59namespace Foam
60{
61namespace vtk
62{
63
64/*---------------------------------------------------------------------------*\
65 Class vtk::patchMeshWriter Declaration
66\*---------------------------------------------------------------------------*/
69:
70 public vtk::fileWriter
71{
72protected:
73
74 // Protected Member Data
75
76 //- The number of field points for the current Piece
77 label numberOfPoints_;
78
79 //- The number of field cells (faces) for the current Piece
80 label numberOfCells_;
81
82 //- Local number of points
83 label nLocalPoints_;
84
85 //- Local number of polys (faces)
86 label nLocalPolys_;
87
88 //- Local connectivity count for polys (faces) == sum of face sizes
89 label nLocalPolyConn_;
90
91 //- Reference to the OpenFOAM mesh (or subset)
92 const polyMesh& mesh_;
93
94 //- The selected patch ids
96
97
98 // Private Member Functions
99
100 //- Determine sizes (nLocalPoints_, nLocalPolys_),
101 //- and begin piece.
102 void beginPiece();
103
104 //- Write patch points
105 void writePoints();
106
107 //- Write patch faces, legacy format
108 // \param pointOffset processor-local point offset
109 void writePolysLegacy(const label pointOffset);
110
111 //- Write patch faces
112 // \param pointOffset processor-local point offset
113 void writePolys(const label pointOffset);
114
115
116 //- No copy construct
117 patchMeshWriter(const patchMeshWriter&) = delete;
118
119 //- No copy assignment
120 void operator=(const patchMeshWriter&) = delete;
121
122
123public:
124
125 // Constructors
126
127 //- Construct from components (default format INLINE_BASE64)
129 (
130 const polyMesh& mesh,
131 const labelList& patchIDs,
133 );
134
135 //- Construct from components (default format INLINE_BASE64),
136 //- and open the file for writing.
137 // The file name is with/without an extension.
139 (
140 const polyMesh& mesh,
141 const labelList& patchIDs,
142 const fileName& file,
144 );
145
146 //- Construct from components (default format INLINE_BASE64),
147 //- Construct from components and open the file for writing.
148 // The file name is with/without an extension.
150 (
151 const polyMesh& mesh,
152 const labelList& patchIDs,
154 const fileName& file,
156 );
157
158
159 //- Destructor
160 virtual ~patchMeshWriter() = default;
161
162
163 // Member Functions
164
165 //- File extension for current format type.
167
168 //- File extension for given output type
169 inline static word ext(vtk::outputOptions opts)
170 {
172 }
173
174 //- The patch IDs
175 const labelList& patchIDs() const noexcept
176 {
177 return patchIDs_;
178 }
179
180 //- Write file header (non-collective)
181 // \note Expected calling states: (OPENED).
182 virtual bool beginFile(std::string title = "");
183
184 //- Write patch topology
185 // Also writes the file header if not previously written.
186 // \note Must be called prior to writing CellData or PointData
187 virtual bool writeGeometry();
188
189 //- Begin CellData output section for specified number of fields.
190 // Must be called prior to writing any cell data fields.
191 // \param nFields is for legacy format only.
192 // When nFields=0, this a no-op for legacy format.
193 // \note Expected calling states: (PIECE | POINT_DATA).
194 //
195 // \return True if the state changed
196 virtual bool beginCellData(label nFields = 0);
197
198 //- Begin PointData for specified number of fields.
199 // Must be called prior to writing any point data fields.
200 // \param nFields is for legacy format only.
201 // When nFields=0, this a no-op for legacy format.
202 // \note Expected calling states: (PIECE | CELL_DATA).
203 //
204 // \return True if the state changed
205 virtual bool beginPointData(label nFields = 0);
206
207
208 //- Write patch ids as CellData.
209 // Must be called within the CELL_DATA state.
210 void writePatchIDs();
211
212 //- Write processor ids as CellData. This is no-op in serial.
213 // Must be called within the CELL_DATA state.
214 bool writeProcIDs();
215
216 //- Write processor neighbour ids as CellData. This is no-op in serial.
217 // Must be called within the CELL_DATA state.
218 bool writeNeighIDs();
219
220
221 // Write
222
223 //- Write a uniform field of Cell (Face) or Point values
224 template<class Type>
225 void writeUniform(const word& fieldName, const Type& val);
226};
227
228
229// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230
231} // End namespace vtk
232} // End namespace Foam
233
234// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235
236#ifdef NoRepository
238#endif
239
240
241// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242
243#endif
244
245// ************************************************************************* //
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
A class for handling file names.
Definition: fileName.H:76
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
vtk::outputOptions opts() const noexcept
The output options in use.
bool parallel() const noexcept
Parallel output requested?
word ext() const
File extension for current format type.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
word ext(vtk::fileTag contentType) const
The file extension (legacy or xml) for the given content-type.
Write OpenFOAM patches and patch fields in VTP or legacy vtk format.
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Face) or Point values.
label nLocalPolys_
Local number of polys (faces)
bool writeNeighIDs()
Write processor neighbour ids as CellData. This is no-op in serial.
void writePolys(const label pointOffset)
Write patch faces.
virtual ~patchMeshWriter()=default
Destructor.
label numberOfPoints_
The number of field points for the current Piece.
label nLocalPoints_
Local number of points.
const labelList & patchIDs() const noexcept
The patch IDs.
static word ext(vtk::outputOptions opts)
File extension for given output type.
label numberOfCells_
The number of field cells (faces) for the current Piece.
bool writeProcIDs()
Write processor ids as CellData. This is no-op in serial.
void operator=(const patchMeshWriter &)=delete
No copy assignment.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
label nLocalPolyConn_
Local connectivity count for polys (faces) == sum of face sizes.
void writePoints()
Write patch points.
patchMeshWriter(const patchMeshWriter &)=delete
No copy construct.
void writePatchIDs()
Write patch ids as CellData.
virtual bool writeGeometry()
Write patch topology.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
const polyMesh & mesh_
Reference to the OpenFOAM mesh (or subset)
labelList patchIDs_
The selected patch ids.
void writePolysLegacy(const label pointOffset)
Write patch faces, legacy format.
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
@ POLY_DATA
"PolyData"
@ INLINE_BASE64
XML inline base64, base64Formatter.
Namespace for OpenFOAM.
const direction noexcept
Definition: Scalar.H:223