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-2023 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
32 
33 SourceFiles
34  faBoundaryMesh.C
35 
36 Author
37  Zeljko Tukovic, FMENA
38  Hrvoje Jasak, Wikki Ltd.
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_faBoundaryMesh_H
43 #define Foam_faBoundaryMesh_H
44 
45 #include "regIOobject.H"
46 #include "faPatch.H"
47 #include "labelPair.H"
48 #include "lduInterfacePtrsList.H"
49 #include "wordList.H"
50 #include "pointField.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 readContents(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  //- Return a list of patch names
194  wordList names() const;
195 
196  //- Return a list of patch types
197  wordList types() const;
198 
199  //- Return a list of patch start indices
200  labelList patchStarts() const;
201 
202  //- Return a list of patch sizes (number of edges in each patch)
204 
205  //- Return a list of patch ranges
207 
208  //- A list of the group names (if any)
209  wordList groupNames() const;
210 
211  //- The start label of the edges in the faMesh edges list
212  // Same as mesh.nInternalEdges()
213  label start() const;
214 
215  //- The number of boundary edges for the underlying mesh
216  // Same as mesh.nBoundaryEdges()
217  label nEdges() const;
218 
219  //- The edge range for all boundary edges
220  // Spans [nInternalEdges, nEdges) of the underlying mesh
221  labelRange range() const;
222 
223 
224  //- Return (sorted) patch indices for all matches.
225  // Optionally matches patch groups.
226  // A no-op (returns empty list) for an empty matcher
228  (
229  const wordRe& matcher,
230  const bool useGroups = true
231  ) const;
232 
233  //- Return (sorted) patch indices for all matches.
234  // Optionally matches patch groups.
235  // A no-op (returns empty list) for an empty matcher
237  (
238  const wordRes& matcher,
239  const bool useGroups = true
240  ) const;
241 
242  //- Return (sorted) patch indices for all selected matches that
243  //- are not ignored.
244  //- The selection logic as per Foam::wordRes::filter.
245  // Optionally matches patch groups.
246  // A no-op (returns empty list) for an empty select matcher
248  (
249  const wordRes& select,
250  const wordRes& ignore,
251  const bool useGroups = true
252  ) const;
253 
254  //- Return patch index for the first match, return -1 if not found
255  // A no-op (returns -1) for an empty key
256  label findIndex(const wordRe& key) const;
257 
258  //- Find patch index given a name, return -1 if not found
259  // A no-op (returns -1) for an empty name
260  label findPatchID
261  (
262  const word& patchName,
263  const bool allowNotFound = true
264  ) const;
265 
266  //- Return patch index for a given edge label
267  label whichPatch(const label edgeIndex) const;
268 
269  //- The patch indices per patch group
270  const HashTable<labelList>& groupPatchIDs() const;
271 
272  //- Set/add group with patches
273  void setGroup(const word& groupName, const labelUList& patchIDs);
274 
275  //- Check boundary definition
276  // \return True if in error.
277  bool checkDefinition(const bool report = false) const;
278 
279  //- Check whether all procs have all patches and in same order.
280  // \return True if in error.
281  bool checkParallelSync(const bool report = false) const;
282 
283 
284  // Edit
285 
286  //- Calculate the geometry for the patches
287  // (transformation tensors etc.)
288  void calcGeometry();
289 
290  //- Correct faBoundaryMesh after moving points
291  void movePoints(const pointField&);
292 
293  //- Correct faBoundaryMesh after topology update
294  void updateMesh();
295 
296 
297  // Write
298 
299  //- Write as a plain list of entries
300  void writeEntry(Ostream& os) const;
301 
302  //- Write as a primitive entry with given name.
303  //- If the keyword is empty, revert to a plain list.
304  void writeEntry(const keyType& keyword, Ostream& os) const;
305 
306  //- The writeData member function required by regIOobject
307  virtual bool writeData(Ostream& os) const;
308 
309  //- Write using stream options, but always UNCOMPRESSED
310  virtual bool writeObject
311  (
312  IOstreamOption streamOpt,
313  const bool writeOnProc = true
314  ) const;
315 
316 
317  // Ostream Operator
318 
319  friend Ostream& operator<<(Ostream&, const faBoundaryMesh&);
320 
321 
322  // Housekeeping
323 
324  //- Identical to the indices() method (AUG-2018)
325  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
326  labelList findIndices(const wordRe& key, bool useGroups=true) const
327  {
328  return indices(key, useGroups);
329  }
330 };
331 
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 } // End namespace Foam
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 #endif
340 
341 // ************************************************************************* //
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:87
List< labelRange > patchRanges() const
Return a list of patch ranges.
const labelList patchIDs(pbm.indices(polyPatchNames, true))
A class for handling keywords in dictionaries.
Definition: keyType.H:66
labelList indices(const wordRe &matcher, const bool useGroups=true) const
Return (sorted) patch indices for all matches.
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
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
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.
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
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: Scalar.H:258
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
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
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.
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:66
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:172
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.