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-2021 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 polyBoundaryMesh_H
40 #define polyBoundaryMesh_H
41 
42 #include "polyPatchList.H"
43 #include "regIOobject.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 /*---------------------------------------------------------------------------*\
61  Class polyBoundaryMesh Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class polyBoundaryMesh
65 :
66  public polyPatchList,
67  public regIOobject
68 {
69  // Private Data
70 
71  //- Reference to mesh
72  const polyMesh& mesh_;
73 
74  //- Demand-driven: list of patch ids per face.
75  mutable autoPtr<labelList> patchIDPtr_;
76 
77  //- Demand-driven: list of patch ids per group
78  mutable autoPtr<HashTable<labelList>> groupIDsPtr_;
79 
80  //- Demand-driven: edges of neighbouring patches
81  mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_;
82 
83 
84  // Private Member Functions
85 
86  //- Calculate geometry for the patches (transformation tensors etc.)
87  void calcGeometry();
88 
89  //- Some patches have inGroup entries
90  bool hasGroupIDs() const;
91 
92  //- Calculate group name to patch ids lookup
93  void calcGroupIDs() const;
94 
95  //- No copy construct
96  polyBoundaryMesh(const polyBoundaryMesh&) = delete;
97 
98  //- No copy assignment
99  void operator=(const polyBoundaryMesh&) = delete;
100 
101 
102 public:
103 
104  //- Declare friendship with polyMesh
105  friend class polyMesh;
106 
107 
108  //- Runtime type information
109  TypeName("polyBoundaryMesh");
110 
111 
112  // Constructors
113 
114  //- Read constructor given IOobject and a polyMesh reference
115  // Note point pointers are unset, only used in copying meshes
117  (
118  const IOobject& io,
119  const polyMesh& mesh
120  );
121 
122  //- Construct given size
124  (
125  const IOobject& io,
126  const polyMesh& mesh,
127  const label size
128  );
129 
130  //- Construct given polyPatchList
132  (
133  const IOobject& io,
134  const polyMesh& mesh,
135  const polyPatchList& ppl
136  );
137 
138 
139  //- Destructor
140  ~polyBoundaryMesh() = default;
141 
142 
143  //- Clear geometry at this level and at patches
144  void clearGeom();
145 
146  //- Clear addressing at this level and at patches
147  void clearAddressing();
148 
149 
150  // Member Functions
151 
152  //- Return the mesh reference
153  const polyMesh& mesh() const noexcept
154  {
155  return mesh_;
156  }
157 
158  //- Return a list of faceCells for each patch
160 
161  //- Per patch the edges on the neighbouring patch.
162  // Is for every external edge the neighbouring patch and
163  // neighbouring (external) patch edge label. Note that edge indices
164  // are offset by nInternalEdges to keep it as much as possible
165  // consistent with coupled patch addressing (where coupling is by
166  // local patch face index). Only valid for singly connected
167  // polyBoundaryMesh and not parallel
168  const List<labelPairList>& neighbourEdges() const;
169 
170  //- The number of patches before the first processor patch.
171  label nNonProcessor() const;
172 
173  //- Return a list of patch names
174  wordList names() const;
175 
176  //- Return a list of patch types
177  wordList types() const;
178 
179  //- Return a list of physical types
180  wordList physicalTypes() const;
181 
182  //- Return a list of patch start face indices
183  labelList patchStarts() const;
184 
185  //- Return a list of patch sizes
186  labelList patchSizes() const;
187 
188  //- Return a list of patch ranges
190 
191  //- The start label of the boundary faces in the polyMesh face list
192  // Same as mesh.nInternalFaces()
193  label start() const;
194 
195  //- The number of boundary faces in the underlying mesh
196  // Same as mesh.nBoundaryFaces()
197  label nFaces() const;
198 
199  //- The face range for all boundary faces
200  // Spans [nInternalFaces, nFaces) of the underlying mesh
201  labelRange range() const;
202 
203  //- Return the range used for boundary faces on patchi.
204  // Always returns an empty range for negative values of patchi,
205  // which allows safe use with findIndex or findPatchID.
206  labelRange range(const label patchi) const;
207 
208 
209  //- Return (sorted) patch indices for all matches.
210  // Optionally matches patch groups.
211  // A no-op (returns empty list) for an empty matcher
213  (
214  const wordRe& matcher,
215  const bool useGroups = true
216  ) const;
217 
218  //- Return (sorted) patch indices for all matches.
219  // Optionally matches patch groups.
220  // A no-op (returns empty list) for an empty matcher
222  (
223  const wordRes& matcher,
224  const bool useGroups = true
225  ) const;
226 
227  //- Return patch index for the first match, return -1 if not found
228  // A no-op (returns -1) for an empty key
229  label findIndex(const wordRe& key) const;
230 
231  //- Find patch index given a name, return -1 if not found
232  // A no-op (returns -1) for an empty patchName
233  label findPatchID
234  (
235  const word& patchName,
236  const bool allowNotFound = true
237  ) const;
238 
239  //- Find patch indices for a given polyPatch type
240  template<class Type>
241  labelHashSet findPatchIDs() const;
242 
243  //- Return patch index for a given face label
244  label whichPatch(const label faceIndex) const;
245 
246  //- Per boundary face label the patch index
247  const labelList& patchID() const;
248 
249  //- The patch indices per patch group
250  const HashTable<labelList>& groupPatchIDs() const;
251 
252  //- Set/add group with patches
253  void setGroup(const word& groupName, const labelUList& patchIDs);
254 
255  //- Return the set of patch IDs corresponding to the given names
256  // By default warns if given names are not found.
257  // Optionally matches to patchGroups as well as patchNames.
259  (
260  const UList<wordRe>& patchNames,
261  const bool warnNotFound = true,
262  const bool useGroups = true
263  ) const;
264 
265  //- Match the patches to groups.
266  // Returns all the (fully matched) groups and any remaining
267  // unmatched patches.
268  void matchGroups
269  (
270  const labelUList& patchIDs,
271  wordList& groups,
272  labelHashSet& nonGroupPatches
273  ) const;
274 
275  //- Check whether all procs have all patches and in same order. Return
276  // true if in error.
277  bool checkParallelSync(const bool report = false) const;
278 
279  //- Check boundary definition. Return true if in error.
280  bool checkDefinition(const bool report = false) const;
281 
282  //- Correct polyBoundaryMesh after moving points
283  void movePoints(const pointField& p);
284 
285  //- Correct polyBoundaryMesh after topology update
286  void updateMesh();
287 
288  //- Reorders patches. Ordering does not have to be done in
289  // ascending or descending order. Reordering has to be unique.
290  // (is shuffle) If validBoundary calls updateMesh()
291  // after reordering to recalculate data (so call needs to be parallel
292  // sync in that case)
293  void reorder(const labelUList& oldToNew, const bool validBoundary);
294 
295  //- writeData member function required by regIOobject
296  virtual bool writeData(Ostream& os) const;
297 
298  //- Write using stream options
299  virtual bool writeObject
300  (
301  IOstreamOption streamOpt,
302  const bool valid
303  ) const;
304 
305 
306  // Member Operators
307 
308  //- Return const and non-const reference to polyPatch by index.
309  using polyPatchList::operator[];
310 
311  //- Return const reference to polyPatch by name.
312  const polyPatch& operator[](const word& patchName) const;
313 
314  //- Return reference to polyPatch by name.
315  polyPatch& operator[](const word& patchName);
316 
317 
318  // Ostream Operator
319 
320  friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
321 
322 
323  // Housekeeping
324 
325  //- Identical to the indices() method (AUG-2018)
326  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
327  labelList findIndices(const wordRe& key, bool useGroups=true) const
328  {
329  return this->indices(key, useGroups);
330  }
331 };
332 
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 } // End namespace Foam
337 
338 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339 
340 #ifdef NoRepository
341  #include "polyBoundaryMeshTemplates.C"
342 #endif
343 
344 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345 
346 #endif
347 
348 // ************************************************************************* //
regIOobject.H
Foam::polyBoundaryMesh::patchSizes
labelList patchSizes() const
Return a list of patch sizes.
Definition: polyBoundaryMesh.C:589
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::polyBoundaryMesh::nFaces
label nFaces() const
The number of boundary faces in the underlying mesh.
Definition: polyBoundaryMesh.C:617
Foam::polyBoundaryMesh::matchGroups
void matchGroups(const labelUList &patchIDs, wordList &groups, labelHashSet &nonGroupPatches) const
Match the patches to groups.
Definition: polyBoundaryMesh.C:933
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::polyBoundaryMesh::physicalTypes
wordList physicalTypes() const
Return a list of physical types.
Definition: polyBoundaryMesh.C:567
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
Foam::polyBoundaryMesh::groupPatchIDs
const HashTable< labelList > & groupPatchIDs() const
The patch indices per patch group.
Definition: polyBoundaryMesh.C:481
Foam::polyBoundaryMesh::reorder
void reorder(const labelUList &oldToNew, const bool validBoundary)
Reorders patches. Ordering does not have to be done in.
Definition: polyBoundaryMesh.C:1214
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
polyPatchList.H
Foam::polyBoundaryMesh::clearGeom
void clearGeom()
Clear geometry at this level and at patches.
Definition: polyBoundaryMesh.C:236
Foam::HashSet< label, Hash< label > >
Foam::polyBoundaryMesh::clearAddressing
void clearAddressing()
Clear addressing at this level and at patches.
Definition: polyBoundaryMesh.C:247
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
Foam::polyBoundaryMesh::start
label start() const
The start label of the boundary faces in the polyMesh face list.
Definition: polyBoundaryMesh.C:611
Foam::polyBoundaryMesh::findIndex
label findIndex(const wordRe &key) const
Return patch index for the first match, return -1 if not found.
Definition: polyBoundaryMesh.C:754
Foam::polyBoundaryMesh::types
wordList types() const
Return a list of patch types.
Definition: polyBoundaryMesh.C:561
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
polyBoundaryMeshTemplates.C
Foam::polyBoundaryMesh::names
wordList names() const
Return a list of patch names.
Definition: polyBoundaryMesh.C:555
Foam::polyBoundaryMesh::range
labelRange range() const
The face range for all boundary faces.
Definition: polyBoundaryMesh.C:623
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::polyBoundaryMesh::patchID
const labelList & patchID() const
Per boundary face label the patch index.
Definition: polyBoundaryMesh.C:456
Foam::polyBoundaryMesh::checkParallelSync
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order. Return.
Definition: polyBoundaryMesh.C:972
Foam::polyBoundaryMesh::mesh
const polyMesh & mesh() const noexcept
Return the mesh reference.
Definition: polyBoundaryMesh.H:152
Foam::Field< vector >
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::polyBoundaryMesh::faceCells
UPtrList< const labelUList > faceCells() const
Return a list of faceCells for each patch.
Definition: polyBoundaryMesh.C:311
Foam::polyBoundaryMesh::checkDefinition
bool checkDefinition(const bool report=false) const
Check boundary definition. Return true if in error.
Definition: polyBoundaryMesh.C:1060
Foam::polyBoundaryMesh::findPatchIDs
labelHashSet findPatchIDs() const
Find patch indices for a given polyPatch type.
Foam::polyBoundaryMesh::TypeName
TypeName("polyBoundaryMesh")
Runtime type information.
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::polyBoundaryMesh::patchStarts
labelList patchStarts() const
Return a list of patch start face indices.
Definition: polyBoundaryMesh.C:578
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:62
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:55
Foam::polyBoundaryMesh::whichPatch
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Definition: polyBoundaryMesh.C:812
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
patchNames
wordList patchNames(nPatches)
Foam::polyBoundaryMesh::findPatchID
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
Definition: polyBoundaryMesh.C:765
HashSet.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyBoundaryMesh::movePoints
void movePoints(const pointField &p)
Correct polyBoundaryMesh after moving points.
Definition: polyBoundaryMesh.C:1117
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::polyBoundaryMesh::updateMesh
void updateMesh()
Correct polyBoundaryMesh after topology update.
Definition: polyBoundaryMesh.C:1163
Foam::polyBoundaryMesh::nNonProcessor
label nNonProcessor() const
The number of patches before the first processor patch.
Definition: polyBoundaryMesh.C:535
Foam::polyBoundaryMesh::writeData
virtual bool writeData(Ostream &os) const
writeData member function required by regIOobject
Definition: polyBoundaryMesh.C:1237
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::polyBoundaryMesh::neighbourEdges
const List< labelPairList > & neighbourEdges() const
Per patch the edges on the neighbouring patch.
Definition: polyBoundaryMesh.C:327
Foam::polyBoundaryMesh::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
Definition: polyBoundaryMesh.C:1258
Foam::polyBoundaryMesh::operator<<
friend Ostream & operator<<(Ostream &os, const polyBoundaryMesh &pbm)
Foam::polyBoundaryMesh::indices
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) patch indices for all matches.
Definition: polyBoundaryMesh.C:642
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::polyBoundaryMesh::setGroup
void setGroup(const word &groupName, const labelUList &patchIDs)
Set/add group with patches.
Definition: polyBoundaryMesh.C:493
Foam::UList< label >
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::polyBoundaryMesh::patchSet
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.
Definition: polyBoundaryMesh.C:864
Foam::polyBoundaryMesh::patchRanges
List< labelRange > patchRanges() const
Return a list of patch ranges.
Definition: polyBoundaryMesh.C:600
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
Foam::polyBoundaryMesh::findIndices
labelList findIndices(const wordRe &key, bool useGroups=true) const
Identical to the indices() method (AUG-2018)
Definition: polyBoundaryMesh.H:326
Foam::IOobject::groupName
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::polyBoundaryMesh::operator[]
const polyPatch & operator[](const word &patchName) const
Return const reference to polyPatch by name.
Definition: polyBoundaryMesh.C:1271
Foam::polyBoundaryMesh::~polyBoundaryMesh
~polyBoundaryMesh()=default
Destructor.
labelPair.H