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-2021 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.C
48 foamVtkInternalMeshWriterTemplates.C
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{
65
66/*---------------------------------------------------------------------------*\
67 Class vtk::internalMeshWriter Declaration
68\*---------------------------------------------------------------------------*/
71:
72 public vtk::fileWriter
73{
74protected:
75
76 // Protected Data
77
78 //- The number of field points for the current Piece
79 label numberOfPoints_;
80
81 //- The number of field cells for the current Piece
82 label numberOfCells_;
83
84 //- Reference to the OpenFOAM mesh (or subset)
85 const polyMesh& mesh_;
86
87 //- The volume cells (internalMesh)
88 const vtuCells& vtuCells_;
89
90
91private:
92
93 // Private Member Functions
94
95 //- Begin piece
96 void beginPiece();
97
98 //- Write mesh points
99 void writePoints();
100
101 //- Write cells (connectivity and type), legacy format
102 // \param pointOffset processor-local point offset
103 void writeCellsLegacy(const label pointOffset);
104
105 //- Write cells connectivity
106 // \param pointOffset processor-local point offset
107 void writeCellsConnectivity(const label pointOffset);
108
109 //- Write cells face streams
110 // \param pointOffset processor-local point offset
111 void writeCellsFaces(const label pointOffset);
112
113
114 //- No copy construct
115 internalMeshWriter(const internalMeshWriter&) = delete;
116
117 //- No copy assignment
118 void operator=(const internalMeshWriter&) = delete;
119
120
121public:
122
123 //- Debug information
124 static int debug;
125
126//- File extension for given output type
127// constexpr static vtk::fileTag content = vtk::fileTag::UNSTRUCTURED_GRID;
128
129
130 // Constructors
131
132 //- Construct from components (default format INLINE_BASE64),
134 (
135 const polyMesh& mesh,
136 const vtk::vtuCells& cells,
138 );
139
140 //- Construct from components (default format INLINE_BASE64),
141 // The file name is with/without an extension.
143 (
144 const polyMesh& mesh,
145 const vtk::vtuCells& cells,
146 const fileName& file,
148 );
149
150 //- Construct from components (default format INLINE_BASE64),
151 // The file name is with/without an extension.
153 (
154 const polyMesh& mesh,
155 const vtk::vtuCells& cells,
157 const fileName& file,
159 );
160
161
162 //- Destructor
163 virtual ~internalMeshWriter() = default;
164
165
166 // Member Functions
167
168 //- File extension for current format type.
170
171 //- File extension for given output type
172 inline static word ext(vtk::outputOptions opts)
173 {
175 }
176
177
178 //- Write file header (non-collective)
179 // \note Expected calling states: (OPENED)
180 virtual bool beginFile(std::string title = "");
181
182 //- Write mesh 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 cell ids as CellData.
207 // Must be called within the CELL_DATA state.
208 void writeCellIDs();
209
210 //- Write processor ids as CellData. This is no-op in serial.
211 // Must be called within the CELL_DATA state.
212 bool writeProcIDs();
213
214 //- Write point ids as PointData.
215 // Must be called within the POINT_DATA state.
216 void writePointIDs();
217
218
219 // Write Fields
220
221 //- Write a uniform field of Cell or Point values
222 template<class Type>
223 void writeUniform(const word& fieldName, const Type& val);
224
225 //- Write primitive field of CellData
226 template<class Type>
227 void writeCellData(const word& fieldName, const UList<Type>& field);
228
229 //- Write primitive field of PointData
230 template<class Type>
231 void writePointData(const word& fieldName, const UList<Type>& field);
232};
233
234
235// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236
237} // End namespace vtk
238} // End namespace Foam
239
240// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241
242#ifdef NoRepository
244#endif
245
246// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247
248#endif
249
250// ************************************************************************* //
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:94
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.
Write an OpenFOAM volume (internal) geometry and internal fields as a vtu file or a legacy vtk file.
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 writePointData(const word &fieldName, const UList< Type > &field)
Write primitive field of PointData.
label numberOfPoints_
The number of field points for the current Piece.
static word ext(vtk::outputOptions opts)
File extension for given output type.
label numberOfCells_
The number of field cells for the current Piece.
bool writeProcIDs()
Write processor ids as CellData. This is no-op in serial.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
void writeCellData(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData.
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
static int debug
Debug information.
virtual ~internalMeshWriter()=default
Destructor.
virtual bool writeGeometry()
Write mesh topology.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
const polyMesh & mesh_
Reference to the OpenFOAM mesh (or subset)
const vtuCells & vtuCells_
The volume cells (internalMesh)
void writeCellIDs()
Write cell ids as CellData.
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.
A deep-copy description of an OpenFOAM volume mesh in data structures suitable for VTK UnstructuredGr...
Definition: foamVtuCells.H:73
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
dynamicFvMesh & mesh
const cellShapeList & cells
@ UNSTRUCTURED_GRID
"UnstructuredGrid"
@ INLINE_BASE64
XML inline base64, base64Formatter.
Namespace for OpenFOAM.