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-2018 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  if (active_)
66  {
67  const polyBoundaryMesh& rbm = regionMesh().boundaryMesh();
68 
69  // Check if region mesh in 1-D
70  label nTotalEdges = 0;
71  const label patchi = intCoupledPatchIDs_[0];
72  nTotalEdges = 2*nLayers_*rbm[patchi].nInternalEdges();
73  nTotalEdges +=
74  nLayers_*(rbm[patchi].nEdges() - rbm[patchi].nInternalEdges());
75 
76  reduce(nTotalEdges, sumOp<label>());
77 
78  label nFaces = 0;
79  forAll(rbm, patchi)
80  {
81  if (
82  rbm[patchi].size()
83  &&
84  (
85  isA<wedgePolyPatch>(rbm[patchi])
86  || isA<emptyPolyPatch>(rbm[patchi])
87  )
88  )
89  {
90  nFaces += rbm[patchi].size();
91  }
92  }
93  reduce(nFaces, sumOp<label>());
94 
95  if (nTotalEdges == nFaces)
96  {
97  oneD_ = true;
98  Info << "\nThe thermal baffle is 1D \n" << endl;
99  }
100  else
101  {
102  Info << "\nThe thermal baffle is 3D \n" << endl;
103  }
104 
106  {
107  const label patchi = intCoupledPatchIDs_[i];
108  const polyPatch& pp = rbm[patchi];
109 
110  if
111  (
112  !isA<mappedVariableThicknessWallPolyPatch>(pp)
113  && oneD_
115  )
116  {
118  << "' not type '"
119  << mappedVariableThicknessWallPolyPatch::typeName
120  << "'. This is necessary for 1D solution "
121  << " and variable thickness"
122  << "\n for patch. " << pp.name()
123  << exit(FatalError);
124  }
125  else if (!isA<mappedWallPolyPatch>(pp))
126  {
128  << "' not type '"
129  << mappedWallPolyPatch::typeName
130  << "'. This is necessary for 3D solution"
131  << "\n for patch. " << pp.name()
132  << exit(FatalError);
133  }
134  }
135 
136  if (oneD_ && !constantThickness_)
137  {
138  const label patchi = intCoupledPatchIDs_[0];
139  const polyPatch& pp = rbm[patchi];
140  const mappedVariableThicknessWallPolyPatch& ppCoupled =
141  refCast
142  <
144  >(pp);
145 
146  thickness_ = ppCoupled.thickness();
147 
148  // Check that thickness has the right size
149  if (thickness_.size() != pp.size())
150  {
152  << " coupled patches in thermalBaffle are " << nl
153  << " different sizes from list thickness" << nl
154  << exit(FatalError);
155  }
156 
157  // Calculate thickness of the baffle on the first face only.
158  if (delta_.value() == 0.0)
159  {
160  forAll(ppCoupled, localFacei)
161  {
162  label facei = ppCoupled.start() + localFacei;
163 
164  label faceO =
165  boundaryFaceOppositeFace_[localFacei];
166 
167  delta_.value() = mag
168  (
169  regionMesh().faceCentres()[facei]
170  - regionMesh().faceCentres()[faceO]
171  );
172  break;
173  }
174  }
175  }
176  }
177 }
178 
179 
180 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
181 
182 thermalBaffleModel::thermalBaffleModel(const fvMesh& mesh)
183 :
184  regionModel1D(mesh, "thermalBaffle"),
185  thickness_(),
186  delta_("delta", dimLength, 0.0),
187  oneD_(false),
188  constantThickness_(true)
189 {}
190 
191 
192 thermalBaffleModel::thermalBaffleModel
193 (
194  const word& modelType,
195  const fvMesh& mesh,
196  const dictionary& dict
197 
198 )
199 :
200  regionModel1D(mesh, "thermalBaffle", modelType, dict, true),
201  thickness_(),
202  delta_("delta", dimLength, 0.0),
203  oneD_(false),
204  constantThickness_(dict.lookupOrDefault<bool>("constantThickness", true))
205 {
206  init();
207 }
208 
209 
210 thermalBaffleModel::thermalBaffleModel
211 (
212  const word& modelType,
213  const fvMesh& mesh
214 )
215 :
216  regionModel1D(mesh, "thermalBaffle", modelType),
217  thickness_(),
218  delta_("delta", dimLength, 0.0),
219  oneD_(false),
220  constantThickness_(lookupOrDefault<bool>("constantThickness", true))
221 {
222  init();
223 }
224 
225 
226 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
227 
229 {}
230 
231 
232 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
233 
235 {}
236 
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 } // End namespace thermalBaffleModels
241 } // End namespace regionModels
242 } // End namespace Foam
243 
244 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:424
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:137
Base class for 1-D region models.
Definition: regionModel1D.H:52
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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:256
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:61
Foam::polyBoundaryMesh.
static const char nl
Definition: Ostream.H:265
Switch active_
Active flag.
Definition: regionModel.H:90
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,.
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
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:300
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:114
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 oppossite coupled patch.
Definition: regionModel1D.H:84