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-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::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 "List.H"
42 #include "regIOobject.H"
43 #include "pointField.H"
44 #include "Map.H"
45 #include "bitSet.H"
46 #include "wordRes.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 
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  //- Map of zone labels for given element
77  mutable Map<label>* zoneMapPtr_;
78 
79 
80  // Private Member Functions
81 
82  //- Read if IOobject flags set. Return true if read.
83  bool read();
84 
85  //- Create zone map
86  void calcZoneMap() const;
87 
88  //- Templated implementation for names()
89  template<class UnaryMatchPredicate>
90  static wordList namesImpl
91  (
92  const PtrList<ZoneType>& list,
93  const UnaryMatchPredicate& matcher,
94  const bool doSort
95  );
96 
97  //- Templated implementation for indices()
98  template<class UnaryMatchPredicate>
99  static labelList indicesImpl
100  (
101  const PtrList<ZoneType>& list,
102  const UnaryMatchPredicate& matcher
103  );
104 
105  //- Templated implementation for findIndex()
106  template<class UnaryMatchPredicate>
107  static label findIndexImpl
108  (
109  const PtrList<ZoneType>& list,
110  const UnaryMatchPredicate& matcher
111  );
112 
113 
114  //- No copy construct
115  ZoneMesh(const ZoneMesh&) = delete;
116 
117  //- No copy assignment
118  void operator=(const ZoneMesh<ZoneType, MeshType>&) = delete;
119 
120 
121 public:
122 
123  //- Debug switch to disallow the use of generic zones
124  static int disallowGenericZones;
125 
126 
127  // Constructors
128 
129  //- Read constructor given IOobject and a MeshType reference
130  ZoneMesh
131  (
132  const IOobject& io,
133  const MeshType& mesh
134  );
135 
136  //- Construct given size
137  ZoneMesh
138  (
139  const IOobject& io,
140  const MeshType& mesh,
141  const label size
142  );
143 
144  //- Construct given a PtrList
145  ZoneMesh
146  (
147  const IOobject& io,
148  const MeshType& mesh,
149  const PtrList<ZoneType>& pzm
150  );
151 
152 
153  //- Destructor
154  ~ZoneMesh();
155 
156 
157  // Member Functions
158 
159  //- Return the mesh reference
160  const MeshType& mesh() const
161  {
162  return mesh_;
163  }
164 
165  //- Map of zones containing zone index for all zoned elements
166  // Return -1 if the object is not in the zone
167  const Map<label>& zoneMap() const;
168 
169  //- Given a global object index, return the zone it is in.
170  // If object does not belong to any zones, return -1
171  label whichZone(const label objectIndex) const;
172 
173  //- Return a list of zone types
174  wordList types() const;
175 
176  //- A list of the zone names
177  wordList names() const;
178 
179  //- A list of zone names satisfying the input matcher
180  wordList names(const wordRe& matcher) const;
181 
182  //- A list of zone names satisfying the input matchers
183  wordList names(const wordRes& matcher) const;
184 
185  //- Sorted list of the zone names
186  wordList sortedNames() const;
187 
188  //- Sorted list of zone names satisfying the input matcher
189  wordList sortedNames(const wordRe& matcher) const;
190 
191  //- Sorted list of zone names satisfying the input matchers
192  wordList sortedNames(const wordRes& matcher) const;
193 
194 
195  //- Return zone indices for all matches
196  // A no-op (returns empty list) for an empty key
197  labelList indices(const keyType& key) const;
198 
199  //- Return zone indices for all matches
200  // A no-op (returns empty list) for an empty matcher
201  labelList indices(const wordRes& matcher) const;
202 
203  //- Zone index for the first match, return -1 if not found
204  // A no-op (returns -1) for an empty key
205  label findIndex(const keyType& key) const;
206 
207  //- Zone index for the first match, return -1 if not found
208  // A no-op (returns -1) for an empty matcher
209  label findIndex(const wordRes& matcher) const;
210 
211  //- Find zone index by name, return -1 if not found
212  // A no-op (returns -1) for an empty zoneName
213  label findZoneID(const word& zoneName) const;
214 
215  //- Find zone by name and return const pointer, nullptr on error
216  // A no-op (returns nullptr) for an empty zoneName
217  const ZoneType* cfindZone(const word& zoneName) const;
218 
219  //- Find zone by name and return pointer, nullptr on error
220  // A no-op (returns nullptr) for an empty zoneName
221  ZoneType* findZone(const word& zoneName);
222 
223 
224  //- Return all elements (cells, faces, points) contained in the
225  //- listed zones.
226  // The bitSet is empty (zero-size) if there are no elements matched
227  // anywhere.
228  bitSet selection(const labelUList& zoneIds) const;
229 
230  //- Return all elements (cells, faces, points) that match the zone
231  //- specification as a bitSet.
232  // The bitSet is empty (zero-size) if there are no elements matched
233  // anywhere.
234  // A no-op (returns empty bitSet) for an empty key
235  bitSet selection(const keyType& key) const;
236 
237  //- Return all elements (cells, faces, points) that match the zone
238  //- specification as a bitSet.
239  // The bitSet is empty (zero-size) if there are no elements matched
240  // anywhere.
241  // A no-op (returns empty bitSet) for an empty matcher
242  bitSet selection(const wordRes& matcher) const;
243 
244 
245  //- Clear addressing
246  void clearAddressing();
247 
248  //- Clear the zones
249  void clear();
250 
251  //- Check zone definition. Return true if in error.
252  bool checkDefinition(const bool report = false) const;
253 
254  //- Check whether all procs have all zones and in same order.
255  // \return True if any errors.
256  bool checkParallelSync(const bool report = false) const;
257 
258  //- Correct zone mesh after moving points
259  void movePoints(const pointField& pts);
260 
261  //- writeData member function required by regIOobject
262  bool writeData(Ostream& os) const;
263 
264 
265  // Member Operators
266 
267  //- Return const and non-const reference to zone by index.
269 
270  //- Return const reference to zone by name.
271  // Fatal if the zone does not exist.
272  const ZoneType& operator[](const word& zoneName) const;
273 
274  //- Return reference to an existing zone by name
275  // Fatal if the zone does not exist.
276  ZoneType& operator[](const word& zoneName);
277 
278  //- Find an existing zone by name or create a new empty one
279  //- if required.
280  //
281  // To determine if the zone already existed or was newly created,
282  // it will be necessary to add additional logic in the caller.
283  // For example,
284  // \code
285  // const label nOrig = zones.size();
286  //
287  // ZoneType& zn = zones("zoneName");
288  //
289  // if (nOrig == zones.size()) { existing... } else { new... }
290  // \endcode
291  // \param zoneName the name of the zone
292  // \param verbose report if an existing zone was selected or
293  // a new zone was created.
294  // \return non-const reference to the existing or new zone
295  ZoneType& operator()(const word& zoneName, const bool verbose=false);
296 
297 
298  // Ostream Operator
299 
300  friend Ostream& operator<< <ZoneType, MeshType>
301  (
302  Ostream& os,
303  const ZoneMesh<ZoneType, MeshType>& zones
304  );
305 
306 
307  // Housekeeping
308 
309  //- Identical to the indices() method (AUG-2018)
310  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
311  labelList findIndices(const keyType& key) const
312  {
313  return indices(key);
314  }
315 };
316 
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 } // End namespace Foam
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #ifdef NoRepository
325  #include "ZoneMesh.C"
326 #endif
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
330 #endif
331 
332 // ************************************************************************* //
Foam::ZoneMesh::zoneMap
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
Definition: ZoneMesh.C:302
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:638
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
wordRes.H
Foam::ZoneMesh::clear
void clear()
Clear the zones.
Definition: ZoneMesh.C:629
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
List.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::ZoneMesh::writeData
bool writeData(Ostream &os) const
writeData member function required by regIOobject
Definition: ZoneMesh.C:745
Foam::ZoneMesh::cfindZone
const ZoneType * cfindZone(const word &zoneName) const
Find zone by name and return const pointer, nullptr on error.
Definition: ZoneMesh.C:518
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
Return the mesh reference.
Definition: ZoneMesh.H:159
Foam::Map< label >
Foam::ZoneMesh::findIndex
label findIndex(const keyType &key) const
Zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:449
bitSet.H
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:72
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.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:292
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
Foam::ZoneMesh::movePoints
void movePoints(const pointField &pts)
Correct zone mesh after moving points.
Definition: ZoneMesh.C:733
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:62
Foam::ZoneMesh::findIndices
labelList findIndices(const keyType &key) const
Identical to the indices() method (AUG-2018)
Definition: ZoneMesh.H:310
Foam::ZoneMesh::whichZone
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
Definition: ZoneMesh.C:315
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:484
Foam::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:340
pointField.H
Foam::ZoneMesh::sortedNames
wordList sortedNames() const
Sorted list of the zone names.
Definition: ZoneMesh.C:377
Foam::List< word >
Foam::UList< label >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
Foam::ZoneMesh::disallowGenericZones
static int disallowGenericZones
Debug switch to disallow the use of generic zones.
Definition: ZoneMesh.H:123
Foam::ZoneMesh::operator[]
const ZoneType & operator[](const word &zoneName) const
Return const reference to zone by name.
Definition: ZoneMesh.C:756
Foam::ZoneMesh::selection
bitSet selection(const labelUList &zoneIds) const
Definition: ZoneMesh.C:564
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:615
Foam::ZoneMesh::indices
labelList indices(const keyType &key) const
Return zone indices for all matches.
Definition: ZoneMesh.C:409
Foam::ZoneMesh::findZone
ZoneType * findZone(const word &zoneName)
Find zone by name and return pointer, nullptr on error.
Definition: ZoneMesh.C:554
Foam::ZoneMesh::checkParallelSync
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order.
Definition: ZoneMesh.C:657
Foam::ZoneMesh::operator()
ZoneType & operator()(const word &zoneName, const bool verbose=false)
Definition: ZoneMesh.C:796
Foam::ZoneMesh::types
wordList types() const
Return a list of zone types.
Definition: ZoneMesh.C:324