polyBoundaryMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::polyBoundaryMesh
26 
27 Description
28  Foam::polyBoundaryMesh
29 
30 SourceFiles
31  polyBoundaryMesh.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef polyBoundaryMesh_H
36 #define polyBoundaryMesh_H
37 
38 #include "polyPatchList.H"
39 #include "regIOobject.H"
40 #include "labelPair.H"
41 #include "HashSet.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of classes
49 class polyMesh;
50 class wordRe;
51 
52 // Forward declaration of friend functions and operators
53 
54 Ostream& operator<<(Ostream&, const polyBoundaryMesh&);
55 
56 
57 /*---------------------------------------------------------------------------*\
58  Class polyBoundaryMesh Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class polyBoundaryMesh
62 :
63  public polyPatchList,
64  public regIOobject
65 {
66  // private data
67 
68  //- Reference to mesh
69  const polyMesh& mesh_;
70 
71  mutable autoPtr<labelList> patchIDPtr_;
72 
73  mutable autoPtr<labelList> patchFaceIDPtr_;
74 
75  mutable autoPtr<HashTable<labelList, word>> groupPatchIDsPtr_;
76 
77  //- Edges of neighbouring patches
78  mutable autoPtr<List<labelPairList>> nbrEdgesPtr_;
79 
80 
81  // Private Member Functions
82 
83  //- Calculate the geometry for the patches (transformation tensors etc.)
84  void calcGeometry();
85 
86 
87 public:
88 
89  //- Declare friendship with polyMesh
90  friend class polyMesh;
91 
92 
93  //- Runtime type information
94  TypeName("polyBoundaryMesh");
95 
96 
97  // Constructors
98 
99  //- Read constructor given IOobject and a polyMesh reference
100  // Note point pointers are unset, only used in copying meshes
102  (
103  const IOobject&,
104  const polyMesh&
105  );
106 
107  //- Construct given size
109  (
110  const IOobject&,
111  const polyMesh&,
112  const label size
113  );
114 
115  //- Construct given polyPatchList
117  (
118  const IOobject&,
119  const polyMesh&,
120  const polyPatchList&
121  );
122 
123  //- Move constructor
124  polyBoundaryMesh(polyBoundaryMesh&&) = default;
125 
126  //- Disallow default bitwise copy construction
127  polyBoundaryMesh(const polyBoundaryMesh&) = delete;
128 
129 
130  //- Destructor
132 
133  //- Clear geometry at this level and at patches
134  void clearGeom();
135 
136  //- Clear addressing at this level and at patches
137  void clearAddressing();
138 
139 
140  // Member Functions
141 
142  //- Return the mesh reference
143  const polyMesh& mesh() const
144  {
145  return mesh_;
146  }
147 
148  //- Per patch the edges on the neighbouring patch. Is for every external
149  // edge the neighbouring patch and neighbouring (external) patch edge
150  // label. Note that edge indices are offset by nInternalEdges to keep
151  // it as much as possible consistent with coupled patch addressing
152  // (where coupling is by local patch face index).
153  // Only valid for singly connected polyBoundaryMesh and not parallel
154  const List<labelPairList>& nbrEdges() const;
155 
156  //- Return a list of patch names
157  wordList names() const;
158 
159  //- Return a list of patch types
160  wordList types() const;
161 
162  //- Return a list of physical types
163  wordList physicalTypes() const;
164 
165  //- Return patch indices for all matches. Optionally matches patchGroups
167  (
168  const wordRe&,
169  const bool usePatchGroups = true
170  ) const;
171 
172  //- Return patch index for the first match, return -1 if not found
173  label findIndex(const wordRe&) const;
174 
175  //- Find patch index given a name
176  label findPatchID(const word& patchName) const;
177 
178  //- Find patch indices for a given polyPatch type
179  template<class Type>
180  labelHashSet findPatchIDs() const;
181 
182  //- Return patch index for a given face label
183  label whichPatch(const label faceIndex) const;
184 
185  //- Per boundary face label the patch index
186  const labelList& patchID() const;
187 
188  //- Per boundary face label the patch face index
189  const labelList& patchFaceID() const;
190 
191  //- Per patch group the patch indices
193 
194  //- Set/add group with patches
195  void setGroup(const word& groupName, const labelList& patchIDs);
196 
197  //- Return the set of patch IDs corresponding to the given names
198  // By default warns if given names are not found. Optionally
199  // matches to patchGroups as well as patchNames
201  (
202  const UList<wordRe>& patchNames,
203  const bool warnNotFound = true,
204  const bool usePatchGroups = true
205  ) const;
206 
207  //- Match the patches to groups. Returns all the (fully matched) groups
208  // and any remaining unmatched patches.
209  void matchGroups
210  (
211  const labelUList& patchIDs,
212  wordList& groups,
213  labelHashSet& nonGroupPatches
214  ) const;
215 
216  //- Check whether all procs have all patches and in same order. Return
217  // true if in error.
218  bool checkParallelSync(const bool report = false) const;
219 
220  //- Check boundary definition. Return true if in error.
221  bool checkDefinition(const bool report = false) const;
222 
223  //- Correct polyBoundaryMesh after moving points
224  void movePoints(const pointField&);
225 
226  //- Correct polyBoundaryMesh after topology update
227  void topoChange();
228 
229  //- Rename the patches. If validBoundary is set this calls topoChange()
230  // after reordering to recalculate data (so the call needs to be
231  // parallel synchronised).
232  void renamePatches(const wordUList& newNames, const bool validBoundary);
233 
234  //- Reorders the patches. Ordering does not have to be done in
235  // ascending or descending order. Reordering has to be unique (is a
236  // shuffle). If validBoundary is set this calls topoChange() after
237  // reordering to recalculate data (so the call needs to be parallel
238  // synchronised).
239  void reorderPatches
240  (
241  const labelUList& newToOld,
242  const bool validBoundary
243  );
244 
245  //- writeData member function required by regIOobject
246  bool writeData(Ostream&) const;
247 
248  //- Write using given format, version and form uncompression
249  bool writeObject
250  (
254  const bool write = true
255  ) const;
256 
257 
258  // Member Operators
259 
260  //- Return const and non-const reference to polyPatch by index.
261  using polyPatchList::operator[];
262 
263  //- Return const reference to polyPatch by name.
264  const polyPatch& operator[](const word&) const;
265 
266  //- Return reference to polyPatch by name.
267  polyPatch& operator[](const word&);
268 
269  //- Disallow default bitwise assignment
270  void operator=(const polyBoundaryMesh&) = delete;
271 
272 
273  // Ostream operator
274 
275  friend Ostream& operator<<(Ostream&, const polyBoundaryMesh&);
276 };
277 
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 } // End namespace Foam
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 #ifdef NoRepository
286  #include "polyBoundaryMeshTemplates.C"
287 #endif
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 #endif
292 
293 // ************************************************************************* //
An STL-conforming hash table.
Definition: HashTable.H:127
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
static word groupName(Name name, const word &group)
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
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:74
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
friend Ostream & operator(Ostream &, const UPtrList< T > &)
Write UPtrList to Ostream.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Foam::polyBoundaryMesh.
bool checkDefinition(const bool report=false) const
Check boundary definition. Return true if in error.
wordList physicalTypes() const
Return a list of physical types.
void topoChange()
Correct polyBoundaryMesh after topology update.
bool writeData(Ostream &) const
writeData member function required by regIOobject
wordList types() const
Return a list of patch types.
void clearGeom()
Clear geometry at this level and at patches.
labelHashSet findPatchIDs() const
Find patch indices for a given polyPatch type.
const HashTable< labelList, word > & groupPatchIDs() const
Per patch group the patch indices.
const polyPatch & operator[](const word &) const
Return const reference to polyPatch by name.
friend Ostream & operator<<(Ostream &, const polyBoundaryMesh &)
void setGroup(const word &groupName, const labelList &patchIDs)
Set/add group with patches.
~polyBoundaryMesh()
Destructor.
TypeName("polyBoundaryMesh")
Runtime type information.
bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool write=true) const
Write using given format, version and form uncompression.
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
void matchGroups(const labelUList &patchIDs, wordList &groups, labelHashSet &nonGroupPatches) const
Match the patches to groups. Returns all the (fully matched) groups.
void clearAddressing()
Clear addressing at this level and at patches.
const labelList & patchFaceID() const
Per boundary face label the patch face index.
void movePoints(const pointField &)
Correct polyBoundaryMesh after moving points.
void operator=(const polyBoundaryMesh &)=delete
Disallow default bitwise assignment.
void renamePatches(const wordUList &newNames, const bool validBoundary)
Rename the patches. If validBoundary is set this calls topoChange()
const labelList & patchID() const
Per boundary face label the patch index.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const
Return the set of patch IDs corresponding to the given names.
label findIndex(const wordRe &) const
Return patch index for the first match, return -1 if not found.
label findPatchID(const word &patchName) const
Find patch index given a name.
void reorderPatches(const labelUList &newToOld, const bool validBoundary)
Reorders the patches. Ordering does not have to be done in.
polyBoundaryMesh(const IOobject &, const polyMesh &)
Read constructor given IOobject and a polyMesh reference.
wordList names() const
Return a list of patch names.
const List< labelPairList > & nbrEdges() const
Per patch the edges on the neighbouring patch. Is for every external.
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order. Return.
labelList findIndices(const wordRe &, const bool usePatchGroups=true) const
Return patch indices for all matches. Optionally matches patchGroups.
const polyMesh & mesh() const
Return the mesh reference.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
virtual bool write(const bool write=true) const
Write using setting from DB.
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:77
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & operator<<(Ostream &, const ensightPart &)
wordList patchNames(nPatches)