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-2020 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 namespace thermalBaffleModels
38 {
39 
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 
42 defineTypeNameAndDebug(thermalBaffleModel, 0);
43 defineRunTimeSelectionTable(thermalBaffleModel, mesh);
44 defineRunTimeSelectionTable(thermalBaffleModel, dictionary);
45 
46 
47 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
48 
50 {
52  return true;
53 }
54 
55 
57 {
58  regionModel1D::read(dict);
59  return true;
60 }
61 
62 
63 void thermalBaffleModel::init()
64 {
65  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
66 
67  // Check if region mesh in 1-D
68  label nTotalEdges = 0;
69  const label patchi = intCoupledPatchIDs_[0];
70  nTotalEdges = 2*nLayers_*rbm[patchi].nInternalEdges();
71  nTotalEdges +=
72  nLayers_*(rbm[patchi].nEdges() - rbm[patchi].nInternalEdges());
73 
74  reduce(nTotalEdges, sumOp<label>());
75 
76  label nFaces = 0;
77  forAll(rbm, patchi)
78  {
79  if (
80  rbm[patchi].size()
81  &&
82  (
83  isA<wedgePolyPatch>(rbm[patchi])
84  || isA<emptyPolyPatch>(rbm[patchi])
85  )
86  )
87  {
88  nFaces += rbm[patchi].size();
89  }
90  }
91  reduce(nFaces, sumOp<label>());
92 
93  if (nTotalEdges == nFaces)
94  {
95  oneD_ = true;
96  Info << "\nThe thermal baffle is 1D \n" << endl;
97  }
98  else
99  {
100  Info << "\nThe thermal baffle is 3D \n" << endl;
101  }
102 
104  {
105  const label patchi = intCoupledPatchIDs_[i];
106  const polyPatch& pp = rbm[patchi];
107 
108  if
109  (
110  !isA<mappedVariableThicknessWallPolyPatch>(pp)
111  && oneD_
113  )
114  {
116  << "' not type '"
117  << mappedVariableThicknessWallPolyPatch::typeName
118  << "'. This is necessary for 1D solution "
119  << " and variable thickness"
120  << "\n for patch. " << pp.name()
121  << exit(FatalError);
122  }
123  else if (!isA<mappedWallPolyPatch>(pp))
124  {
126  << "' not type '"
127  << mappedWallPolyPatch::typeName
128  << "'. This is necessary for 3D solution"
129  << "\n for patch. " << pp.name()
130  << exit(FatalError);
131  }
132  }
133 
134  if (oneD_ && !constantThickness_)
135  {
136  const label patchi = intCoupledPatchIDs_[0];
137  const polyPatch& pp = rbm[patchi];
138  const mappedVariableThicknessWallPolyPatch& ppCoupled =
139  refCast
140  <
142  >(pp);
143 
144  thickness_ = ppCoupled.thickness();
145 
146  // Check that thickness has the right size
147  if (thickness_.size() != pp.size())
148  {
150  << " coupled patches in thermalBaffle are " << nl
151  << " different sizes from list thickness" << nl
152  << exit(FatalError);
153  }
154 
155  // Calculate thickness of the baffle on the first face only.
156  if (delta_.value() == 0.0)
157  {
158  forAll(ppCoupled, localFacei)
159  {
160  label facei = ppCoupled.start() + localFacei;
161 
162  label faceO =
163  boundaryFaceOppositeFace_[localFacei];
164 
165  delta_.value() = mag
166  (
167  regionMesh().faceCentres()[facei]
168  - regionMesh().faceCentres()[faceO]
169  );
170  break;
171  }
172  }
173  }
174 }
175 
176 
177 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
178 
180 :
181  regionModel1D(mesh, "thermalBaffle"),
182  thickness_(),
183  delta_("delta", dimLength, 0.0),
184  oneD_(false),
185  constantThickness_(true)
186 {}
187 
188 
190 (
191  const word& modelType,
192  const fvMesh& mesh,
193  const dictionary& dict
194 
195 )
196 :
197  regionModel1D(mesh, "thermalBaffle", modelType, dict, true),
198  thickness_(),
199  delta_("delta", dimLength, 0.0),
200  oneD_(false),
201  constantThickness_(dict.lookupOrDefault<bool>("constantThickness", true))
202 {
203  init();
204 }
205 
206 
208 (
209  const word& modelType,
210  const fvMesh& mesh
211 )
212 :
213  regionModel1D(mesh, "thermalBaffle", modelType),
214  thickness_(),
215  delta_("delta", dimLength, 0.0),
216  oneD_(false),
217  constantThickness_(lookupOrDefault<bool>("constantThickness", true))
218 {
219  init();
220 }
221 
222 
223 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
224 
226 {}
227 
228 
229 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
230 
232 {}
233 
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 } // End namespace thermalBaffleModels
238 } // End namespace regionModels
239 } // End namespace Foam
240 
241 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
thermalBaffleModel(const fvMesh &mesh)
Construct null from mesh.
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
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
Base class for 1-D region models.
Definition: regionModel1D.H:52
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
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.
dynamicFvMesh & mesh
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
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:78
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:309
virtual bool read()
Read control parameters from IO dictionary.
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
label nLayers_
Number of layers in the region.
Definition: regionModel1D.H:87
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
defineRunTimeSelectionTable(thermalBaffleModel, mesh)
Namespace for OpenFOAM.
labelList boundaryFaceOppositeFace_
Global boundary face IDs opposite coupled patch.
Definition: regionModel1D.H:84