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-2020 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 ensightMesh_H
61 #define 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 
83 class ensightMesh
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 
118  // Private Member Functions
119 
120  //- Clear all storage
121  void clear();
122 
123  //- Enforce consistent index/part numbering
124  void renumber();
125 
126  //- No copy construct
127  ensightMesh(const ensightMesh&) = delete;
128 
129  //- No copy assignment
130  void operator=(const ensightMesh&) = delete;
131 
132 
133 public:
134 
135  // Constructors
136 
137  //- Construct from mesh with all default options
138  explicit ensightMesh(const polyMesh& mesh);
139 
140  //- Construct from components
141  ensightMesh(const polyMesh& mesh, const options& opts);
142 
143 
144  // Member Functions
145 
146  // Access
147 
148  //- Reference to the underlying polyMesh
149  const polyMesh& mesh() const noexcept
150  {
151  return mesh_;
152  }
153 
154  //- Reference to the writer/mesh options
155  inline const ensightMesh::options& option() const;
156 
157  //- Face elements per selected patch, lookup by patch index
158  // Process in sorted order.
159  // May require special treatment for zone -1 (internal).
160  const Map<ensightCells>& cellZoneParts() const noexcept
161  {
162  return cellZoneParts_;
163  }
164 
165  //- Face elements per faceZone, lookup by zone index.
166  // Process in sorted order.
167  const Map<ensightFaces>& faceZoneParts() const noexcept
168  {
169  return faceZoneParts_;
170  }
171 
172  //- Face elements per selected patch, lookup by patch index
173  // Process in sorted order.
174  const Map<ensightFaces>& boundaryParts() const noexcept
175  {
176  return boundaryParts_;
177  }
178 
179 
180  // Sizing Information
181 
182  //- Any parts?
183  inline bool empty() const noexcept;
184 
185  //- Number of parts
186  inline label size() const noexcept;
187 
188 
189  // Other
190 
191  //- Does the content need an update?
192  bool needsUpdate() const noexcept
193  {
194  return needsUpdate_;
195  }
196 
197  //- Mark as needing an update.
198  // May also free up unneeded data.
199  // Return false if already marked as expired.
200  inline bool expire();
201 
202  //- Update for new mesh
203  void correct();
204 
205 
206  // Output
207 
208  //- Write geometry to file. Normally in parallel
209  void write
210  (
212  bool parallel = Pstream::parRun()
213  ) const;
214 
215  //- Write geometry to file. Normally in parallel
216  inline void write
217  (
219  bool parallel = Pstream::parRun()
220  ) const;
221 };
222 
223 
224 /*---------------------------------------------------------------------------*\
225  Class ensightMesh::options Declaration
226 \*---------------------------------------------------------------------------*/
227 
228 //- Configuration options for the ensightMesh
230 {
231  // Private Data
232 
233  //- Create in 'expired' mode
234  bool lazy_;
235 
236  //- Use the internal mesh
237  bool internal_;
238 
239  //- Use the boundary mesh
240  bool boundary_;
241 
242  //- Handle cellZones (if internal_ is true)
243  bool cellZones_;
244 
245  //- Selected patches only
246  wordRes patchInclude_;
247 
248  //- Deselected patches
249  wordRes patchExclude_;
250 
251  //- Selected cellZones
252  wordRes cellZoneInclude_;
253 
254  //- Selected faceZones
255  wordRes faceZoneInclude_;
256 
257 
258 public:
259 
260  // Constructors
261 
262  //- Default construct. Non-lazy with internal/boundary/cellZones.
263  options();
264 
265 
266  // Member Functions
267 
268  // Access
269 
270  //- Lazy creation? (ie, starts as needsUpdate)
271  bool lazy() const noexcept;
272 
273  //- Using internal?
274  bool useInternalMesh() const noexcept;
275 
276  //- Using boundary?
277  bool useBoundaryMesh() const noexcept;
278 
279  //- Using faceZones?
280  bool useFaceZones() const noexcept;
281 
282  //- Using cellZones?
283  bool useCellZones() const noexcept;
284 
285  //- Selection of patches. Empty if unspecified.
286  const wordRes& patchSelection() const noexcept
287  {
288  return patchInclude_;
289  }
290 
291  //- Selection of black listed patches. Empty if unspecified.
292  const wordRes& patchExclude() const noexcept
293  {
294  return patchExclude_;
295  }
296 
297  //- Selection of faceZones. Empty if unspecified.
298  const wordRes& faceZoneSelection() const noexcept
299  {
300  return faceZoneInclude_;
301  }
302 
303  //- Selection of faceZones. Empty if unspecified.
304  const wordRes& cellZoneSelection() const noexcept
305  {
306  return cellZoneInclude_;
307  }
308 
309 
310  // Edit
311 
312  //- Reset to defaults
313  void reset();
314 
315  //- Lazy creation - ensightMesh starts as needsUpdate
316  // \return old value
317  bool lazy(bool on) noexcept;
318 
319  //- Alter the useBoundaryMesh state
320  // \return old value
321  bool useInternalMesh(bool on) noexcept;
322 
323  //- Alter the useBoundaryMesh state
324  // \return old value
325  bool useBoundaryMesh(bool on);
326 
327  //- Alter the useCellZones state
328  // \return old value
329  bool useCellZones(bool on);
330 
331  //- Define patch selection matcher
332  void patchSelection(const UList<wordRe>& patterns);
333 
334  //- Define patch selection matcher
335  void patchSelection(List<wordRe>&& patterns);
336 
337  //- Define patch selection to exclude
338  void patchExclude(const UList<wordRe>& patterns);
339 
340  //- Define patch selection to exclude
341  void patchExclude(List<wordRe>&& patterns);
342 
343  //- Define faceZone selection matcher
344  void faceZoneSelection(const UList<wordRe>& patterns);
345 
346  //- Define faceZone selection matcher
347  void faceZoneSelection(List<wordRe>&& patterns);
348 
349  //- Define cellZone selection matcher
350  void cellZoneSelection(const UList<wordRe>& patterns);
351 
352  //- Define cellZone selection matcher
353  void cellZoneSelection(List<wordRe>&& patterns);
354 
355 
356  // Output
357 
358  //- Report values
359  void print(Ostream& os) const;
360 };
361 
362 
363 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 
365 } // End namespace Foam
366 
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 
369 #include "ensightMeshI.H"
370 
371 #endif
372 
373 // ************************************************************************* //
wordRes.H
Foam::ensightMesh::cellZoneParts
const Map< ensightCells > & cellZoneParts() const noexcept
Face elements per selected patch, lookup by patch index.
Definition: ensightMesh.H:159
Foam::ensightMesh
Encapsulation of volume meshes for writing in ensight format. It manages cellZones,...
Definition: ensightMesh.H:82
Foam::ensightMesh::empty
bool empty() const noexcept
Any parts?
Definition: ensightMeshI.H:51
ensightFaces.H
Foam::ensightMesh::options::patchExclude
const wordRes & patchExclude() const noexcept
Selection of black listed patches. Empty if unspecified.
Definition: ensightMesh.H:291
Foam::ensightMesh::options::useInternalMesh
bool useInternalMesh() const noexcept
Using internal?
Definition: ensightMeshOptions.C:81
Foam::ensightMesh::options::faceZoneSelection
const wordRes & faceZoneSelection() const noexcept
Selection of faceZones. Empty if unspecified.
Definition: ensightMesh.H:297
Foam::ensightMesh::correct
void correct()
Update for new mesh.
Definition: ensightMesh.C:124
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::ensightMesh::options::useFaceZones
bool useFaceZones() const noexcept
Using faceZones?
Definition: ensightMeshOptions.C:99
Foam::ensightMesh::needsUpdate
bool needsUpdate() const noexcept
Does the content need an update?
Definition: ensightMesh.H:191
Foam::ensightMesh::mesh
const polyMesh & mesh() const noexcept
Reference to the underlying polyMesh.
Definition: ensightMesh.H:148
Foam::ensightMesh::options::lazy
bool lazy() const noexcept
Lazy creation? (ie, starts as needsUpdate)
Definition: ensightMeshOptions.C:75
Foam::ensightMesh::write
void write(ensightGeoFile &os, bool parallel=Pstream::parRun()) const
Write geometry to file. Normally in parallel.
Definition: ensightMesh.C:396
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::ensightMesh::internalZone
static const label internalZone
The zone-id for internal mesh or unzoned cells.
Definition: ensightMesh.H:87
Map.H
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:48
Foam::ensightMesh::options::useCellZones
bool useCellZones() const noexcept
Using cellZones?
Definition: ensightMeshOptions.C:93
Foam::ensightMesh::expire
bool expire()
Mark as needing an update.
Definition: ensightMeshI.H:36
Foam::ensightMesh::options::reset
void reset()
Reset to defaults.
Definition: ensightMeshOptions.C:105
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ensightMesh::options::patchSelection
const wordRes & patchSelection() const noexcept
Selection of patches. Empty if unspecified.
Definition: ensightMesh.H:285
Foam::ensightMesh::size
label size() const noexcept
Number of parts.
Definition: ensightMeshI.H:62
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::renumber
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values (not the indices) of a list.
Definition: ListOpsTemplates.C:37
clear
patchWriters clear()
Foam::ensightMesh::options
Configuration options for the ensightMesh.
Definition: ensightMesh.H:228
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< wordRe >
Foam::ensightMesh::options::cellZoneSelection
const wordRes & cellZoneSelection() const noexcept
Selection of faceZones. Empty if unspecified.
Definition: ensightMesh.H:303
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::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
ensightMeshI.H
Foam::ensightMesh::options::print
void print(Ostream &os) const
Report values.
Definition: ensightMeshOptions.C:280
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::ensightMesh::faceZoneParts
const Map< ensightFaces > & faceZoneParts() const noexcept
Face elements per faceZone, lookup by zone index.
Definition: ensightMesh.H:166
Foam::ensightMesh::option
const ensightMesh::options & option() const
Reference to the writer/mesh options.
Definition: ensightMeshI.H:30
Foam::ensightMesh::options::options
options()
Default construct. Non-lazy with internal/boundary/cellZones.
Definition: ensightMeshOptions.C:60
Foam::ensightMesh::options::useBoundaryMesh
bool useBoundaryMesh() const noexcept
Using boundary?
Definition: ensightMeshOptions.C:87
Foam::ensightMesh::boundaryParts
const Map< ensightFaces > & boundaryParts() const noexcept
Face elements per selected patch, lookup by patch index.
Definition: ensightMesh.H:173
ensightCells.H