ZoneMesh.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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::ZoneMesh
29
30Description
31 A list of mesh zones.
32
33SourceFiles
34 ZoneMesh.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_ZoneMesh_H
39#define Foam_ZoneMesh_H
40
41#include "regIOobject.H"
42#include "pointField.H"
43#include "Map.H"
44#include "HashSet.H"
45#include "PtrList.H"
46#include "bitSet.H"
47#include "wordRes.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55template<class ZoneType, class MeshType> class ZoneMesh;
56
57template<class ZoneType, class MeshType>
59
60
61/*---------------------------------------------------------------------------*\
62 Class ZoneMesh Declaration
63\*---------------------------------------------------------------------------*/
64
65template<class ZoneType, class MeshType>
66class ZoneMesh
67:
68 public PtrList<ZoneType>,
69 public regIOobject
70{
71 // Private Data
72
73 //- Reference to mesh
74 const MeshType& mesh_;
75
76 //- Demand-driven: map of zone labels for given element
77 mutable autoPtr<Map<label>> zoneMapPtr_;
78
79 //- Demand-driven: list of zone ids per group
80 mutable autoPtr<HashTable<labelList>> groupIDsPtr_;
81
82
83 // Private Member Functions
84
85 //- Read if IOobject flags set. Return true if read.
86 bool readContents();
87
88 //- Create zone map
89 void calcZoneMap() const;
90
91 //- Some zones have inGroup entries
92 bool hasGroupIDs() const;
93
94 //- Calculate group name to zone ids lookup
95 void calcGroupIDs() const;
96
97 //- No copy construct
98 ZoneMesh(const ZoneMesh&) = delete;
99
100 //- No copy assignment
101 void operator=(const ZoneMesh<ZoneType, MeshType>&) = delete;
102
103
104public:
105
106 //- Debug switch to disallow the use of generic zones
107 static int disallowGenericZones;
108
109
110 // Constructors
111
112 //- Read constructor given IOobject and a MeshType reference
114 (
115 const IOobject& io,
116 const MeshType& mesh
117 );
118
119 //- Construct given size
121 (
122 const IOobject& io,
123 const MeshType& mesh,
124 const label size
125 );
126
127 //- Construct given a PtrList
129 (
130 const IOobject& io,
131 const MeshType& mesh,
132 const PtrList<ZoneType>& pzm
133 );
134
135
136 //- Destructor
137 ~ZoneMesh();
138
139
140 // Member Functions
141
142 //- Return the mesh reference
143 const MeshType& mesh() const noexcept
144 {
145 return mesh_;
146 }
147
148 //- Map of zones containing zone index for all zoned elements
149 // Return -1 if the object is not in the zone
150 const Map<label>& zoneMap() const;
151
152 //- Given a global object index, return the zone it is in.
153 // If object does not belong to any zones, return -1
154 label whichZone(const label objectIndex) const;
155
156 //- Return a list of zone types
157 wordList types() const;
158
159 //- A list of the zone names
160 wordList names() const;
161
162 //- A list of the zone group names (if any)
163 wordList groupNames() const;
164
165 //- A list of zone names satisfying the input matcher
166 wordList names(const wordRe& matcher) const;
167
168 //- A list of zone names satisfying the input matchers
169 wordList names(const wordRes& matcher) const;
170
171 //- Sorted list of the zone names
172 wordList sortedNames() const;
173
174 //- Sorted list of zone names satisfying the input matcher
175 wordList sortedNames(const wordRe& matcher) const;
176
177 //- Sorted list of zone names satisfying the input matchers
178 wordList sortedNames(const wordRes& matcher) const;
179
180
181 //- Return (sorted) zone indices for all matches
182 // Optionally matches zone groups.
183 // A no-op (returns empty list) for an empty matcher
185 (
186 const wordRe& matcher,
187 const bool useGroups = true
188 ) const;
189
190 //- Return (sorted) zone indices for all matches
191 // Optionally matches zone groups.
192 // A no-op (returns empty list) for an empty matcher
194 (
195 const wordRes& matcher,
196 const bool useGroups = true
197 ) const;
198
199 //- Zone index for the first match, return -1 if not found
200 // A no-op (returns -1) for an empty key
201 label findIndex(const wordRe& key) const;
202
203 //- Zone index for the first match, return -1 if not found
204 // A no-op (returns -1) for an empty matcher
205 label findIndex(const wordRes& matcher) const;
206
207 //- Find zone index by name, return -1 if not found
208 // A no-op (returns -1) for an empty zoneName
209 label findZoneID(const word& zoneName) const;
210
211 //- Find zone by name and return const pointer, nullptr on error
212 // A no-op (returns nullptr) for an empty zoneName
213 const ZoneType* cfindZone(const word& zoneName) const;
214
215 //- Find zone by name and return pointer, nullptr on error
216 // A no-op (returns nullptr) for an empty zoneName
217 ZoneType* findZone(const word& zoneName);
218
219
220 //- Return all elements (cells, faces, points) contained in the
221 //- listed zones.
222 // The bitSet is empty (zero-size) if there are no elements matched
223 // anywhere.
224 bitSet selection(const labelUList& zoneIds) const;
225
226 //- Return all elements (cells, faces, points) that match the zone
227 //- specification as a bitSet.
228 // The bitSet is empty (zero-size) if there are no elements matched
229 // anywhere.
230 // Optionally matches zoneGroups.
231 // A no-op (returns empty bitSet) for an empty matcher
233 (
234 const wordRe& matcher,
235 const bool useGroups = true
236 ) const;
237
238 //- Return all elements (cells, faces, points) that match the zone
239 //- specification as a bitSet.
240 // The bitSet is empty (zero-size) if there are no elements matched
241 // anywhere.
242 // A no-op (returns empty bitSet) for an empty matcher
244 (
245 const wordRes& matcher,
246 const bool useGroups = true
247 ) const;
248
249 //- The zone indices per zone group
250 const HashTable<labelList>& groupZoneIDs() const;
251
252 //- Set/add group with zones
253 void setGroup(const word& groupName, const labelUList& zoneIDs);
254
255 //- Check zone definition. Return true if in error.
256 bool checkDefinition(const bool report = false) const;
257
258 //- Check whether all procs have all zones and in same order.
259 // \return True if any errors.
260 bool checkParallelSync(const bool report = false) const;
261
262 //- Correct zone mesh after moving points
263 void movePoints(const pointField& pts);
264
265
266 // Storage Management
267
268 //- Clear addressing
269 void clearAddressing();
270
271 //- Clear the zones
272 void clear();
274 bool hasFaceAreas() const { return bool(zoneMapPtr_); }
275
276
277 // Member Operators
278
279 //- Return const and non-const reference to zone by index.
280 using PtrList<ZoneType>::operator[];
281
282 //- Return const reference to zone by name.
283 // Fatal if the zone does not exist.
284 const ZoneType& operator[](const word& zoneName) const;
285
286 //- Return reference to an existing zone by name
287 // Fatal if the zone does not exist.
288 ZoneType& operator[](const word& zoneName);
289
290 //- Find an existing zone by name or create a new empty one
291 //- if required.
292 //
293 // To determine if the zone already existed or was newly created,
294 // it will be necessary to add additional logic in the caller.
295 // For example,
296 // \code
297 // const label nOrig = zones.size();
298 //
299 // ZoneType& zn = zones("zoneName");
300 //
301 // if (nOrig == zones.size()) { existing... } else { new... }
302 // \endcode
303 // \param zoneName the name of the zone
304 // \param verbose report if an existing zone was selected or
305 // a new zone was created.
306 // \return non-const reference to the existing or new zone
307 ZoneType& operator()(const word& zoneName, const bool verbose=false);
308
309
310 // IO
311
312 //- Update internal meta-data (eg, prior to writing)
313 void updateMetaData();
314
315 //- The writeData member function required by regIOobject
316 bool writeData(Ostream& os) const;
317
318
319 // Ostream Operator
321 friend Ostream& operator<< <ZoneType, MeshType>
322 (
323 Ostream& os,
325 );
326
327
328 // Housekeeping
329
330 //- Identical to the indices() method (AUG-2018)
331 FOAM_DEPRECATED_FOR(2018-08, "indices() method")
332 labelList findIndices(const wordRes& key) const
333 {
334 return indices(key);
335 }
336};
337
338
339// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340
341} // End namespace Foam
342
343// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344
345#ifdef NoRepository
346 #include "ZoneMesh.C"
347#endif
348
349// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
350
351#endif
352
353// ************************************************************************* //
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
A list of mesh zones.
Definition: ZoneMesh.H:69
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: ZoneMesh.C:739
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
Definition: ZoneMesh.C:525
friend Ostream & operator(Ostream &os, const ZoneMesh< ZoneType, MeshType > &zones)
wordList sortedNames() const
Sorted list of the zone names.
Definition: ZoneMesh.C:339
void setGroup(const word &groupName, const labelUList &zoneIDs)
Set/add group with zones.
Definition: ZoneMesh.C:672
wordList types() const
Return a list of zone types.
Definition: ZoneMesh.C:297
bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
Definition: ZoneMesh.C:866
bool hasFaceAreas() const
Definition: ZoneMesh.H:273
ZoneType * findZone(const word &zoneName)
Find zone by name and return pointer, nullptr on error.
Definition: ZoneMesh.C:595
const ZoneType * cfindZone(const word &zoneName) const
Find zone by name and return const pointer, nullptr on error.
Definition: ZoneMesh.C:559
const MeshType & mesh() const noexcept
Return the mesh reference.
Definition: ZoneMesh.H:142
void updateMetaData()
Update internal meta-data (eg, prior to writing)
Definition: ZoneMesh.C:850
labelList findIndices(const wordRes &key) const
Identical to the indices() method (AUG-2018)
Definition: ZoneMesh.H:331
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
Definition: ZoneMesh.C:275
static int disallowGenericZones
Debug switch to disallow the use of generic zones.
Definition: ZoneMesh.H:106
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:715
bitSet selection(const labelUList &zoneIds) const
Definition: ZoneMesh.C:605
const ZoneType & operator[](const word &zoneName) const
Return const reference to zone by name.
Definition: ZoneMesh.C:877
~ZoneMesh()
Destructor.
Definition: ZoneMesh.C:265
void movePoints(const pointField &pts)
Correct zone mesh after moving points.
Definition: ZoneMesh.C:838
void clear()
Clear the zones.
Definition: ZoneMesh.C:730
wordList groupNames() const
A list of the zone group names (if any)
Definition: ZoneMesh.C:311
const HashTable< labelList > & groupZoneIDs() const
The zone indices per zone group.
Definition: ZoneMesh.C:659
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
Definition: ZoneMesh.C:288
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:304
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order.
Definition: ZoneMesh.C:758
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) zone indices for all matches.
Definition: ZoneMesh.C:377
ZoneType & operator()(const word &zoneName, const bool verbose=false)
Definition: ZoneMesh.C:917
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:497
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:83
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
bool
Definition: EEqn.H:20
OBJstream os(runTime.globalPath()/outputName)
const labelIOList & zoneIDs
Definition: correctPhi.H:59
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
const direction noexcept
Definition: Scalar.H:223
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52