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-2024 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  It manages cellZones, facesZone, patches.
33 
34  When cellZones are present (and not disabled), the cells are grouped
35  in parts according to the zone.
36  Any remaining \em unzoned cells are placed into the "internalMesh" part,
37  which is always part 0. If cellZones are missing or disabled,
38  all cells are placed into the "internalMesh" part.
39 
40  If one or more cellZones are explicitly requested, all other cells
41  (including any unzoned cells) are ignored.
42 
43  The converted patch faces are restricted by the volume mesh coverage.
44  Except when the entire internal mesh has been explicitly suppressed.
45 
46 Note
47  The internal data management uses a Map for cellZones, faceZones and
48  patches. The internalMesh is treated as cellZone with a special index.
49 
50  Since the patches are subsetted by the internal mesh coverage,
51  they are treated as indirect patches rather than regular poly patches.
52 
53 SourceFiles
54  ensightMesh.C
55  ensightMeshI.H
56  ensightMeshOptions.C
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #ifndef Foam_ensightMesh_H
61 #define Foam_ensightMesh_H
62 
63 #include "Map.H"
64 #include "ensightCells.H"
65 #include "ensightFaces.H"
66 #include "wordRes.H"
67 #include <memory>
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 // Forward Declarations
75 class polyMesh;
76 class ensightGeoFile;
77 class ensightMesh;
78 
79 /*---------------------------------------------------------------------------*\
80  Class ensightMesh Declaration
81 \*---------------------------------------------------------------------------*/
82 
84 {
85 public:
86 
87  // Forward Declarations
88  class options;
89 
90  //- The zone-id for internal mesh or unzoned cells.
91  static const label internalZone;
92 
93 
94 private:
95 
96  // Private Data
97 
98  //- Writer options
99  const std::unique_ptr<options> options_;
100 
101  //- Reference to the OpenFOAM mesh
102  const polyMesh& mesh_;
103 
104  //- Volume elements per cellZone, lookup by zone index.
105  // The zone -1 is reserved for internal mesh (unzoned cells)
106  Map<ensightCells> cellZoneParts_;
107 
108  //- Face elements per faceZone, lookup by zone index.
109  Map<ensightFaces> faceZoneParts_;
110 
111  //- Face elements per selected patch, lookup by patch index
112  Map<ensightFaces> boundaryParts_;
113 
114  //- Track if it needs an update
115  mutable bool needsUpdate_;
116 
117  //- Output verbosity level
118  int verbose_;
119 
120 
121  // Private Member Functions
122 
123  //- Clear all storage
124  void clear();
125 
126  //- Enforce consistent index/part numbering
127  void renumber();
128 
129  //- No copy construct
130  ensightMesh(const ensightMesh&) = delete;
131 
132  //- No copy assignment
133  void operator=(const ensightMesh&) = delete;
134 
135 
136 public:
137 
138  // Constructors
139 
140  //- Construct from mesh with all default options
141  explicit ensightMesh(const polyMesh& mesh);
142 
143  //- Construct from components
144  ensightMesh(const polyMesh& mesh, const options& opts);
145 
146 
147  // Member Functions
148 
149  //- Output verbosity level
150  int verbose() const noexcept;
151 
152  //- Change the output verbosity level.
153  // \return old level
154  int verbose(const int level) noexcept;
155 
156 
157  // Access
158 
159  //- Reference to the underlying polyMesh
160  const polyMesh& mesh() const noexcept
161  {
162  return mesh_;
163  }
164 
165  //- Reference to the writer/mesh options
166  inline const ensightMesh::options& option() const;
167 
168  //- Face elements per selected patch, lookup by patch index
169  // Process in sorted order.
170  // May require special treatment for zone -1 (internal).
172  {
173  return cellZoneParts_;
174  }
175 
176  //- Face elements per faceZone, lookup by zone index.
177  // Process in sorted order.
179  {
180  return faceZoneParts_;
181  }
182 
183  //- Face elements per selected patch, lookup by patch index
184  // Process in sorted order.
186  {
187  return boundaryParts_;
188  }
189 
190 
191  // Sizing Information
192 
193  //- Any parts?
194  inline bool empty() const noexcept;
195 
196  //- Number of parts
197  inline label size() const noexcept;
198 
199 
200  // Other
201 
202  //- Does the content need an update?
203  bool needsUpdate() const noexcept
204  {
205  return needsUpdate_;
206  }
208  //- Mark as needing an update.
209  // May also free up unneeded data.
210  // Return false if already marked as expired.
211  inline bool expire();
212 
213  //- Update for new mesh
214  void correct();
215 
216 
217  // Output
218 
219  //- Write geometry to file (normally in parallel).
220  //- Adds beginGeometry() marker.
221  // If all geometry is disabled, it will simply writes the mesh
222  // bounding box (to ensure that the geometry file is non-empty)
223  void write
224  (
226  bool parallel = UPstream::parRun()
227  ) const;
228 
229  //- Write geometry to file (normally in parallel).
230  //- Adds beginGeometry() marker.
231  FOAM_DEPRECATED_FOR(2024-05, "write(ensightGeoFile&, ...")
232  inline void write
233  (
235  bool parallel = UPstream::parRun()
236  ) const;
237 };
238 
239 
240 /*---------------------------------------------------------------------------*\
241  Class ensightMesh::options Declaration
242 \*---------------------------------------------------------------------------*/
243 
244 //- Configuration options for the ensightMesh
245 class ensightMesh::options
246 {
247  // Private Data
248 
249  //- Create in 'expired' mode
250  bool lazy_;
252  //- Use the internal mesh
253  bool internal_;
254 
255  //- Use the boundary mesh
256  bool boundary_;
257 
258  //- Handle cellZones (if internal_ is true)
259  bool cellZones_;
260 
261  //- Selected patches only
262  wordRes patchInclude_;
263 
264  //- Deselected patches
265  wordRes patchExclude_;
266 
267  //- Selected cellZones
268  wordRes cellZoneInclude_;
269 
270  //- Selected faceZones
271  wordRes faceZoneInclude_;
272 
273 
274 public:
275 
276  // Constructors
277 
278  //- Default construct. Non-lazy with internal/boundary/cellZones.
279  options();
280 
281 
282  // Member Functions
283 
284  // Access
285 
286  //- Lazy creation? (ie, starts as needsUpdate)
287  bool lazy() const noexcept;
288 
289  //- Using internal?
290  bool useInternalMesh() const noexcept;
291 
292  //- Using boundary?
293  bool useBoundaryMesh() const noexcept;
294 
295  //- Using faceZones?
296  bool useFaceZones() const noexcept;
297 
298  //- Using cellZones?
299  bool useCellZones() const noexcept;
300 
301  //- Selection of patches. Empty if unspecified.
302  const wordRes& patchSelection() const noexcept
303  {
304  return patchInclude_;
305  }
306 
307  //- Selection of black listed patches. Empty if unspecified.
308  const wordRes& patchExclude() const noexcept
309  {
310  return patchExclude_;
311  }
312 
313  //- Selection of faceZones. Empty if unspecified.
314  const wordRes& faceZoneSelection() const noexcept
315  {
316  return faceZoneInclude_;
317  }
318 
319  //- Selection of faceZones. Empty if unspecified.
320  const wordRes& cellZoneSelection() const noexcept
321  {
322  return cellZoneInclude_;
323  }
324 
325 
326  // Edit
327 
328  //- Reset to defaults
329  void reset();
330 
331  //- Lazy creation - ensightMesh starts as needsUpdate
332  // \return old value
333  bool lazy(bool on) noexcept;
334 
335  //- Alter the useBoundaryMesh state
336  // \return old value
337  bool useInternalMesh(bool on) noexcept;
338 
339  //- Alter the useBoundaryMesh state
340  // \return old value
341  bool useBoundaryMesh(bool on);
342 
343  //- Alter the useCellZones state
344  // \return old value
345  bool useCellZones(bool on);
346 
347  //- Define patch selection matcher
348  void patchSelection(const UList<wordRe>& patterns);
349 
350  //- Define patch selection matcher
351  void patchSelection(List<wordRe>&& patterns);
352 
353  //- Define patch selection to exclude
354  void patchExclude(const UList<wordRe>& patterns);
355 
356  //- Define patch selection to exclude
357  void patchExclude(List<wordRe>&& patterns);
358 
359  //- Define faceZone selection matcher
360  void faceZoneSelection(const UList<wordRe>& patterns);
361 
362  //- Define faceZone selection matcher
363  void faceZoneSelection(List<wordRe>&& patterns);
364 
365  //- Define cellZone selection matcher
366  void cellZoneSelection(const UList<wordRe>& patterns);
367 
368  //- Define cellZone selection matcher
369  void cellZoneSelection(List<wordRe>&& patterns);
370 
371 
372  // Output
373 
374  //- Report values
375  void print(Ostream& os) const;
376 };
377 
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 } // End namespace Foam
382 
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 
385 #include "ensightMeshI.H"
386 
387 #endif
388 
389 // ************************************************************************* //
const ensightMesh::options & option() const
Reference to the writer/mesh options.
Definition: ensightMeshI.H:23
Ostream & print(Ostream &os, UIntType value, char off='0', char on='1')
Print 0/1 bits in the (unsigned) integral type.
Definition: BitOps.H:323
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values within a list.
A variant of ensightFile (Ensight writing) that includes the extra geometry file header information...
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1061
const polyMesh & mesh() const noexcept
Reference to the underlying polyMesh.
Definition: ensightMesh.H:191
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:65
void correct()
Update for new mesh.
Definition: ensightMesh.C:133
void write(ensightGeoFile &os, bool parallel=UPstream::parRun()) const
Write geometry to file (normally in parallel). Adds beginGeometry() marker.
Definition: ensightMesh.C:424
const Map< ensightFaces > & boundaryParts() const noexcept
Face elements per selected patch, lookup by patch index.
Definition: ensightMesh.H:227
bool needsUpdate() const noexcept
Does the content need an update?
Definition: ensightMesh.H:251
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
const Map< ensightFaces > & faceZoneParts() const noexcept
Face elements per faceZone, lookup by zone index.
Definition: ensightMesh.H:217
const Map< ensightCells > & cellZoneParts() const noexcept
Face elements per selected patch, lookup by patch index.
Definition: ensightMesh.H:207
const direction noexcept
Definition: Scalar.H:258
Encapsulation of volume meshes for writing in ensight format. It manages cellZones, facesZone, patches.
Definition: ensightMesh.H:78
OBJstream os(runTime.globalPath()/outputName)
bool expire()
Mark as needing an update.
Definition: ensightMeshI.H:29
surface1 clear()
label size() const noexcept
Number of parts.
Definition: ensightMeshI.H:55
static const label internalZone
The zone-id for internal mesh or unzoned cells.
Definition: ensightMesh.H:83
Configuration options for the ensightMesh.
Definition: ensightMesh.H:305
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
int verbose() const noexcept
Output verbosity level.
Definition: ensightMesh.C:119
bool empty() const noexcept
Any parts?
Definition: ensightMeshI.H:44
Inter-processor communications stream.
Definition: UPstream.H:65
Namespace for OpenFOAM.
A HashTable to objects of type <T> with a label key.