foamVtkPatchWriter.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::patchWriter
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 SourceFiles
43  foamVtkPatchWriter.C
44  foamVtkPatchWriterTemplates.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef foamVtkPatchWriter_H
49 #define foamVtkPatchWriter_H
50 
51 #include "foamVtkFileWriter.H"
52 #include "volFields.H"
53 #include "pointFields.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 namespace vtk
61 {
62 
63 /*---------------------------------------------------------------------------*\
64  Class vtk::patchWriter Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class patchWriter
68 :
69  public vtk::fileWriter
70 {
71  // Private Member Data
72 
73  //- Reference to the OpenFOAM mesh (or subset)
74  const fvMesh& mesh_;
75 
76  //- The selected patch ids
77  labelList patchIDs_;
78 
79  //- Use internal field value instead of patch value
80  bool useNearCellValue_;
81 
82  //- The numer of field points for the current Piece
83  label numberOfPoints_;
84 
85  //- The numer 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  //- Determing 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  patchWriter(const patchWriter&) = delete;
118 
119  //- No copy assignment
120  void operator=(const patchWriter&) = 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 fvMesh& mesh,
132  const labelList& patchIDs,
134  const bool useNearCellValue = false
135  );
136 
137  //- Construct from components (default format INLINE_BASE64),
138  //- and open the file for writing.
139  // The file name is with/without an extension.
141  (
142  const fvMesh& mesh,
143  const labelList& patchIDs,
144  const fileName& file,
145  bool parallel = Pstream::parRun()
146  );
147 
148  //- Construct from components (default format INLINE_BASE64),
149  //- Construct from components and open the file for writing.
150  // The file name is with/without an extension.
152  (
153  const fvMesh& mesh,
154  const labelList& patchIDs,
155  const vtk::outputOptions opts,
156  const fileName& file,
157  bool parallel = Pstream::parRun()
158  );
159 
160  //- Construct from components and open the file for writing.
161  // The file name is with/without an extension.
162  // \param useNearCellValue to use cell instead of patch values
164  (
165  const fvMesh& mesh,
166  const labelList& patchIDs,
167  const vtk::outputOptions opts,
168  const bool useNearCellValue,
169  const fileName& file,
170  bool parallel = Pstream::parRun()
171  );
172 
173 
174  //- Destructor
175  virtual ~patchWriter() = default;
176 
177 
178  // Member Functions
179 
180  //- File extension for current format type.
181  using vtk::fileWriter::ext;
182 
183  //- File extension for given output type
184  inline static word ext(vtk::outputOptions opts)
185  {
187  }
188 
189  //- The patch IDs
190  inline const labelList& patchIDs() const
191  {
192  return patchIDs_;
193  }
194 
195  //- Write file header (non-collective)
196  // \note Expected calling states: (OPENED).
197  virtual bool beginFile(std::string title = "");
198 
199  //- Write patch topology
200  // Also writes the file header if not previously written.
201  // \note Must be called prior to writing CellData or PointData
202  virtual bool writeGeometry();
203 
204  //- Begin CellData output section for specified number of fields.
205  // Must be called prior to writing any cell data fields.
206  // \param nFields is for legacy format only.
207  // When nFields=0, this a no-op for legacy format.
208  // \note Expected calling states: (PIECE | POINT_DATA).
209  //
210  // \return True if the state changed
211  virtual bool beginCellData(label nFields = 0);
212 
213  //- Begin PointData for specified number of fields.
214  // Must be called prior to writing any point data fields.
215  // \param nFields is for legacy format only.
216  // When nFields=0, this a no-op for legacy format.
217  // \note Expected calling states: (PIECE | CELL_DATA).
218  //
219  // \return True if the state changed
220  virtual bool beginPointData(label nFields = 0);
221 
222 
223  //- Write patch ids as CellData.
224  // Must be called within the CELL_DATA state.
225  void writePatchIDs();
226 
227  //- Write processor ids as CellData. This is no-op in serial.
228  // Must be called within the CELL_DATA state.
229  bool writeProcIDs();
230 
231  //- Write processor neighbour ids as CellData. This is no-op in serial.
232  // Must be called within the CELL_DATA state.
233  bool writeNeighIDs();
234 
235 
236  // Write
237 
238  //- Write a uniform field of Cell (Face) or Point values
239  template<class Type>
240  void writeUniform(const word& fieldName, const Type& val);
241 
242  //- Write point field
243  template<class Type, template<class> class PatchField>
244  void write
245  (
247  );
248 
249  //- Write volume field
250  template<class Type, template<class> class PatchField>
251  void write
252  (
254  );
255 
256  //- Write volume field with point interpolation
257  template<class Type>
258  void write
259  (
262  );
263 
264  //- Write volume field with point interpolation
265  template<class Type>
266  void write
267  (
270  );
271 };
272 
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 } // End namespace vtk
277 } // End namespace Foam
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 #ifdef NoRepository
283 #endif
284 
285 
286 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
287 
288 #endif
289 
290 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
volFields.H
Foam::vtk::fileWriter::parallel
bool parallel() const
Parallel output requested?
Definition: foamVtkFileWriterI.H:80
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::vtk::fileWriter
Base class for VTK output writers that handle geometry and fields (eg, vtp, vtu data)....
Definition: foamVtkFileWriter.H:66
Foam::vtk::patchWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val)
Write a uniform field of Cell (Face) or Point values.
Definition: foamVtkPatchWriterTemplates.C:35
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
PrimitivePatchInterpolation.H
Foam::vtk::fileWriter::opts
vtk::outputOptions opts() const
The output options in use.
Definition: foamVtkFileWriterI.H:62
Foam::vtk::patchWriter::ext
static word ext(vtk::outputOptions opts)
File extension for given output type.
Definition: foamVtkPatchWriter.H:183
Foam::vtk::fileTag::POLY_DATA
"PolyData"
foamVtkFileWriter.H
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:414
Foam::vtk::patchWriter::beginPointData
virtual bool beginPointData(label nFields=0)
Begin PointData for specified number of fields.
Definition: foamVtkPatchWriter.C:542
Foam::vtk::patchWriter::writeGeometry
virtual bool writeGeometry()
Write patch topology.
Definition: foamVtkPatchWriter.C:510
Foam::vtk::patchWriter::~patchWriter
virtual ~patchWriter()=default
Destructor.
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::vtk::patchWriter::patchIDs
const labelList & patchIDs() const
The patch IDs.
Definition: foamVtkPatchWriter.H:189
Foam::vtk::patchWriter::writeNeighIDs
bool writeNeighIDs()
Write processor neighbour ids as CellData. This is no-op in serial.
Definition: foamVtkPatchWriter.C:743
field
rDeltaTY field()
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vtk::formatType::INLINE_BASE64
XML inline base64, base64Formatter.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::patchWriter
Write OpenFOAM patches and patch fields in VTP or legacy vtk format.
Definition: foamVtkPatchWriter.H:66
Foam::PrimitivePatchInterpolation
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
Definition: PrimitivePatchInterpolation.H:53
Foam::List< label >
Foam::vtk::patchWriter::beginCellData
virtual bool beginCellData(label nFields=0)
Begin CellData output section for specified number of fields.
Definition: foamVtkPatchWriter.C:536
Foam::vtk::patchWriter::writePatchIDs
void writePatchIDs()
Write patch ids as CellData.
Definition: foamVtkPatchWriter.C:548
Foam::vtk::patchWriter::write
void write(const GeometricField< Type, PatchField, pointMesh > &field)
Write point field.
Definition: foamVtkPatchWriterTemplates.C:62
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::patchWriter::writeProcIDs
bool writeProcIDs()
Write processor ids as CellData. This is no-op in serial.
Definition: foamVtkPatchWriter.C:659
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::vtk::fileWriter::ext
word ext() const
File extension for current format type.
Definition: foamVtkFileWriterI.H:68
foamVtkPatchWriterTemplates.C
pointFields.H
pInterp
autoPtr< volPointInterpolation > pInterp
Definition: convertVolumeFields.H:81
Foam::vtk::patchWriter::beginFile
virtual bool beginFile(std::string title="")
Write file header (non-collective)
Definition: foamVtkPatchWriter.C:460