temperatureCoupledBase.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "temperatureCoupledBase.H"
30 #include "volFields.H"
31 #include "fluidThermo.H"
32 #include "solidThermo.H"
34 
35 // * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
36 
37 const Foam::Enum
38 <
40 >
42 {
43  { KMethodType::mtFluidThermo, "fluidThermo" },
44  { KMethodType::mtSolidThermo, "solidThermo" },
45  { KMethodType::mtDirectionalSolidThermo, "directionalSolidThermo" },
46  { KMethodType::mtLookup, "lookup" },
47  { KMethodType::mtFunction, "function" }
48 };
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
54 (
55  const fvPatch& patch,
56  const word& calculationType,
57  const word& kappaName,
58  const word& alphaAniName,
59  const word& alphaName
60 )
61 :
62  patch_(patch),
63  method_(KMethodTypeNames_[calculationType]),
64  kappaName_(kappaName),
65  alphaAniName_(alphaAniName),
66  alphaName_(alphaName)
67 {}
68 
69 
71 (
72  const fvPatch& patch,
73  const dictionary& dict
74 )
75 :
76  patch_(patch),
77  method_(KMethodTypeNames_.get("kappaMethod", dict)),
78  kappaName_(dict.getOrDefault<word>("kappa", word::null)),
79  alphaAniName_(dict.getOrDefault<word>("alphaAni", word::null)),
80  alphaName_(dict.getOrDefault<word>("alpha", word::null))
81 {
82  switch (method_)
83  {
84  case mtDirectionalSolidThermo:
85  {
86  if (!dict.found("alphaAni"))
87  {
89  << "Did not find entry 'alphaAni'"
90  " required for 'kappaMethod' "
91  << KMethodTypeNames_[method_]
92  << exit(FatalIOError);
93  }
94 
95  break;
96  }
97 
98  case mtLookup:
99  {
100  if (!dict.found("kappa"))
101  {
103  << "Did not find entry 'kappa'"
104  " required for 'kappaMethod' "
105  << KMethodTypeNames_[method_] << nl
106  << " Please set 'kappa' to the name of a volScalarField"
107  " or volSymmTensorField"
108  << exit(FatalIOError);
109  }
110 
111  break;
112  }
113 
114  case mtFunction:
115  {
116  kappaFunction1_ = PatchFunction1<scalar>::New
117  (
118  patch.patch(),
119  "kappaValue",
120  dict
121  );
122  alphaFunction1_ = PatchFunction1<scalar>::New
123  (
124  patch.patch(),
125  "alphaValue",
126  dict
127  );
128  }
129 
130  default:
131  {
132  break;
133  }
134  }
135 }
136 
137 
139 (
140  const temperatureCoupledBase& base
141 )
142 :
143  patch_(base.patch_),
144  method_(base.method_),
145  kappaName_(base.kappaName_),
146  alphaAniName_(base.alphaAniName_),
147  alphaName_(base.alphaName_),
148  kappaFunction1_(base.kappaFunction1_.clone(patch_.patch())),
149  alphaFunction1_(base.alphaFunction1_.clone(patch_.patch()))
150 {}
151 
152 
154 (
155  const fvPatch& patch,
156  const temperatureCoupledBase& base
157 )
158 :
159  patch_(patch),
160  method_(base.method_),
161  kappaName_(base.kappaName_),
162  alphaAniName_(base.alphaAniName_),
163  alphaName_(base.alphaName_),
164  kappaFunction1_(base.kappaFunction1_.clone(patch_.patch())),
165  alphaFunction1_(base.alphaFunction1_.clone(patch_.patch()))
166 {}
167 
168 
169 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
170 
172 (
173  const fvPatchFieldMapper& mapper
174 )
175 {
176  if (kappaFunction1_)
177  {
178  kappaFunction1_().autoMap(mapper);
179  }
180  if (alphaFunction1_)
181  {
182  alphaFunction1_().autoMap(mapper);
183  }
184 }
185 
186 
188 (
189  const fvPatchField<scalar>& ptf,
190  const labelList& addr
191 )
192 {
193  const auto* tcb = isA<temperatureCoupledBase>(ptf);
194 
195  if (tcb)
196  {
197  if (kappaFunction1_)
198  {
199  kappaFunction1_().rmap(tcb->kappaFunction1_(), addr);
200  }
201  if (alphaFunction1_)
202  {
203  alphaFunction1_().rmap(tcb->alphaFunction1_(), addr);
204  }
205  }
206 }
207 
208 
210 (
211  const scalarField& Tp
212 ) const
213 {
214  const fvMesh& mesh = patch_.boundaryMesh().mesh();
215  const label patchi = patch_.index();
216 
217  switch (method_)
218  {
219  case mtFluidThermo:
220  {
222 
223  {
224  const auto* ptr =
225  mesh.cfindObject<turbulenceModel>
226  (
227  turbulenceModel::propertiesName
228  );
229 
230  if (ptr)
231  {
232  return ptr->kappaEff(patchi);
233  }
234  }
235 
236  {
237  const auto* ptr =
238  mesh.cfindObject<fluidThermo>(basicThermo::dictName);
239 
240  if (ptr)
241  {
242  return ptr->kappa(patchi);
243  }
244  }
245 
246  {
247  const auto* ptr =
248  mesh.cfindObject<basicThermo>(basicThermo::dictName);
249 
250  if (ptr)
251  {
252  return ptr->kappa(patchi);
253  }
254  }
255 
256  {
257  const auto* ptr =
258  mesh.cfindObject<basicThermo>("phaseProperties");
259 
260  if (ptr)
261  {
262  return ptr->kappa(patchi);
263  }
264  }
265 
267  << "Using kappaMethod " << KMethodTypeNames_[method_]
268  << ", but thermo package not available\n"
269  << exit(FatalError);
270 
271  break;
272  }
273 
274  case mtSolidThermo:
275  {
276  const solidThermo& thermo =
277  mesh.lookupObject<solidThermo>(basicThermo::dictName);
278 
279  return thermo.kappa(patchi);
280  break;
281  }
282 
283  case mtDirectionalSolidThermo:
284  {
285  const solidThermo& thermo =
286  mesh.lookupObject<solidThermo>(basicThermo::dictName);
287 
288  const symmTensorField& alphaAni =
289  patch_.lookupPatchField<volSymmTensorField, scalar>
290  (
291  alphaAniName_
292  );
293 
294  const scalarField& pp = thermo.p().boundaryField()[patchi];
295 
296  const symmTensorField kappa(alphaAni*thermo.Cp(pp, Tp, patchi));
297 
298  const vectorField n(patch_.nf());
299 
300  return n & kappa & n;
301  }
302 
303  case mtLookup:
304  {
305  if (mesh.foundObject<volScalarField>(kappaName_))
306  {
307  return patch_.lookupPatchField<volScalarField, scalar>
308  (
309  kappaName_
310  );
311  }
312  else if (mesh.foundObject<volSymmTensorField>(kappaName_))
313  {
314  const symmTensorField& KWall =
315  patch_.lookupPatchField<volSymmTensorField, scalar>
316  (
317  kappaName_
318  );
319 
320  const vectorField n(patch_.nf());
321 
322  return n & KWall & n;
323  }
324  else
325  {
327  << "Did not find field " << kappaName_
328  << " on mesh " << mesh.name() << " patch " << patch_.name()
329  << nl
330  << " Please set 'kappa' to the name of a volScalarField"
331  << " or volSymmTensorField."
332  << exit(FatalError);
333  }
334  break;
335  }
336 
337  case KMethodType::mtFunction:
338  {
339  const auto& tm = patch_.patch().boundaryMesh().mesh().time();
340  return kappaFunction1_->value(tm.timeOutputValue());
341  break;
342  }
343 
344  default:
345  {
347  << "Unimplemented method " << KMethodTypeNames_[method_] << nl
348  << "Please set 'kappaMethod' to one of "
349  << flatOutput(KMethodTypeNames_.sortedToc()) << nl
350  << "and 'kappa' to the name of the volScalar"
351  << " or volSymmTensor field (if kappaMethod=lookup)"
352  << exit(FatalError);
353 
354  break;
355  }
356  }
357 
358  return scalarField();
359 }
360 
361 
363 (
364  const scalarField& Tp
365 ) const
366 {
367  const fvMesh& mesh = patch_.boundaryMesh().mesh();
368  const label patchi = patch_.index();
369 
370  switch (method_)
371  {
372  case mtFluidThermo:
373  {
375 
376  {
377  const auto* ptr =
378  mesh.cfindObject<turbulenceModel>
379  (
380  turbulenceModel::propertiesName
381  );
382 
383  if (ptr)
384  {
385  return ptr->alphaEff(patchi);
386  }
387  }
388 
389  {
390  const auto* ptr =
391  mesh.cfindObject<fluidThermo>(basicThermo::dictName);
392 
393  if (ptr)
394  {
395  return ptr->alpha(patchi);
396  }
397  }
398 
399  {
400  const auto* ptr =
401  mesh.cfindObject<basicThermo>(basicThermo::dictName);
402 
403  if (ptr)
404  {
405  return ptr->alpha(patchi);
406  }
407  }
408 
409  {
410  const auto* ptr =
411  mesh.cfindObject<basicThermo>("phaseProperties");
412 
413  if (ptr)
414  {
415  return ptr->alpha(patchi);
416  }
417  }
418 
420  << "Using kappaMethod " << KMethodTypeNames_[method_]
421  << ", but thermo package not available\n"
422  << exit(FatalError);
423 
424  break;
425  }
426 
427  case mtSolidThermo:
428  {
429  const solidThermo& thermo =
430  mesh.lookupObject<solidThermo>(basicThermo::dictName);
431 
432  return thermo.alpha(patchi);
433  break;
434  }
435 
436  case mtDirectionalSolidThermo:
437  {
438  const symmTensorField& alphaAni =
439  patch_.lookupPatchField<volSymmTensorField, scalar>
440  (
441  alphaAniName_
442  );
443 
444  const vectorField n(patch_.nf());
445 
446  return n & alphaAni & n;
447  }
448 
449  case mtLookup:
450  {
451  if (mesh.foundObject<volScalarField>(alphaName_))
452  {
453  return
454  patch_.lookupPatchField<volScalarField, scalar>
455  (
456  alphaName_
457  );
458  }
459  else if (mesh.foundObject<volSymmTensorField>(alphaName_))
460  {
461  const symmTensorField& alphaWall =
462  patch_.lookupPatchField<volSymmTensorField, scalar>
463  (
464  alphaName_
465  );
466 
467  const vectorField n(patch_.nf());
468 
469  return n & alphaWall & n;
470  }
471  else
472  {
474  << "Did not find field " << alphaName_
475  << " on mesh " << mesh.name() << " patch " << patch_.name()
476  << nl
477  << "Please set 'kappaMethod' to one of "
478  << flatOutput(KMethodTypeNames_.sortedToc()) << nl
479  << "and 'alpha' to the name of the volScalar"
480  << " or volSymmTensor field (if kappaMethod=lookup)"
481  << exit(FatalError);
482  }
483 
484  break;
485  }
486 
487  case KMethodType::mtFunction:
488  {
489  const auto& tm = patch_.patch().boundaryMesh().mesh().time();
490  return alphaFunction1_->value(tm.timeOutputValue());
491  break;
492  }
493 
494  default:
495  {
497  << "Unimplemented method " << KMethodTypeNames_[method_] << nl
498  << "Please set 'kappaMethod' to one of "
499  << flatOutput(KMethodTypeNames_.sortedToc()) << nl
500  << "and 'alpha' to the name of the volScalar"
501  << " or volSymmTensor field (if kappaMethod=lookup)"
502  << exit(FatalError);
503 
504  break;
505  }
506  }
507 
508  return scalarField();
509 }
510 
511 
513 {
514  os.writeEntry("kappaMethod", KMethodTypeNames_[method_]);
515  if (!kappaName_.empty())
516  {
517  os.writeEntry("kappa", kappaName_);
518  }
519  if (!alphaAniName_.empty())
520  {
521  os.writeEntry("alphaAni", alphaAniName_);
522  }
523  if (!alphaName_.empty())
524  {
525  os.writeEntry("alpha", alphaName_);
526  }
527  if (kappaFunction1_)
528  {
529  kappaFunction1_->writeData(os);
530  }
531  if (alphaFunction1_)
532  {
533  alphaFunction1_->writeData(os);
534  }
535 }
536 
537 
538 // ************************************************************************* //
Foam::fvPatchField< scalar >
volFields.H
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::temperatureCoupledBase::alphaAniName_
const word alphaAniName_
Name of the non-Isotropic alpha (default: Anialpha)
Definition: temperatureCoupledBase.H:168
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
fluidThermo.H
Foam::temperatureCoupledBase::kappaFunction1_
autoPtr< PatchFunction1< scalar > > kappaFunction1_
Function1 for kappa.
Definition: temperatureCoupledBase.H:174
dictName
const word dictName("faMeshDefinition")
Foam::fluidThermo
Fundamental fluid thermodynamic properties.
Definition: fluidThermo.H:52
Foam::temperatureCoupledBase
Common functions used in temperature coupled boundaries.
Definition: temperatureCoupledBase.H:135
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::basicThermo
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:63
Foam::FatalIOError
IOerror FatalIOError
Foam::temperatureCoupledBase::KMethodTypeNames_
static const Enum< KMethodType > KMethodTypeNames_
Definition: temperatureCoupledBase.H:156
Foam::temperatureCoupledBase::alphaFunction1_
autoPtr< PatchFunction1< scalar > > alphaFunction1_
Function1 for alpha.
Definition: temperatureCoupledBase.H:177
Foam::constant::electromagnetic::kappa
const dimensionedScalar kappa
Coulomb constant: default SI units: [N.m2/C2].
Foam::temperatureCoupledBase::autoMap
virtual void autoMap(const fvPatchFieldMapper &)=0
Map (and resize as needed) from self given a mapping object.
Definition: temperatureCoupledBase.C:172
solidThermo.H
Foam::solidThermo
Fundamental solid thermodynamic properties.
Definition: solidThermo.H:52
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::temperatureCoupledBase::method_
const KMethodType method_
How to get K.
Definition: temperatureCoupledBase.H:162
Foam::Field< scalar >
Foam::volSymmTensorField
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
Definition: volFieldsFwd.H:65
Foam::compressible::turbulenceModel
ThermalDiffusivity< CompressibleTurbulenceModel< fluidThermo > > turbulenceModel
Definition: turbulentFluidThermoModel.H:63
Foam::temperatureCoupledBase::KMethodType
KMethodType
Type of supplied Kappa.
Definition: temperatureCoupledBase.H:142
Foam::temperatureCoupledBase::patch_
const fvPatch & patch_
Underlying patch.
Definition: temperatureCoupledBase.H:159
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::temperatureCoupledBase::alpha
virtual tmp< scalarField > alpha(const scalarField &Tp) const
Given patch temperature calculate corresponding alphaEff field.
Definition: temperatureCoupledBase.C:363
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::basicThermo::kappa
virtual tmp< volScalarField > kappa() const =0
Thermal diffusivity for temperature of mixture [J/m/s/K].
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::turbulenceModel
Abstract base class for turbulence models (RAS, LES and laminar).
Definition: turbulenceModel.H:63
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
temperatureCoupledBase.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::temperatureCoupledBase::alphaName_
const word alphaName_
Name of thermal diffusivity.
Definition: temperatureCoupledBase.H:171
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::temperatureCoupledBase::rmap
virtual void rmap(const fvPatchField< scalar > &, const labelList &)=0
Reverse map the given fvPatchField onto this fvPatchField.
Definition: temperatureCoupledBase.C:188
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::temperatureCoupledBase::kappaName_
const word kappaName_
Name of thermal conductivity field (if looked up from database)
Definition: temperatureCoupledBase.H:165
Foam::basicThermo::alpha
virtual const volScalarField & alpha() const
Thermal diffusivity for enthalpy of mixture [kg/m/s].
Definition: basicThermo.C:626
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::ThermalDiffusivity
Templated wrapper class to provide compressible turbulence models thermal diffusivity based thermal t...
Definition: phaseCompressibleTurbulenceModelFwd.H:47
Foam::List< label >
Foam::temperatureCoupledBase::kappa
virtual tmp< scalarField > kappa(const scalarField &Tp) const
Given patch temperature calculate corresponding K field.
Definition: temperatureCoupledBase.C:210
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::fvPatchFieldMapper
Foam::fvPatchFieldMapper.
Definition: fvPatchFieldMapper.H:47
Foam::temperatureCoupledBase::write
void write(Ostream &os) const
Write.
Definition: temperatureCoupledBase.C:512
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::temperatureCoupledBase::temperatureCoupledBase
temperatureCoupledBase(const fvPatch &patch, const word &calculationMethod, const word &kappaName, const word &alphaAniName, const word &alphaName)
Construct from patch and K name.
Definition: temperatureCoupledBase.C:54
turbulentFluidThermoModel.H