fvBoundaryMesh.C
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-2024 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 \*---------------------------------------------------------------------------*/
25 
26 #include "fvBoundaryMesh.H"
27 #include "fvMesh.H"
28 
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::fvBoundaryMesh::addPatches(const polyBoundaryMesh& basicBdry)
33 {
34  setSize(basicBdry.size());
35 
36  // Set boundary patches
37  fvPatchList& Patches = *this;
38 
39  forAll(Patches, patchi)
40  {
41  Patches.set(patchi, fvPatch::New(basicBdry[patchi], *this));
42  }
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const fvMesh& m
51 )
52 :
53  fvPatchList(0),
54  mesh_(m)
55 {}
56 
57 
59 (
60  const fvMesh& m,
61  const polyBoundaryMesh& basicBdry
62 )
63 :
64  fvPatchList(basicBdry.size()),
65  mesh_(m)
66 {
67  addPatches(basicBdry);
68 }
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
74 {
75  const fvPatchList& patches = *this;
76 
78  {
79  if (patches[patchi].name() == patchName)
80  {
81  return patchi;
82  }
83  }
84 
85  // Not found, return -1
86  return -1;
87 }
88 
89 
91 (
92  const wordRe& key,
93  const bool usePatchGroups
94 ) const
95 {
96  return mesh().boundaryMesh().findIndices(key, usePatchGroups);
97 }
98 
99 
101 (
102  const labelUList& newToOld,
103  const bool validBoundary
104 )
105 {
106  fvPatchList& patches = *this;
107  patches.shuffle(newToOld);
108 }
109 
110 
112 {
113  lduInterfacePtrsList interfaces(size());
114 
115  forAll(interfaces, patchi)
116  {
117  if (isA<lduInterface>(this->operator[](patchi)))
118  {
119  interfaces.set
120  (
121  patchi,
122  &refCast<const lduInterface>(this->operator[](patchi))
123  );
124  }
125  }
126 
127  return interfaces;
128 }
129 
130 
131 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
132 
134 {
135  clear();
136  addPatches(basicBdry);
137 }
138 
139 
140 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
141 
143 (
144  const word& patchName
145 ) const
146 {
147  const label patchi = findIndex(patchName);
148 
149  if (patchi < 0)
150  {
152  << "Patch named " << patchName << " not found." << nl
153  << abort(FatalError);
154  }
155 
156  return operator[](patchi);
157 }
158 
159 
161 (
162  const word& patchName
163 )
164 {
165  const label patchi = findIndex(patchName);
166 
167  if (patchi < 0)
168  {
170  << "Patch named " << patchName << " not found." << nl
171  << abort(FatalError);
172  }
173 
174  return operator[](patchi);
175 }
176 
177 
178 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
void shuffle(const labelUList &newToOld)
Reorders elements. Ordering does not have to be done in.
Definition: PtrList.C:272
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
bool set(const label) const
Is element set.
Definition: UPtrListI.H:87
friend Ostream & operator(Ostream &, const UPtrList< T > &)
Write UPtrList to Ostream.
lduInterfacePtrsList interfaces() const
Return a list of pointers for each patch.
label findIndex(const word &patchName) const
Find patch index given a name.
fvBoundaryMesh(const fvMesh &)
Construct with zero size.
void readUpdate(const polyBoundaryMesh &)
Update boundary based on new polyBoundaryMesh.
labelList findIndices(const wordRe &, const bool useGroups) const
Find patch indices given a name.
void shuffle(const labelUList &newToOld, const bool validBoundary)
Reorders patches. Ordering does not have to be done in.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
static autoPtr< fvPatch > New(const polyPatch &, const fvBoundaryMesh &)
Return a pointer to a new patch created on freestore from polyPatch.
Definition: fvPatchNew.C:32
Foam::polyBoundaryMesh.
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
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
const fvPatchList & patches
tUEqn clear()
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
errorManip< error > abort(error &err)
Definition: errorManip.H:131
PtrList< fvPatch > fvPatchList
container classes for fvPatch
Definition: fvPatchList.H:45
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
error FatalError
static const char nl
Definition: Ostream.H:266