Loading...
Searching...
No Matches
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-2025 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 registered IO,
32 a reference to the associated polyMesh,
33 with additional search methods etc.
34
35SourceFiles
36 polyBoundaryMesh.C
37 polyBoundaryMesh.txx
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_polyBoundaryMesh_H
42#define Foam_polyBoundaryMesh_H
43
44#include "regIOobject.H"
45#include "polyPatch.H"
46#include "labelPair.H"
47#include "HashSet.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55class entry;
56class polyMesh;
57class wordRe;
58class wordRes;
59
62/*---------------------------------------------------------------------------*\
63 Class polyBoundaryMesh Declaration
64\*---------------------------------------------------------------------------*/
65
67:
68 public polyPatchList,
69 public regIOobject
70{
71 // Private Data
72
73 //- Reference to mesh
74 const polyMesh& mesh_;
75
76 //- Demand-driven: list of patch ids per face.
77 mutable autoPtr<labelList> patchIDPtr_;
78
79 //- Demand-driven: list of patch ids per group
80 mutable autoPtr<HashTable<labelList>> groupIDsPtr_;
81
82 //- Demand-driven: edges of neighbouring patches
83 mutable autoPtr<List<labelPairList>> neighbourEdgesPtr_;
84
85
86 // Private Member Functions
87
88 //- Calculate geometry for the patches (transformation tensors etc.)
89 void calcGeometry();
90
91 //- Some patches have inGroup entries
92 bool hasGroupIDs() const;
93
94 //- Calculate group name to patch ids lookup
95 void calcGroupIDs() const;
96
97 //- Clear addressing at this level
98 void clearLocalAddressing();
99
100 //- Populate/recreate from dictionary entries
101 void populate(PtrList<entry>&& entries);
102
103 //- Return true if contents were read
104 //- (controlled by IOobject readOption flags).
105 bool readIOcontents(const bool allowOptionalRead);
106
107public:
108
109 //- Declare friendship with polyMesh
110 friend class polyMesh;
111
112 //- Runtime type information
113 TypeName("polyBoundaryMesh");
114
115
116 // Generated Methods
117
118 //- No copy construct
119 polyBoundaryMesh(const polyBoundaryMesh&) = delete;
120
121 //- No copy assignment
122 void operator=(const polyBoundaryMesh&) = delete;
123
124
125 // Constructors
126
127 //- Read construct given IOobject and a mesh reference.
128 //- It will only read for MUST_READ variants (not READ_IF_PRESENT).
130 (
131 const IOobject& io,
133 );
134
135 //- Construct empty with IOobject properties and a mesh reference.
136 //- Does not read.
138 (
139 const IOobject& io,
142 );
143
144 //- Construct with specified size. Does not read.
146 (
147 const IOobject& io,
148 const polyMesh& mesh,
149 const label size
150 );
151
152 //- Read construct (mandatory, optional) based on IOobject properties
153 //- or use the fallback PtrList (with cloning).
155 (
156 const IOobject& io,
157 const polyMesh& mesh,
158 const polyPatchList& list
159 );
160
161 //- Read construct (mandatory, optional) based on IOobject properties
162 //- or fallback to constructing from a list of dictionary entries
164 (
165 const IOobject& io,
166 const polyMesh& mesh,
167 PtrList<entry>&& entries
168 );
169
170
171 //- Destructor
172 ~polyBoundaryMesh() = default;
173
174
175 // Member Functions
176
177 //- Clear the patch list and all demand-driven data
178 void clear();
179
180 //- Clear geometry at this level and at patches
181 void clearGeom();
182
183 //- Clear addressing at this level and at patches
184 void clearAddressing();
185
186 //- Return the mesh reference
187 const polyMesh& mesh() const noexcept
188 {
189 return mesh_;
190 }
191
192 //- Return mesh faces for the entire boundary
193 const faceList::subList faces() const;
194
195 //- Return face owner for the entire boundary
196 const labelList::subList faceOwner() const;
197
198 //- Return a list of faceCells for each patch
200
201 //- Per patch the edges on the neighbouring patch.
202 // Is for every external edge the neighbouring patch and
203 // neighbouring (external) patch edge label. Note that edge indices
204 // are offset by nInternalEdges to keep it as much as possible
205 // consistent with coupled patch addressing (where coupling is by
206 // local patch face index). Only valid for singly connected
207 // polyBoundaryMesh and not parallel
208 const List<labelPairList>& neighbourEdges() const;
209
210 //- The number of patches before the first processor patch.
211 label nNonProcessor() const;
212
213 //- The number of processorPolyPatch patches
214 label nProcessorPatches() const;
215
216 //- The number of boundary faces before the first processor patch.
217 label nNonProcessorFaces() const;
218
219 //- Return a list of patch names
220 wordList names() const;
221
222 //- Return a list of patch types
223 wordList types() const;
224
225 //- Return a list of physical types
226 wordList physicalTypes() const;
227
228 //- Return a list of patch start face indices
229 labelList patchStarts() const;
231 //- Return a list of patch sizes
232 labelList patchSizes() const;
233
234 //- Return a list of patch ranges
236
237 //- A list of the group names (if any)
238 wordList groupNames() const;
239
240 //- The start label of boundary faces in the polyMesh face list
241 // Same as polyMesh::nInternalFaces()
242 label start() const noexcept;
243
244 //- The number of boundary faces in the underlying mesh
245 // Same as polyMesh::nBoundaryFaces()
246 label nFaces() const noexcept;
247
248 //- The number of boundary faces with patches that match the
249 //- given predicate.
250 template<class UnaryPredicate>
251 label nFaces_if(UnaryPredicate pred) const;
252
253 //- The face range for all boundary faces
254 // Spans [nInternalFaces, nFaces) of the underlying mesh
255 labelRange range() const noexcept;
256
257 //- Return the range used for boundary faces on patchi.
258 // Always returns an empty range for negative values of patchi,
259 // which allows safe use with findIndex or findPatchID.
260 labelRange range(const label patchi) const;
261
262
263 //- The (sorted) patch indices for all matches,
264 //- optionally matching patch groups.
265 // \returns an empty list for an empty matcher
267 (
268 const wordRe& matcher,
269 const bool useGroups = true
270 ) const;
271
272 //- The (sorted) patch indices for all matches,
273 //- optionally matching patch groups.
274 // \returns an empty list for an empty matcher
276 (
277 const wordRes& matcher,
278 const bool useGroups = true
279 ) const;
280
281 //- The (sorted) patch indices: logic as per Foam::wordRes::filter,
282 //- optionally matching patch groups.
283 //
284 // An empty \em allow accepts everything not in \em deny.
285 // A literal \em allow match has higher priority than any \em deny.
286 // A regex \em allow match has lower priority than any \em deny.
287 //
288 // \returns identity list when allow/deny are both empty.
290 (
291 const wordRes& allow,
292 const wordRes& deny,
293 const bool useGroups = true
294 ) const;
295
296 //- Return (sorted) patch indices for patches that match the
297 //- given polyPatch type (uses \c isA test).
298 //- Can be used as a direct alternative to findPatchIDs
299 template<class PatchType>
300 labelList indices_if() const;
301
302 //- Return (sorted) patch indices for patches that match the
303 //- given predicate. Can be used as an alternative to findPatchIDs
304 template<class UnaryPredicate>
305 labelList indices_if(UnaryPredicate pred) const;
306
307 //- Return patch index for the first match, return -1 if not found
308 // A no-op (returns -1) for an empty key
309 label findIndex(const wordRe& key) const;
310
311 //- Find patch index given a name, return -1 if not found
312 // A no-op (returns -1) for an empty patchName
313 label findPatchID
314 (
315 const word& patchName,
316 const bool allowNotFound = true
317 ) const;
318
319 //- Find patch by name and return const pointer.
320 //- \returns nullptr on error or for an empty patchName
321 const polyPatch* cfindPatch(const word& patchName) const;
322
323 //- Find patch indices for a given polyPatch type (uses \c isA test).
324 template<class PatchType>
326
327 //- Lookup mesh face index and return (patchi, patchFacei) tuple
328 //- or (-1, meshFacei) for internal faces
329 labelPair whichPatchFace(const label meshFacei) const;
330
331 //- Lookup mesh face indices and return (patchi, patchFacei) tuples
332 labelPairList whichPatchFace(const labelUList& meshFaceIndices) const;
333
334 //- Return patch index for a given mesh face index.
335 //- Uses binary search.
336 label whichPatch(const label meshFacei) const
337 {
338 return whichPatchFace(meshFacei).first();
339 }
340
341 //- Per boundary face label the patch index
342 const labelList& patchID() const;
343
344 //- Return patch index for a given mesh face index.
345 //- Uses direct lookup into patchID() list.
346 //- Returns -1 for internal or out-of-range faces
347 label patchID(const label meshFacei) const;
348
349 //- Lookup mesh face indices and return patch indices.
350 //- Uses direct lookup into patchID() list.
351 //- Returns values of -1 for internal or out-of-range faces
352 labelList patchID(const labelUList& meshFaceIndices) const;
353
354 //- The patch indices per patch group
355 const HashTable<labelList>& groupPatchIDs() const;
356
357 //- Set/add group with patches
358 void setGroup(const word& groupName, const labelUList& patchIDs);
359
360 //- Return the set of patch IDs corresponding to the given names
361 // By default warns if given names are not found.
362 // Optionally matches to patchGroups as well as patchNames.
364 (
365 const UList<wordRe>& select,
366 const bool warnNotFound = true,
367 const bool useGroups = true
368 ) const;
369
370 //- Match the patches to groups.
371 // Returns all the (fully matched) groups and any remaining
372 // unmatched patches.
373 void matchGroups
374 (
375 const labelUList& patchIDs,
376 wordList& groups,
377 labelHashSet& nonGroupPatches
378 ) const;
379
380 //- Check whether all procs have all patches and in same order.
381 // \return True if in error.
382 bool checkParallelSync(const bool report = false) const;
383
384 //- Check boundary definition.
385 // \return True if in error.
386 bool checkDefinition(const bool report = false) const;
387
388 //- Correct polyBoundaryMesh after moving points
389 void movePoints(const pointField& p);
390
391 //- Correct polyBoundaryMesh after topology update
392 void updateMesh();
393
394 //- Reorders patches. Ordering does not have to be done in
395 // ascending or descending order. Reordering has to be unique.
396 // (is shuffle) If validBoundary calls updateMesh()
397 // after reordering to recalculate data (so call needs to be parallel
398 // sync in that case)
399 void reorder(const labelUList& oldToNew, const bool validBoundary);
400
401
402 // Write
403
404 //- Write as a plain list of entries
405 void writeEntry(Ostream& os) const;
406
407 //- Write as a primitive entry with given name.
408 //- If the keyword is empty, revert to a plain list.
409 void writeEntry(const word& keyword, Ostream& os) const;
410
411 //- The writeData member function required by regIOobject
412 virtual bool writeData(Ostream& os) const;
413
414 //- Write using stream options, but always UNCOMPRESSED
415 virtual bool writeObject
416 (
417 IOstreamOption streamOpt,
418 const bool writeOnProc = true
419 ) const;
420
421
422 // Member Operators
423
424 //- Return const and non-const reference to polyPatch by index.
425 using polyPatchList::operator[];
426
427 //- Return const reference to polyPatch by name.
428 const polyPatch& operator[](const word& patchName) const;
429
430 //- Return reference to polyPatch by name.
431 polyPatch& operator[](const word& patchName);
432
433
434 // Ostream Operator
435
437
438
439 // Housekeeping
440
441 //- Identical to the indices() method (AUG-2018)
442 FOAM_DEPRECATED_FOR(2018-08, "indices() method")
443 labelList findIndices(const wordRe& key, bool useGroups=true) const
444 {
445 return this->indices(key, useGroups);
446 }
447};
448
449
450// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
452} // End namespace Foam
453
454// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
455
456#ifdef NoRepository
457 #include "polyBoundaryMesh.txx"
458#endif
459
460// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
461
462#endif
463
464// ************************************************************************* //
labelList patchIDs
const polyBoundaryMesh & pbm
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
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:72
SubList< face > subList
Definition List.H:129
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
const T & first() const noexcept
Access the first element.
Definition Pair.H:137
constexpr PtrList() noexcept
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition UPtrList.H:101
label size() const noexcept
The number of entries in the list.
Definition UPtrListI.H:106
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
bool checkDefinition(const bool report=false) const
Check boundary definition.
label nNonProcessorFaces() const
The number of boundary faces before the first processor patch.
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.
labelList indices_if() const
Return (sorted) patch indices for patches that match the given polyPatch type (uses isA test)....
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write using stream options, but always UNCOMPRESSED.
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.
label whichPatch(const label meshFacei) const
Return patch index for a given mesh face index. Uses binary search.
UPtrList< const labelUList > faceCells() const
Return a list of faceCells for each patch.
virtual bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
labelHashSet patchSet(const UList< wordRe > &select, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
labelHashSet findPatchIDs() const
Find patch indices for a given polyPatch type (uses isA test).
friend Ostream & operator<<(Ostream &os, const polyBoundaryMesh &pbm)
const polyPatch & operator[](const word &patchName) const
Return const reference to polyPatch by name.
const faceList::subList faces() const
Return mesh faces for the entire boundary.
void setGroup(const word &groupName, const labelUList &patchIDs)
Set/add group with patches.
label nFaces_if(UnaryPredicate pred) const
The number of boundary faces with patches that match the given predicate.
labelRange range() const noexcept
The face range for all boundary faces.
void movePoints(const pointField &p)
Correct polyBoundaryMesh after moving points.
TypeName("polyBoundaryMesh")
Runtime type information.
~polyBoundaryMesh()=default
Destructor.
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.
friend class polyMesh
Declare friendship with polyMesh.
label start() const noexcept
The start label of boundary faces in the polyMesh face list.
void writeEntry(Ostream &os) const
Write as a plain list of entries.
void operator=(const polyBoundaryMesh &)=delete
No copy assignment.
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.
void clear()
Clear the patch list and all demand-driven data.
wordList groupNames() const
A list of the group names (if any).
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.
const polyPatch * cfindPatch(const word &patchName) const
Find patch by name and return const pointer.
const labelList::subList faceOwner() const
Return face owner for the entire boundary.
label nProcessorPatches() const
The number of processorPolyPatch patches.
polyBoundaryMesh(const polyBoundaryMesh &)=delete
No copy construct.
labelList indices(const wordRe &matcher, const bool useGroups=true) const
The (sorted) patch indices for all matches, optionally matching patch groups.
label findIndex(const wordRe &key) const
Return patch index for the first match, return -1 if not found.
labelPair whichPatchFace(const label meshFacei) const
Lookup mesh face index and return (patchi, patchFacei) tuple or (-1, meshFacei) for internal faces.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
volScalarField & p
OBJstream os(runTime.globalPath()/outputName)
const auto & io
Namespace for OpenFOAM.
Pair< label > labelPair
A pair of labels.
Definition Pair.H:54
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition polyPatch.H:61
List< word > wordList
List of word.
Definition fileName.H:60
List< labelPair > labelPairList
List of labelPair.
Definition labelPair.H:33
List< label > labelList
A List of labels.
Definition List.H:62
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
const direction noexcept
Definition scalarImpl.H:265
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition stdFoam.H:43
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68