polyBoundaryMesh.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-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2023 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::polyBoundaryMesh
29 
30 Description
31  A polyBoundaryMesh is a polyPatch list with additional search methods
32  and registered IO.
33 
34 SourceFiles
35  polyBoundaryMesh.C
36  polyBoundaryMeshTemplates.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Foam_polyBoundaryMesh_H
41 #define Foam_polyBoundaryMesh_H
42 
43 #include "regIOobject.H"
44 #include "polyPatch.H"
45 #include "labelPair.H"
46 #include "HashSet.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward Declarations
54 class entry;
55 class polyMesh;
56 class wordRe;
57 class wordRes;
58 
59 Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
60 
61 /*---------------------------------------------------------------------------*\
62  Class polyBoundaryMesh Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 class polyBoundaryMesh
66 :
67  public polyPatchList,
68  public regIOobject
69 {
70  // Private Data
71 
72  //- Reference to mesh
73  const polyMesh& mesh_;
74 
75  //- Demand-driven: list of patch ids per face.
76  mutable autoPtr<labelList> patchIDPtr_;
77 
78  //- Demand-driven: list of patch ids per group
79  mutable autoPtr<HashTable<labelList>> groupIDsPtr_;
80 
81  //- Demand-driven: edges of neighbouring patches
82  mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_;
83 
84 
85  // Private Member Functions
86 
87  //- Calculate geometry for the patches (transformation tensors etc.)
88  void calcGeometry();
89 
90  //- Some patches have inGroup entries
91  bool hasGroupIDs() const;
92 
93  //- Calculate group name to patch ids lookup
94  void calcGroupIDs() const;
95 
96  //- Clear addressing at this level
97  void clearLocalAddressing();
98 
99  //- Populate/recreate from dictionary entries
100  void populate(PtrList<entry>&& entries);
101 
102  //- Return true if contents were read
103  //- (controlled by IOobject readOption flags).
104  bool readContents(const bool allowOptionalRead);
105 
106 public:
107 
108  //- Declare friendship with polyMesh
109  friend class polyMesh;
110 
111  //- Runtime type information
112  TypeName("polyBoundaryMesh");
113 
114 
115  // Generated Methods
116 
117  //- No copy construct
118  polyBoundaryMesh(const polyBoundaryMesh&) = delete;
119 
120  //- No copy assignment
121  void operator=(const polyBoundaryMesh&) = delete;
122 
123 
124  // Constructors
125 
126  //- Read construct given IOobject and a mesh reference.
127  //- It will only read for MUST_READ variants (not READ_IF_PRESENT).
129  (
130  const IOobject& io,
131  const polyMesh& mesh
132  );
133 
134  //- Construct empty with IOobject properties and a mesh reference.
135  //- Does not read.
137  (
138  const IOobject& io,
139  const polyMesh& mesh,
140  Foam::zero
141  );
142 
143  //- Construct with specified size. Does not read.
145  (
146  const IOobject& io,
147  const polyMesh& mesh,
148  const label size
149  );
150 
151  //- Read construct (mandatory, optional) based on IOobject properties
152  //- or use the fallback PtrList (with cloning).
154  (
155  const IOobject& io,
156  const polyMesh& mesh,
157  const polyPatchList& list
158  );
159 
160  //- Read construct (mandatory, optional) based on IOobject properties
161  //- or fallback to constructing from a list of dictionary entries
163  (
164  const IOobject& io,
165  const polyMesh& mesh,
166  PtrList<entry>&& entries
167  );
168 
169 
170  //- Destructor
171  ~polyBoundaryMesh() = default;
172 
173 
174  // Member Functions
175 
176  //- Clear the patch list and all demand-driven data
177  void clear();
178 
179  //- Clear geometry at this level and at patches
180  void clearGeom();
181 
182  //- Clear addressing at this level and at patches
183  void clearAddressing();
184 
185  //- Return the mesh reference
186  const polyMesh& mesh() const noexcept
187  {
188  return mesh_;
189  }
190 
191  //- Return mesh faces for the entire boundary
192  const faceList::subList faces() const;
193 
194  //- Return face owner for the entire boundary
195  const labelList::subList faceOwner() const;
196 
197  //- Return a list of faceCells for each patch
199 
200  //- Per patch the edges on the neighbouring patch.
201  // Is for every external edge the neighbouring patch and
202  // neighbouring (external) patch edge label. Note that edge indices
203  // are offset by nInternalEdges to keep it as much as possible
204  // consistent with coupled patch addressing (where coupling is by
205  // local patch face index). Only valid for singly connected
206  // polyBoundaryMesh and not parallel
207  const List<labelPairList>& neighbourEdges() const;
208 
209  //- The number of patches before the first processor patch.
210  label nNonProcessor() const;
211 
212  //- The number of processorPolyPatch patches
213  label nProcessorPatches() const;
214 
215  //- Return a list of patch names
216  wordList names() const;
217 
218  //- Return a list of patch types
219  wordList types() const;
220 
221  //- Return a list of physical types
222  wordList physicalTypes() const;
223 
224  //- Return a list of patch start face indices
225  labelList patchStarts() const;
226 
227  //- Return a list of patch sizes
228  labelList patchSizes() const;
230  //- Return a list of patch ranges
232 
233  //- A list of the group names (if any)
234  wordList groupNames() const;
235 
236  //- The start label of boundary faces in the polyMesh face list
237  // Same as polyMesh::nInternalFaces()
238  label start() const noexcept;
239 
240  //- The number of boundary faces in the underlying mesh
241  // Same as polyMesh::nBoundaryFaces()
242  label nFaces() const noexcept;
243 
244  //- The face range for all boundary faces
245  // Spans [nInternalFaces, nFaces) of the underlying mesh
246  labelRange range() const noexcept;
247 
248  //- Return the range used for boundary faces on patchi.
249  // Always returns an empty range for negative values of patchi,
250  // which allows safe use with findIndex or findPatchID.
251  labelRange range(const label patchi) const;
252 
253 
254  //- Return (sorted) patch indices for all matches.
255  // Optionally matches patch groups.
256  // A no-op (returns empty list) for an empty matcher
258  (
259  const wordRe& matcher,
260  const bool useGroups = true
261  ) const;
262 
263  //- Return (sorted) patch indices for all matches.
264  // Optionally matches patch groups.
265  // A no-op (returns empty list) for an empty matcher
267  (
268  const wordRes& matcher,
269  const bool useGroups = true
270  ) const;
271 
272  //- Return (sorted) patch indices for all selected matches that
273  //- are not ignored.
274  //- The selection logic as per Foam::wordRes::filter.
275  // Optionally matches patch groups.
276  // A no-op (returns empty list) for an empty select matcher
278  (
279  const wordRes& select,
280  const wordRes& ignore,
281  const bool useGroups = true
282  ) const;
283 
284  //- Return patch index for the first match, return -1 if not found
285  // A no-op (returns -1) for an empty key
286  label findIndex(const wordRe& key) const;
287 
288  //- Find patch index given a name, return -1 if not found
289  // A no-op (returns -1) for an empty patchName
290  label findPatchID
291  (
292  const word& patchName,
293  const bool allowNotFound = true
294  ) const;
295 
296  //- Find patch indices for a given polyPatch type
297  template<class Type>
298  labelHashSet findPatchIDs() const;
299 
300  //- Lookup mesh face index and return (patchi, patchFacei) tuple
301  //- or (-1, meshFacei) for internal faces
302  labelPair whichPatchFace(const label meshFacei) const;
303 
304  //- Lookup mesh face indices and return (patchi, patchFacei) tuples
305  labelPairList whichPatchFace(const labelUList& meshFaceIndices) const;
306 
307  //- Return patch index for a given mesh face index.
308  //- Uses binary search.
309  label whichPatch(const label meshFacei) const
310  {
311  return whichPatchFace(meshFacei).first();
312  }
313 
314  //- Per boundary face label the patch index
315  const labelList& patchID() const;
316 
317  //- Return patch index for a given mesh face index.
318  //- Uses direct lookup into patchID() list.
319  //- Returns -1 for internal or out-of-range faces
320  label patchID(const label meshFacei) const;
321 
322  //- Lookup mesh face indices and return patch indices.
323  //- Uses direct lookup into patchID() list.
324  //- Returns values of -1 for internal or out-of-range faces
325  labelList patchID(const labelUList& meshFaceIndices) const;
326 
327  //- The patch indices per patch group
328  const HashTable<labelList>& groupPatchIDs() const;
329 
330  //- Set/add group with patches
331  void setGroup(const word& groupName, const labelUList& patchIDs);
332 
333  //- Return the set of patch IDs corresponding to the given names
334  // By default warns if given names are not found.
335  // Optionally matches to patchGroups as well as patchNames.
337  (
338  const UList<wordRe>& select,
339  const bool warnNotFound = true,
340  const bool useGroups = true
341  ) const;
342 
343  //- Match the patches to groups.
344  // Returns all the (fully matched) groups and any remaining
345  // unmatched patches.
346  void matchGroups
347  (
348  const labelUList& patchIDs,
349  wordList& groups,
350  labelHashSet& nonGroupPatches
351  ) const;
352 
353  //- Check whether all procs have all patches and in same order.
354  // \return True if in error.
355  bool checkParallelSync(const bool report = false) const;
356 
357  //- Check boundary definition.
358  // \return True if in error.
359  bool checkDefinition(const bool report = false) const;
360 
361  //- Correct polyBoundaryMesh after moving points
362  void movePoints(const pointField& p);
363 
364  //- Correct polyBoundaryMesh after topology update
365  void updateMesh();
366 
367  //- Reorders patches. Ordering does not have to be done in
368  // ascending or descending order. Reordering has to be unique.
369  // (is shuffle) If validBoundary calls updateMesh()
370  // after reordering to recalculate data (so call needs to be parallel
371  // sync in that case)
372  void reorder(const labelUList& oldToNew, const bool validBoundary);
373 
374 
375  // Write
376 
377  //- Write as a plain list of entries
378  void writeEntry(Ostream& os) const;
379 
380  //- Write as a primitive entry with given name.
381  //- If the keyword is empty, revert to a plain list.
382  void writeEntry(const keyType& keyword, Ostream& os) const;
383 
384  //- The writeData member function required by regIOobject
385  virtual bool writeData(Ostream& os) const;
386 
387  //- Write using stream options, but always UNCOMPRESSED
388  virtual bool writeObject
389  (
390  IOstreamOption streamOpt,
391  const bool writeOnProc = true
392  ) const;
393 
394 
395  // Member Operators
396 
397  //- Return const and non-const reference to polyPatch by index.
398  using polyPatchList::operator[];
399 
400  //- Return const reference to polyPatch by name.
401  const polyPatch& operator[](const word& patchName) const;
402 
403  //- Return reference to polyPatch by name.
404  polyPatch& operator[](const word& patchName);
405 
406 
407  // Ostream Operator
408 
409  friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
410 
411 
412  // Housekeeping
413 
414  //- Identical to the indices() method (AUG-2018)
415  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
416  labelList findIndices(const wordRe& key, bool useGroups=true) const
417  {
418  return this->indices(key, useGroups);
419  }
420 };
421 
422 
423 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
424 
425 } // End namespace Foam
426 
427 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
428 
429 #ifdef NoRepository
430  #include "polyBoundaryMeshTemplates.C"
431 #endif
432 
433 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
434 
435 #endif
436 
437 // ************************************************************************* //
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
const labelList patchIDs(pbm.indices(polyPatchNames, true))
A class for handling keywords in dictionaries.
Definition: keyType.H:66
const polyBoundaryMesh & pbm
const T & first() const noexcept
Access the first element.
Definition: Pair.H:137
labelList patchSizes() const
Return a list of patch sizes.
const List< labelPairList > & neighbourEdges() const
Per patch the edges on the neighbouring patch.
void setGroup(const word &groupName, const labelUList &patchIDs)
Set/add group with patches.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
labelHashSet patchSet(const UList< wordRe > &select, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
polyBoundaryMesh(const polyBoundaryMesh &)=delete
No copy construct.
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
label start() const noexcept
The start label of boundary faces in the polyMesh face list.
virtual bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
void reorder(const labelUList &oldToNew, const bool validBoundary)
Reorders patches. Ordering does not have to be done in.
labelPair whichPatchFace(const label meshFacei) const
Lookup mesh face index and return (patchi, patchFacei) tuple or (-1, meshFacei) for internal faces...
const labelList & patchID() const
Per boundary face label the patch index.
FOAM_DEPRECATED_FOR(2022-09, "get(), set() or test() methods") const T *operator()(const label i) const
Deprecated(2022-09) - same as get()
Definition: UPtrList.H:492
wordList groupNames() const
A list of the group names (if any)
void clearGeom()
Clear geometry at this level and at patches.
~polyBoundaryMesh()=default
Destructor.
labelRange range() const noexcept
The face range for all boundary faces.
A simple container for options an IOstream can normally have.
wordList types() const
Return a list of patch types.
const polyPatch & operator[](const word &patchName) const
Return const reference to polyPatch by name.
void movePoints(const pointField &p)
Correct polyBoundaryMesh after moving points.
label nProcessorPatches() const
The number of processorPolyPatch patches.
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) patch indices for all matches.
void matchGroups(const labelUList &patchIDs, wordList &groups, labelHashSet &nonGroupPatches) const
Match the patches to groups.
void operator=(const polyBoundaryMesh &)=delete
No copy assignment.
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
A List obtained as a section of another List.
Definition: SubList.H:50
UPtrList< const labelUList > faceCells() const
Return a list of faceCells for each patch.
const polyMesh & mesh() const noexcept
Return the mesh reference.
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool checkDefinition(const bool report=false) const
Check boundary definition.
wordList names() const
Return a list of patch names.
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
wordList physicalTypes() const
Return a list of physical types.
friend Ostream & operator(Ostream &os, const UPtrList< T > &list)
Write UPtrList to Ostream.
label whichPatch(const label meshFacei) const
Return patch index for a given mesh face index. Uses binary search.
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
const HashTable< labelList > & groupPatchIDs() const
The patch indices per patch group.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
const faceList::subList faces() const
Return mesh faces for the entire boundary.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
void clear()
Clear the patch list and all demand-driven data.
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order.
void writeEntry(Ostream &os) const
Write as a plain list of entries.
void updateMesh()
Correct polyBoundaryMesh after topology update.
OBJstream os(runTime.globalPath()/outputName)
labelList findIndices(const wordRe &key, bool useGroups=true) const
Identical to the indices() method (AUG-2018)
TypeName("polyBoundaryMesh")
Runtime type information.
labelList patchStarts() const
Return a list of patch start face indices.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
label nFaces() const noexcept
The number of boundary faces in the underlying mesh.
List< labelRange > patchRanges() const
Return a list of patch ranges.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
void clearAddressing()
Clear addressing at this level and at patches.
friend Ostream & operator<<(Ostream &os, const polyBoundaryMesh &pbm)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write using stream options, but always UNCOMPRESSED.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
label nNonProcessor() const
The number of patches before the first processor patch.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
label findIndex(const wordRe &key) const
Return patch index for the first match, return -1 if not found.
labelHashSet findPatchIDs() const
Find patch indices for a given polyPatch type.
Namespace for OpenFOAM.
const labelList::subList faceOwner() const
Return face owner for the entire boundary.