ensightMesh.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::ensightMesh
29 
30 Description
31  Encapsulation of volume meshes for writing in ensight format.
32 
33 SourceFiles
34  ensightMesh.C
35  ensightMeshIO.C
36  ensightMeshOptions.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef ensightMesh_H
41 #define ensightMesh_H
42 
43 #include "ensightCells.H"
44 #include "ensightFaces.H"
45 #include "ensightGeoFile.H"
46 #include "cellList.H"
47 #include "faceList.H"
48 #include "cellShapeList.H"
49 #include "HashTable.H"
50 #include "Map.H"
51 #include "scalarField.H"
52 #include "wordRes.H"
53 #include "globalIndex.H"
54 
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward declarations
62 class fvMesh;
63 class ensightMesh;
64 
65 /*---------------------------------------------------------------------------*\
66  Class ensightMesh Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class ensightMesh
70 {
71 public:
72 
73  // Forward declarations
74  class options;
75 
76 
77 private:
78 
79  // Private data
80 
81  //- Writer options
82  const options* options_;
83 
84  //- Reference to the OpenFOAM mesh
85  const fvMesh& mesh_;
86 
87  //- The volume cells (internalMesh)
88  ensightCells meshCells_;
89 
90  //- Face elements per patch
91  HashTable<ensightFaces> boundaryPatchFaces_;
92 
93  //- Face elements per faceZone
94  HashTable<ensightFaces> faceZoneFaces_;
95 
96  //- The list of patches to be output
97  Map<word> patchLookup_;
98 
99  //- Track if it needs an update
100  mutable bool needsUpdate_;
101 
102 
103  // Parallel merged points
104 
105  //- Global numbering for merged points
106  autoPtr<globalIndex> globalPointsPtr_;
107 
108  //- From mesh point to global merged point
109  labelList pointToGlobal_;
110 
111  //- Local points that are unique
112  labelList uniquePointMap_;
113 
114 
115  // Private Member Functions
116 
117  //- Clear some storage
118  void clear();
119 
120 
121  //- Inplace renumber of cell-shapes
122  static cellShapeList& renumberShapes
123  (
124  cellShapeList& shapes,
126  );
127 
128  //- Copy and return renumbered cell-shapes
129  static cellShapeList renumberShapes
130  (
131  const cellShapeList& shapes,
132  const labelUList& addr,
134  );
135 
136  //- Write list of faces
137  static void writeFaceList
138  (
139  const faceList& faces,
140  ensightGeoFile& os
141  );
142 
143  //- Write list of faces
144  static void writeFaceList
145  (
146  const UIndirectList<face>& faces,
147  ensightGeoFile& os
148  );
149 
150  //- Return sizes of faces in the list
151  static labelList getFaceSizes
152  (
153  const faceList& faces
154  );
155 
156  //- Return sizes of faces in the list
157  static labelList getFaceSizes
158  (
159  const UIndirectList<face>& faces
160  );
161 
162  //- Write sizes of faces in the list
163  static void writeFaceSizes
164  (
165  const faceList& faces,
166  ensightGeoFile& os
167  );
168 
169  //- Write sizes of faces in the list
170  static void writeFaceSizes
171  (
172  const UIndirectList<face>& faces,
173  ensightGeoFile& os
174  );
175 
176  //- Write cell connectivity via cell shapes
177  static void writeCellShapes
178  (
179  const cellShapeList& shapes,
180  ensightGeoFile& os
181  );
182 
183  //- Return the number of faces per poly element
184  static labelList getPolysNFaces
185  (
186  const labelUList& polys,
187  const cellList& cellFaces
188  );
189 
190  //- Write the number of faces per poly element
191  static void writePolysNFaces
192  (
193  const labelUList& polys,
194  const cellList& cellFaces,
195  ensightGeoFile& os
196  );
197 
198  //- Return the number of points per poly element
199  static labelList getPolysNPointsPerFace
200  (
201  const labelUList& polys,
202  const cellList& cellFaces,
203  const faceList& faces
204  );
205 
206  //- Write the number of points per poly element
207  static void writePolysNPointsPerFace
208  (
209  const labelUList& polys,
210  const cellList& cellFaces,
211  const faceList& faces,
212  ensightGeoFile& os
213  );
214 
215  //- Write the point ids per poly element
216  static void writePolysPoints
217  (
218  const labelUList& addr,
219  const cellList& cellFaces,
220  const faceList& faces,
221  const labelList& faceOwner,
222  ensightGeoFile& os
223  );
224 
225  //- Write the poly connectivity
226  void writePolysConnectivity
227  (
228  const labelUList& polys,
229  const labelList& pointToGlobal,
231  ) const;
232 
233  //- Write the regular cell connectivity for all types
234  void writeCellConnectivity
235  (
236  const ensightCells& ensCells,
237  const labelList& pointToGlobal,
238  ensightGeoFile& os
239  ) const;
240 
241  //- Write the regular cell connectivity for specified type
242  void writeCellConnectivity
243  (
244  ensightCells::elemType elemType,
245  const ensightCells& ensCells,
246  const labelList& pointToGlobal,
247  ensightGeoFile& os
248  ) const;
249 
250  //- Write the regular face connectivity for specified type and
251  //- and specified faces
252  void writeFaceConnectivity
253  (
254  ensightFaces::elemType elemType,
255  const label nTotal,
256  const faceList& faces,
257  const labelUList& addr,
259  ) const;
260 
261  //- Write the regular face connectivity for specified type
262  void writeFaceConnectivity
263  (
264  ensightFaces::elemType elemType,
265  const label nTotal,
266  const faceList& faces,
267  ensightGeoFile& os
268  ) const;
269 
270 
271  void writeFaceConnectivity
272  (
273  const ensightFaces& ensFaces,
274  const faceList& faces,
275  ensightGeoFile& os,
276  const bool raw = false
277  ) const;
278 
279 
280  void writeAllPoints
281  (
282  const label partId,
283  const word& ensightPartName,
284  const label nTotal,
285  const pointField& uniquePoints,
287  ) const;
288 
289 
290  //- No copy construct
291  ensightMesh(const ensightMesh&) = delete;
292 
293  //- No copy assignment
294  void operator=(const ensightMesh&) = delete;
295 
296 
297 public:
298 
299  // Constructors
300 
301  //- Construct from components
302  ensightMesh(const fvMesh& mesh, const options& opts);
303 
304  //- Construct from fvMesh with all default options, binary output
305  explicit ensightMesh(const fvMesh& mesh);
306 
307  //- Construct from fvMesh with all default options and specified format
309 
310 
311  //- Destructor
312  ~ensightMesh();
313 
314 
315  // Member Functions
316 
317  // Access
318 
319  //- Reference to the underlying fvMesh
320  inline const fvMesh& mesh() const;
321 
322  //- Reference to the writer/mesh options
323  inline const ensightMesh::options& option() const;
324 
325  //- Ascii/Binary file output
326  inline IOstream::streamFormat format() const;
327 
328  //- Using internal?
329  inline bool useInternalMesh() const;
330 
331  //- Using boundary?
332  inline bool useBoundaryMesh() const;
333 
334  //- The volume cells (internalMesh)
335  inline const ensightCells& meshCells() const;
336 
337  //- The list of patches to be output
338  inline const Map<word>& patches() const;
339 
340  //- Face elements per selected patch
341  inline const HashTable<ensightFaces>& boundaryPatchFaces() const;
342 
343  //- Face elements per selected faceZone.
344  // To be output in sorted order.
345  inline const HashTable<ensightFaces>& faceZoneFaces() const;
346 
347 
348  // Parallel point merging
349 
350  //- Global numbering for merged points
351  const globalIndex& globalPoints() const
352  {
353  return globalPointsPtr_();
354  }
355 
356  //- From mesh point to global merged point
357  const labelList& pointToGlobal() const
358  {
359  return pointToGlobal_;
360  }
361 
362  //- Local points that are unique
363  const labelList& uniquePointMap() const
364  {
365  return uniquePointMap_;
366  }
367 
368 
369  // Other
370 
371  //- Does the content need an update?
372  bool needsUpdate() const;
373 
374  //- Mark as needing an update.
375  // May also free up unneeded data.
376  // Return false if already marked as expired.
377  bool expire();
378 
379  //- Update for new mesh
380  void correct();
381 
382 
383  // Output
384 
385  //- Write to file
386  inline void write(autoPtr<ensightGeoFile>& os) const;
387 
388  //- Write to file
389  void write(ensightGeoFile& os) const;
390 
391 };
392 
393 
394 //- Configuration options for the ensightMesh
396 {
397  //- Ascii/Binary file output
398  IOstream::streamFormat format_;
399 
400  //- Create in 'expired' mode
401  bool lazy_;
402 
403  //- Use the internal mesh
404  bool internal_;
405 
406  //- Use the boundary mesh
407  bool boundary_;
408 
409  //- Output of selected patches only
410  wordRes patchPatterns_;
411 
412  //- Output of selected faceZones
413  wordRes faceZonePatterns_;
414 
415 
416 public:
417 
418  // Constructors
419 
420  //- Construct for binary output
421  options();
422 
423  //- Construct for specified format
425 
426 
427  // Member Functions
428 
429  // Access
430 
431  //- File output format (ascii | binary)
433 
434  //- Lazy creation? (ie, ensightMesh starts as needsUpdate)
435  bool lazy() const;
436 
437  //- Using internal?
438  bool useInternalMesh() const;
439 
440  //- Using boundary?
441  bool useBoundaryMesh() const;
442 
443  //- Using faceZones?
444  bool useFaceZones() const;
445 
446  //- Selection of patches. Empty if unspecified.
447  const wordRes& patchSelection() const;
448 
449  //- Selection of faceZones. Empty if unspecified.
450  const wordRes& faceZoneSelection() const;
451 
452 
453  // Edit
454 
455  //- Reset to defaults
456  void reset();
457 
458  //- Lazy creation - ensightMesh starts as needsUpdate.
459  void lazy(bool beLazy);
460 
461  //- Alter the useBoundaryMesh state
462  void useInternalMesh(bool on);
463 
464  //- Alter the useBoundaryMesh state
465  void useBoundaryMesh(bool on);
466 
467  //- Define patch selection matcher
468  void patchSelection(const UList<wordRe>& patterns);
469 
470  //- Define patch selection matcher
471  void patchSelection(List<wordRe>&& patterns);
472 
473  //- Define faceZone selection matcher
474  void faceZoneSelection(const UList<wordRe>& patterns);
475 
476  //- Define faceZone selection matcher
477  void faceZoneSelection(List<wordRe>&& patterns);
478 
479 
480  // Housekeeping
481 
482  //- Older name for useBoundaryMesh()
483  // \deprecated OCT-2018
484  bool usePatches() const { return useBoundaryMesh(); }
485 
486  //- Older name for useBoundaryMesh()
487  // \deprecated OCT-2018
488  void noPatches(bool off) { useBoundaryMesh(!off); }
489 
490 };
491 
492 
493 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
494 
495 } // End namespace Foam
496 
497 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
498 
499 #include "ensightMeshI.H"
500 
501 #endif
502 
503 // ************************************************************************* //
wordRes.H
Foam::ensightMesh::options::useBoundaryMesh
bool useBoundaryMesh() const
Using boundary?
Definition: ensightMeshOptions.C:69
Foam::ensightMesh
Encapsulation of volume meshes for writing in ensight format.
Definition: ensightMesh.H:68
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::ensightMesh::needsUpdate
bool needsUpdate() const
Does the content need an update?
Definition: ensightMesh.C:106
HashTable.H
ensightFaces.H
scalarField.H
Foam::ensightMesh::pointToGlobal
const labelList & pointToGlobal() const
From mesh point to global merged point.
Definition: ensightMesh.H:356
Foam::ensightMesh::useInternalMesh
bool useInternalMesh() const
Using internal?
Definition: ensightMeshI.H:48
Foam::ensightMesh::faceZoneFaces
const HashTable< ensightFaces > & faceZoneFaces() const
Face elements per selected faceZone.
Definition: ensightMeshI.H:80
Foam::ensightMesh::mesh
const fvMesh & mesh() const
Reference to the underlying fvMesh.
Definition: ensightMeshI.H:30
globalIndex.H
Foam::ensightMesh::correct
void correct()
Update for new mesh.
Definition: ensightMesh.C:127
Foam::ensightMesh::useBoundaryMesh
bool useBoundaryMesh() const
Using boundary?
Definition: ensightMeshI.H:54
Foam::ensightMesh::format
IOstream::streamFormat format() const
Ascii/Binary file output.
Definition: ensightMeshI.H:42
cellShapeList.H
Foam::ensightMesh::options::faceZoneSelection
const wordRes & faceZoneSelection() const
Selection of faceZones. Empty if unspecified.
Definition: ensightMeshOptions.C:177
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: HashTableFwd.H:46
Foam::ensightMesh::options::usePatches
bool usePatches() const
Older name for useBoundaryMesh()
Definition: ensightMesh.H:483
faceList.H
Foam::ensightFaces
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:51
Foam::ensightMesh::options::useFaceZones
bool useFaceZones() const
Using faceZones?
Definition: ensightMeshOptions.C:75
Foam::ensightMesh::options::format
IOstream::streamFormat format() const
File output format (ascii | binary)
Definition: ensightMeshOptions.C:51
Foam::ensightMesh::~ensightMesh
~ensightMesh()
Destructor.
Definition: ensightMesh.C:98
Map.H
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:48
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::ensightMesh::options::useInternalMesh
bool useInternalMesh() const
Using internal?
Definition: ensightMeshOptions.C:63
Foam::Field< vector >
Foam::ensightMesh::options::noPatches
void noPatches(bool off)
Older name for useBoundaryMesh()
Definition: ensightMesh.H:487
cellList.H
Foam::ensightCells
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:53
Foam::ensightMesh::expire
bool expire()
Mark as needing an update.
Definition: ensightMesh.C:112
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam::ensightMesh::options::reset
void reset()
Reset to defaults.
Definition: ensightMeshOptions.C:81
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ensightMesh::options::lazy
bool lazy() const
Lazy creation? (ie, ensightMesh starts as needsUpdate)
Definition: ensightMeshOptions.C:57
Foam::ensightMesh::boundaryPatchFaces
const HashTable< ensightFaces > & boundaryPatchFaces() const
Face elements per selected patch.
Definition: ensightMeshI.H:73
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::ensightMesh::options::patchSelection
const wordRes & patchSelection() const
Selection of patches. Empty if unspecified.
Definition: ensightMeshOptions.C:171
Foam::ensightCells::elemType
elemType
Addressable ensight element types.
Definition: ensightCells.H:60
ensightGeoFile.H
Foam::ensightFaces::elemType
elemType
Addressable ensight element types.
Definition: ensightFaces.H:58
Foam::ensightMesh::patches
const Map< word > & patches() const
The list of patches to be output.
Definition: ensightMeshI.H:66
clear
patchWriters clear()
Foam::ensightMesh::options
Configuration options for the ensightMesh.
Definition: ensightMesh.H:394
Foam::List< label >
Foam::UList< label >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
ensightMeshI.H
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:109
Foam::ensightMesh::write
void write(autoPtr< ensightGeoFile > &os) const
Write to file.
Definition: ensightMeshI.H:86
Foam::ensightMesh::option
const ensightMesh::options & option() const
Reference to the writer/mesh options.
Definition: ensightMeshI.H:36
Foam::ensightMesh::options::options
options()
Construct for binary output.
Definition: ensightMeshOptions.C:32
Foam::ensightMesh::globalPoints
const globalIndex & globalPoints() const
Global numbering for merged points.
Definition: ensightMesh.H:350
Foam::ensightMesh::meshCells
const ensightCells & meshCells() const
The volume cells (internalMesh)
Definition: ensightMeshI.H:60
Foam::ensightMesh::uniquePointMap
const labelList & uniquePointMap() const
Local points that are unique.
Definition: ensightMesh.H:362
ensightCells.H