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 -------------------------------------------------------------------------------
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::internalMeshWriter
28 
29 Description
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 
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 See Also
44  Foam::vtk::internalWriter
45 
46 SourceFiles
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 
61 namespace Foam
62 {
63 namespace vtk
64 {
65 
66 /*---------------------------------------------------------------------------*\
67  Class vtk::internalMeshWriter Declaration
68 \*---------------------------------------------------------------------------*/
69 
71 :
72  public vtk::fileWriter
73 {
74 protected:
75 
76  // Protected Data
77 
78  //- Reference to the OpenFOAM mesh (or subset)
79  const polyMesh& mesh_;
80 
81  //- The volume cells (internalMesh)
82  const vtk::vtuCells& vtuCells_;
83 
84  //- Slab addressing for field points of the current Piece
86 
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 
99 
100 private:
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 
119 public:
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  (
141  const polyMesh& mesh,
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,
153  bool parallel = UPstream::parRun()
154  );
155 
156  //- Construct from components (default format INLINE_BASE64),
157  // The file name is with/without an extension.
159  (
160  const polyMesh& mesh,
161  const vtk::vtuCells& cells,
162  const vtk::outputOptions opts,
163  const fileName& file,
164  bool parallel = UPstream::parRun()
165  );
166 
167 
168  //- Destructor
169  virtual ~internalMeshWriter() = default;
170 
171 
172  // Member Functions
173 
174  //- File extension for current format type.
175  using vtk::fileWriter::ext;
176 
177  //- File extension for given output type
178  inline static word ext(vtk::outputOptions opts)
179  {
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();
192 
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.
218  bool writeProcIDs();
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 // ************************************************************************* //
bool parallel() const noexcept
Parallel output requested?
rDeltaTY field()
virtual ~internalMeshWriter()=default
Destructor.
A class for handling file names.
Definition: fileName.H:72
void writePointIDs()
Write point ids as PointData.
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data). These output formats are structured as DECLARED, FIELD_DATA, PIECE followed by any CELL_DATA or POINT_DATA.
static int debug
Debug information.
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1681
const polyMesh & mesh_
Reference to the OpenFOAM mesh (or subset)
vtk::outputOptions opts() const noexcept
The output options in use.
label nTotalPoints() const noexcept
Total number of field points for the current Piece.
IntType total() const noexcept
The total size.
Definition: OffsetRange.H:218
bool writeProcIDs()
Write processor ids as CellData. This is no-op in serial.
OffsetRange< label > cellSlab_
Slab addressing for field cells of the current Piece.
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
virtual bool writeGeometry()
Write mesh topology.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
void writePointData(const word &fieldName, const UList< Type > &field)
Write primitive field of PointData.
dynamicFvMesh & mesh
const cellShapeList & cells
word ext() const
File extension for current format type.
A class for handling words, derived from Foam::string.
Definition: word.H:63
label nTotalCells() const noexcept
Total number of field cells for the current Piece.
const direction noexcept
Definition: scalarImpl.H:265
const vtk::vtuCells & vtuCells_
The volume cells (internalMesh)
Write an OpenFOAM volume (internal) geometry and internal fields as a vtu file or a legacy vtk file...
OffsetRange< label > pointSlab_
Slab addressing for field points of the current Piece.
XML inline base64, base64Formatter.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
void writeCellData(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData.
const word & ext(vtk::fileTag contentType) const
The file extension (legacy or xml) for the given content-type.
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell or Point values.
A deep-copy description of an OpenFOAM volume mesh in data structures suitable for VTK UnstructuredGr...
Definition: foamVtuCells.H:73
void operator=(const internalMeshWriter &)=delete
No copy assignment.
Namespace for OpenFOAM.
internalMeshWriter(const internalMeshWriter &)=delete
File extension for given output type.
void writeCellIDs()
Write cell ids as CellData.