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-2018 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  labelList indices(const keyType& key) const;
197 
198  //- Return zone indices for all matches
199  labelList indices(const wordRes& matcher) const;
200 
201 
202  //- Return zone index for the first match, return -1 if not found
203  label findIndex(const keyType& key) const;
204 
205  //- Return zone index for the first match, return -1 if not found
206  label findIndex(const wordRes& matcher) const;
207 
208 
209  //- Find zone index given a name, return -1 if not found
210  label findZoneID(const word& zoneName) const;
211 
212 
213  //- Return all elements (cells, faces, points) contained in the
214  //- listed zones.
215  // The bitSet is empty (zero-size) if there are no elements matched
216  // anywhere.
217  bitSet selection(const labelUList& zoneIds) const;
218 
219  //- Return all elements (cells, faces, points) that match the zone
220  //- specification as a bitSet.
221  // The bitSet is empty (zero-size) if there are no elements matched
222  // anywhere.
223  bitSet selection(const keyType& key) const;
224 
225  //- Return all elements (cells, faces, points) that match the zone
226  //- specification as a bitSet.
227  // The bitSet is empty (zero-size) if there are no elements matched
228  // anywhere.
229  bitSet selection(const wordRes& matcher) const;
230 
231 
232  //- Lookup zone by name and return const pointer, nullptr on error.
233  const ZoneType* zonePtr(const word& zoneName) const;
234 
235  //- Lookup zone by name and return pointer, nullptr on error.
236  ZoneType* zonePtr(const word& zoneName);
237 
238 
239  //- Clear addressing
240  void clearAddressing();
241 
242  //- Clear the zones
243  void clear();
244 
245  //- Check zone definition. Return true if in error.
246  bool checkDefinition(const bool report = false) const;
247 
248  //- Check whether all procs have all zones and in same order.
249  // \return True if any errors.
250  bool checkParallelSync(const bool report = false) const;
251 
252  //- Correct zone mesh after moving points
253  void movePoints(const pointField& pts);
254 
255  //- writeData member function required by regIOobject
256  bool writeData(Ostream& os) const;
257 
258 
259  // Member Operators
260 
261  //- Return const and non-const reference to zone by index.
263 
264  //- Return const reference to zone by name.
265  // Fatal if the zone does not exist.
266  const ZoneType& operator[](const word& zoneName) const;
267 
268  //- Return reference to an existing zone by name
269  // Fatal if the zone does not exist.
270  ZoneType& operator[](const word& zoneName);
271 
272  //- Find an existing zone by name or create a new empty one
273  //- if required.
274  //
275  // To determine if the zone already existed or was newly created,
276  // it will be necessary to add additional logic in the caller.
277  // For example,
278  // \code
279  // const label nOrig = zones.size();
280  //
281  // ZoneType& zn = zones("zoneName");
282  //
283  // if (nOrig == zones.size()) { existing... } else { new... }
284  // \endcode
285  // \param zoneName the name of the zone
286  // \param verbose report if an existing zone was selected or
287  // a new zone was created.
288  // \return non-const reference to the existing or new zone
289  ZoneType& operator()(const word& zoneName, const bool verbose=false);
290 
291 
292  // Ostream operator
293 
294  friend Ostream& operator<< <ZoneType, MeshType>
295  (
296  Ostream& os,
297  const ZoneMesh<ZoneType, MeshType>& zones
298  );
299 
300 
301  // Housekeeping
302 
303  //- Identical to the indices() method (AUG-2018)
304  labelList findIndices(const keyType& key) const
305  {
306  return indices(key);
307  }
308 };
309 
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 } // End namespace Foam
314 
315 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 
317 #ifdef NoRepository
318  #include "ZoneMesh.C"
319 #endif
320 
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 
323 #endif
324 
325 // ************************************************************************* //
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:644
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
wordRes.H
Foam::ZoneMesh::clear
void clear()
Clear the zones.
Definition: ZoneMesh.C:635
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:751
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
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
Return 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
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::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::ZoneMesh::movePoints
void movePoints(const pointField &pts)
Correct zone mesh after moving points.
Definition: ZoneMesh.C:739
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:65
Foam::ZoneMesh::findIndices
labelList findIndices(const keyType &key) const
Identical to the indices() method (AUG-2018)
Definition: ZoneMesh.H:303
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 given a 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::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:762
Foam::ZoneMesh::selection
bitSet selection(const labelUList &zoneIds) const
Definition: ZoneMesh.C:528
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:621
Foam::ZoneMesh::indices
labelList indices(const keyType &key) const
Return zone indices for all matches.
Definition: ZoneMesh.C:409
Foam::ZoneMesh::zonePtr
const ZoneType * zonePtr(const word &zoneName) const
Lookup zone by name and return const pointer, nullptr on error.
Definition: ZoneMesh.C:578
Foam::ZoneMesh::checkParallelSync
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order.
Definition: ZoneMesh.C:663
Foam::ZoneMesh::operator()
ZoneType & operator()(const word &zoneName, const bool verbose=false)
Definition: ZoneMesh.C:802
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
Foam::ZoneMesh::types
wordList types() const
Return a list of zone types.
Definition: ZoneMesh.C:324