thermalBaffleModel.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) 2020-2022 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 "thermalBaffleModel.H"
30 #include "fvMesh.H"
32 #include "wedgePolyPatch.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace regionModels
39 {
40 namespace thermalBaffleModels
41 {
42 
43 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44 
48 
49 
50 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
51 
53 {
55  return true;
56 }
57 
58 
60 {
62  return true;
63 }
64 
65 
66 void thermalBaffleModel::init()
67 {
68  if (active_)
69  {
70  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
71 
72  // Check if region mesh in 1-D
73  label nTotalEdges = 0;
74  const label patchi = intCoupledPatchIDs_[0];
75  nTotalEdges = 2*nLayers_*rbm[patchi].nInternalEdges();
76  nTotalEdges +=
77  nLayers_*(rbm[patchi].nEdges() - rbm[patchi].nInternalEdges());
78 
79  label nTotalFaces = 0;
80  forAll(rbm, patchi)
81  {
82  if (
83  rbm[patchi].size()
84  &&
85  (
86  isA<wedgePolyPatch>(rbm[patchi])
87  || isA<emptyPolyPatch>(rbm[patchi])
88  )
89  )
90  {
91  nTotalFaces += rbm[patchi].size();
92  }
93  }
94 
95  oneD_ =
96  (
97  returnReduce(nTotalEdges, sumOp<label>())
98  == returnReduce(nTotalFaces, sumOp<label>())
99  );
100 
101  if (oneD_)
102  {
103  Info << "\nThe thermal baffle is 1D\n" << endl;
104  }
105  else
106  {
107  Info << "\nThe thermal baffle is 3D\n" << endl;
108  }
109 
111  {
112  const label patchi = intCoupledPatchIDs_[i];
113  const polyPatch& pp = rbm[patchi];
114 
115  if
116  (
117  !isA<mappedVariableThicknessWallPolyPatch>(pp)
118  && oneD_
120  )
121  {
123  << "' not type '"
124  << mappedVariableThicknessWallPolyPatch::typeName
125  << "'. This is necessary for 1D solution "
126  << " and variable thickness"
127  << "\n for patch. " << pp.name()
128  << exit(FatalError);
129  }
130  else if (!isA<mappedWallPolyPatch>(pp))
131  {
133  << "' not type '"
134  << mappedWallPolyPatch::typeName
135  << "'. This is necessary for 3D solution"
136  << "\n for patch. " << pp.name()
137  << exit(FatalError);
138  }
139  }
140 
141  if (oneD_ && !constantThickness_)
142  {
143  const label patchi = intCoupledPatchIDs_[0];
144  const polyPatch& pp = rbm[patchi];
145  const mappedVariableThicknessWallPolyPatch& ppCoupled =
146  refCast
147  <
148  const mappedVariableThicknessWallPolyPatch
149  >(pp);
150 
151  thickness_ = ppCoupled.thickness();
152 
153  // Check that thickness has the right size
154  if (thickness_.size() != pp.size())
155  {
157  << " coupled patches in thermalBaffle are " << nl
158  << " different sizes from list thickness" << nl
159  << exit(FatalError);
160  }
161 
162  // Calculate thickness of the baffle on the first face only.
163  if (delta_.value() == 0.0)
164  {
165  forAll(ppCoupled, localFacei)
166  {
167  label facei = ppCoupled.start() + localFacei;
168 
169  label faceO =
170  boundaryFaceOppositeFace_[localFacei];
171 
172  delta_.value() = mag
173  (
174  regionMesh().faceCentres()[facei]
175  - regionMesh().faceCentres()[faceO]
176  );
177  break;
178  }
179  }
180  }
181  }
182 }
183 
184 
185 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
186 
187 thermalBaffleModel::thermalBaffleModel(const fvMesh& mesh)
188 :
189  regionModel1D(mesh, "thermalBaffle"),
190  thickness_(),
191  delta_("delta", dimLength, Zero),
192  oneD_(false),
193  constantThickness_(true)
194 {}
195 
196 
197 thermalBaffleModel::thermalBaffleModel
198 (
199  const word& modelType,
200  const fvMesh& mesh,
201  const dictionary& dict
202 
203 )
204 :
205  regionModel1D(mesh, "thermalBaffle", modelType, dict, true),
206  thickness_(),
207  delta_("delta", dimLength, Zero),
208  oneD_(false),
209  constantThickness_(dict.getOrDefault("constantThickness", true))
210 {
211  init();
212 }
213 
214 
215 thermalBaffleModel::thermalBaffleModel
216 (
217  const word& modelType,
218  const fvMesh& mesh
219 )
220 :
221  regionModel1D(mesh, "thermalBaffle", modelType),
222  thickness_(),
223  delta_("delta", dimLength, Zero),
224  oneD_(false),
225  constantThickness_(getOrDefault("constantThickness", true))
226 {
227  init();
228 }
229 
230 
231 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
234 {}
235 
236 
237 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
238 
240 {}
241 
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 } // End namespace thermalBaffleModels
246 } // End namespace regionModels
247 } // End namespace Foam
248 
249 // ************************************************************************* //
const Type & value() const noexcept
Return const reference to value.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Base class for 1-D region models.
Definition: regionModel1D.H:50
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
dynamicFvMesh & mesh
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
A class for handling words, derived from Foam::string.
Definition: word.H:63
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:26
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
Switch active_
Active flag.
Definition: regionModel.H:102
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
virtual bool read()
Read control parameters from dictionary.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual bool read()
Read control parameters from IO dictionary.
messageStream Info
Information stream (stdout output on master, null elsewhere)
label nLayers_
Number of layers in the region.
labelList intCoupledPatchIDs_
List of patch IDs internally coupled with the primary region.
Definition: regionModel.H:135
defineRunTimeSelectionTable(thermalBaffleModel, mesh)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
labelList boundaryFaceOppositeFace_
Global boundary face IDs oppositte coupled patch.
Definition: regionModel1D.H:96
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127