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-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::polyBoundaryMesh
29
30Description
31 A polyBoundaryMesh is a polyPatch list with additional search methods
32 and registered IO.
33
34SourceFiles
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
49namespace Foam
50{
51
52// Forward Declarations
53class polyMesh;
54class wordRe;
55class wordRes;
56
57Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
58
59/*---------------------------------------------------------------------------*\
60 Class polyBoundaryMesh Declaration
61\*---------------------------------------------------------------------------*/
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 //- No copy construct
98 polyBoundaryMesh(const polyBoundaryMesh&) = delete;
99
100 //- No copy assignment
101 void operator=(const polyBoundaryMesh&) = delete;
102
103
104public:
105
106 //- Declare friendship with polyMesh
107 friend class polyMesh;
108
109
110 //- Runtime type information
111 TypeName("polyBoundaryMesh");
112
113
114 // Constructors
115
116 //- Read constructor given IOobject and a polyMesh reference
117 // Note point pointers are unset, only used in copying meshes
119 (
120 const IOobject& io,
121 const polyMesh& mesh
122 );
123
124 //- Construct given size
126 (
127 const IOobject& io,
128 const polyMesh& mesh,
129 const label size
130 );
131
132 //- Construct given polyPatchList
134 (
135 const IOobject& io,
136 const polyMesh& mesh,
137 const polyPatchList& ppl
138 );
139
140
141 //- Destructor
142 ~polyBoundaryMesh() = default;
143
144
145 //- Clear geometry at this level and at patches
146 void clearGeom();
147
148 //- Clear addressing at this level and at patches
149 void clearAddressing();
150
151
152 // Member Functions
153
154 //- Return the mesh reference
155 const polyMesh& mesh() const noexcept
156 {
157 return mesh_;
158 }
159
160 //- Return a list of faceCells for each patch
162
163 //- Per patch the edges on the neighbouring patch.
164 // Is for every external edge the neighbouring patch and
165 // neighbouring (external) patch edge label. Note that edge indices
166 // are offset by nInternalEdges to keep it as much as possible
167 // consistent with coupled patch addressing (where coupling is by
168 // local patch face index). Only valid for singly connected
169 // polyBoundaryMesh and not parallel
170 const List<labelPairList>& neighbourEdges() const;
171
172 //- The number of patches before the first processor patch.
173 label nNonProcessor() const;
174
175 //- Return a list of patch names
176 wordList names() const;
177
178 //- Return a list of patch types
179 wordList types() const;
180
181 //- Return a list of physical types
182 wordList physicalTypes() const;
183
184 //- Return a list of patch start face indices
185 labelList patchStarts() const;
186
187 //- Return a list of patch sizes
188 labelList patchSizes() const;
189
190 //- Return a list of patch ranges
192
193 //- The start label of boundary faces in the polyMesh face list
194 // Same as polyMesh::nInternalFaces()
195 label start() const noexcept;
196
197 //- The number of boundary faces in the underlying mesh
198 // Same as polyMesh::nBoundaryFaces()
199 label nFaces() const noexcept;
200
201 //- The face range for all boundary faces
202 // Spans [nInternalFaces, nFaces) of the underlying mesh
203 labelRange range() const noexcept;
204
205 //- Return the range used for boundary faces on patchi.
206 // Always returns an empty range for negative values of patchi,
207 // which allows safe use with findIndex or findPatchID.
208 labelRange range(const label patchi) const;
209
210
211 //- Return (sorted) patch indices for all matches.
212 // Optionally matches patch groups.
213 // A no-op (returns empty list) for an empty matcher
215 (
216 const wordRe& matcher,
217 const bool useGroups = true
218 ) const;
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 wordRes& matcher,
226 const bool useGroups = true
227 ) const;
228
229 //- Return patch index for the first match, return -1 if not found
230 // A no-op (returns -1) for an empty key
231 label findIndex(const wordRe& key) const;
232
233 //- Find patch index given a name, return -1 if not found
234 // A no-op (returns -1) for an empty patchName
235 label findPatchID
236 (
237 const word& patchName,
238 const bool allowNotFound = true
239 ) const;
240
241 //- Find patch indices for a given polyPatch type
242 template<class Type>
244
245 //- Return patch index for a given face label
246 label whichPatch(const label faceIndex) const;
247
248 //- Per boundary face label the patch index
249 const labelList& patchID() const;
250
251 //- The patch indices per patch group
252 const HashTable<labelList>& groupPatchIDs() const;
253
254 //- Set/add group with patches
255 void setGroup(const word& groupName, const labelUList& patchIDs);
256
257 //- Return the set of patch IDs corresponding to the given names
258 // By default warns if given names are not found.
259 // Optionally matches to patchGroups as well as patchNames.
261 (
262 const UList<wordRe>& patchNames,
263 const bool warnNotFound = true,
264 const bool useGroups = true
265 ) const;
266
267 //- Match the patches to groups.
268 // Returns all the (fully matched) groups and any remaining
269 // unmatched patches.
270 void matchGroups
271 (
272 const labelUList& patchIDs,
273 wordList& groups,
274 labelHashSet& nonGroupPatches
275 ) const;
276
277 //- Check whether all procs have all patches and in same order.
278 // \return True if in error.
279 bool checkParallelSync(const bool report = false) const;
280
281 //- Check boundary definition.
282 // \return True if in error.
283 bool checkDefinition(const bool report = false) const;
284
285 //- Correct polyBoundaryMesh after moving points
286 void movePoints(const pointField& p);
287
288 //- Correct polyBoundaryMesh after topology update
289 void updateMesh();
290
291 //- Reorders patches. Ordering does not have to be done in
292 // ascending or descending order. Reordering has to be unique.
293 // (is shuffle) If validBoundary calls updateMesh()
294 // after reordering to recalculate data (so call needs to be parallel
295 // sync in that case)
296 void reorder(const labelUList& oldToNew, const bool validBoundary);
297
298 //- writeData member function required by regIOobject
299 virtual bool writeData(Ostream& os) const;
300
301 //- Write using stream options
302 virtual bool writeObject
303 (
304 IOstreamOption streamOpt,
305 const bool valid
306 ) const;
307
308
309 // Member Operators
310
311 //- Return const and non-const reference to polyPatch by index.
312 using polyPatchList::operator[];
313
314 //- Return const reference to polyPatch by name.
315 const polyPatch& operator[](const word& patchName) const;
316
317 //- Return reference to polyPatch by name.
318 polyPatch& operator[](const word& patchName);
319
320
321 // Ostream Operator
323 friend Ostream& operator<<(Ostream& os, const polyBoundaryMesh& pbm);
324
325
326 // Housekeeping
327
328 //- Identical to the indices() method (AUG-2018)
329 FOAM_DEPRECATED_FOR(2018-08, "indices() method")
330 labelList findIndices(const wordRe& key, bool useGroups=true) const
331 {
332 return this->indices(key, useGroups);
333 }
334};
335
336
337// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338
339} // End namespace Foam
340
341// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
342
343#ifdef NoRepository
345#endif
346
347// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348
349#endif
350
351// ************************************************************************* //
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
The IOstreamOption is a simple container for options an IOstream can normally have.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:71
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
friend Ostream & operator(Ostream &os, const UPtrList< T > &list)
Write UPtrList to Ostream.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:58
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
bool checkDefinition(const bool report=false) const
Check boundary definition.
label nNonProcessor() const
The number of patches before the first processor patch.
wordList physicalTypes() const
Return a list of physical types.
const HashTable< labelList > & groupPatchIDs() const
The patch indices per patch group.
labelList patchStarts() const
Return a list of patch start face indices.
const List< labelPairList > & neighbourEdges() const
Per patch the edges on the neighbouring patch.
void reorder(const labelUList &oldToNew, const bool validBoundary)
Reorders patches. Ordering does not have to be done in.
wordList types() const
Return a list of patch types.
void clearGeom()
Clear geometry at this level and at patches.
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
UPtrList< const labelUList > faceCells() const
Return a list of faceCells for each patch.
virtual bool writeData(Ostream &os) const
writeData member function required by regIOobject
labelHashSet findPatchIDs() const
Find patch indices for a given polyPatch type.
void setGroup(const word &groupName, const labelUList &patchIDs)
Set/add group with patches.
labelRange range() const noexcept
The face range for all boundary faces.
void movePoints(const pointField &p)
Correct polyBoundaryMesh after moving points.
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.
TypeName("polyBoundaryMesh")
Runtime type information.
~polyBoundaryMesh()=default
Destructor.
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
List< labelRange > patchRanges() const
Return a list of patch ranges.
labelList findIndices(const wordRe &key, bool useGroups=true) const
Identical to the indices() method (AUG-2018)
void matchGroups(const labelUList &patchIDs, wordList &groups, labelHashSet &nonGroupPatches) const
Match the patches to groups.
void clearAddressing()
Clear addressing at this level and at patches.
label nFaces() const noexcept
The number of boundary faces in the underlying mesh.
label start() const noexcept
The start label of boundary faces in the polyMesh face list.
const labelList & patchID() const
Per boundary face label the patch index.
const polyMesh & mesh() const noexcept
Return the mesh reference.
labelList patchSizes() const
Return a list of patch sizes.
wordList names() const
Return a list of patch names.
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.
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) patch indices for all matches.
label findIndex(const wordRe &key) const
Return patch index for the first match, return -1 if not found.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:83
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
const direction noexcept
Definition: Scalar.H:223
wordList patchNames(nPatches)
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73