Loading...
Searching...
No Matches
foamVtkInternalMeshWriter.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::internalMeshWriter
28
29Description
30 Write an OpenFOAM volume (internal) geometry and internal fields
31 as a vtu 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
36Note
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
43See Also
44 Foam::vtk::internalWriter
45
46SourceFiles
47 foamVtkInternalMeshWriter.cxx
48 foamVtkInternalMeshWriter.txx
49
50\*---------------------------------------------------------------------------*/
51
52#ifndef Foam_vtk_InternalMeshWriter_H
53#define Foam_vtk_InternalMeshWriter_H
54
55#include "foamVtkFileWriter.H"
56#include "foamVtuCells.H"
57#include "polyMesh.H"
58
59// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60
61namespace Foam
62{
63namespace vtk
64{
66/*---------------------------------------------------------------------------*\
67 Class vtk::internalMeshWriter Declaration
68\*---------------------------------------------------------------------------*/
69
71:
72 public vtk::fileWriter
73{
74protected:
75
76 // Protected Data
77
78 //- Reference to the OpenFOAM mesh (or subset)
79 const polyMesh& mesh_;
80
81 //- The volume cells (internalMesh)
83
84 //- Slab addressing for field points of the current Piece
87 //- Slab addressing for field cells of the current Piece
89
90
91 // Protected Member Functions
92
93 //- Total number of field points for the current Piece
94 label nTotalPoints() const noexcept { return pointSlab_.total(); }
95
96 //- Total number of field cells for the current Piece
97 label nTotalCells() const noexcept { return cellSlab_.total(); }
98
100private:
101
102 // Private Member Functions
103
104 //- Begin piece
105 void beginPiece();
106
107 //- Write mesh points
108 void writePoints();
109
110 //- Write cells (connectivity and type), legacy format
111 void writeCells_legacy();
112
113 //- Write cells connectivity
114 void writeCellsConnectivity();
115
116 //- Write cells face streams
117 void writeCellsFaces();
118
119public:
120
121 //- Debug information
122 static int debug;
123
124//- File extension for given output type
125// constexpr static vtk::fileTag content = vtk::fileTag::UNSTRUCTURED_GRID;
126
127 // Generated Methods
128
129 //- No copy construct
130 internalMeshWriter(const internalMeshWriter&) = delete;
131
132 //- No copy assignment
133 void operator=(const internalMeshWriter&) = delete;
134
135
136 // Constructors
137
138 //- Construct from components (default format INLINE_BASE64),
140 (
142 const vtk::vtuCells& cells,
144 );
145
146 //- Construct from components (default format INLINE_BASE64),
147 // The file name is with/without an extension.
149 (
150 const polyMesh& mesh,
151 const vtk::vtuCells& cells,
152 const fileName& file,
154 );
155
156 //- Construct from components (default format INLINE_BASE64),
157 // The file name is with/without an extension.
160 const polyMesh& mesh,
161 const vtk::vtuCells& cells,
163 const fileName& file,
165 );
166
168 //- Destructor
169 virtual ~internalMeshWriter() = default;
170
171
172 // Member Functions
173
174 //- File extension for current format type.
176
177 //- File extension for given output type
178 inline static word ext(vtk::outputOptions opts)
181 }
182
183
184 //- Write file header (non-collective)
185 // \note Expected calling states: (OPENED)
186 virtual bool beginFile(std::string title = "");
187
188 //- Write mesh topology.
189 // Also writes the file header if not previously written.
190 // \note Must be called prior to writing CellData or PointData
191 virtual bool writeGeometry();
193 //- Begin CellData output section for specified number of fields.
194 // Must be called prior to writing any cell data fields.
195 // \param nFields is for legacy format only.
196 // When nFields=0, this a no-op for legacy format.
197 // \note Expected calling states: (PIECE | POINT_DATA).
198 //
199 // \return True if the state changed
200 virtual bool beginCellData(label nFields = 0);
201
202 //- Begin PointData for specified number of fields.
203 // Must be called prior to writing any point data fields.
204 // \param nFields is for legacy format only.
205 // When nFields=0, this a no-op for legacy format.
206 // \note Expected calling states: (PIECE | CELL_DATA).
207 //
208 // \return True if the state changed
209 virtual bool beginPointData(label nFields = 0);
210
211
212 //- Write cell ids as CellData.
213 // Must be called within the CELL_DATA state.
214 void writeCellIDs();
215
216 //- Write processor ids as CellData. This is no-op in serial.
217 // Must be called within the CELL_DATA state.
219
220 //- Write point ids as PointData.
221 // Must be called within the POINT_DATA state.
222 void writePointIDs();
223
224
225 // Write Fields
226
227 //- Write a uniform field of Cell or Point values
228 template<class Type>
229 void writeUniform(const word& fieldName, const Type& val);
230
231 //- Write primitive field of CellData
232 template<class Type>
233 void writeCellData(const word& fieldName, const UList<Type>& field);
234
235 //- Write primitive field of PointData
236 template<class Type>
237 void writePointData(const word& fieldName, const UList<Type>& field);
238};
239
240
241// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242
243} // End namespace vtk
244} // End namespace Foam
245
246// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247
248#ifdef NoRepository
249 #include "foamVtkInternalMeshWriter.txx"
250#endif
251
252// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253
254#endif
255
256// ************************************************************************* //
A tuple of integers comprising start, size, total.
Definition OffsetRange.H:82
IntType total() const noexcept
The total size.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
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.
const vtk::vtuCells & vtuCells_
The volume cells (internalMesh).
internalMeshWriter(const polyMesh &mesh, const vtk::vtuCells &cells, const vtk::outputOptions opts, const fileName &file, bool parallel=UPstream::parRun())
Construct from components (default format INLINE_BASE64),.
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell or Point values.
void writePointIDs()
Write point ids as PointData.
void operator=(const internalMeshWriter &)=delete
No copy assignment.
void writePointData(const word &fieldName, const UList< Type > &field)
Write primitive field of PointData.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
static word ext(vtk::outputOptions opts)
File extension for given output type.
bool writeProcIDs()
Write processor ids as CellData. This is no-op in serial.
internalMeshWriter(const internalMeshWriter &)=delete
File extension for given output type.
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
OffsetRange< label > cellSlab_
Slab addressing for field cells of the current Piece.
word ext() const
File extension for current format type.
internalMeshWriter(const polyMesh &mesh, const vtk::vtuCells &cells, const vtk::outputOptions opts=vtk::formatType::INLINE_BASE64)
Construct from components (default format INLINE_BASE64),.
void writeCellData(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData.
static int debug
Debug information.
virtual ~internalMeshWriter()=default
Destructor.
label nTotalPoints() const noexcept
Total number of field points for the current Piece.
virtual bool writeGeometry()
Write mesh topology.
const polyMesh & mesh_
Reference to the OpenFOAM mesh (or subset).
label nTotalCells() const noexcept
Total number of field cells for the current Piece.
internalMeshWriter(const polyMesh &mesh, const vtk::vtuCells &cells, const fileName &file, bool parallel=UPstream::parRun())
Construct from components (default format INLINE_BASE64),.
OffsetRange< label > pointSlab_
Slab addressing for field points of the current Piece.
void writeCellIDs()
Write cell ids as CellData.
virtual bool beginFile(std::string title="")
Write file header (non-collective).
Encapsulated combinations of output format options. This is primarily useful when defining the output...
A deep-copy description of an OpenFOAM volume mesh in data structures suitable for VTK UnstructuredGr...
A class for handling words, derived from Foam::string.
Definition word.H:66
rDeltaTY field()
dynamicFvMesh & mesh
const cellShapeList & cells
Namespace for handling VTK output. Contains classes and functions for writing VTK file content.
@ UNSTRUCTURED_GRID
"UnstructuredGrid"
@ INLINE_BASE64
XML inline base64, base64Formatter.
Definition foamVtkCore.H:91
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265