foamVtuSizing.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-2018 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::vtuSizing
28 
29 Description
30  Sizing descriptions and routines for transcribing an OpenFOAM volume mesh
31  into a VTK unstructured grid, with possible decomposition of polyhedral
32  cells into primitive cell types.
33 
34  This class is intended to populate externally allocated arrays with content
35  that is compatible with what VTK expects. This approach allows an improved
36  separation of the OpenFOAM mesh description and the storage, and allows
37  support of alternative storage containers (eg, std::vector, vtkDataArray).
38  The ideal goal would be a zero-copy mechanism, but this does not work for
39  several reasons:
40  \par
41  - OpenFOAM and VTK have different point ordering for prism
42  - polyhedral decomposition
43  - face-stream are required for VTK
44  - VTK internal storage includes list size as part of the data
45  - VTK includes storage may be a different base size (eg, long long)
46  compared to the OpenFOAM label.
47 
48  \par Data Entries (slots)
49 
50  These are the storage entries normally associate with each output-type:
51  \table
52  legacy output
53  \c types | vtk cell type (1-255)
54  \c cells | nLabels and unique vertex labels used by the cell, or
55  | [nLabels nFaces, nFace0Pts, id1, id2, ..., nFace1Pts, id1, id2, ...]
56  \endtable
57 
58  \table
59  xml output
60  \c types | vtk cell type (1-255)
61  \c connectivity | unique vertex labels used by the cell
62  \c offsets | end offset for each of \c connectivity
63  \c faces | face stream for polyhedral cells
64  | [nFaces, nFace0Pts, id1, id2, ..., nFace1Pts, id1, id2, ...]
65  \c faceoffsets | end offset for each of \c faces, with -1 for primitive cells
66  \endtable
67 
68  \table
69  internal storage
70  \c types | vtk cell type (1-255)
71  \c connectivity | nLabels and unique vertex labels used by the cell
72  \c location | begin location for each of \c connectivity
73  \c faces | face stream for polyhedral cells
74  | [nFaces, nFace0Pts, id1, id2, ..., nFace1Pts, id1, id2, ...]
75  \c facelocation | begin location for each of \c faces, with -1 for primitive cells
76  \endtable
77 
78  The VTK storage concept for "connectivity" and "faces" somewhat resemble
79  a CompactListList.
80 
81 Note
82  It is possible to specify a global point offset (via the globalIndex)
83  so that the cell point labels will use global numbering.
84  There is no support for point renumbering with merged mesh points,
85  since it likely more efficient to use VTK point-blanking to mark duplicate
86  points instead of merging points ourselves.
87 
88 SourceFiles
89  foamVtuSizing.C
90  foamVtuSizingI.H
91 
92 \*---------------------------------------------------------------------------*/
93 
94 #ifndef foamVtuSizing_H
95 #define foamVtuSizing_H
96 
97 #include "label.H"
98 #include "labelList.H"
99 #include "foamVtkMeshMaps.H"
100 
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
102 
103 namespace Foam
104 {
105 
106 // Forward declarations
107 class polyMesh;
108 
109 namespace vtk
110 {
111 
112 /*---------------------------------------------------------------------------*\
113  Class Foam::vtk::vtuSizing Declaration
114 \*---------------------------------------------------------------------------*/
115 
116 class vtuSizing
117 {
118 public:
119 
120  // Public data
121 
122  //- Types of content that the storage may represent
123  enum contentType
124  {
125  LEGACY,
126  XML,
127  INTERNAL
128  };
129 
130  //- The possible storage 'slots' that can be used
131  enum slotType
132  {
133  CELLS,
134  CELLS_OFFSETS,
135  FACES,
137  };
138 
139 
140 private:
141 
142  // Private Member Data
143 
144  //- Polyhedral decomposition requested
145  bool decompose_;
146 
147  //- Number of cells in the mesh
148  label nCells_;
149 
150  //- Number of points in the mesh
151  label nPoints_;
152 
153  //- Number of vertex labels to represent the mesh
154  label nVertLabels_;
155 
156  // Polyhedrals
157 
158  //- Number of polyhedral face labels for the mesh
159  label nFaceLabels_;
160 
161  //- Number of polyhedral cells (informational)
162  label nCellsPoly_;
163 
164  //- Number of vertex labels used by polyhedrals
165  label nVertPoly_;
166 
167  // Decomposed polyhedrals
168 
169  //- Number of additional (decomposed) cells for the mesh
170  label nAddCells_;
171 
172  //- Number of additional (decomposed) points for the mesh
173  label nAddPoints_;
174 
175  //- Number of additional (decomposed) vertices for the mesh
176  label nAddVerts_;
177 
178 
179  // Private Member Functions
180 
181  //- set-size for cellMap and additionalIds
182  void presizeMaps(foamVtkMeshMaps& maps) const;
183 
184  //- Populate lists. For (legacy | xml | internal) VTK representations
185  template<class LabelType, class LabelType2>
186  static void populateArrays
187  (
188  const polyMesh& mesh,
189  const vtk::vtuSizing& sizing,
191  UList<LabelType>& vertLabels,
192  UList<LabelType>& vertOffset,
193  UList<LabelType>& faceLabels,
194  UList<LabelType>& faceOffset,
195  const enum contentType output,
196  UList<LabelType2>& cellMap,
197  UList<LabelType2>& addPointsIds
198  );
199 
200 
201 public:
202 
203  // Constructors
204 
205  //- Construct null.
206  vtuSizing();
207 
208  //- Construct sizing by analyzing the mesh.
209  // No polyhedral decomposition.
210  explicit vtuSizing(const polyMesh& mesh);
211 
212  //- Construct sizing by analyzing the mesh.
213  // Optionally with polyhedral decomposition.
214  vtuSizing(const polyMesh& mesh, const bool decompose);
215 
216 
217  //- Destructor
218  ~vtuSizing() = default;
219 
220 
221  // Member Functions
222 
223  // Edit
224 
225  //- Reset sizing by analyzing the mesh.
226  // Optionally with polyhedral decomposition.
227  void reset(const polyMesh& mesh, const bool decompose=false);
228 
229  //- Reset all sizes to zero.
230  void clear();
231 
232 
233  // Access
234 
235  //- Query the decompose flag (normally off)
236  inline bool decompose() const;
237 
238  //- Number of cells for the mesh
239  inline label nCells() const;
240 
241  //- Number of points for the mesh
242  inline label nPoints() const;
243 
244  //- Number of vertex labels for the mesh
245  inline label nVertLabels() const;
246 
247  //- Number of polyhedral face labels for the mesh
248  inline label nFaceLabels() const;
249 
250  //- Number of polyhedral cells for the mesh
251  inline label nCellsPoly() const;
252 
253  //- Number of vertex labels for polyhedral cells of the mesh
254  inline label nVertPoly() const;
255 
256  //- Number of additional (decomposed) cells for the mesh
257  inline label nAddCells() const;
258 
259  //- Number of additional (decomposed) points for the mesh
260  inline label nAddPoints() const;
261 
262  //- Number of additional (decomposed) vertices for the mesh
263  inline label nAddVerts() const;
264 
265 
266  //- Number of field cells = nCells + nAddCells
267  inline label nFieldCells() const;
268 
269  //- Number of field points = nPoints + nAddPoints
270  inline label nFieldPoints() const;
271 
272 
273  // Derived sizes
274 
275  //- Return the required size for the storage slot
276  label sizeOf
277  (
278  const enum contentType output,
279  const enum slotType slot
280  ) const;
281 
282 
283  //- The calculated size for legacy storage
284  inline label sizeLegacy() const;
285 
286  //- The calculated size for legacy storage of the specified slot
287  inline label sizeLegacy(const enum slotType slot) const;
288 
289  //- The calculated size for xml storage of the specified slot
290  inline label sizeXml(const enum slotType slot) const;
291 
292  //- The calculated size for vtk-internal storage of the specified slot
293  inline label sizeInternal(const enum slotType slot) const;
294 
295 
296  // Routines for populating the output lists
297 
298  //- Populate lists for Legacy output
299  void populateLegacy
300  (
301  const polyMesh& mesh,
303  labelUList& connectivity,
304  foamVtkMeshMaps& maps
305  ) const;
306 
307  //- Populate lists for XML output
308  void populateXml
309  (
310  const polyMesh& mesh,
312  labelUList& connectivity,
313  labelUList& offsets,
314  labelUList& faces,
315  labelUList& facesOffsets,
316  foamVtkMeshMaps& maps
317  ) const;
318 
319  //- Populate lists for Internal VTK format
320  void populateInternal
321  (
322  const polyMesh& mesh,
324  UList<int>& connectivity,
325  UList<int>& offsets,
326  UList<int>& faces,
327  UList<int>& facesOffsets,
328  foamVtkMeshMaps& maps
329  ) const;
330 
331  //- Populate lists for Internal VTK format
332  void populateInternal
333  (
334  const polyMesh& mesh,
336  UList<long>& connectivity,
337  UList<long>& offsets,
338  UList<long>& faces,
339  UList<long>& facesOffsets,
340  foamVtkMeshMaps& maps
341  ) const;
342 
343  //- Populate lists for Internal VTK format
344  void populateInternal
345  (
346  const polyMesh& mesh,
348  UList<long long>& connectivity,
349  UList<long long>& offsets,
350  UList<long long>& faces,
351  UList<long long>& facesOffsets,
352  foamVtkMeshMaps& maps
353  ) const;
354 
355  //- Populate lists for Internal VTK format
356  void populateInternal
357  (
358  const polyMesh& mesh,
360  UList<int>& connectivity,
361  UList<int>& offsets,
362  UList<int>& faces,
363  UList<int>& facesOffsets,
364  labelUList& cellMap,
365  labelUList& addPointsIds
366  ) const;
367 
368  //- Populate lists for Internal VTK format
369  void populateInternal
370  (
371  const polyMesh& mesh,
373  UList<long>& connectivity,
374  UList<long>& offsets,
375  UList<long>& faces,
376  UList<long>& facesOffsets,
377  labelUList& cellMap,
378  labelUList& addPointsIds
379  ) const;
380 
381  //- Populate lists for Internal VTK format
382  void populateInternal
383  (
384  const polyMesh& mesh,
386  UList<long long>& connectivity,
387  UList<long long>& offsets,
388  UList<long long>& faces,
389  UList<long long>& facesOffsets,
390  labelUList& cellMap,
391  labelUList& addPointsIds
392  ) const;
393 
394 
395  // Routines for renumber vertices with a global point offset
396  // Legacy and xml only, internal version less likely to be needed
397 
398  //- Copy vertex labels with a global point offset - legacy format
400  (
401  const labelUList& connectivity,
402  const label globalPointOffset
403  );
404 
405  //- Copy vertex labels with a global point offset - XML format
407  (
408  const labelUList& connectivity,
409  const label globalPointOffset
410  );
411 
412  //- Copy faces stream labels with a global point offset - XML format
414  (
415  const labelUList& faceLabels,
416  const label globalPointOffset
417  );
418 
419  //- Copy face offsets with an offset from previous - XML format
421  (
422  const labelUList& faceOffsets,
423  const label prevOffset
424  );
425 
426  //- Renumber vertex labels by global point offset - legacy format
427  static void renumberVertLabelsLegacy
428  (
429  labelUList& connectivity,
430  const label globalPointOffset
431  );
432 
433  //- Renumber vertex labels by global point offset - XML format
434  static void renumberVertLabelsXml
435  (
436  labelUList& connectivity,
437  const label globalPointOffset
438  );
439 
440  //- Renumber faces stream labels by global point offset - XML format
441  static void renumberFaceLabelsXml
442  (
443  labelUList& faceLabels,
444  const label globalPointOffset
445  );
446 
447  //- Renumber face offsets with an offset from previous - XML format
448  static void renumberFaceOffsetsXml
449  (
450  labelUList& faceOffsets,
451  const label prevOffset
452  );
453 
454 
455  // Write
456 
457  //- Report some information
458  void info(Ostream& os) const;
459 
460 
461  // Member Operators
462 
463  //- Test equality
464  bool operator==(const vtuSizing& rhs) const;
465 
466  //- Test inequality
467  bool operator!=(const vtuSizing& rhs) const;
468 
469 };
470 
471 
472 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
473 
474 } // End namespace vtk
475 } // End namespace Foam
476 
477 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
478 
479 #include "foamVtuSizingI.H"
480 
481 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
482 
483 #endif
484 
485 // ************************************************************************* //
Foam::vtk::vtuSizing::nCells
label nCells() const
Number of cells for the mesh.
Definition: foamVtuSizingI.H:38
Foam::vtk::vtuSizing::renumberFaceLabelsXml
static void renumberFaceLabelsXml(labelUList &faceLabels, const label globalPointOffset)
Renumber faces stream labels by global point offset - XML format.
Definition: foamVtuSizing.C:660
Foam::vtk::vtuSizing::CELLS_OFFSETS
End-offsets (XML) or locations (INTERNAL) for cells.
Definition: foamVtuSizing.H:184
Foam::vtk::vtuSizing::~vtuSizing
~vtuSizing()=default
Destructor.
Foam::vtk::vtuSizing::decompose
bool decompose() const
Query the decompose flag (normally off)
Definition: foamVtuSizingI.H:32
Foam::vtk::vtuSizing::nCellsPoly
label nCellsPoly() const
Number of polyhedral cells for the mesh.
Definition: foamVtuSizingI.H:62
Foam::vtk::vtuSizing::vtuSizing
vtuSizing()
Construct null.
Definition: foamVtuSizing.C:47
Foam::vtk::vtuSizing::INTERNAL
Internal vtkUnstructuredGrid content.
Definition: foamVtuSizing.H:177
Foam::vtk::vtuSizing::populateLegacy
void populateLegacy(const polyMesh &mesh, UList< uint8_t > &cellTypes, labelUList &connectivity, foamVtkMeshMaps &maps) const
Populate lists for Legacy output.
Definition: foamVtuSizing.C:289
Foam::vtk::vtuSizing::nAddVerts
label nAddVerts() const
Number of additional (decomposed) vertices for the mesh.
Definition: foamVtuSizingI.H:86
Foam::vtk::vtuSizing::info
void info(Ostream &os) const
Report some information.
Definition: foamVtuSizing.C:740
Foam::vtk::vtuSizing::clear
void clear()
Reset all sizes to zero.
Definition: foamVtuSizing.C:66
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::vtk::vtuSizing::copyVertLabelsLegacy
static labelList copyVertLabelsLegacy(const labelUList &connectivity, const label globalPointOffset)
Copy vertex labels with a global point offset - legacy format.
Definition: foamVtuSizing.C:520
Foam::vtk::vtuSizing::operator!=
bool operator!=(const vtuSizing &rhs) const
Test inequality.
Definition: foamVtuSizing.C:794
Foam::vtk::vtuSizing::sizeLegacy
label sizeLegacy() const
The calculated size for legacy storage.
Definition: foamVtuSizingI.H:104
Foam::vtk::vtuSizing::nFieldCells
label nFieldCells() const
Number of field cells = nCells + nAddCells.
Definition: foamVtuSizingI.H:92
Foam::vtk::vtuSizing::nVertPoly
label nVertPoly() const
Number of vertex labels for polyhedral cells of the mesh.
Definition: foamVtuSizingI.H:68
Foam::vtk::vtuSizing::populateXml
void populateXml(const polyMesh &mesh, UList< uint8_t > &cellTypes, labelUList &connectivity, labelUList &offsets, labelUList &faces, labelUList &facesOffsets, foamVtkMeshMaps &maps) const
Populate lists for XML output.
Definition: foamVtuSizing.C:318
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::vtuSizing::XML
XML (VTU) content.
Definition: foamVtuSizing.H:176
labelList.H
foamVtuSizingI.H
Foam::vtk::vtuSizing::nFaceLabels
label nFaceLabels() const
Number of polyhedral face labels for the mesh.
Definition: foamVtuSizingI.H:56
Foam::vtk::vtuSizing::FACES_OFFSETS
End-offsets (XML) or locations (INTERNAL) for faces.
Definition: foamVtuSizing.H:186
Foam::vtk::vtuSizing::renumberVertLabelsLegacy
static void renumberVertLabelsLegacy(labelUList &connectivity, const label globalPointOffset)
Renumber vertex labels by global point offset - legacy format.
Definition: foamVtuSizing.C:538
Foam::vtk::vtuSizing::populateInternal
void populateInternal(const polyMesh &mesh, UList< uint8_t > &cellTypes, UList< int > &connectivity, UList< int > &offsets, UList< int > &faces, UList< int > &facesOffsets, foamVtkMeshMaps &maps) const
Populate lists for Internal VTK format.
Definition: foamVtuSizing.C:347
Foam::vtk::vtuSizing::nFieldPoints
label nFieldPoints() const
Number of field points = nPoints + nAddPoints.
Definition: foamVtuSizingI.H:98
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::vtk::vtuSizing::nPoints
label nPoints() const
Number of points for the mesh.
Definition: foamVtuSizingI.H:44
Foam::vtk::vtuSizing::CELLS
Cell connectivity (ALL)
Definition: foamVtuSizing.H:183
Foam::vtk::vtuSizing::nVertLabels
label nVertLabels() const
Number of vertex labels for the mesh.
Definition: foamVtuSizingI.H:50
Foam::vtk::vtuSizing::contentType
contentType
Types of content that the storage may represent.
Definition: foamVtuSizing.H:173
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::vtuSizing
Sizing descriptions and routines for transcribing an OpenFOAM volume mesh into a VTK unstructured gri...
Definition: foamVtuSizing.H:166
Foam::vtk::vtuSizing::renumberFaceOffsetsXml
static void renumberFaceOffsetsXml(labelUList &faceOffsets, const label prevOffset)
Renumber face offsets with an offset from previous - XML format.
Definition: foamVtuSizing.C:715
Foam::vtk::vtuSizing::FACES
Face-stream (XML, INTERNAL)
Definition: foamVtuSizing.H:185
Foam::vtk::vtuSizing::copyVertLabelsXml
static labelList copyVertLabelsXml(const labelUList &connectivity, const label globalPointOffset)
Copy vertex labels with a global point offset - XML format.
Definition: foamVtuSizing.C:603
cellTypes
const labelList & cellTypes
Definition: setCellMask.H:33
Foam::vtk::vtuSizing::copyFaceOffsetsXml
static labelList copyFaceOffsetsXml(const labelUList &faceOffsets, const label prevOffset)
Copy face offsets with an offset from previous - XML format.
Definition: foamVtuSizing.C:697
Foam::vtk::vtuSizing::sizeInternal
label sizeInternal(const enum slotType slot) const
The calculated size for vtk-internal storage of the specified slot.
Definition: foamVtuSizingI.H:129
label.H
Foam::List< label >
Foam::vtk::vtuSizing::renumberVertLabelsXml
static void renumberVertLabelsXml(labelUList &connectivity, const label globalPointOffset)
Renumber vertex labels by global point offset - XML format.
Definition: foamVtuSizing.C:621
Foam::vtk::vtuSizing::copyFaceLabelsXml
static labelList copyFaceLabelsXml(const labelUList &faceLabels, const label globalPointOffset)
Copy faces stream labels with a global point offset - XML format.
Definition: foamVtuSizing.C:642
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::vtk::vtuSizing::LEGACY
Legacy VTK content.
Definition: foamVtuSizing.H:175
Foam::vtk::vtuSizing::slotType
slotType
The possible storage 'slots' that can be used.
Definition: foamVtuSizing.H:181
Foam::vtk::vtuSizing::nAddPoints
label nAddPoints() const
Number of additional (decomposed) points for the mesh.
Definition: foamVtuSizingI.H:80
Foam::vtk::vtuSizing::sizeXml
label sizeXml(const enum slotType slot) const
The calculated size for xml storage of the specified slot.
Definition: foamVtuSizingI.H:120
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::vtk::vtuSizing::nAddCells
label nAddCells() const
Number of additional (decomposed) cells for the mesh.
Definition: foamVtuSizingI.H:74
Foam::vtk::vtuSizing::operator==
bool operator==(const vtuSizing &rhs) const
Test equality.
Definition: foamVtuSizing.C:775
Foam::vtk::vtuSizing::reset
void reset(const polyMesh &mesh, const bool decompose=false)
Reset sizing by analyzing the mesh.
Definition: foamVtuSizing.C:84
foamVtkMeshMaps.H
Foam::foamVtkMeshMaps
Bookkeeping for mesh subsetting and/or polyhedral cell decomposition. Although the main use case is f...
Definition: foamVtkMeshMaps.H:57
Foam::vtk::vtuSizing::sizeOf
label sizeOf(const enum contentType output, const enum slotType slot) const
Return the required size for the storage slot.
Definition: foamVtuSizing.C:207