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-2021 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::ZoneMesh
29 
30 Description
31  A list of mesh zones.
32 
33 SourceFiles
34  ZoneMesh.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef ZoneMesh_H
39 #define 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 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 template<class ZoneType, class MeshType> class ZoneMesh;
56 
57 template<class ZoneType, class MeshType>
58 Ostream& operator<<(Ostream& os, const ZoneMesh<ZoneType, MeshType>& zones);
59 
60 
61 /*---------------------------------------------------------------------------*\
62  Class ZoneMesh Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class ZoneType, class MeshType>
66 class 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 read();
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 
104 public:
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
113  ZoneMesh
114  (
115  const IOobject& io,
116  const MeshType& mesh
117  );
118 
119  //- Construct given size
120  ZoneMesh
121  (
122  const IOobject& io,
123  const MeshType& mesh,
124  const label size
125  );
126 
127  //- Construct given a PtrList
128  ZoneMesh
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 zone names satisfying the input matcher
163  wordList names(const wordRe& matcher) const;
164 
165  //- A list of zone names satisfying the input matchers
166  wordList names(const wordRes& matcher) const;
167 
168  //- Sorted list of the zone names
169  wordList sortedNames() const;
170 
171  //- Sorted list of zone names satisfying the input matcher
172  wordList sortedNames(const wordRe& matcher) const;
173 
174  //- Sorted list of zone names satisfying the input matchers
175  wordList sortedNames(const wordRes& matcher) const;
176 
177 
178  //- Return (sorted) zone indices for all matches
179  // Optionally matches zone groups.
180  // A no-op (returns empty list) for an empty matcher
182  (
183  const wordRe& matcher,
184  const bool useGroups = true
185  ) const;
186 
187  //- Return (sorted) zone indices for all matches
188  // Optionally matches zone groups.
189  // A no-op (returns empty list) for an empty matcher
191  (
192  const wordRes& matcher,
193  const bool useGroups = true
194  ) const;
195 
196  //- Zone index for the first match, return -1 if not found
197  // A no-op (returns -1) for an empty key
198  label findIndex(const wordRe& key) const;
199 
200  //- Zone index for the first match, return -1 if not found
201  // A no-op (returns -1) for an empty matcher
202  label findIndex(const wordRes& matcher) const;
203 
204  //- Find zone index by name, return -1 if not found
205  // A no-op (returns -1) for an empty zoneName
206  label findZoneID(const word& zoneName) const;
207 
208  //- Find zone by name and return const pointer, nullptr on error
209  // A no-op (returns nullptr) for an empty zoneName
210  const ZoneType* cfindZone(const word& zoneName) const;
211 
212  //- Find zone by name and return pointer, nullptr on error
213  // A no-op (returns nullptr) for an empty zoneName
214  ZoneType* findZone(const word& zoneName);
215 
216 
217  //- Return all elements (cells, faces, points) contained in the
218  //- listed zones.
219  // The bitSet is empty (zero-size) if there are no elements matched
220  // anywhere.
221  bitSet selection(const labelUList& zoneIds) const;
222 
223  //- Return all elements (cells, faces, points) that match the zone
224  //- specification as a bitSet.
225  // The bitSet is empty (zero-size) if there are no elements matched
226  // anywhere.
227  // Optionally matches zoneGroups.
228  // A no-op (returns empty bitSet) for an empty matcher
230  (
231  const wordRe& matcher,
232  const bool useGroups = true
233  ) const;
234 
235  //- Return all elements (cells, faces, points) that match the zone
236  //- specification as a bitSet.
237  // The bitSet is empty (zero-size) if there are no elements matched
238  // anywhere.
239  // A no-op (returns empty bitSet) for an empty matcher
241  (
242  const wordRes& matcher,
243  const bool useGroups = true
244  ) const;
245 
246  //- The zone indices per zone group
247  const HashTable<labelList>& groupZoneIDs() const;
248 
249  //- Set/add group with zones
250  void setGroup(const word& groupName, const labelUList& zoneIDs);
251 
252  //- Check zone definition. Return true if in error.
253  bool checkDefinition(const bool report = false) const;
254 
255  //- Check whether all procs have all zones and in same order.
256  // \return True if any errors.
257  bool checkParallelSync(const bool report = false) const;
258 
259  //- Correct zone mesh after moving points
260  void movePoints(const pointField& pts);
261 
262 
263  // Storage Management
264 
265  //- Clear addressing
266  void clearAddressing();
267 
268  //- Clear the zones
269  void clear();
270 
271  bool hasFaceAreas() const { return bool(zoneMapPtr_); }
272 
273 
274  // Member Operators
275 
276  //- Return const and non-const reference to zone by index.
278 
279  //- Return const reference to zone by name.
280  // Fatal if the zone does not exist.
281  const ZoneType& operator[](const word& zoneName) const;
282 
283  //- Return reference to an existing zone by name
284  // Fatal if the zone does not exist.
285  ZoneType& operator[](const word& zoneName);
286 
287  //- Find an existing zone by name or create a new empty one
288  //- if required.
289  //
290  // To determine if the zone already existed or was newly created,
291  // it will be necessary to add additional logic in the caller.
292  // For example,
293  // \code
294  // const label nOrig = zones.size();
295  //
296  // ZoneType& zn = zones("zoneName");
297  //
298  // if (nOrig == zones.size()) { existing... } else { new... }
299  // \endcode
300  // \param zoneName the name of the zone
301  // \param verbose report if an existing zone was selected or
302  // a new zone was created.
303  // \return non-const reference to the existing or new zone
304  ZoneType& operator()(const word& zoneName, const bool verbose=false);
305 
306 
307  // IO
308 
309  //- Update internal meta-data (eg, prior to writing)
310  void updateMetaData();
311 
312  //- The writeData member function required by regIOobject
313  bool writeData(Ostream& os) const;
314 
315 
316  // Ostream Operator
317 
318  friend Ostream& operator<< <ZoneType, MeshType>
319  (
320  Ostream& os,
321  const ZoneMesh<ZoneType, MeshType>& zones
322  );
323 
324 
325  // Housekeeping
326 
327  //- Identical to the indices() method (AUG-2018)
328  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
329  labelList findIndices(const wordRes& key) const
330  {
331  return indices(key);
332  }
333 };
334 
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 } // End namespace Foam
339 
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 
342 #ifdef NoRepository
343  #include "ZoneMesh.C"
344 #endif
345 
346 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
347 
348 #endif
349 
350 // ************************************************************************* //
Foam::ZoneMesh::zoneMap
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
Definition: ZoneMesh.C:276
ZoneMesh.C
regIOobject.H
Foam::ZoneMesh::checkDefinition
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: ZoneMesh.C:733
wordRes.H
Foam::ZoneMesh::clear
void clear()
Clear the zones.
Definition: ZoneMesh.C:724
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::ZoneMesh::writeData
bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
Definition: ZoneMesh.C:856
Foam::ZoneMesh::findIndex
label findIndex(const wordRe &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:491
Foam::ZoneMesh::cfindZone
const ZoneType * cfindZone(const word &zoneName) const
Find zone by name and return const pointer, nullptr on error.
Definition: ZoneMesh.C:553
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::ZoneMesh::mesh
const MeshType & mesh() const noexcept
Return the mesh reference.
Definition: ZoneMesh.H:142
Foam::ZoneMesh::groupZoneIDs
const HashTable< labelList > & groupZoneIDs() const
The zone indices per zone group.
Definition: ZoneMesh.C:653
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::Map< label >
bitSet.H
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
zoneIDs
const labelIOList & zoneIDs
Definition: correctPhi.H:59
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Map.H
Foam::ZoneMesh::~ZoneMesh
~ZoneMesh()
Destructor.
Definition: ZoneMesh.C:266
Foam::ZoneMesh::setGroup
void setGroup(const word &groupName, const labelUList &zoneIDs)
Set/add group with zones.
Definition: ZoneMesh.C:666
Foam::ZoneMesh::movePoints
void movePoints(const pointField &pts)
Correct zone mesh after moving points.
Definition: ZoneMesh.C:828
Foam::Field< vector >
Foam::ZoneMesh
A list of mesh zones.
Definition: cellZoneMeshFwd.H:44
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::ZoneMesh::whichZone
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
Definition: ZoneMesh.C:289
HashSet.H
Foam::ZoneMesh::findIndices
labelList findIndices(const wordRes &key) const
Identical to the indices() method (AUG-2018)
Definition: ZoneMesh.H:328
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
Definition: ZoneMesh.C:519
Foam::ZoneMesh::indices
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) zone indices for all matches.
Definition: ZoneMesh.C:371
Foam::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:305
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
pointField.H
Foam::ZoneMesh::sortedNames
wordList sortedNames() const
Sorted list of the zone names.
Definition: ZoneMesh.C:333
Foam::List< word >
Foam::UList< label >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
bool
bool
Definition: EEqn.H:20
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
Foam::ZoneMesh::updateMetaData
void updateMetaData()
Update internal meta-data (eg, prior to writing)
Definition: ZoneMesh.C:840
PtrList.H
Foam::ZoneMesh::disallowGenericZones
static int disallowGenericZones
Debug switch to disallow the use of generic zones.
Definition: ZoneMesh.H:106
Foam::ZoneMesh::operator[]
const ZoneType & operator[](const word &zoneName) const
Return const reference to zone by name.
Definition: ZoneMesh.C:867
Foam::ZoneMesh::selection
bitSet selection(const labelUList &zoneIds) const
Definition: ZoneMesh.C:599
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::ZoneMesh::clearAddressing
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:709
Foam::ZoneMesh::hasFaceAreas
bool hasFaceAreas() const
Definition: ZoneMesh.H:270
Foam::ZoneMesh::findZone
ZoneType * findZone(const word &zoneName)
Find zone by name and return pointer, nullptr on error.
Definition: ZoneMesh.C:589
Foam::ZoneMesh::checkParallelSync
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order.
Definition: ZoneMesh.C:752
Foam::ZoneMesh::operator()
ZoneType & operator()(const word &zoneName, const bool verbose=false)
Definition: ZoneMesh.C:907
Foam::ZoneMesh::types
wordList types() const
Return a list of zone types.
Definition: ZoneMesh.C:298