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 | Copyright (C) 2011-2013 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  (
119  "thermalBaffleModel::thermalBaffleModel"
120  "("
121  " const word&,"
122  " const fvMesh&"
123  ")"
124  ) << "\n patch type '" << pp.type()
125  << "' not type '"
126  << mappedVariableThicknessWallPolyPatch::typeName
127  << "'. This is necessary for 1D solution "
128  << " and variable thickness"
129  << "\n for patch. " << pp.name()
130  << exit(FatalError);
131  }
132  else if (!isA<mappedWallPolyPatch>(pp))
133  {
135  (
136  "thermalBaffleModel::thermalBaffleModel"
137  "("
138  " const word&,"
139  " const fvMesh&"
140  ")"
141  ) << "\n patch type '" << pp.type()
142  << "' not type '"
143  << mappedWallPolyPatch::typeName
144  << "'. This is necessary for 3D solution"
145  << "\n for patch. " << pp.name()
146  << exit(FatalError);
147  }
148  }
149 
150  if (oneD_ && !constantThickness_)
151  {
152  const label patchI = intCoupledPatchIDs_[0];
153  const polyPatch& pp = rbm[patchI];
154  const mappedVariableThicknessWallPolyPatch& ppCoupled =
155  refCast
156  <
158  >(pp);
159 
160  thickness_ = ppCoupled.thickness();
161 
162  // Check that thickness has the right size
163  if (thickness_.size() != pp.size())
164  {
166  (
167  "thermalBaffleModel::thermalBaffleModel"
168  "("
169  " const word&,"
170  " const fvMesh&"
171  ")"
172  ) << " coupled patches in thermalBaffle are " << nl
173  << " different sizes from list thickness" << nl
174  << exit(FatalError);
175  }
176 
177  // Calculate thickness of the baffle on the first face only.
178  if (delta_.value() == 0.0)
179  {
180  forAll (ppCoupled, localFaceI)
181  {
182  label faceI = ppCoupled.start() + localFaceI;
183 
184  label faceO =
185  boundaryFaceOppositeFace_[localFaceI];
186 
187  delta_.value() = mag
188  (
189  regionMesh().faceCentres()[faceI]
190  - regionMesh().faceCentres()[faceO]
191  );
192  break;
193  }
194  }
195  }
196  }
197 }
198 
199 
200 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
201 
202 thermalBaffleModel::thermalBaffleModel(const fvMesh& mesh)
203 :
204  regionModel1D(mesh, "thermalBaffle"),
205  thickness_(),
206  delta_("delta", dimLength, 0.0),
207  oneD_(false),
208  constantThickness_(true)
209 {}
210 
211 
212 thermalBaffleModel::thermalBaffleModel
213 (
214  const word& modelType,
215  const fvMesh& mesh,
216  const dictionary& dict
217 
218 )
219 :
220  regionModel1D(mesh, "thermalBaffle", modelType, dict, true),
221  thickness_(),
222  delta_("delta", dimLength, 0.0),
223  oneD_(false),
224  constantThickness_(dict.lookupOrDefault<bool>("constantThickness", true))
225 {
226  init();
227 }
228 
229 
230 thermalBaffleModel::thermalBaffleModel
231 (
232  const word& modelType,
233  const fvMesh& mesh
234 )
235 :
236  regionModel1D(mesh, "thermalBaffle", modelType),
237  thickness_(),
238  delta_("delta", dimLength, 0.0),
239  oneD_(false),
240  constantThickness_(lookupOrDefault<bool>("constantThickness", true))
241 {
242  init();
243 }
244 
245 
246 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
247 
249 {}
250 
251 
252 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
253 
255 {}
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 } // End namespace thermalBaffleModels
261 } // End namespace regionModels
262 } // End namespace Foam
263 
264 // ************************************************************************* //
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Foam::mappedVariableThicknessWallPolyPatch.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
label size() const
Return the number of elements in the PtrList.
Definition: PtrListI.H:32
const word & name() const
Return name.
dimensioned< scalar > mag(const dimensioned< Type > &)
virtual bool read()
Read control parameters from dictionary.
virtual bool read()
Read control parameters from IO dictionary.
Switch active_
Active flag.
Definition: regionModel.H:93
A class for handling words, derived from string.
Definition: word.H:59
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const fvMesh & regionMesh() const
Return the region mesh database.
Definition: regionModelI.H:61
scalarList & thickness()
Return non const thickness.
messageStream Info
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
labelList intCoupledPatchIDs_
List of patch IDs internally coupled with the primary region.
Definition: regionModel.H:117
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
label size() const
Return number of elements in list.
Definition: DLListBaseI.H:77
Namespace for OpenFOAM.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
dictionary dict
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::polyBoundaryMesh.
#define forAll(list, i)
Definition: UList.H:421
label nLayers_
Number of layers in the region.
Definition: regionModel1D.H:90
label patchi
defineRunTimeSelectionTable(thermalBaffleModel, mesh)
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:300
error FatalError
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
labelList boundaryFaceOppositeFace_
Global boundary face IDs oppossite coupled patch.
Definition: regionModel1D.H:87
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:106
const Type & value() const
Return const reference to value.