thermalBaffleModel.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-2021 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 "thermalBaffleModel.H"
27 #include "fvMesh.H"
29 #include "wedgePolyPatch.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace regionModels
36 {
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 defineTypeNameAndDebug(thermalBaffleModel, 0);
41 defineRunTimeSelectionTable(thermalBaffleModel, mesh);
42 defineRunTimeSelectionTable(thermalBaffleModel, dictionary);
43 
44 
45 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
46 
48 {
50  return true;
51 }
52 
53 
55 {
56  regionModel1D::read(dict);
57  return true;
58 }
59 
60 
61 void thermalBaffleModel::init()
62 {
63  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
64 
65  // Check if region mesh in 1-D
66  label nTotalEdges = 0;
67  const label patchi = intCoupledPatchIDs_[0];
68  nTotalEdges = 2*nLayers_*rbm[patchi].nInternalEdges();
69  nTotalEdges +=
70  nLayers_*(rbm[patchi].nEdges() - rbm[patchi].nInternalEdges());
71 
72  reduce(nTotalEdges, sumOp<label>());
73 
74  label nFaces = 0;
75  forAll(rbm, patchi)
76  {
77  if (
78  rbm[patchi].size()
79  &&
80  (
81  isA<wedgePolyPatch>(rbm[patchi])
82  || isA<emptyPolyPatch>(rbm[patchi])
83  )
84  )
85  {
86  nFaces += rbm[patchi].size();
87  }
88  }
89  reduce(nFaces, sumOp<label>());
90 
91  if (nTotalEdges == nFaces)
92  {
93  oneD_ = true;
94  Info << "\nThe thermal baffle is 1D \n" << endl;
95  }
96  else
97  {
98  Info << "\nThe thermal baffle is 3D \n" << endl;
99  }
100 
102  {
103  const label patchi = intCoupledPatchIDs_[i];
104  const polyPatch& pp = rbm[patchi];
105 
106  if
107  (
108  !isA<mappedVariableThicknessWallPolyPatch>(pp)
109  && oneD_
111  )
112  {
114  << "' not type '"
115  << mappedVariableThicknessWallPolyPatch::typeName
116  << "'. This is necessary for 1D solution "
117  << " and variable thickness"
118  << "\n for patch. " << pp.name()
119  << exit(FatalError);
120  }
121  else if (!isA<mappedWallPolyPatch>(pp))
122  {
124  << "' not type '"
125  << mappedWallPolyPatch::typeName
126  << "'. This is necessary for 3D solution"
127  << "\n for patch. " << pp.name()
128  << exit(FatalError);
129  }
130  }
131 
132  if (oneD_ && !constantThickness_)
133  {
134  const label patchi = intCoupledPatchIDs_[0];
135  const polyPatch& pp = rbm[patchi];
136  const mappedVariableThicknessWallPolyPatch& ppCoupled =
137  refCast
138  <
140  >(pp);
141 
142  thickness_ = ppCoupled.thickness();
143 
144  // Check that thickness has the right size
145  if (thickness_.size() != pp.size())
146  {
148  << " coupled patches in thermalBaffle are " << nl
149  << " different sizes from list thickness" << nl
150  << exit(FatalError);
151  }
152 
153  // Calculate thickness of the baffle on the first face only.
154  if (delta_.value() == 0.0)
155  {
156  forAll(ppCoupled, localFacei)
157  {
158  label facei = ppCoupled.start() + localFacei;
159 
160  label faceO =
161  boundaryFaceOppositeFace_[localFacei];
162 
163  delta_.value() = mag
164  (
165  regionMesh().faceCentres()[facei]
166  - regionMesh().faceCentres()[faceO]
167  );
168  break;
169  }
170  }
171  }
172 }
173 
174 
175 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
176 
178 :
179  regionModel1D(mesh, "thermalBaffle"),
180  thickness_(),
181  delta_("delta", dimLength, 0.0),
182  oneD_(false),
183  constantThickness_(true)
184 {}
185 
186 
188 (
189  const word& modelType,
190  const fvMesh& mesh,
191  const dictionary& dict
192 
193 )
194 :
195  regionModel1D(mesh, "thermalBaffle", modelType, dict, true),
196  thickness_(),
197  delta_("delta", dimLength, 0.0),
198  oneD_(false),
199  constantThickness_(dict.lookupOrDefault<bool>("constantThickness", true))
200 {
201  init();
202 }
203 
204 
206 (
207  const word& modelType,
208  const fvMesh& mesh
209 )
210 :
211  regionModel1D(mesh, "thermalBaffle", modelType),
212  thickness_(),
213  delta_("delta", dimLength, 0.0),
214  oneD_(false),
215  constantThickness_(lookupOrDefault<bool>("constantThickness", true))
216 {
217  init();
218 }
219 
220 
221 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
222 
224 {}
225 
226 
227 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
228 
230 {}
231 
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 } // End namespace regionModels
236 } // End namespace Foam
237 
238 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:453
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const word & name() const
Return name.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual void preEvolveRegion()
Pre-evolve region.
Base class for 1-D region models.
Definition: regionModel1D.H:52
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:106
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const dimensionSet dimLength
scalarList & thickness()
Return non const thickness.
defineTypeNameAndDebug(regionModel, 0)
virtual bool read()
Read control parameters from IO dictionary.
defineRunTimeSelectionTable(regionModelFunctionObject, dictionary)
A class for handling words, derived from string.
Definition: word.H:59
const Type & value() const
Return const reference to value.
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:55
Foam::polyBoundaryMesh.
static const char nl
Definition: Ostream.H:260
scalarField thickness_
Baffle physical thickness.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Foam::mappedVariableThicknessWallPolyPatch.
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
label patchi
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
virtual bool read()
Read control parameters from dictionary.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:306
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
dimensionedScalar delta_
Baffle mesh thickness.
label nLayers_
Number of layers in the region.
Definition: regionModel1D.H:87
thermalBaffleModel(const fvMesh &mesh)
Construct null from mesh.
labelList intCoupledPatchIDs_
List of patch IDs internally coupled with the primary region.
Definition: regionModel.H:106
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Namespace for OpenFOAM.
labelList boundaryFaceOppositeFace_
Global boundary face IDs opposite coupled patch.
Definition: regionModel1D.H:84
bool constantThickness_
Is thickness constant.