Loading...
Searching...
No Matches
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-2025 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.cxx
47 foamVtkPatchMeshWriter.txx
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{
64/*---------------------------------------------------------------------------*\
65 Class vtk::patchMeshWriter Declaration
66\*---------------------------------------------------------------------------*/
67
69:
70 public vtk::fileWriter
71{
72protected:
73
74 // Protected Member Data
75
76 //- Reference to the OpenFOAM mesh (or subset)
77 const polyMesh& mesh_;
78
79 //- The selected patch ids
81
82 //- Slab addressing for field points of the current Piece
85 //- Slab addressing for field cells (faces) for the current Piece
87
88 //- Slab addressing for cell (face) connectivity count,
89 //- which is just the sum of the face sizes.
91
92
93 // Protected Member Functions
94
95 //- Total number of field points for the current Piece
96 label nTotalPoints() const noexcept { return pointSlab_.total(); }
97
98 //- Total number of field cells (faces) for the current Piece
99 label nTotalCells() const noexcept { return cellSlab_.total(); }
100
101 //- Determine sizes and begin piece.
102 void beginPiece();
104 //- Write patch points
105 void writePoints();
106
107 //- Write patch faces, legacy format
109
110 //- Write patch faces
111 void writePolys();
112
113public:
114
115 // Generated Methods
116
117 //- No copy construct
119
120 //- No copy assignment
121 void operator=(const patchMeshWriter&) = delete;
122
124 // Constructors
125
126 //- Construct from components (default format INLINE_BASE64)
129 const polyMesh& mesh,
130 const labelUList& patchIDs,
132 );
133
134 //- Construct from components (default format INLINE_BASE64),
135 //- and open the file for writing.
136 // The file name is with/without an extension.
138 (
139 const polyMesh& mesh,
140 const labelUList& patchIDs,
141 const fileName& file,
143 );
144
145 //- Construct from components and open the file for writing.
146 // The file name is with/without an extension.
148 (
149 const polyMesh& mesh,
152 const fileName& file,
154 );
155
156
157 //- Destructor
158 virtual ~patchMeshWriter() = default;
159
160
161 // Member Functions
162
163 //- File extension for current format type.
165
166 //- File extension for given output type
167 inline static word ext(vtk::outputOptions opts)
168 {
169 return opts.ext(vtk::fileTag::POLY_DATA);
170 }
171
172 //- The patch IDs
173 const labelList& patchIDs() const noexcept
174 {
175 return patchIDs_;
177
178 //- Write file header (non-collective)
179 // \note Expected calling states: (OPENED).
180 virtual bool beginFile(std::string title = "");
181
182 //- Write patch topology
183 // Also writes the file header if not previously written.
184 // \note Must be called prior to writing CellData or PointData
185 virtual bool writeGeometry();
186
187 //- Begin CellData output section for specified number of fields.
188 // Must be called prior to writing any cell data fields.
189 // \param nFields is for legacy format only.
190 // When nFields=0, this a no-op for legacy format.
191 // \note Expected calling states: (PIECE | POINT_DATA).
192 //
193 // \return True if the state changed
194 virtual bool beginCellData(label nFields = 0);
195
196 //- Begin PointData for specified number of fields.
197 // Must be called prior to writing any point data fields.
198 // \param nFields is for legacy format only.
199 // When nFields=0, this a no-op for legacy format.
200 // \note Expected calling states: (PIECE | CELL_DATA).
201 //
202 // \return True if the state changed
203 virtual bool beginPointData(label nFields = 0);
204
205
206 //- Write patch ids as CellData.
207 // Must be called within the CELL_DATA state.
208 void writePatchIDs();
209
210 //- Write processor ids for each line as CellData or for each point
211 //- as PointData, depending on isPointData() state. No-op in serial.
212 bool writeProcIDs();
213
214 //- Write processor neighbour ids as CellData. This is no-op in serial.
215 // Must be called within the CELL_DATA state.
216 bool writeNeighIDs();
217
218
219 // Write
221 //- Write a uniform field of Cell (Face) or Point values
222 template<class Type>
223 void writeUniform(const word& fieldName, const Type& val);
224};
225
226
227// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229} // End namespace vtk
230} // End namespace Foam
231
232// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233
234#ifdef NoRepository
235 #include "foamVtkPatchMeshWriter.txx"
236#endif
237
238
239// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241#endif
242
243// ************************************************************************* //
A tuple of integers comprising start, size, total.
Definition OffsetRange.H:82
IntType total() const noexcept
The total size.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
Definition UPstream.H:1669
A class for handling file names.
Definition fileName.H:75
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
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...
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Face) or Point values.
bool writeNeighIDs()
Write processor neighbour ids as CellData. This is no-op in serial.
virtual ~patchMeshWriter()=default
Destructor.
patchMeshWriter(const polyMesh &mesh, const labelUList &patchIDs, const fileName &file, bool parallel=UPstream::parRun())
Construct from components (default format INLINE_BASE64), and open the file for writing.
patchMeshWriter(const polyMesh &mesh, const labelUList &patchIDs, const vtk::outputOptions opts, const fileName &file, bool parallel=UPstream::parRun())
Construct from components and open the file for writing.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
void beginPiece()
Determine sizes and begin piece.
const labelList & patchIDs() const noexcept
The patch IDs.
static word ext(vtk::outputOptions opts)
File extension for given output type.
bool writeProcIDs()
Write processor ids for each line as CellData or for each point as PointData, depending on isPointDat...
void operator=(const patchMeshWriter &)=delete
No copy assignment.
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
patchMeshWriter(const polyMesh &mesh, const labelUList &patchIDs, const vtk::outputOptions opts=vtk::formatType::INLINE_BASE64)
Construct from components (default format INLINE_BASE64).
OffsetRange< label > cellSlab_
Slab addressing for field cells (faces) for the current Piece.
word ext() const
File extension for current format type.
void writePoints()
Write patch points.
patchMeshWriter(const patchMeshWriter &)=delete
No copy construct.
void writePolys()
Write patch faces.
void writePatchIDs()
Write patch ids as CellData.
label nTotalPoints() const noexcept
Total number of field points for the current Piece.
virtual bool writeGeometry()
Write patch topology.
OffsetRange< label > connectivitySlab_
Slab addressing for cell (face) connectivity count, which is just the sum of the face sizes.
const polyMesh & mesh_
Reference to the OpenFOAM mesh (or subset).
label nTotalCells() const noexcept
Total number of field cells (faces) for the current Piece.
OffsetRange< label > pointSlab_
Slab addressing for field points of the current Piece.
virtual bool beginFile(std::string title="")
Write file header (non-collective).
void writePolys_legacy()
Write patch faces, legacy format.
labelList patchIDs_
The selected patch ids.
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
Namespace for handling VTK output. Contains classes and functions for writing VTK file content.
@ POLY_DATA
"PolyData"
@ INLINE_BASE64
XML inline base64, base64Formatter.
Definition foamVtkCore.H:91
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
const direction noexcept
Definition scalarImpl.H:265
UList< label > labelUList
A UList of labels.
Definition UList.H:75