thermalBaffle1DFvPatchScalarField.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-2016 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 "volFields.H"
27 #include "surfaceFields.H"
28 #include "mappedPatchBase.H"
30 #include "mapDistribute.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace compressible
37 {
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 template<class solidType>
44 (
45  const fvPatch& p,
47 )
48 :
50  mixedFvPatchScalarField(p, iF),
51  TName_("T"),
52  baffleActivated_(true),
53  thickness_(p.size()),
54  Qs_(p.size()),
55  solidDict_(),
56  solidPtr_(NULL),
57  QrPrevious_(p.size()),
58  QrRelaxation_(1),
59  QrName_("undefined-Qr")
60 {}
61 
62 
63 template<class solidType>
66 (
68  const fvPatch& p,
70  const fvPatchFieldMapper& mapper
71 )
72 :
73  mappedPatchBase(p.patch(), ptf),
74  mixedFvPatchScalarField(ptf, p, iF, mapper),
75  TName_(ptf.TName_),
76  baffleActivated_(ptf.baffleActivated_),
77  thickness_(ptf.thickness_, mapper),
78  Qs_(ptf.Qs_, mapper),
79  solidDict_(ptf.solidDict_),
80  solidPtr_(ptf.solidPtr_),
81  QrPrevious_(ptf.QrPrevious_, mapper),
82  QrRelaxation_(ptf.QrRelaxation_),
83  QrName_(ptf.QrName_)
84 {}
85 
86 
87 template<class solidType>
90 (
91  const fvPatch& p,
93  const dictionary& dict
94 )
95 :
96  mappedPatchBase(p.patch(), NEARESTPATCHFACE, dict),
97  mixedFvPatchScalarField(p, iF),
98  TName_("T"),
99  baffleActivated_(dict.lookupOrDefault<bool>("baffleActivated", true)),
100  thickness_(),
101  Qs_(p.size(), 0),
102  solidDict_(dict),
103  solidPtr_(),
104  QrPrevious_(p.size(), 0.0),
105  QrRelaxation_(dict.lookupOrDefault<scalar>("relaxation", 1)),
106  QrName_(dict.lookupOrDefault<word>("Qr", "none"))
107 {
108  fvPatchScalarField::operator=(scalarField("value", dict, p.size()));
109 
110  if (dict.found("thickness"))
111  {
112  thickness_ = scalarField("thickness", dict, p.size());
113  }
114 
115  if (dict.found("Qs"))
116  {
117  Qs_ = scalarField("Qs", dict, p.size());
118  }
119 
120  if (dict.found("QrPrevious"))
121  {
122  QrPrevious_ = scalarField("QrPrevious", dict, p.size());
123  }
124 
125  if (dict.found("refValue") && baffleActivated_)
126  {
127  // Full restart
128  refValue() = scalarField("refValue", dict, p.size());
129  refGrad() = scalarField("refGradient", dict, p.size());
130  valueFraction() = scalarField("valueFraction", dict, p.size());
131  }
132  else
133  {
134  // Start from user entered data. Assume zeroGradient.
135  refValue() = *this;
136  refGrad() = 0.0;
137  valueFraction() = 0.0;
138  }
139 
140 }
141 
142 
143 template<class solidType>
146 (
148 )
149 :
150  mappedPatchBase(ptf.patch().patch(), ptf),
151  mixedFvPatchScalarField(ptf),
152  TName_(ptf.TName_),
153  baffleActivated_(ptf.baffleActivated_),
154  thickness_(ptf.thickness_),
155  Qs_(ptf.Qs_),
156  solidDict_(ptf.solidDict_),
157  solidPtr_(ptf.solidPtr_),
158  QrPrevious_(ptf.QrPrevious_),
159  QrRelaxation_(ptf.QrRelaxation_),
160  QrName_(ptf.QrName_)
161 {}
162 
163 
164 template<class solidType>
167 (
170 )
171 :
172  mappedPatchBase(ptf.patch().patch(), ptf),
173  mixedFvPatchScalarField(ptf, iF),
174  TName_(ptf.TName_),
175  baffleActivated_(ptf.baffleActivated_),
176  thickness_(ptf.thickness_),
177  Qs_(ptf.Qs_),
178  solidDict_(ptf.solidDict_),
179  solidPtr_(ptf.solidPtr_),
180  QrPrevious_(ptf.QrPrevious_),
181  QrRelaxation_(ptf.QrRelaxation_),
182  QrName_(ptf.QrName_)
183 {}
184 
185 
186 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
187 
188 template<class solidType>
190 {
191  const label patchi = patch().index();
192 
193  const label nbrPatchi = samplePolyPatch().index();
194 
195  return (patchi < nbrPatchi);
196 }
197 
198 
199 template<class solidType>
201 {
202  if (this->owner())
203  {
204  if (solidPtr_.empty())
205  {
206  solidPtr_.reset(new solidType(solidDict_));
207  }
208  return solidPtr_();
209  }
210  else
211  {
212  const fvPatch& nbrPatch =
213  patch().boundaryMesh()[samplePolyPatch().index()];
214 
215  const thermalBaffle1DFvPatchScalarField& nbrField =
216  refCast<const thermalBaffle1DFvPatchScalarField>
217  (
218  nbrPatch.template lookupPatchField<volScalarField, scalar>(TName_)
219  );
220 
221  return nbrField.solid();
222  }
223 }
224 
225 
226 template<class solidType>
228 baffleThickness() const
229 {
230  if (this->owner())
231  {
232  if (thickness_.size() != patch().size())
233  {
235  (
236  solidDict_
237  )<< " Field thickness has not been specified "
238  << " for patch " << this->patch().name()
239  << exit(FatalIOError);
240  }
241 
242  return thickness_;
243  }
244  else
245  {
246  const mapDistribute& mapDist = this->mappedPatchBase::map();
247 
248  const fvPatch& nbrPatch =
249  patch().boundaryMesh()[samplePolyPatch().index()];
250  const thermalBaffle1DFvPatchScalarField& nbrField =
251  refCast<const thermalBaffle1DFvPatchScalarField>
252  (
253  nbrPatch.template lookupPatchField<volScalarField, scalar>(TName_)
254  );
255 
256  tmp<scalarField> tthickness
257  (
258  new scalarField(nbrField.baffleThickness())
259  );
260  scalarField& thickness = tthickness.ref();
261  mapDist.distribute(thickness);
262  return tthickness;
263  }
264 }
265 
266 
267 template<class solidType>
269 {
270  if (this->owner())
271  {
272  return Qs_;
273  }
274  else
275  {
276  const mapDistribute& mapDist = this->mappedPatchBase::map();
277 
278  const fvPatch& nbrPatch =
279  patch().boundaryMesh()[samplePolyPatch().index()];
280 
281  const thermalBaffle1DFvPatchScalarField& nbrField =
282  refCast<const thermalBaffle1DFvPatchScalarField>
283  (
284  nbrPatch.template lookupPatchField<volScalarField, scalar>(TName_)
285  );
286 
287  tmp<scalarField> tQs(new scalarField(nbrField.Qs()));
288  scalarField& Qs = tQs.ref();
289  mapDist.distribute(Qs);
290  return tQs;
291  }
292 }
293 
294 
295 template<class solidType>
297 (
298  const fvPatchFieldMapper& m
299 )
300 {
301  mixedFvPatchScalarField::autoMap(m);
302 
303  if (this->owner())
304  {
305  thickness_.autoMap(m);
306  Qs_.autoMap(m);
307  }
308 }
309 
310 
311 template<class solidType>
313 (
314  const fvPatchScalarField& ptf,
315  const labelList& addr
316 )
317 {
318  mixedFvPatchScalarField::rmap(ptf, addr);
319 
320  const thermalBaffle1DFvPatchScalarField& tiptf =
321  refCast<const thermalBaffle1DFvPatchScalarField>(ptf);
322 
323  if (this->owner())
324  {
325  thickness_.rmap(tiptf.thickness_, addr);
326  Qs_.rmap(tiptf.Qs_, addr);
327  }
328 }
329 
330 
331 template<class solidType>
333 {
334  if (updated())
335  {
336  return;
337  }
338  // Since we're inside initEvaluate/evaluate there might be processor
339  // comms underway. Change the tag we use.
340  int oldTag = UPstream::msgType();
341  UPstream::msgType() = oldTag+1;
342 
343  const mapDistribute& mapDist = this->mappedPatchBase::map();
344 
345  const label patchi = patch().index();
346 
347  const label nbrPatchi = samplePolyPatch().index();
348 
349  if (baffleActivated_)
350  {
351  const fvPatch& nbrPatch = patch().boundaryMesh()[nbrPatchi];
352 
353  const compressible::turbulenceModel& turbModel =
354  db().template lookupObject<compressible::turbulenceModel>
355  (
357  );
358 
359  // local properties
360  const scalarField kappaw(turbModel.kappaEff(patchi));
361 
362  const fvPatchScalarField& Tp =
363  patch().template lookupPatchField<volScalarField, scalar>(TName_);
364 
365 
366  scalarField Qr(Tp.size(), 0.0);
367 
368  if (QrName_ != "none")
369  {
370  Qr = patch().template lookupPatchField<volScalarField, scalar>
371  (QrName_);
372 
373  Qr = QrRelaxation_*Qr + (1.0 - QrRelaxation_)*QrPrevious_;
374  QrPrevious_ = Qr;
375  }
376 
377  tmp<scalarField> Ti = patchInternalField();
378 
379  scalarField myKDelta(patch().deltaCoeffs()*kappaw);
380 
381  // nrb properties
382  scalarField nbrTp =
383  turbModel.transport().T().boundaryField()[nbrPatchi];
384  mapDist.distribute(nbrTp);
385 
386  // solid properties
387  scalarField kappas(patch().size(), 0.0);
388  forAll(kappas, i)
389  {
390  kappas[i] = solid().kappa(0.0, (Tp[i] + nbrTp[i])/2.0);
391  }
392 
393  scalarField KDeltaSolid(kappas/baffleThickness());
394 
395  scalarField alpha(KDeltaSolid - Qr/Tp);
396 
397  valueFraction() = alpha/(alpha + myKDelta);
398 
399  refValue() = (KDeltaSolid*nbrTp + Qs()/2.0)/alpha;
400 
401  if (debug)
402  {
403  scalar Q = gAverage(kappaw*snGrad());
404  Info<< patch().boundaryMesh().mesh().name() << ':'
405  << patch().name() << ':'
406  << this->internalField().name() << " <- "
407  << nbrPatch.name() << ':'
408  << this->internalField().name() << " :"
409  << " heat[W]:" << Q
410  << " walltemperature "
411  << " min:" << gMin(*this)
412  << " max:" << gMax(*this)
413  << " avg:" << gAverage(*this)
414  << endl;
415  }
416  }
417 
418  // Restore tag
419  UPstream::msgType() = oldTag;
420 
421  mixedFvPatchScalarField::updateCoeffs();
422 }
423 
424 template<class solidType>
426 {
429 
430  if (this->owner())
431  {
432  baffleThickness()().writeEntry("thickness", os);
433  Qs()().writeEntry("Qs", os);
434  solid().write(os);
435  }
436 
437  QrPrevious_.writeEntry("QrPrevious", os);
438  os.writeKeyword("Qr")<< QrName_ << token::END_STATEMENT << nl;
439  os.writeKeyword("relaxation")<< QrRelaxation_
440  << token::END_STATEMENT << nl;
441 }
442 
443 
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
445 
446 } // End namespace compressible
447 } // End namespace Foam
448 
449 // ************************************************************************* //
Foam::surfaceFields.
virtual void write(Ostream &) const
Write as a dictionary.
dictionary dict
thermalBaffle1DFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
#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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Type gMin(const FieldField< Field, Type > &f)
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
const word & name() const
Return name.
Definition: fvPatch.H:149
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:464
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
virtual void rmap(const fvPatchScalarField &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
const polyPatch & patch() const
Return the polyPatch.
Definition: fvPatch.H:143
const mapDistribute & map() const
Return reference to the parallel distribution map.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
static const word propertiesName
Default name of the turbulence properties dictionary.
A class for handling words, derived from string.
Definition: word.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Foam::fvPatchFieldMapper.
virtual label size() const
Return size.
Definition: fvPatch.H:161
Determines a mapping between patch face centres and mesh cell or face centres and processors they&#39;re ...
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
Type gMax(const FieldField< Field, Type > &f)
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
label patchi
Class containing processor-to-processor mapping information.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Type gAverage(const FieldField< Field, Type > &f)
virtual void operator=(const UList< Type > &)
Definition: fvPatchField.C:396
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
messageStream Info
virtual tmp< volScalarField > kappaEff() const
Return the effective turbulent thermal diffusivity for temperature.
A class for managing temporary objects.
Definition: PtrList.H:54
volScalarField Qr(IOobject("Qr", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE), mesh, dimensionedScalar("Qr", dimMass/pow3(dimTime), 0.0))
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
runTime write()
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45
Namespace for OpenFOAM.
IOerror FatalIOError
bool compressible
Definition: pEqn.H:30
const fvBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: fvPatch.H:185