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 -------------------------------------------------------------------------------
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.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 
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  //- 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 
91 private:
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 
121 public:
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,
147  bool parallel = Pstream::parRun()
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,
156  const vtk::outputOptions opts,
157  const fileName& file,
158  bool parallel = Pstream::parRun()
159  );
160 
161 
162  //- Destructor
163  virtual ~internalMeshWriter() = default;
164 
165 
166  // Member Functions
167 
168  //- File extension for current format type.
169  using vtk::fileWriter::ext;
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 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::vtk::fileWriter
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
Definition: foamVtkFileWriter.H:66
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::vtk::fileWriter::opts
vtk::outputOptions opts() const
The output options in use.
Definition: foamVtkFileWriterI.H:62
Foam::vtk::internalMeshWriter::writeCellIDs
void writeCellIDs()
Write cell ids as CellData.
Definition: foamVtkInternalMeshWriter.C:608
Foam::vtk::internalMeshWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell or Point values.
Definition: foamVtkInternalMeshWriterTemplates.C:35
foamVtkFileWriter.H
Foam::vtk::internalMeshWriter::writePointData
void writePointData(const word &fieldName, const UList< Type > &field)
Write primitive field of PointData.
Definition: foamVtkInternalMeshWriterTemplates.C:107
polyMesh.H
foamVtuCells.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::vtk::internalMeshWriter::writeProcIDs
bool writeProcIDs()
Write processor ids as CellData. This is no-op in serial.
Definition: foamVtkInternalMeshWriter.C:642
Foam::vtk::fileWriter::parallel
bool parallel() const noexcept
Parallel output requested?
Definition: foamVtkFileWriterI.H:80
Foam::vtk::internalMeshWriter::beginPointData
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
Definition: foamVtkInternalMeshWriter.C:602
foamVtkInternalMeshWriterTemplates.C
Foam::vtk::internalMeshWriter::vtuCells_
const vtuCells & vtuCells_
The volume cells (internalMesh)
Definition: foamVtkInternalMeshWriter.H:87
field
rDeltaTY field()
Foam::vtk::internalMeshWriter::writeCellData
void writeCellData(const word &fieldName, const UList< Type > &field)
Write primitive field of CellData.
Definition: foamVtkInternalMeshWriterTemplates.C:72
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vtk::formatType::INLINE_BASE64
XML inline base64, base64Formatter.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::fileTag::UNSTRUCTURED_GRID
"UnstructuredGrid"
Foam::vtk::internalMeshWriter::debug
static int debug
Debug information.
Definition: foamVtkInternalMeshWriter.H:123
Foam::vtk::internalMeshWriter::beginFile
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Definition: foamVtkInternalMeshWriter.C:521
Foam::vtk::internalMeshWriter::ext
static word ext(vtk::outputOptions opts)
File extension for given output type.
Definition: foamVtkInternalMeshWriter.H:171
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::vtk::internalMeshWriter::~internalMeshWriter
virtual ~internalMeshWriter()=default
Destructor.
Foam::UList< Type >
Foam::vtk::vtuCells
A deep-copy description of an OpenFOAM volume mesh in data structures suitable for VTK UnstructuredGr...
Definition: foamVtuCells.H:70
Foam::vtk::internalMeshWriter::beginCellData
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Definition: foamVtkInternalMeshWriter.C:596
Foam::vtk::internalMeshWriter::numberOfPoints_
label numberOfPoints_
The number of field points for the current Piece.
Definition: foamVtkInternalMeshWriter.H:78
Foam::vtk::outputOptions::ext
word ext(vtk::fileTag contentType) const
The file extension (legacy or xml) for the given content-type.
Definition: foamVtkOutputOptionsI.H:77
Foam::vtk::internalMeshWriter::numberOfCells_
label numberOfCells_
The number of field cells for the current Piece.
Definition: foamVtkInternalMeshWriter.H:81
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::vtk::internalMeshWriter::writePointIDs
void writePointIDs()
Write point ids as PointData.
Definition: foamVtkInternalMeshWriter.C:654
Foam::vtk::internalMeshWriter
Write an OpenFOAM volume (internal) geometry and internal fields as a vtu file or a legacy vtk file.
Definition: foamVtkInternalMeshWriter.H:69
Foam::vtk::fileWriter::ext
word ext() const
File extension for current format type.
Definition: foamVtkFileWriterI.H:68
Foam::vtk::internalMeshWriter::writeGeometry
virtual bool writeGeometry()
Write mesh topology.
Definition: foamVtkInternalMeshWriter.C:559
Foam::vtk::internalMeshWriter::mesh_
const polyMesh & mesh_
Reference to the OpenFOAM mesh (or subset)
Definition: foamVtkInternalMeshWriter.H:84