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-2019 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::patchMeshWriter
28 
29 Description
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 
35 Note
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 
42 See Also
43  Foam::vtk::patchWriter
44 
45 SourceFiles
46  foamVtkPatchMeshWriter.C
47  foamVtkPatchMeshWriterTemplates.C
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #ifndef foamVtkPatchMeshWriter_H
52 #define foamVtkPatchMeshWriter_H
53 
54 #include "foamVtkFileWriter.H"
55 #include "polyMesh.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 namespace vtk
62 {
63 
64 /*---------------------------------------------------------------------------*\
65  Class vtk::patchMeshWriter Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 class patchMeshWriter
69 :
70  public vtk::fileWriter
71 {
72 protected:
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  //- The number of field points for the current Piece
83  label numberOfPoints_;
84 
85  //- The number of field cells (faces) for the current Piece
86  label numberOfCells_;
87 
88  //- Local number of points
89  label nLocalPoints_;
90 
91  //- Local number of faces
92  label nLocalFaces_;
93 
94  //- Local face vertices (connectivity) count. Sum of face sizes.
95  label nLocalVerts_;
96 
97 
98  // Private Member Functions
99 
100  //- Determine sizes (nLocalPoints_, nLocalFaces_, nLocalVerts_),
101  //- and begin piece.
102  void beginPiece();
103 
104  //- Write patch points
105  void writePoints();
106 
107  //- Write patch faces, legacy format
108  // \param pointOffset processor-local point offset
109  void writePolysLegacy(const label pointOffset);
110 
111  //- Write patch faces
112  // \param pointOffset processor-local point offset
113  void writePolys(const label pointOffset);
114 
115 
116  //- No copy construct
117  patchMeshWriter(const patchMeshWriter&) = delete;
118 
119  //- No copy assignment
120  void operator=(const patchMeshWriter&) = delete;
121 
122 
123 public:
124 
125  // Constructors
126 
127  //- Construct from components (default format INLINE_BASE64)
128  // \param useNearCellValue to use cell instead of patch values
130  (
131  const polyMesh& mesh,
132  const labelList& patchIDs,
134  );
135 
136  //- Construct from components (default format INLINE_BASE64),
137  //- and open the file for writing.
138  // The file name is with/without an extension.
140  (
141  const polyMesh& mesh,
142  const labelList& patchIDs,
143  const fileName& file,
144  bool parallel = Pstream::parRun()
145  );
146 
147  //- Construct from components (default format INLINE_BASE64),
148  //- Construct from components and open the file for writing.
149  // The file name is with/without an extension.
151  (
152  const polyMesh& mesh,
153  const labelList& patchIDs,
154  const vtk::outputOptions opts,
155  const fileName& file,
156  bool parallel = Pstream::parRun()
157  );
158 
159 
160  //- Destructor
161  virtual ~patchMeshWriter() = default;
162 
163 
164  // Member Functions
165 
166  //- File extension for current format type.
167  using vtk::fileWriter::ext;
168 
169  //- File extension for given output type
170  inline static word ext(vtk::outputOptions opts)
171  {
173  }
174 
175  //- The patch IDs
176  inline const labelList& patchIDs() const
177  {
178  return patchIDs_;
179  }
180 
181  //- Write file header (non-collective)
182  // \note Expected calling states: (OPENED).
183  virtual bool beginFile(std::string title = "");
184 
185  //- Write patch topology
186  // Also writes the file header if not previously written.
187  // \note Must be called prior to writing CellData or PointData
188  virtual bool writeGeometry();
189 
190  //- Begin CellData output section for specified number of fields.
191  // Must be called prior to writing any cell data fields.
192  // \param nFields is for legacy format only.
193  // When nFields=0, this a no-op for legacy format.
194  // \note Expected calling states: (PIECE | POINT_DATA).
195  //
196  // \return True if the state changed
197  virtual bool beginCellData(label nFields = 0);
198 
199  //- Begin PointData for specified number of fields.
200  // Must be called prior to writing any point data fields.
201  // \param nFields is for legacy format only.
202  // When nFields=0, this a no-op for legacy format.
203  // \note Expected calling states: (PIECE | CELL_DATA).
204  //
205  // \return True if the state changed
206  virtual bool beginPointData(label nFields = 0);
207 
208 
209  //- Write patch ids as CellData.
210  // Must be called within the CELL_DATA state.
211  void writePatchIDs();
212 
213  //- Write processor ids as CellData. This is no-op in serial.
214  // Must be called within the CELL_DATA state.
215  bool writeProcIDs();
216 
217  //- Write processor neighbour ids as CellData. This is no-op in serial.
218  // Must be called within the CELL_DATA state.
219  bool writeNeighIDs();
220 
221 
222  // Write
223 
224  //- Write a uniform field of Cell (Face) or Point values
225  template<class Type>
226  void writeUniform(const word& fieldName, const Type& val);
227 };
228 
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 } // End namespace vtk
233 } // End namespace Foam
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 #ifdef NoRepository
239 #endif
240 
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 #endif
245 
246 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
Foam::vtk::patchMeshWriter::beginPointData
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
Definition: foamVtkPatchMeshWriter.C:521
Foam::vtk::fileWriter::parallel
bool parallel() const
Parallel output requested?
Definition: foamVtkFileWriterI.H:80
Foam::vtk::patchMeshWriter::writePolysLegacy
void writePolysLegacy(const label pointOffset)
Write patch faces, legacy format.
Definition: foamVtkPatchMeshWriter.C:173
Foam::vtk::fileWriter
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
Definition: foamVtkFileWriter.H:66
Foam::vtk::patchMeshWriter
Write OpenFOAM patches and patch fields in VTP or legacy vtk format.
Definition: foamVtkPatchMeshWriter.H:67
Foam::vtk::patchMeshWriter::ext
static word ext(vtk::outputOptions opts)
File extension for given output type.
Definition: foamVtkPatchMeshWriter.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
foamVtkPatchMeshWriterTemplates.C
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::vtk::patchMeshWriter::writeProcIDs
bool writeProcIDs()
Write processor ids as CellData. This is no-op in serial.
Definition: foamVtkPatchMeshWriter.C:633
Foam::vtk::fileWriter::opts
vtk::outputOptions opts() const
The output options in use.
Definition: foamVtkFileWriterI.H:62
Foam::vtk::fileTag::POLY_DATA
"PolyData"
foamVtkFileWriter.H
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
Foam::vtk::patchMeshWriter::patchMeshWriter
patchMeshWriter(const patchMeshWriter &)=delete
No copy construct.
polyMesh.H
Foam::vtk::patchMeshWriter::nLocalFaces_
label nLocalFaces_
Local number of faces.
Definition: foamVtkPatchMeshWriter.H:91
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::vtk::patchMeshWriter::writeNeighIDs
bool writeNeighIDs()
Write processor neighbour ids as CellData. This is no-op in serial.
Definition: foamVtkPatchMeshWriter.C:717
Foam::vtk::patchMeshWriter::mesh_
const polyMesh & mesh_
Reference to the OpenFOAM mesh (or subset)
Definition: foamVtkPatchMeshWriter.H:76
Foam::vtk::patchMeshWriter::nLocalVerts_
label nLocalVerts_
Local face vertices (connectivity) count. Sum of face sizes.
Definition: foamVtkPatchMeshWriter.H:94
Foam::vtk::patchMeshWriter::operator=
void operator=(const patchMeshWriter &)=delete
No copy assignment.
Foam::vtk::patchMeshWriter::beginFile
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Definition: foamVtkPatchMeshWriter.C:439
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::patchMeshWriter::beginCellData
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Definition: foamVtkPatchMeshWriter.C:515
Foam::vtk::patchMeshWriter::~patchMeshWriter
virtual ~patchMeshWriter()=default
Destructor.
Foam::vtk::patchMeshWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Face) or Point values.
Definition: foamVtkPatchMeshWriterTemplates.C:35
Foam::vtk::patchMeshWriter::nLocalPoints_
label nLocalPoints_
Local number of points.
Definition: foamVtkPatchMeshWriter.H:88
Foam::vtk::patchMeshWriter::patchIDs
const labelList & patchIDs() const
The patch IDs.
Definition: foamVtkPatchMeshWriter.H:175
Foam::vtk::patchMeshWriter::numberOfPoints_
label numberOfPoints_
The number of field points for the current Piece.
Definition: foamVtkPatchMeshWriter.H:82
Foam::List< label >
Foam::vtk::patchMeshWriter::writeGeometry
virtual bool writeGeometry()
Write patch topology.
Definition: foamVtkPatchMeshWriter.C:489
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::patchMeshWriter::patchIDs_
labelList patchIDs_
The selected patch ids.
Definition: foamVtkPatchMeshWriter.H:79
Foam::vtk::patchMeshWriter::numberOfCells_
label numberOfCells_
The number of field cells (faces) for the current Piece.
Definition: foamVtkPatchMeshWriter.H:85
Foam::vtk::patchMeshWriter::writePoints
void writePoints()
Write patch points.
Definition: foamVtkPatchMeshWriter.C:83
Foam::vtk::patchMeshWriter::writePatchIDs
void writePatchIDs()
Write patch ids as CellData.
Definition: foamVtkPatchMeshWriter.C:527
Foam::vtk::patchMeshWriter::writePolys
void writePolys(const label pointOffset)
Write patch faces.
Definition: foamVtkPatchMeshWriter.C:244
Foam::vtk::fileWriter::ext
word ext() const
File extension for current format type.
Definition: foamVtkFileWriterI.H:68
Foam::vtk::patchMeshWriter::beginPiece
void beginPiece()
Definition: foamVtkPatchMeshWriter.C:36