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-2020 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 };
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const fvPatch& patch,
55  const word& calculationType,
56  const word& kappaName,
57  const word& alphaAniName,
58  const word& alphaName
59 )
60 :
61  patch_(patch),
62  method_(KMethodTypeNames_[calculationType]),
63  kappaName_(kappaName),
64  alphaAniName_(alphaAniName),
65  alphaName_(alphaName)
66 {}
67 
68 
70 (
71  const fvPatch& patch,
72  const dictionary& dict
73 )
74 :
75  patch_(patch),
76  method_(KMethodTypeNames_.get("kappaMethod", dict)),
77  kappaName_(dict.getOrDefault<word>("kappa", "none")),
78  alphaAniName_(dict.getOrDefault<word>("alphaAni", "none")),
79  alphaName_(dict.getOrDefault<word>("alpha", "none"))
80 {
81  switch (method_)
82  {
83  case mtDirectionalSolidThermo:
84  {
85  if (!dict.found("alphaAni"))
86  {
88  << "Did not find entry 'alphaAni'"
89  " required for 'kappaMethod' "
90  << KMethodTypeNames_[method_]
91  << exit(FatalIOError);
92  }
93 
94  break;
95  }
96 
97  case mtLookup:
98  {
99  if (!dict.found("kappa"))
100  {
102  << "Did not find entry 'kappa'"
103  " required for 'kappaMethod' "
104  << KMethodTypeNames_[method_] << nl
105  << " Please set 'kappa' to the name of a volScalarField"
106  " or volSymmTensorField"
107  << exit(FatalIOError);
108  }
109 
110  break;
111  }
112 
113  default:
114  {
115  break;
116  }
117  }
118 }
119 
120 
122 (
123  const fvPatch& patch,
124  const temperatureCoupledBase& base
125 )
126 :
127  patch_(patch),
128  method_(base.method_),
129  kappaName_(base.kappaName_),
130  alphaAniName_(base.alphaAniName_),
131  alphaName_(base.alphaName_)
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
138 (
139  const scalarField& Tp
140 ) const
141 {
142  const fvMesh& mesh = patch_.boundaryMesh().mesh();
143  const label patchi = patch_.index();
144 
145  switch (method_)
146  {
147  case mtFluidThermo:
148  {
150 
151  {
152  const auto* ptr =
153  mesh.cfindObject<turbulenceModel>
154  (
155  turbulenceModel::propertiesName
156  );
157 
158  if (ptr)
159  {
160  return ptr->kappaEff(patchi);
161  }
162  }
163 
164  {
165  const auto* ptr =
166  mesh.cfindObject<fluidThermo>(basicThermo::dictName);
167 
168  if (ptr)
169  {
170  return ptr->kappa(patchi);
171  }
172  }
173 
174  {
175  const auto* ptr =
176  mesh.cfindObject<basicThermo>(basicThermo::dictName);
177 
178  if (ptr)
179  {
180  return ptr->kappa(patchi);
181  }
182  }
183 
184  {
185  const auto* ptr =
186  mesh.cfindObject<basicThermo>("phaseProperties");
187 
188  if (ptr)
189  {
190  return ptr->kappa(patchi);
191  }
192  }
193 
195  << "Using kappaMethod " << KMethodTypeNames_[method_]
196  << ", but thermo package not available\n"
197  << exit(FatalError);
198 
199  break;
200  }
201 
202  case mtSolidThermo:
203  {
204  const solidThermo& thermo =
205  mesh.lookupObject<solidThermo>(basicThermo::dictName);
206 
207  return thermo.kappa(patchi);
208  break;
209  }
210 
211  case mtDirectionalSolidThermo:
212  {
213  const solidThermo& thermo =
214  mesh.lookupObject<solidThermo>(basicThermo::dictName);
215 
216  const symmTensorField& alphaAni =
217  patch_.lookupPatchField<volSymmTensorField, scalar>
218  (
219  alphaAniName_
220  );
221 
222  const scalarField& pp = thermo.p().boundaryField()[patchi];
223 
224  const symmTensorField kappa(alphaAni*thermo.Cp(pp, Tp, patchi));
225 
226  const vectorField n(patch_.nf());
227 
228  return n & kappa & n;
229  }
230 
231  case mtLookup:
232  {
233  if (mesh.foundObject<volScalarField>(kappaName_))
234  {
235  return patch_.lookupPatchField<volScalarField, scalar>
236  (
237  kappaName_
238  );
239  }
240  else if (mesh.foundObject<volSymmTensorField>(kappaName_))
241  {
242  const symmTensorField& KWall =
243  patch_.lookupPatchField<volSymmTensorField, scalar>
244  (
245  kappaName_
246  );
247 
248  const vectorField n(patch_.nf());
249 
250  return n & KWall & n;
251  }
252  else
253  {
255  << "Did not find field " << kappaName_
256  << " on mesh " << mesh.name() << " patch " << patch_.name()
257  << nl
258  << " Please set 'kappa' to the name of a volScalarField"
259  << " or volSymmTensorField."
260  << exit(FatalError);
261  }
262  break;
263  }
264 
265  default:
266  {
268  << "Unimplemented method " << KMethodTypeNames_[method_] << nl
269  << "Please set 'kappaMethod' to one of "
270  << flatOutput(KMethodTypeNames_.sortedToc()) << nl
271  << "and 'kappa' to the name of the volScalar"
272  << " or volSymmTensor field (if kappaMethod=lookup)"
273  << exit(FatalError);
274 
275  break;
276  }
277  }
278 
279  return scalarField();
280 }
281 
282 
284 (
285  const scalarField& Tp
286 ) const
287 {
288  const fvMesh& mesh = patch_.boundaryMesh().mesh();
289  const label patchi = patch_.index();
290 
291  switch (method_)
292  {
293  case mtFluidThermo:
294  {
296 
297  {
298  const auto* ptr =
299  mesh.cfindObject<turbulenceModel>
300  (
301  turbulenceModel::propertiesName
302  );
303 
304  if (ptr)
305  {
306  return ptr->alphaEff(patchi);
307  }
308  }
309 
310  {
311  const auto* ptr =
312  mesh.cfindObject<fluidThermo>(basicThermo::dictName);
313 
314  if (ptr)
315  {
316  return ptr->alpha(patchi);
317  }
318  }
319 
320  {
321  const auto* ptr =
322  mesh.cfindObject<basicThermo>(basicThermo::dictName);
323 
324  if (ptr)
325  {
326  return ptr->alpha(patchi);
327  }
328  }
329 
330  {
331  const auto* ptr =
332  mesh.cfindObject<basicThermo>("phaseProperties");
333 
334  if (ptr)
335  {
336  return ptr->alpha(patchi);
337  }
338  }
339 
341  << "Using kappaMethod " << KMethodTypeNames_[method_]
342  << ", but thermo package not available\n"
343  << exit(FatalError);
344 
345  break;
346  }
347 
348  case mtSolidThermo:
349  {
350  const solidThermo& thermo =
351  mesh.lookupObject<solidThermo>(basicThermo::dictName);
352 
353  return thermo.alpha(patchi);
354  break;
355  }
356 
357  case mtDirectionalSolidThermo:
358  {
359  const symmTensorField& alphaAni =
360  patch_.lookupPatchField<volSymmTensorField, scalar>
361  (
362  alphaAniName_
363  );
364 
365  const vectorField n(patch_.nf());
366 
367  return n & alphaAni & n;
368  }
369 
370  case mtLookup:
371  {
372  if (mesh.foundObject<volScalarField>(alphaName_))
373  {
374  return
375  patch_.lookupPatchField<volScalarField, scalar>
376  (
377  alphaName_
378  );
379  }
380  else if (mesh.foundObject<volSymmTensorField>(alphaName_))
381  {
382  const symmTensorField& alphaWall =
383  patch_.lookupPatchField<volSymmTensorField, scalar>
384  (
385  alphaName_
386  );
387 
388  const vectorField n(patch_.nf());
389 
390  return n & alphaWall & n;
391  }
392  else
393  {
395  << "Did not find field " << alphaName_
396  << " on mesh " << mesh.name() << " patch " << patch_.name()
397  << nl
398  << "Please set 'kappaMethod' to one of "
399  << flatOutput(KMethodTypeNames_.sortedToc()) << nl
400  << "and 'alpha' to the name of the volScalar"
401  << " or volSymmTensor field (if kappaMethod=lookup)"
402  << exit(FatalError);
403  }
404 
405  break;
406  }
407 
408  default:
409  {
411  << "Unimplemented method " << KMethodTypeNames_[method_] << nl
412  << "Please set 'kappaMethod' to one of "
413  << flatOutput(KMethodTypeNames_.sortedToc()) << nl
414  << "and 'alpha' to the name of the volScalar"
415  << " or volSymmTensor field (if kappaMethod=lookup)"
416  << exit(FatalError);
417 
418  break;
419  }
420  }
421 
422  return scalarField();
423 }
424 
425 
427 {
428  os.writeEntry("kappaMethod", KMethodTypeNames_[method_]);
429  os.writeEntry("kappa", kappaName_);
430  os.writeEntry("alphaAni", alphaAniName_);
431  os.writeEntry("alpha", alphaName_);
432 }
433 
434 
435 // ************************************************************************* //
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:62
Foam::temperatureCoupledBase::alphaAniName_
const word alphaAniName_
Name of the non-Isotropic alpha (default: Anialpha)
Definition: temperatureCoupledBase.H:142
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
fluidThermo.H
Foam::fluidThermo
Fundamental fluid thermodynamic properties.
Definition: fluidThermo.H:52
dictName
const word dictName("blockMeshDict")
Foam::temperatureCoupledBase
Common functions used in temperature coupled boundaries.
Definition: temperatureCoupledBase.H:110
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:130
Foam::constant::electromagnetic::kappa
const dimensionedScalar kappa
Coulomb constant: default SI units: [N.m2/C2].
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:136
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:117
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:284
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:121
temperatureCoupledBase.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::temperatureCoupledBase::alphaName_
const word alphaName_
Name of thermal diffusivity.
Definition: temperatureCoupledBase.H:145
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:217
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::temperatureCoupledBase::kappaName_
const word kappaName_
Name of thermal conductivity field (if looked up from database)
Definition: temperatureCoupledBase.H:139
Foam::basicThermo::alpha
virtual const volScalarField & alpha() const
Thermal diffusivity for enthalpy of mixture [kg/m/s].
Definition: basicThermo.C:536
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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::temperatureCoupledBase::kappa
virtual tmp< scalarField > kappa(const scalarField &Tp) const
Given patch temperature calculate corresponding K field.
Definition: temperatureCoupledBase.C:138
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::temperatureCoupledBase::write
void write(Ostream &os) const
Write.
Definition: temperatureCoupledBase.C:426
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:53
turbulentFluidThermoModel.H