faBoundaryMesh.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2018-2025 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::faBoundaryMesh
29 
30 Description
31  Finite area boundary mesh, which is a faPatch list with registered IO,
32  a reference to the associated faMesh,
33  with additional search methods etc.
34 
35 SourceFiles
36  faBoundaryMesh.C
37 
38 Author
39  Zeljko Tukovic, FMENA
40  Hrvoje Jasak, Wikki Ltd.
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef Foam_faBoundaryMesh_H
45 #define Foam_faBoundaryMesh_H
46 
47 #include "regIOobject.H"
48 #include "faPatch.H"
49 #include "labelPair.H"
50 #include "lduInterfacePtrsList.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 // Forward Declarations
58 class entry;
59 class faMesh;
60 class faBoundaryMesh;
61 class wordRes;
62 
63 Ostream& operator<<(Ostream&, const faBoundaryMesh&);
64 
65 /*---------------------------------------------------------------------------*\
66  Class faBoundaryMesh Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class faBoundaryMesh
70 :
71  public faPatchList,
72  public regIOobject
73 {
74  // Private Data
75 
76  //- Reference to mesh
77  const faMesh& mesh_;
78 
79  //- Demand-driven: list of patch ids per group
80  mutable autoPtr<HashTable<labelList>> groupIDsPtr_;
81 
82 
83  // Private Member Functions
84 
85  //- Some patches have inGroup entries
86  bool hasGroupIDs() const;
87 
88  //- Calculate group name to patch ids lookup
89  void calcGroupIDs() const;
90 
91  //- Clear addressing at this level
92  void clearLocalAddressing();
93 
94  //- Populate/recreate from dictionary entries
95  void populate(PtrList<entry>&& entries);
96 
97  //- Return true if contents were read
98  //- (controlled by IOobject readOption flags).
99  bool readIOcontents(const bool allowOptionalRead);
100 
101 public:
102 
103  //- Runtime type information
104  TypeName("faBoundaryMesh");
105 
106 
107  // Generated Methods
108 
109  //- No copy construct
110  faBoundaryMesh(const faBoundaryMesh&) = delete;
111 
112  //- No copy assignment
113  void operator=(const faBoundaryMesh&) = delete;
114 
115 
116  // Constructors
117 
118  //- Read construct given IOobject and a mesh reference.
119  //- It will only read for MUST_READ variants (not READ_IF_PRESENT).
121  (
122  const IOobject& io,
123  const faMesh& fam
124  );
125 
126  //- Construct empty with IOobject properties and a mesh reference.
127  //- Does not read.
129  (
130  const IOobject& io,
131  const faMesh& fam,
132  Foam::zero
133  );
134 
135  //- Construct with specified size. Does not read.
137  (
138  const IOobject& io,
139  const faMesh& fam,
140  const label size
141  );
142 
143  //- Read construct (mandatory, optional) based on IOobject properties
144  //- or use the fallback PtrList (with cloning).
146  (
147  const IOobject& io,
148  const faMesh& fam,
149  const faPatchList& list
150  );
151 
152  //- Read construct (mandatory, optional) based on IOobject properties
153  //- or fallback to constructing from a list of dictionary entries
155  (
156  const IOobject& io,
157  const faMesh& fam,
158  PtrList<entry>&& entries
159  );
160 
161 
162  //- Destructor
163  ~faBoundaryMesh() = default;
164 
165 
166  // Member Functions
167 
168  //- Clear the patch list and all demand-driven data
169  void clear();
170 
171  //- Return the mesh reference
172  const faMesh& mesh() const noexcept
173  {
174  return mesh_;
175  }
176 
177  //- Return a list of edgeLabels for each patch
179 
180  //- Return a list of edgeFaces for each patch
182 
183  //- Return a list of pointers for each patch
184  //- with only those pointing to interfaces being set
186 
187  //- The number of patches before the first processor patch.
188  label nNonProcessor() const;
189 
190  //- The number of processorFaPatch patches
191  label nProcessorPatches() const;
192 
193  //- The number of boundary edges before the first processor patch.
194  label nNonProcessorEdges() const;
195 
196  //- Return a list of patch names
197  wordList names() const;
198 
199  //- Return a list of patch types
200  wordList types() const;
201 
202  //- Return a list of patch start indices
204 
205  //- Return a list of patch sizes (number of edges in each patch)
206  labelList patchSizes() const;
207 
208  //- Return a list of patch ranges
210 
211  //- A list of the group names (if any)
212  wordList groupNames() const;
213 
214  //- The start label of the edges in the faMesh edges list
215  // Same as mesh.nInternalEdges()
216  label start() const;
217 
218  //- The number of boundary edges for the underlying mesh
219  // Same as mesh.nBoundaryEdges()
220  label nEdges() const;
221 
222  //- The edge range for all boundary edges
223  // Spans [nInternalEdges, nEdges) of the underlying mesh
224  labelRange range() const;
225 
226 
227  //- The (sorted) patch indices for all matches,
228  //- optionally matching patch groups.
229  // \returns an empty list for an empty matcher
231  (
232  const wordRe& matcher,
233  const bool useGroups = true
234  ) const;
235 
236  //- The (sorted) patch indices for all matches,
237  //- optionally matching patch groups.
238  // \returns an empty list for an empty matcher
240  (
241  const wordRes& matcher,
242  const bool useGroups = true
243  ) const;
244 
245  //- The (sorted) patch indices: logic as per Foam::wordRes::filter,
246  //- optionally matching patch groups.
247  //
248  // An empty \em allow accepts everything not in \em deny.
249  // A literal \em allow match has higher priority than any \em deny.
250  // A regex \em allow match has lower priority than any \em deny.
251  //
252  // \returns identity list when allow/deny are both empty.
254  (
255  const wordRes& allow,
256  const wordRes& deny,
257  const bool useGroups = true
258  ) const;
259 
260  //- Return patch index for the first match, return -1 if not found
261  // A no-op (returns -1) for an empty key
262  label findIndex(const wordRe& key) const;
263 
264  //- Find patch index given a name, return -1 if not found
265  // A no-op (returns -1) for an empty name
266  label findPatchID
267  (
268  const word& patchName,
269  const bool allowNotFound = true
270  ) const;
271 
272  //- Return patch index for a given edge label
273  label whichPatch(const label edgeIndex) const;
274 
275  //- The patch indices per patch group
276  const HashTable<labelList>& groupPatchIDs() const;
277 
278  //- Set/add group with patches
279  void setGroup(const word& groupName, const labelUList& patchIDs);
280 
281  //- Check boundary definition
282  // \return True if in error.
283  bool checkDefinition(const bool report = false) const;
284 
285  //- Check whether all procs have all patches and in same order.
286  // \return True if in error.
287  bool checkParallelSync(const bool report = false) const;
288 
289 
290  // Edit
291 
292  //- Calculate the geometry for the patches
293  // (transformation tensors etc.)
294  void calcGeometry();
295 
296  //- Correct faBoundaryMesh after moving points
297  void movePoints(const pointField&);
298 
299  //- Correct faBoundaryMesh after topology update
300  void updateMesh();
301 
302 
303  // Write
304 
305  //- Write as a plain list of entries
306  void writeEntry(Ostream& os) const;
307 
308  //- Write as a primitive entry with given name.
309  //- If the keyword is empty, revert to a plain list.
310  void writeEntry(const word& keyword, Ostream& os) const;
311 
312  //- The writeData member function required by regIOobject
313  virtual bool writeData(Ostream& os) const;
314 
315  //- Write using stream options, but always UNCOMPRESSED
316  virtual bool writeObject
317  (
318  IOstreamOption streamOpt,
319  const bool writeOnProc = true
320  ) const;
321 
322 
323  // Ostream Operator
324 
325  friend Ostream& operator<<(Ostream&, const faBoundaryMesh&);
326 
327 
328  // Housekeeping
329 
330  //- Identical to the indices() method (AUG-2018)
331  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
332  labelList findIndices(const wordRe& key, bool useGroups=true) const
333  {
334  return indices(key, useGroups);
335  }
336 };
337 
338 
339 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340 
341 } // End namespace Foam
342 
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 
345 #endif
346 
347 // ************************************************************************* //
wordList groupNames() const
A list of the group names (if any)
label whichPatch(const label edgeIndex) const
Return patch index for a given edge label.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:133
List< labelRange > patchRanges() const
Return a list of patch ranges.
const labelList patchIDs(pbm.indices(polyPatchNames, true))
labelList indices(const wordRe &matcher, const bool useGroups=true) const
The (sorted) patch indices for all matches, optionally matching patch groups.
bool checkDefinition(const bool report=false) const
Check boundary definition.
void clear()
Clear the patch list and all demand-driven data.
virtual bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
friend Ostream & operator<<(Ostream &, const faBoundaryMesh &)
lduInterfacePtrsList interfaces() const
Return a list of pointers for each patch with only those pointing to interfaces being set...
void calcGeometry()
Calculate the geometry for the patches.
labelList patchSizes() const
Return a list of patch sizes (number of edges in each patch)
labelList findIndices(const wordRe &key, bool useGroups=true) const
Identical to the indices() method (AUG-2018)
UPtrList< const labelUList > edgeFaces() const
Return a list of edgeFaces for each patch.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
void updateMesh()
Correct faBoundaryMesh after topology update.
FOAM_DEPRECATED_FOR(2022-09, "get(), set() or test() methods") const T *operator()(const label i) const
Deprecated(2022-09) - same as get()
Definition: UPtrList.H:492
A simple container for options an IOstream can normally have.
const HashTable< labelList > & groupPatchIDs() const
The patch indices per patch group.
label findIndex(const wordRe &key) const
Return patch index for the first match, return -1 if not found.
void writeEntry(Ostream &os) const
Write as a plain list of entries.
TypeName("faBoundaryMesh")
Runtime type information.
void operator=(const faBoundaryMesh &)=delete
No copy assignment.
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
label nNonProcessorEdges() const
The number of boundary edges before the first processor patch.
void movePoints(const pointField &)
Correct faBoundaryMesh after moving points.
A class for handling words, derived from Foam::string.
Definition: word.H:63
wordList names() const
Return a list of patch names.
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
auto key(const Type &t) -> std::enable_if_t< std::is_enum_v< Type >, std::underlying_type_t< Type > >
Definition: foamGltfBase.H:103
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
~faBoundaryMesh()=default
Destructor.
const faMesh & mesh() const noexcept
Return the mesh reference.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: scalarImpl.H:255
wordList types() const
Return a list of patch types.
OBJstream os(runTime.globalPath()/outputName)
faBoundaryMesh(const faBoundaryMesh &)=delete
No copy construct.
label start() const
The start label of the edges in the faMesh edges list.
UPtrList< const labelUList > edgeLabels() const
Return a list of edgeLabels for each patch.
label nEdges() const
The number of boundary edges for the underlying mesh.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:54
label nNonProcessor() const
The number of patches before the first processor patch.
void setGroup(const word &groupName, const labelUList &patchIDs)
Set/add group with patches.
Finite area boundary mesh, which is a faPatch list with registered IO, a reference to the associated ...
bool checkParallelSync(const bool report=false) const
Check whether all procs have all patches and in same order.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
labelRange range() const
The edge range for all boundary edges.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write using stream options, but always UNCOMPRESSED.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Calculate the matrix for the second temporal derivative.
labelList patchStarts() const
Return a list of patch start indices.
label nProcessorPatches() const
The number of processorFaPatch patches.
Namespace for OpenFOAM.