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 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_polyBoundaryMesh_H
40 #define Foam_polyBoundaryMesh_H
41 
42 #include "regIOobject.H"
43 #include "polyPatch.H"
44 #include "labelPair.H"
45 #include "HashSet.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward Declarations
53 class polyMesh;
54 class wordRe;
55 class wordRes;
56 
57 Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
58 
59 /*---------------------------------------------------------------------------*\
60  Class polyBoundaryMesh Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class polyBoundaryMesh
64 :
65  public polyPatchList,
66  public regIOobject
67 {
68  // Private Data
69 
70  //- Reference to mesh
71  const polyMesh& mesh_;
72 
73  //- Demand-driven: list of patch ids per face.
74  mutable autoPtr<labelList> patchIDPtr_;
75 
76  //- Demand-driven: list of patch ids per group
77  mutable autoPtr<HashTable<labelList>> groupIDsPtr_;
78 
79  //- Demand-driven: edges of neighbouring patches
80  mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_;
81 
82 
83  // Private Member Functions
84 
85  //- Calculate geometry for the patches (transformation tensors etc.)
86  void calcGeometry();
87 
88  //- Some patches have inGroup entries
89  bool hasGroupIDs() const;
90 
91  //- Calculate group name to patch ids lookup
92  void calcGroupIDs() const;
93 
94  //- Read if IOobject flags set. Return true if read.
95  bool readContents(const bool allowReadIfPresent);
96 
97 public:
98 
99  //- Declare friendship with polyMesh
100  friend class polyMesh;
101 
102  //- Runtime type information
103  TypeName("polyBoundaryMesh");
104 
105 
106  // Generated Methods
107 
108  //- No copy construct
109  polyBoundaryMesh(const polyBoundaryMesh&) = delete;
110 
111  //- No copy assignment
112  void operator=(const polyBoundaryMesh&) = delete;
114 
115  // Constructors
116 
117  //- Read constructor given IOobject and a polyMesh reference
118  // Note point pointers are unset, only used in copying meshes
120  (
121  const IOobject& io,
122  const polyMesh& mesh
123  );
124 
125  //- Construct given size
127  (
128  const IOobject& io,
129  const polyMesh& mesh,
130  const label size
131  );
132 
133  //- Construct given polyPatchList
135  (
136  const IOobject& io,
137  const polyMesh& mesh,
138  const polyPatchList& ppl
139  );
140 
141 
142  //- Destructor
143  ~polyBoundaryMesh() = default;
144 
145 
146  // Member Functions
147 
148  //- Clear the patch list and all demand-driven data
149  void clear();
150 
151  //- Clear geometry at this level and at patches
152  void clearGeom();
153 
154  //- Clear addressing at this level and at patches
155  void clearAddressing();
156 
157  //- Return the mesh reference
158  const polyMesh& mesh() const noexcept
159  {
160  return mesh_;
161  }
162 
163  //- Return a list of faceCells for each patch
165 
166  //- Per patch the edges on the neighbouring patch.
167  // Is for every external edge the neighbouring patch and
168  // neighbouring (external) patch edge label. Note that edge indices
169  // are offset by nInternalEdges to keep it as much as possible
170  // consistent with coupled patch addressing (where coupling is by
171  // local patch face index). Only valid for singly connected
172  // polyBoundaryMesh and not parallel
173  const List<labelPairList>& neighbourEdges() const;
174 
175  //- The number of patches before the first processor patch.
176  label nNonProcessor() const;
177 
178  //- The number of processorPolyPatch patches
179  label nProcessorPatches() const;
180 
181  //- Return a list of patch names
182  wordList names() const;
183 
184  //- Return a list of patch types
185  wordList types() const;
186 
187  //- Return a list of physical types
188  wordList physicalTypes() const;
189 
190  //- Return a list of patch start face indices
191  labelList patchStarts() const;
192 
193  //- Return a list of patch sizes
195 
196  //- Return a list of patch ranges
198 
199  //- A list of the group names (if any)
200  wordList groupNames() const;
201 
202  //- The start label of boundary faces in the polyMesh face list
203  // Same as polyMesh::nInternalFaces()
204  label start() const noexcept;
205 
206  //- The number of boundary faces in the underlying mesh
207  // Same as polyMesh::nBoundaryFaces()
208  label nFaces() const noexcept;
209 
210  //- The face range for all boundary faces
211  // Spans [nInternalFaces, nFaces) of the underlying mesh
212  labelRange range() const noexcept;
213 
214  //- Return the range used for boundary faces on patchi.
215  // Always returns an empty range for negative values of patchi,
216  // which allows safe use with findIndex or findPatchID.
217  labelRange range(const label patchi) const;
218 
219 
220  //- Return (sorted) patch indices for all matches.
221  // Optionally matches patch groups.
222  // A no-op (returns empty list) for an empty matcher
224  (
225  const wordRe& matcher,
226  const bool useGroups = true
227  ) const;
228 
229  //- Return (sorted) patch indices for all matches.
230  // Optionally matches patch groups.
231  // A no-op (returns empty list) for an empty matcher
233  (
234  const wordRes& matcher,
235  const bool useGroups = true
236  ) const;
237 
238  //- Return patch index for the first match, return -1 if not found
239  // A no-op (returns -1) for an empty key
240  label findIndex(const wordRe& key) const;
241 
242  //- Find patch index given a name, return -1 if not found
243  // A no-op (returns -1) for an empty patchName
244  label findPatchID
245  (
246  const word& patchName,
247  const bool allowNotFound = true
248  ) const;
249 
250  //- Find patch indices for a given polyPatch type
251  template<class Type>
252  labelHashSet findPatchIDs() const;
253 
254  //- Lookup mesh face index and return (patchi, patchFacei) tuple
255  //- or (-1, meshFacei) for internal faces
256  labelPair whichPatchFace(const label meshFacei) const;
257 
258  //- Lookup mesh face indices and return (patchi, patchFacei) tuples
259  labelPairList whichPatchFace(const labelUList& meshFaceIndices) const;
260 
261  //- Return patch index for a given mesh face index.
262  //- Uses binary search.
263  label whichPatch(const label meshFacei) const
264  {
265  return whichPatchFace(meshFacei).first();
266  }
267 
268  //- Per boundary face label the patch index
269  const labelList& patchID() const;
270 
271  //- Return patch index for a given mesh face index.
272  //- Uses direct lookup into patchID() list.
273  //- Returns -1 for internal or out-of-range faces
274  label patchID(const label meshFacei) const;
275 
276  //- Lookup mesh face indices and return patch indices.
277  //- Uses direct lookup into patchID() list.
278  //- Returns values of -1 for internal or out-of-range faces
279  labelList patchID(const labelUList& meshFaceIndices) const;
280 
281  //- The patch indices per patch group
282  const HashTable<labelList>& groupPatchIDs() const;
283 
284  //- Set/add group with patches
285  void setGroup(const word& groupName, const labelUList& patchIDs);
286 
287  //- Return the set of patch IDs corresponding to the given names
288  // By default warns if given names are not found.
289  // Optionally matches to patchGroups as well as patchNames.
291  (
292  const UList<wordRe>& patchNames,
293  const bool warnNotFound = true,
294  const bool useGroups = true
295  ) const;
296 
297  //- Match the patches to groups.
298  // Returns all the (fully matched) groups and any remaining
299  // unmatched patches.
300  void matchGroups
301  (
302  const labelUList& patchIDs,
303  wordList& groups,
304  labelHashSet& nonGroupPatches
305  ) const;
306 
307  //- Check whether all procs have all patches and in same order.
308  // \return True if in error.
309  bool checkParallelSync(const bool report = false) const;
310 
311  //- Check boundary definition.
312  // \return True if in error.
313  bool checkDefinition(const bool report = false) const;
314 
315  //- Correct polyBoundaryMesh after moving points
316  void movePoints(const pointField& p);
317 
318  //- Correct polyBoundaryMesh after topology update
319  void updateMesh();
320 
321  //- Reorders patches. Ordering does not have to be done in
322  // ascending or descending order. Reordering has to be unique.
323  // (is shuffle) If validBoundary calls updateMesh()
324  // after reordering to recalculate data (so call needs to be parallel
325  // sync in that case)
326  void reorder(const labelUList& oldToNew, const bool validBoundary);
327 
328  //- writeData member function required by regIOobject
329  virtual bool writeData(Ostream& os) const;
330 
331  //- Write using stream options
332  virtual bool writeObject
333  (
334  IOstreamOption streamOpt,
335  const bool writeOnProc
336  ) const;
337 
338 
339  // Member Operators
340 
341  //- Return const and non-const reference to polyPatch by index.
342  using polyPatchList::operator[];
343 
344  //- Return const reference to polyPatch by name.
345  const polyPatch& operator[](const word& patchName) const;
346 
347  //- Return reference to polyPatch by name.
348  polyPatch& operator[](const word& patchName);
349 
350 
351  // Ostream Operator
352 
353  friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
355 
356  // Housekeeping
357 
358  //- Identical to the indices() method (AUG-2018)
359  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
360  labelList findIndices(const wordRe& key, bool useGroups=true) const
361  {
362  return this->indices(key, useGroups);
363  }
364 };
365 
366 
367 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
368 
369 } // End namespace Foam
370 
371 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
372 
373 #ifdef NoRepository
374  #include "polyBoundaryMeshTemplates.C"
375 #endif
376 
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378 
379 #endif
380 
381 // ************************************************************************* //
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
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.
const labelList patchIDs(pbm.patchSet(polyPatchNames, false, true).sortedToc())
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
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:51
polyBoundaryMesh(const polyBoundaryMesh &)=delete
No copy construct.
label start() const noexcept
The start label of boundary faces in the polyMesh face list.
virtual bool writeData(Ostream &os) const
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:482
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.
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
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.
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:113
wordList patchNames(nPatches)
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:102
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:100
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...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
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 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:76
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:65
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
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:73
volScalarField & p
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
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:171
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.