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-2025 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 registered IO,
32  a reference to the associated polyMesh,
33  with additional search methods etc.
34 
35 SourceFiles
36  polyBoundaryMesh.C
37  polyBoundaryMesh.txx
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_polyBoundaryMesh_H
42 #define Foam_polyBoundaryMesh_H
43 
44 #include "regIOobject.H"
45 #include "polyPatch.H"
46 #include "labelPair.H"
47 #include "HashSet.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class entry;
56 class polyMesh;
57 class wordRe;
58 class wordRes;
59 
60 Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
61 
62 /*---------------------------------------------------------------------------*\
63  Class polyBoundaryMesh Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class polyBoundaryMesh
67 :
68  public polyPatchList,
69  public regIOobject
70 {
71  // Private Data
72 
73  //- Reference to mesh
74  const polyMesh& mesh_;
75 
76  //- Demand-driven: list of patch ids per face.
77  mutable autoPtr<labelList> patchIDPtr_;
78 
79  //- Demand-driven: list of patch ids per group
80  mutable autoPtr<HashTable<labelList>> groupIDsPtr_;
81 
82  //- Demand-driven: edges of neighbouring patches
83  mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_;
84 
85 
86  // Private Member Functions
87 
88  //- Calculate geometry for the patches (transformation tensors etc.)
89  void calcGeometry();
90 
91  //- Some patches have inGroup entries
92  bool hasGroupIDs() const;
93 
94  //- Calculate group name to patch ids lookup
95  void calcGroupIDs() const;
96 
97  //- Clear addressing at this level
98  void clearLocalAddressing();
99 
100  //- Populate/recreate from dictionary entries
101  void populate(PtrList<entry>&& entries);
102 
103  //- Return true if contents were read
104  //- (controlled by IOobject readOption flags).
105  bool readIOcontents(const bool allowOptionalRead);
106 
107 public:
108 
109  //- Declare friendship with polyMesh
110  friend class polyMesh;
111 
112  //- Runtime type information
113  TypeName("polyBoundaryMesh");
114 
115 
116  // Generated Methods
117 
118  //- No copy construct
119  polyBoundaryMesh(const polyBoundaryMesh&) = delete;
120 
121  //- No copy assignment
122  void operator=(const polyBoundaryMesh&) = delete;
123 
124 
125  // Constructors
126 
127  //- Read construct given IOobject and a mesh reference.
128  //- It will only read for MUST_READ variants (not READ_IF_PRESENT).
130  (
131  const IOobject& io,
132  const polyMesh& mesh
133  );
134 
135  //- Construct empty with IOobject properties and a mesh reference.
136  //- Does not read.
138  (
139  const IOobject& io,
140  const polyMesh& mesh,
141  Foam::zero
142  );
143 
144  //- Construct with specified size. Does not read.
146  (
147  const IOobject& io,
148  const polyMesh& mesh,
149  const label size
150  );
151 
152  //- Read construct (mandatory, optional) based on IOobject properties
153  //- or use the fallback PtrList (with cloning).
155  (
156  const IOobject& io,
157  const polyMesh& mesh,
158  const polyPatchList& list
159  );
160 
161  //- Read construct (mandatory, optional) based on IOobject properties
162  //- or fallback to constructing from a list of dictionary entries
164  (
165  const IOobject& io,
166  const polyMesh& mesh,
167  PtrList<entry>&& entries
168  );
169 
170 
171  //- Destructor
172  ~polyBoundaryMesh() = default;
173 
174 
175  // Member Functions
176 
177  //- Clear the patch list and all demand-driven data
178  void clear();
179 
180  //- Clear geometry at this level and at patches
181  void clearGeom();
182 
183  //- Clear addressing at this level and at patches
184  void clearAddressing();
185 
186  //- Return the mesh reference
187  const polyMesh& mesh() const noexcept
188  {
189  return mesh_;
190  }
191 
192  //- Return mesh faces for the entire boundary
193  const faceList::subList faces() const;
194 
195  //- Return face owner for the entire boundary
196  const labelList::subList faceOwner() const;
197 
198  //- Return a list of faceCells for each patch
200 
201  //- Per patch the edges on the neighbouring patch.
202  // Is for every external edge the neighbouring patch and
203  // neighbouring (external) patch edge label. Note that edge indices
204  // are offset by nInternalEdges to keep it as much as possible
205  // consistent with coupled patch addressing (where coupling is by
206  // local patch face index). Only valid for singly connected
207  // polyBoundaryMesh and not parallel
208  const List<labelPairList>& neighbourEdges() const;
209 
210  //- The number of patches before the first processor patch.
211  label nNonProcessor() const;
212 
213  //- The number of processorPolyPatch patches
214  label nProcessorPatches() const;
215 
216  //- The number of boundary faces before the first processor patch.
217  label nNonProcessorFaces() const;
218 
219  //- Return a list of patch names
220  wordList names() const;
221 
222  //- Return a list of patch types
223  wordList types() const;
224 
225  //- Return a list of physical types
226  wordList physicalTypes() const;
227 
228  //- Return a list of patch start face indices
229  labelList patchStarts() const;
231  //- Return a list of patch sizes
232  labelList patchSizes() const;
233 
234  //- Return a list of patch ranges
236 
237  //- A list of the group names (if any)
238  wordList groupNames() const;
239 
240  //- The start label of boundary faces in the polyMesh face list
241  // Same as polyMesh::nInternalFaces()
242  label start() const noexcept;
243 
244  //- The number of boundary faces in the underlying mesh
245  // Same as polyMesh::nBoundaryFaces()
246  label nFaces() const noexcept;
247 
248  //- The number of boundary faces with patches that match the
249  //- given predicate.
250  template<class UnaryPredicate>
251  label nFaces_if(UnaryPredicate pred) const;
252 
253  //- The face range for all boundary faces
254  // Spans [nInternalFaces, nFaces) of the underlying mesh
255  labelRange range() const noexcept;
256 
257  //- Return the range used for boundary faces on patchi.
258  // Always returns an empty range for negative values of patchi,
259  // which allows safe use with findIndex or findPatchID.
260  labelRange range(const label patchi) const;
261 
262 
263  //- The (sorted) patch indices for all matches,
264  //- optionally matching patch groups.
265  // \returns an empty list for an empty matcher
267  (
268  const wordRe& matcher,
269  const bool useGroups = true
270  ) const;
271 
272  //- The (sorted) patch indices for all matches,
273  //- optionally matching patch groups.
274  // \returns an empty list for an empty matcher
276  (
277  const wordRes& matcher,
278  const bool useGroups = true
279  ) const;
280 
281  //- The (sorted) patch indices: logic as per Foam::wordRes::filter,
282  //- optionally matching patch groups.
283  //
284  // An empty \em allow accepts everything not in \em deny.
285  // A literal \em allow match has higher priority than any \em deny.
286  // A regex \em allow match has lower priority than any \em deny.
287  //
288  // \returns identity list when allow/deny are both empty.
290  (
291  const wordRes& allow,
292  const wordRes& deny,
293  const bool useGroups = true
294  ) const;
295 
296  //- Return (sorted) patch indices for patches that match the
297  //- given polyPatch type (uses \c isA test).
298  //- Can be used as a direct alternative to findPatchIDs
299  template<class PatchType>
300  labelList indices_if() const;
301 
302  //- Return (sorted) patch indices for patches that match the
303  //- given predicate. Can be used as an alternative to findPatchIDs
304  template<class UnaryPredicate>
305  labelList indices_if(UnaryPredicate pred) const;
306 
307  //- Return patch index for the first match, return -1 if not found
308  // A no-op (returns -1) for an empty key
309  label findIndex(const wordRe& key) const;
310 
311  //- Find patch index given a name, return -1 if not found
312  // A no-op (returns -1) for an empty patchName
313  label findPatchID
314  (
315  const word& patchName,
316  const bool allowNotFound = true
317  ) const;
318 
319  //- Find patch by name and return const pointer.
320  //- \returns nullptr on error or for an empty patchName
321  const polyPatch* cfindPatch(const word& patchName) const;
322 
323  //- Find patch indices for a given polyPatch type (uses \c isA test).
324  template<class PatchType>
325  labelHashSet findPatchIDs() const;
326 
327  //- Lookup mesh face index and return (patchi, patchFacei) tuple
328  //- or (-1, meshFacei) for internal faces
329  labelPair whichPatchFace(const label meshFacei) const;
330 
331  //- Lookup mesh face indices and return (patchi, patchFacei) tuples
332  labelPairList whichPatchFace(const labelUList& meshFaceIndices) const;
333 
334  //- Return patch index for a given mesh face index.
335  //- Uses binary search.
336  label whichPatch(const label meshFacei) const
337  {
338  return whichPatchFace(meshFacei).first();
339  }
340 
341  //- Per boundary face label the patch index
342  const labelList& patchID() const;
343 
344  //- Return patch index for a given mesh face index.
345  //- Uses direct lookup into patchID() list.
346  //- Returns -1 for internal or out-of-range faces
347  label patchID(const label meshFacei) const;
348 
349  //- Lookup mesh face indices and return patch indices.
350  //- Uses direct lookup into patchID() list.
351  //- Returns values of -1 for internal or out-of-range faces
352  labelList patchID(const labelUList& meshFaceIndices) const;
353 
354  //- The patch indices per patch group
355  const HashTable<labelList>& groupPatchIDs() const;
356 
357  //- Set/add group with patches
358  void setGroup(const word& groupName, const labelUList& patchIDs);
359 
360  //- Return the set of patch IDs corresponding to the given names
361  // By default warns if given names are not found.
362  // Optionally matches to patchGroups as well as patchNames.
364  (
365  const UList<wordRe>& select,
366  const bool warnNotFound = true,
367  const bool useGroups = true
368  ) const;
369 
370  //- Match the patches to groups.
371  // Returns all the (fully matched) groups and any remaining
372  // unmatched patches.
373  void matchGroups
374  (
375  const labelUList& patchIDs,
376  wordList& groups,
377  labelHashSet& nonGroupPatches
378  ) const;
379 
380  //- Check whether all procs have all patches and in same order.
381  // \return True if in error.
382  bool checkParallelSync(const bool report = false) const;
383 
384  //- Check boundary definition.
385  // \return True if in error.
386  bool checkDefinition(const bool report = false) const;
387 
388  //- Correct polyBoundaryMesh after moving points
389  void movePoints(const pointField& p);
390 
391  //- Correct polyBoundaryMesh after topology update
392  void updateMesh();
393 
394  //- Reorders patches. Ordering does not have to be done in
395  // ascending or descending order. Reordering has to be unique.
396  // (is shuffle) If validBoundary calls updateMesh()
397  // after reordering to recalculate data (so call needs to be parallel
398  // sync in that case)
399  void reorder(const labelUList& oldToNew, const bool validBoundary);
400 
401 
402  // Write
403 
404  //- Write as a plain list of entries
405  void writeEntry(Ostream& os) const;
406 
407  //- Write as a primitive entry with given name.
408  //- If the keyword is empty, revert to a plain list.
409  void writeEntry(const word& keyword, Ostream& os) const;
410 
411  //- The writeData member function required by regIOobject
412  virtual bool writeData(Ostream& os) const;
413 
414  //- Write using stream options, but always UNCOMPRESSED
415  virtual bool writeObject
416  (
417  IOstreamOption streamOpt,
418  const bool writeOnProc = true
419  ) const;
420 
421 
422  // Member Operators
423 
424  //- Return const and non-const reference to polyPatch by index.
425  using polyPatchList::operator[];
426 
427  //- Return const reference to polyPatch by name.
428  const polyPatch& operator[](const word& patchName) const;
429 
430  //- Return reference to polyPatch by name.
431  polyPatch& operator[](const word& patchName);
432 
433 
434  // Ostream Operator
435 
436  friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
437 
438 
439  // Housekeeping
440 
441  //- Identical to the indices() method (AUG-2018)
442  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
443  labelList findIndices(const wordRe& key, bool useGroups=true) const
444  {
445  return this->indices(key, useGroups);
446  }
447 };
448 
449 
450 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
452 } // End namespace Foam
453 
454 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
455 
456 #ifdef NoRepository
457  #include "polyBoundaryMesh.txx"
458 #endif
459 
460 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
461 
462 #endif
463 
464 // ************************************************************************* //
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
label nNonProcessorFaces() const
The number of boundary faces before the first processor patch.
const polyBoundaryMesh & pbm
const T & first() const noexcept
Access the first element.
Definition: Pair.H:167
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:63
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:139
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:485
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
The (sorted) patch indices for all matches, optionally matching patch groups.
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 non-owning sub-view of a List (allocated or unallocated storage).
Definition: SubList.H:44
UPtrList< const labelUList > faceCells() const
Return a list of faceCells for each patch.
const polyPatch * cfindPatch(const word &patchName) const
Find patch by name and return const pointer.
labelList indices_if() const
Return (sorted) patch indices for patches that match the given polyPatch type (uses isA test)...
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
const auto & io
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. Does not ignore null entries.
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 registered IO, a reference to the associated polyMesh...
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: scalarImpl.H:265
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.
labelList findIndices(const wordRe &key, bool useGroups=true) const
Identical to the indices() method (AUG-2018)
label nFaces_if(UnaryPredicate pred) const
The number of boundary faces with patches that match the given predicate.
TypeName("polyBoundaryMesh")
Runtime type information.
labelList patchStarts() const
Return a list of patch start face indices.
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
Definition: foamGltfBase.H:105
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.
labelList patchIDs
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: PtrList.H:56
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:68
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:76
volScalarField & p
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:188
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 (uses isA test).
Namespace for OpenFOAM.
const labelList::subList faceOwner() const
Return face owner for the entire boundary.