fvBoundaryMesh.C
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-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2020 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 \*---------------------------------------------------------------------------*/
28 
29 #include "fvBoundaryMesh.H"
30 #include "fvMesh.H"
31 
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 void Foam::fvBoundaryMesh::addPatches(const polyBoundaryMesh& basicBdry)
36 {
37  setSize(basicBdry.size());
38 
39  // Set boundary patches
40  fvPatchList& Patches = *this;
41 
42  forAll(Patches, patchi)
43  {
44  Patches.set(patchi, fvPatch::New(basicBdry[patchi], *this));
45  }
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::fvBoundaryMesh::fvBoundaryMesh
52 (
53  const fvMesh& m
54 )
55 :
56  fvPatchList(),
57  mesh_(m)
58 {}
59 
60 
61 Foam::fvBoundaryMesh::fvBoundaryMesh
62 (
63  const fvMesh& m,
64  const polyBoundaryMesh& basicBdry
65 )
66 :
67  fvPatchList(basicBdry.size()),
68  mesh_(m)
69 {
70  addPatches(basicBdry);
71 }
72 
73 
74 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
75 
77 (
78  const keyType& key,
79  const bool useGroups
80 ) const
81 {
82  return mesh().boundaryMesh().indices(key, useGroups);
83 }
84 
85 
86 Foam::label Foam::fvBoundaryMesh::findPatchID(const word& patchName) const
87 {
88  if (patchName.empty())
89  {
90  return -1;
91  }
92 
93  const fvPatchList& patches = *this;
94 
95  forAll(patches, patchi)
96  {
97  if (patches[patchi].name() == patchName)
98  {
99  return patchi;
100  }
101  }
102 
103  // Not found, return -1
104  return -1;
105 }
106 
107 
109 {
110  fvPatchList& patches = *this;
111 
112  for (fvPatch& p : patches)
113  {
114  p.initMovePoints();
115  }
116 
117  for (fvPatch& p : patches)
118  {
119  p.movePoints();
120  }
121 }
122 
123 
125 {
126  lduInterfacePtrsList interfaces(size());
127 
128  forAll(interfaces, patchi)
129  {
130  if (isA<lduInterface>(this->operator[](patchi)))
131  {
132  interfaces.set
133  (
134  patchi,
135  &refCast<const lduInterface>(this->operator[](patchi))
136  );
137  }
138  }
139 
140  return interfaces;
141 }
142 
143 
144 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
145 
147 {
148  clear();
149  addPatches(basicBdry);
150 }
151 
152 
153 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
154 
155 const Foam::fvPatch& Foam::fvBoundaryMesh::operator[]
156 (
157  const word& patchName
158 ) const
159 {
160  const label patchi = findPatchID(patchName);
161 
162  if (patchi < 0)
163  {
165  << "Patch named " << patchName << " not found." << nl
166  << abort(FatalError);
167  }
168 
169  return operator[](patchi);
170 }
171 
172 
173 Foam::fvPatch& Foam::fvBoundaryMesh::operator[]
174 (
175  const word& patchName
176 )
177 {
178  const label patchi = findPatchID(patchName);
179 
180  if (patchi < 0)
181  {
183  << "Patch named " << patchName << " not found." << nl
184  << abort(FatalError);
185  }
186 
187  return operator[](patchi);
188 }
189 
190 
191 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::fvBoundaryMesh::findPatchID
label findPatchID(const word &patchName) const
Find patch index given a name.
Definition: fvBoundaryMesh.C:86
Foam::fvPatch::New
static autoPtr< fvPatch > New(const polyPatch &, const fvBoundaryMesh &)
Return a pointer to a new patch created on freestore from polyPatch.
Definition: fvPatchNew.C:35
Foam::fvBoundaryMesh::readUpdate
void readUpdate(const polyBoundaryMesh &)
Update boundary based on new polyBoundaryMesh.
Definition: fvBoundaryMesh.C:146
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fvPatchList
PtrList< fvPatch > fvPatchList
container classes for fvPatch
Definition: fvPatchList.H:47
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::PtrList::setSize
void setSize(const label newLen)
Same as resize()
Definition: PtrListI.H:105
Foam::fvBoundaryMesh::interfaces
lduInterfacePtrsList interfaces() const
Definition: fvBoundaryMesh.C:124
Foam::UPtrList< const lduInterface >
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
fvBoundaryMesh.H
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvBoundaryMesh::indices
labelList indices(const keyType &key, const bool useGroups) const
Return patch indices for all matches.
Definition: fvBoundaryMesh.C:77
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
fvMesh.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::polyBoundaryMesh::indices
labelList indices(const keyType &key, const bool useGroups=true) const
Return patch indices for all matches.
Definition: polyBoundaryMesh.C:669
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::UPtrList::set
const T * set(const label i) const
Return const pointer to element (can be nullptr),.
Definition: UPtrList.H:170
clear
patchWriters clear()
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::List< label >
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::fvBoundaryMesh::movePoints
void movePoints()
Correct patches after moving points.
Definition: fvBoundaryMesh.C:108