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
197  // A no-op (returns empty list) for an empty key
199  (
200  const keyType& key,
201  const bool useGroups = true
202  ) const;
203 
204 
205  //- Return patch index for the first match, return -1 if not found
206  // A no-op (returns -1) for an empty key
207  label findIndex(const keyType& key) const;
208 
209  //- Find patch index given a name, return -1 if not found
210  // A no-op (returns -1) for an empty patchName
211  label findPatchID
212  (
213  const word& patchName,
214  const bool allowNotFound = true
215  ) const;
216 
217  //- Find patch indices for a given polyPatch type
218  template<class Type>
219  labelHashSet findPatchIDs() const;
220 
221  //- Return patch index for a given face label
222  label whichPatch(const label faceIndex) const;
223 
224  //- Per boundary face label the patch index
225  const labelList& patchID() const;
226 
227  //- The patch indices per patch group
228  const HashTable<labelList>& groupPatchIDs() const;
229 
230  //- Set/add group with patches
231  void setGroup(const word& groupName, const labelUList& patchIDs);
232 
233  //- Return the set of patch IDs corresponding to the given names
234  // By default warns if given names are not found.
235  // Optionally matches to patchGroups as well as patchNames.
237  (
238  const UList<wordRe>& patchNames,
239  const bool warnNotFound = true,
240  const bool useGroups = true
241  ) const;
242 
243  //- Match the patches to groups.
244  // Returns all the (fully matched) groups and any remaining
245  // unmatched patches.
246  void matchGroups
247  (
248  const labelUList& patchIDs,
249  wordList& groups,
250  labelHashSet& nonGroupPatches
251  ) const;
252 
253  //- Check whether all procs have all patches and in same order. Return
254  // true if in error.
255  bool checkParallelSync(const bool report = false) const;
256 
257  //- Check boundary definition. Return true if in error.
258  bool checkDefinition(const bool report = false) const;
259 
260  //- Correct polyBoundaryMesh after moving points
261  void movePoints(const pointField& p);
262 
263  //- Correct polyBoundaryMesh after topology update
264  void updateMesh();
265 
266  //- Reorders patches. Ordering does not have to be done in
267  // ascending or descending order. Reordering has to be unique.
268  // (is shuffle) If validBoundary calls updateMesh()
269  // after reordering to recalculate data (so call needs to be parallel
270  // sync in that case)
271  void reorder(const labelUList& oldToNew, const bool validBoundary);
272 
273  //- writeData member function required by regIOobject
274  virtual bool writeData(Ostream& os) const;
275 
276  //- Write using stream options
277  virtual bool writeObject
278  (
279  IOstreamOption streamOpt,
280  const bool valid
281  ) const;
282 
283 
284  // Member Operators
285 
286  //- Return const and non-const reference to polyPatch by index.
287  using polyPatchList::operator[];
288 
289  //- Return const reference to polyPatch by name.
290  const polyPatch& operator[](const word& patchName) const;
291 
292  //- Return reference to polyPatch by name.
293  polyPatch& operator[](const word& patchName);
294 
295 
296  // Ostream operator
297 
298  friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
299 
300 
301  // Housekeeping
302 
303  //- Identical to the indices() method (AUG-2018)
304  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
306  (
307  const keyType& key,
308  const bool useGroups = true
309  ) const
310  {
311  return this->indices(key, useGroups);
312  }
313 };
314 
315 
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 
318 } // End namespace Foam
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 #ifdef NoRepository
323  #include "polyBoundaryMeshTemplates.C"
324 #endif
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 #endif
329 
330 // ************************************************************************* //
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:916
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:305
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:1197
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:955
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::checkDefinition
bool checkDefinition(const bool report=false) const
Check boundary definition. Return true if in error.
Definition: polyBoundaryMesh.C:1043
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:55
Foam::polyBoundaryMesh::whichPatch
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
Definition: polyBoundaryMesh.C:810
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:1100
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:1146
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:1220
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:71
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:1241
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: BitOps.H:63
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:862
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
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:1254
Foam::polyBoundaryMesh::~polyBoundaryMesh
~polyBoundaryMesh()=default
Destructor.
labelPair.H