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-2020 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 
56 Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
57 
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:
77  mutable autoPtr<HashTable<labelList>> groupPatchIDsPtr_;
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  //- No copy construct
89  polyBoundaryMesh(const polyBoundaryMesh&) = delete;
90 
91  //- No copy assignment
92  void operator=(const polyBoundaryMesh&) = delete;
93 
94 
95 public:
96 
97  //- Declare friendship with polyMesh
98  friend class polyMesh;
99 
100 
101  //- Runtime type information
102  TypeName("polyBoundaryMesh");
103 
104 
105  // Constructors
106 
107  //- Read constructor given IOobject and a polyMesh reference
108  // Note point pointers are unset, only used in copying meshes
110  (
111  const IOobject& io,
112  const polyMesh& mesh
113  );
114 
115  //- Construct given size
117  (
118  const IOobject& io,
119  const polyMesh& mesh,
120  const label size
121  );
122 
123  //- Construct given polyPatchList
125  (
126  const IOobject& io,
127  const polyMesh& mesh,
128  const polyPatchList& ppl
129  );
130 
131 
132  //- Destructor
133  ~polyBoundaryMesh() = default;
134 
135  //- Clear geometry at this level and at patches
136  void clearGeom();
137 
138  //- Clear addressing at this level and at patches
139  void clearAddressing();
140 
141 
142  // Member Functions
143 
144  //- Return the mesh reference
145  const polyMesh& mesh() const
146  {
147  return mesh_;
148  }
149 
150  //- Per patch the edges on the neighbouring patch.
151  // Is for every external edge the neighbouring patch and
152  // neighbouring (external) patch edge label. Note that edge indices
153  // are offset by nInternalEdges to keep it as much as possible
154  // consistent with coupled patch addressing (where coupling is by
155  // local patch face index). Only valid for singly connected
156  // polyBoundaryMesh and not parallel
157  const List<labelPairList>& neighbourEdges() const;
158 
159  //- The number of patches before the first processor patch.
160  label nNonProcessor() const;
161 
162  //- Return a list of patch names
163  wordList names() const;
164 
165  //- Return a list of patch types
166  wordList types() const;
167 
168  //- Return a list of physical types
169  wordList physicalTypes() const;
170 
171  //- Return a list of patch start face indices
172  labelList patchStarts() const;
173 
174  //- Return a list of patch sizes
175  labelList patchSizes() const;
176 
177  //- The start label of the boundary faces in the polyMesh face list
178  // Same as mesh.nInternalFaces()
179  label start() const;
180 
181  //- The number of boundary faces in the underlying mesh
182  // Same as mesh.nBoundaryFaces()
183  label nFaces() const;
184 
185  //- The face range for all boundary faces
186  // Spans [nInternalFaces, nFaces) of the underlying mesh
187  labelRange range() const;
188 
189  //- Return the range used for boundary faces on patchi.
190  // Always returns an empty range for negative values of patchi,
191  // which allows safe use with findIndex or findPatchID.
192  labelRange range(const label patchi) const;
193 
194 
195  //- Return patch indices for all matches.
196  // Optionally matches patchGroups
198  (
199  const keyType& key,
200  const bool useGroups = true
201  ) const;
202 
203 
204  //- Return patch index for the first match, return -1 if not found
205  label findIndex(const keyType& key) const;
206 
207  //- Find patch index given a name, return -1 if not found
208  label findPatchID
209  (
210  const word& patchName,
211  const bool allowNotFound = true
212  ) const;
213 
214  //- Find patch indices for a given polyPatch type
215  template<class Type>
216  labelHashSet findPatchIDs() const;
217 
218  //- Return patch index for a given face label
219  label whichPatch(const label faceIndex) const;
220 
221  //- Per boundary face label the patch index
222  const labelList& patchID() const;
223 
224  //- The patch indices per patch group
225  const HashTable<labelList>& groupPatchIDs() const;
226 
227  //- Set/add group with patches
228  void setGroup(const word& groupName, const labelUList& patchIDs);
229 
230  //- Return the set of patch IDs corresponding to the given names
231  // By default warns if given names are not found.
232  // Optionally matches to patchGroups as well as patchNames.
234  (
235  const UList<wordRe>& patchNames,
236  const bool warnNotFound = true,
237  const bool useGroups = true
238  ) const;
239 
240  //- Match the patches to groups.
241  // Returns all the (fully matched) groups and any remaining
242  // unmatched patches.
243  void matchGroups
244  (
245  const labelUList& patchIDs,
246  wordList& groups,
247  labelHashSet& nonGroupPatches
248  ) const;
249 
250  //- Check whether all procs have all patches and in same order. Return
251  // true if in error.
252  bool checkParallelSync(const bool report = false) const;
253 
254  //- Check boundary definition. Return true if in error.
255  bool checkDefinition(const bool report = false) const;
256 
257  //- Correct polyBoundaryMesh after moving points
258  void movePoints(const pointField& p);
259 
260  //- Correct polyBoundaryMesh after topology update
261  void updateMesh();
262 
263  //- Reorders patches. Ordering does not have to be done in
264  // ascending or descending order. Reordering has to be unique.
265  // (is shuffle) If validBoundary calls updateMesh()
266  // after reordering to recalculate data (so call needs to be parallel
267  // sync in that case)
268  void reorder(const labelUList& oldToNew, const bool validBoundary);
269 
270  //- writeData member function required by regIOobject
271  virtual bool writeData(Ostream& os) const;
272 
273  //- Write using stream options
274  virtual bool writeObject
275  (
276  IOstreamOption streamOpt,
277  const bool valid
278  ) const;
279 
280 
281  // Member Operators
282 
283  //- Return const and non-const reference to polyPatch by index.
284  using polyPatchList::operator[];
285 
286  //- Return const reference to polyPatch by name.
287  const polyPatch& operator[](const word& patchName) const;
288 
289  //- Return reference to polyPatch by name.
290  polyPatch& operator[](const word& patchName);
291 
292 
293  // Ostream operator
294 
295  friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
296 
297 
298  // Housekeeping
299 
300  //- Identical to the indices() method (AUG-2018)
302  (
303  const keyType& key,
304  const bool useGroups = true
305  ) const
306  {
307  return this->indices(key, useGroups);
308  }
309 };
310 
311 
312 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313 
314 } // End namespace Foam
315 
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 
318 #ifdef NoRepository
319  #include "polyBoundaryMeshTemplates.C"
320 #endif
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #endif
325 
326 // ************************************************************************* //
regIOobject.H
Foam::polyBoundaryMesh::patchSizes
labelList patchSizes() const
Return a list of patch sizes.
Definition: polyBoundaryMesh.C:627
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
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:644
Foam::polyBoundaryMesh::matchGroups
void matchGroups(const labelUList &patchIDs, wordList &groups, labelHashSet &nonGroupPatches) const
Match the patches to groups.
Definition: polyBoundaryMesh.C:911
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyBoundaryMesh::physicalTypes
wordList physicalTypes() const
Return a list of physical types.
Definition: polyBoundaryMesh.C:605
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::polyBoundaryMesh::findIndices
labelList findIndices(const keyType &key, const bool useGroups=true) const
Identical to the indices() method (AUG-2018)
Definition: polyBoundaryMesh.H:301
Foam::polyBoundaryMesh::findIndex
label findIndex(const keyType &key) const
Return patch index for the first match, return -1 if not found.
Definition: polyBoundaryMesh.C:744
Foam::polyBoundaryMesh::groupPatchIDs
const HashTable< labelList > & groupPatchIDs() const
The patch indices per patch group.
Definition: polyBoundaryMesh.C:477
Foam::polyBoundaryMesh::reorder
void reorder(const labelUList &oldToNew, const bool validBoundary)
Reorders patches. Ordering does not have to be done in.
Definition: polyBoundaryMesh.C:1192
polyPatchList.H
Foam::polyBoundaryMesh::clearGeom
void clearGeom()
Clear geometry at this level and at patches.
Definition: polyBoundaryMesh.C:248
Foam::HashSet< label, Hash< label > >
Foam::polyBoundaryMesh::clearAddressing
void clearAddressing()
Clear addressing at this level and at patches.
Definition: polyBoundaryMesh.C:259
Foam::polyBoundaryMesh::start
label start() const
The start label of the boundary faces in the polyMesh face list.
Definition: polyBoundaryMesh.C:638
Foam::polyBoundaryMesh::types
wordList types() const
Return a list of patch types.
Definition: polyBoundaryMesh.C:599
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:593
Foam::polyBoundaryMesh::range
labelRange range() const
The face range for all boundary faces.
Definition: polyBoundaryMesh.C:650
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
Foam::polyBoundaryMesh::patchID
const labelList & patchID() const
Per boundary face label the patch index.
Definition: polyBoundaryMesh.C:452
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:950
Foam::Field< vector >
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:67
Foam::polyBoundaryMesh::checkDefinition
bool checkDefinition(const bool report=false) const
Check boundary definition. Return true if in error.
Definition: polyBoundaryMesh.C:1038
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:616
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
Foam::polyBoundaryMesh::whichPatch
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Definition: polyBoundaryMesh.C:805
Foam::polyBoundaryMesh::mesh
const polyMesh & mesh() const
Return the mesh reference.
Definition: polyBoundaryMesh.H:144
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
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:766
HashSet.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::polyBoundaryMesh::movePoints
void movePoints(const pointField &p)
Correct polyBoundaryMesh after moving points.
Definition: polyBoundaryMesh.C:1095
Foam::polyBoundaryMesh::indices
labelList indices(const keyType &key, const bool useGroups=true) const
Return patch indices for all matches.
Definition: polyBoundaryMesh.C:669
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:1141
Foam::polyBoundaryMesh::nNonProcessor
label nNonProcessor() const
The number of patches before the first processor patch.
Definition: polyBoundaryMesh.C:573
Foam::polyBoundaryMesh::writeData
virtual bool writeData(Ostream &os) const
writeData member function required by regIOobject
Definition: polyBoundaryMesh.C:1215
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:68
Foam::polyBoundaryMesh::neighbourEdges
const List< labelPairList > & neighbourEdges() const
Per patch the edges on the neighbouring patch.
Definition: polyBoundaryMesh.C:323
Foam::polyBoundaryMesh::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
Definition: polyBoundaryMesh.C:1236
Foam::polyBoundaryMesh::operator<<
friend Ostream & operator<<(Ostream &os, const polyBoundaryMesh &pbm)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::polyBoundaryMesh::setGroup
void setGroup(const word &groupName, const labelUList &patchIDs)
Set/add group with patches.
Definition: polyBoundaryMesh.C:524
Foam::UList< label >
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:857
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:1249
Foam::polyBoundaryMesh::~polyBoundaryMesh
~polyBoundaryMesh()=default
Destructor.
labelPair.H