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  inline const polyMesh& mesh() const;
150 
151  //- Reference to the writer/mesh options
152  inline const ensightMesh::options& option() const;
153 
154  //- Face elements per selected patch, lookup by patch index
155  // Process in sorted order.
156  // May require special treatment for zone -1 (internal).
157  inline const Map<ensightCells>& cellZoneParts() const;
158 
159  //- Face elements per faceZone, lookup by zone index.
160  // Process in sorted order.
161  inline const Map<ensightFaces>& faceZoneParts() const;
162 
163  //- Face elements per selected patch, lookup by patch index
164  // Process in sorted order.
165  inline const Map<ensightFaces>& boundaryParts() const;
166 
167 
168  // Sizing Information
169 
170  //- Any parts?
171  inline bool empty() const;
172 
173  //- Number of parts
174  inline label size() const;
175 
176 
177  // Other
178 
179  //- Does the content need an update?
180  inline bool needsUpdate() const;
181 
182  //- Mark as needing an update.
183  // May also free up unneeded data.
184  // Return false if already marked as expired.
185  inline bool expire();
186 
187  //- Update for new mesh
188  void correct();
189 
190 
191  // Output
192 
193  //- Write geometry to file. Normally in parallel
194  inline void write
195  (
197  bool parallel = Pstream::parRun()
198  ) const;
199 
200  //- Write geometry to file. Normally in parallel
201  void write
202  (
203  ensightGeoFile& os,
204  bool parallel = Pstream::parRun()
205  ) const;
206 };
207 
208 
209 /*---------------------------------------------------------------------------*\
210  Class ensightMesh::options Declaration
211 \*---------------------------------------------------------------------------*/
212 
213 //- Configuration options for the ensightMesh
215 {
216  // Private Data
217 
218  //- Create in 'expired' mode
219  bool lazy_;
220 
221  //- Use the internal mesh
222  bool internal_;
223 
224  //- Use the boundary mesh
225  bool boundary_;
226 
227  //- Handle cellZones (if internal_ is true)
228  bool cellZones_;
229 
230  //- Selected patches only
231  wordRes patchInclude_;
232 
233  //- Deselected patches
234  wordRes patchExclude_;
235 
236  //- Selected cellZones
237  wordRes cellZoneInclude_;
238 
239  //- Selected faceZones
240  wordRes faceZoneInclude_;
241 
242 
243 public:
244 
245  // Constructors
246 
247  //- Default construct. Non-lazy with internal/boundary/cellZones.
248  options();
249 
250 
251  // Member Functions
252 
253  // Access
254 
255  //- Lazy creation? (ie, ensightMesh starts as needsUpdate)
256  bool lazy() const;
257 
258  //- Using internal?
259  bool useInternalMesh() const;
260 
261  //- Using boundary?
262  bool useBoundaryMesh() const;
263 
264  //- Using faceZones?
265  bool useFaceZones() const;
266 
267  //- Using cellZones?
268  bool useCellZones() const;
269 
270  //- Selection of patches. Empty if unspecified.
271  const wordRes& patchSelection() const;
272 
273  //- Selection of black listed patches. Empty if unspecified.
274  const wordRes& patchExclude() const;
275 
276  //- Selection of faceZones. Empty if unspecified.
277  const wordRes& faceZoneSelection() const;
278 
279  //- Selection of faceZones. Empty if unspecified.
280  const wordRes& cellZoneSelection() const;
281 
282 
283  // Edit
284 
285  //- Reset to defaults
286  void reset();
287 
288  //- Lazy creation - ensightMesh starts as needsUpdate
289  void lazy(bool beLazy);
290 
291  //- Alter the useBoundaryMesh state
292  void useInternalMesh(bool on);
293 
294  //- Alter the useBoundaryMesh state
295  void useBoundaryMesh(bool on);
296 
297  //- Alter the useCellZones state
298  void useCellZones(bool on);
299 
300  //- Define patch selection matcher
301  void patchSelection(const UList<wordRe>& patterns);
302 
303  //- Define patch selection matcher
304  void patchSelection(List<wordRe>&& patterns);
305 
306  //- Define patch selection to exclude
307  void patchExclude(const UList<wordRe>& patterns);
308 
309  //- Define patch selection to exclude
310  void patchExclude(List<wordRe>&& patterns);
311 
312  //- Define faceZone selection matcher
313  void faceZoneSelection(const UList<wordRe>& patterns);
314 
315  //- Define faceZone selection matcher
316  void faceZoneSelection(List<wordRe>&& patterns);
317 
318  //- Define cellZone selection matcher
319  void cellZoneSelection(const UList<wordRe>& patterns);
320 
321  //- Define cellZone selection matcher
322  void cellZoneSelection(List<wordRe>&& patterns);
323 
324 
325  // Output
326 
327  //- Report values
328  void print(Ostream& os) const;
329 };
330 
331 
332 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 
334 } // End namespace Foam
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 #include "ensightMeshI.H"
339 
340 #endif
341 
342 // ************************************************************************* //
Foam::ensightMesh::options::useCellZones
bool useCellZones() const
Using cellZones?
Definition: ensightMeshOptions.C:93
wordRes.H
Foam::ensightMesh::options::useBoundaryMesh
bool useBoundaryMesh() const
Using boundary?
Definition: ensightMeshOptions.C:87
Foam::ensightMesh
Encapsulation of volume meshes for writing in ensight format. It manages cellZones,...
Definition: ensightMesh.H:82
Foam::ensightMesh::needsUpdate
bool needsUpdate() const
Does the content need an update?
Definition: ensightMeshI.H:78
ensightFaces.H
Foam::ensightMesh::correct
void correct()
Update for new mesh.
Definition: ensightMesh.C:124
Foam::ensightMesh::boundaryParts
const Map< ensightFaces > & boundaryParts() const
Face elements per selected patch, lookup by patch index.
Definition: ensightMeshI.H:57
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
Foam::ensightMesh::options::faceZoneSelection
const wordRes & faceZoneSelection() const
Selection of faceZones. Empty if unspecified.
Definition: ensightMeshOptions.C:282
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: lumpedPointController.H:69
Foam::ensightMesh::write
void write(autoPtr< ensightGeoFile > &os, bool parallel=Pstream::parRun()) const
Write geometry to file. Normally in parallel.
Definition: ensightMeshI.H:107
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::ensightMesh::options::useFaceZones
bool useFaceZones() const
Using faceZones?
Definition: ensightMeshOptions.C:99
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::useInternalMesh
bool useInternalMesh() const
Using internal?
Definition: ensightMeshOptions.C:81
Foam::ensightMesh::options::cellZoneSelection
const wordRes & cellZoneSelection() const
Selection of faceZones. Empty if unspecified.
Definition: ensightMeshOptions.C:288
Foam::ensightMesh::size
label size() const
Number of parts.
Definition: ensightMeshI.H:95
Foam::ensightMesh::empty
bool empty() const
Any parts?
Definition: ensightMeshI.H:84
Foam::ensightMesh::expire
bool expire()
Mark as needing an update.
Definition: ensightMeshI.H:63
Foam::ensightMesh::options::reset
void reset()
Reset to defaults.
Definition: ensightMeshOptions.C:105
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:75
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:270
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:213
Foam::List< wordRe >
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:294
Foam::ensightMesh::cellZoneParts
const Map< ensightCells > & cellZoneParts() const
Face elements per selected patch, lookup by patch index.
Definition: ensightMeshI.H:43
Foam::ensightMesh::faceZoneParts
const Map< ensightFaces > & faceZoneParts() const
Face elements per faceZone, lookup by zone index.
Definition: ensightMeshI.H:50
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::ensightMesh::option
const ensightMesh::options & option() const
Reference to the writer/mesh options.
Definition: ensightMeshI.H:36
Foam::ensightMesh::mesh
const polyMesh & mesh() const
Reference to the underlying polyMesh.
Definition: ensightMeshI.H:30
Foam::ensightMesh::options::options
options()
Default construct. Non-lazy with internal/boundary/cellZones.
Definition: ensightMeshOptions.C:60
Foam::ensightMesh::options::patchExclude
const wordRes & patchExclude() const
Selection of black listed patches. Empty if unspecified.
Definition: ensightMeshOptions.C:276
ensightCells.H