basicThermo.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 "basicThermo.H"
34 #include "fixedJumpFvPatchFields.H"
38 
39 
40 /* * * * * * * * * * * * * * * private static data * * * * * * * * * * * * * */
41 
42 namespace Foam
43 {
44  defineTypeNameAndDebug(basicThermo, 0);
45  defineRunTimeSelectionTable(basicThermo, fvMesh);
46  defineRunTimeSelectionTable(basicThermo, fvMeshDictPhase);
47 }
48 
49 const Foam::word Foam::basicThermo::dictName("thermophysicalProperties");
50 
51 
52 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
53 
55 {
56  const volScalarField::Boundary& tbf = this->T_.boundaryField();
57 
58  wordList hbt(tbf.size(), word::null);
59 
60  forAll(tbf, patchi)
61  {
62  if (isA<fixedJumpFvPatchScalarField>(tbf[patchi]))
63  {
64  const fixedJumpFvPatchScalarField& pf =
65  dynamic_cast<const fixedJumpFvPatchScalarField&>(tbf[patchi]);
66 
67  hbt[patchi] = pf.interfaceFieldType();
68  }
69  else if (isA<fixedJumpAMIFvPatchScalarField>(tbf[patchi]))
70  {
71  const fixedJumpAMIFvPatchScalarField& pf =
72  dynamic_cast<const fixedJumpAMIFvPatchScalarField&>
73  (
74  tbf[patchi]
75  );
76 
77  hbt[patchi] = pf.interfaceFieldType();
78  }
79  }
80 
81  return hbt;
82 }
83 
84 
86 {
87  const volScalarField::Boundary& tbf = this->T_.boundaryField();
88 
89  wordList hbt = tbf.types();
90 
91  forAll(tbf, patchi)
92  {
93  if (isA<fixedValueFvPatchScalarField>(tbf[patchi]))
94  {
95  hbt[patchi] = fixedEnergyFvPatchScalarField::typeName;
96  }
97  else if
98  (
99  isA<zeroGradientFvPatchScalarField>(tbf[patchi])
100  || isA<fixedGradientFvPatchScalarField>(tbf[patchi])
101  )
102  {
103  hbt[patchi] = gradientEnergyFvPatchScalarField::typeName;
104  }
105  else if (isA<mixedFvPatchScalarField>(tbf[patchi]))
106  {
107  hbt[patchi] = mixedEnergyFvPatchScalarField::typeName;
108  }
109  else if (isA<fixedJumpFvPatchScalarField>(tbf[patchi]))
110  {
111  hbt[patchi] = energyJumpFvPatchScalarField::typeName;
112  }
113  else if (isA<fixedJumpAMIFvPatchScalarField>(tbf[patchi]))
114  {
115  hbt[patchi] = energyJumpAMIFvPatchScalarField::typeName;
116  }
117  }
118 
119  return hbt;
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
124 
126 (
127  const fvMesh& mesh,
128  const word& name,
129  bool& isOwner
130 )
131 {
132  volScalarField* ptr =
133  mesh.objectRegistry::getObjectPtr<volScalarField>(name);
134 
135  isOwner = !ptr;
136 
137  if (!ptr)
138  {
139  ptr = new volScalarField
140  (
141  IOobject
142  (
143  name,
144  mesh.time().timeName(),
145  mesh,
148  ),
149  mesh
150  );
151 
152  // Transfer ownership of this object to the objectRegistry
153  ptr->store();
154  }
155 
156  return *ptr;
157 }
158 
159 
161 (
162  const fvMesh& mesh,
163  const word& phaseName
164 )
165 :
167  (
168  IOobject
169  (
170  phasePropertyName(dictName, phaseName),
171  mesh.time().constant(),
172  mesh,
175  )
176  ),
177 
178  phaseName_(phaseName),
179 
180  p_(lookupOrConstruct(mesh, "p", pOwner_)),
181 
182  T_(lookupOrConstruct(mesh, phasePropertyName("T"), TOwner_)),
183  TOwner_(getOrDefault<Switch>("updateT", TOwner_)),
184 
185  alpha_
186  (
187  IOobject
188  (
189  phasePropertyName("thermo:alpha"),
190  mesh.time().timeName(),
191  mesh,
194  ),
195  mesh,
196  dimensionedScalar(dimensionSet(1, -1, -1, 0, 0), Zero)
197  ),
198 
199  dpdt_(getOrDefault<Switch>("dpdt", true))
200 {}
201 
202 
204 (
205  const fvMesh& mesh,
206  const dictionary& dict,
207  const word& phaseName
208 )
209 :
211  (
212  IOobject
213  (
214  phasePropertyName(dictName, phaseName),
215  mesh.time().constant(),
216  mesh,
219  ),
220  dict
221  ),
222 
223  phaseName_(phaseName),
224 
225  p_(lookupOrConstruct(mesh, "p", pOwner_)),
226 
227  T_(lookupOrConstruct(mesh, phasePropertyName("T"), TOwner_)),
228  TOwner_(getOrDefault<Switch>("updateT", TOwner_)),
229 
230  alpha_
231  (
232  IOobject
233  (
234  phasePropertyName("thermo:alpha"),
235  mesh.time().timeName(),
236  mesh,
239  ),
240  mesh,
241  dimensionedScalar(dimensionSet(1, -1, -1, 0, 0), Zero)
242  ),
243 
244  dpdt_(getOrDefault<Switch>("dpdt", true))
245 {}
246 
247 
249 (
250  const fvMesh& mesh,
251  const word& phaseName,
252  const word& dictionaryName
253 )
254 :
256  (
257  IOobject
258  (
259  dictionaryName,
260  mesh.time().constant(),
261  mesh,
264  )
265  ),
266 
267  phaseName_(phaseName),
268 
269  p_(lookupOrConstruct(mesh, "p", pOwner_)),
270 
271  T_(lookupOrConstruct(mesh, "T", TOwner_)),
272  TOwner_(getOrDefault<Switch>("updateT", TOwner_)),
273 
274  alpha_
275  (
276  IOobject
277  (
278  phasePropertyName("thermo:alpha"),
279  mesh.time().timeName(),
280  mesh,
283  ),
284  mesh,
285  dimensionedScalar(dimensionSet(1, -1, -1, 0, 0), Zero)
286  ),
287 
288  dpdt_(getOrDefault<Switch>("dpdt", true))
289 {
290  if (debug)
291  {
292  Pout<< "Constructed shared thermo : mesh:" << mesh.name()
293  << " phase:" << phaseName
294  << " dictionary:" << dictionaryName
295  << " T:" << T_.name()
296  << " updateT:" << TOwner_
297  << " alphaName:" << alpha_.name()
298  << endl;
299  }
300 }
301 
302 
303 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
304 
306 (
307  const fvMesh& mesh,
308  const word& phaseName
309 )
310 {
311  return New<basicThermo>(mesh, phaseName);
312 }
313 
314 
315 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
316 
318 {
319  db().checkOut("p");
320 }
321 
322 
323 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
324 
326 (
327  const fvPatchScalarField& pf
328 )
329 {
331 
332  if (thermo)
333  {
334  return *thermo;
335  }
336 
338  pf.db().lookupClass<basicThermo>();
339 
341  {
342  if
343  (
344  &(iter()->he().internalField())
345  == &(pf.internalField())
346  )
347  {
348  return *iter();
349  }
350  }
351 
352  return pf.db().lookupObject<basicThermo>(dictName);
353 }
354 
355 
357 (
358  const string& app,
359  const word& a
360 ) const
361 {
362  if (!(he().name() == phasePropertyName(a)))
363  {
365  << "Supported energy type is " << phasePropertyName(a)
366  << ", thermodynamics package provides " << he().name()
367  << exit(FatalError);
368  }
369 }
370 
372 (
373  const string& app,
374  const word& a,
375  const word& b
376 ) const
377 {
378  if
379  (
380  !(
381  he().name() == phasePropertyName(a)
382  || he().name() == phasePropertyName(b)
383  )
384  )
385  {
387  << "Supported energy types are " << phasePropertyName(a)
388  << " and " << phasePropertyName(b)
389  << ", thermodynamics package provides " << he().name()
390  << exit(FatalError);
391  }
392 }
393 
395 (
396  const string& app,
397  const word& a,
398  const word& b,
399  const word& c
400 ) const
401 {
402  if
403  (
404  !(
405  he().name() == phasePropertyName(a)
406  || he().name() == phasePropertyName(b)
407  || he().name() == phasePropertyName(c)
408  )
409  )
410  {
412  << "Supported energy types are " << phasePropertyName(a)
413  << ", " << phasePropertyName(b)
414  << " and " << phasePropertyName(c)
415  << ", thermodynamics package provides " << he().name()
416  << exit(FatalError);
417  }
418 }
419 
421 (
422  const string& app,
423  const word& a,
424  const word& b,
425  const word& c,
426  const word& d
427 ) const
428 {
429  if
430  (
431  !(
432  he().name() == phasePropertyName(a)
433  || he().name() == phasePropertyName(b)
434  || he().name() == phasePropertyName(c)
435  || he().name() == phasePropertyName(d)
436  )
437  )
438  {
440  << "Supported energy types are " << phasePropertyName(a)
441  << ", " << phasePropertyName(b)
442  << ", " << phasePropertyName(c)
443  << " and " << phasePropertyName(d)
444  << ", thermodynamics package provides " << he().name()
445  << exit(FatalError);
446  }
447 }
448 
449 
451 (
452  const word& thermoName,
453  const int nCmpt
454 )
455 {
456  wordList cmpts(nCmpt);
457 
458  string::size_type beg=0, end=0, endb=0, endc=0;
459  int i = 0;
460 
461  while
462  (
463  (endb = thermoName.find('<', beg)) != string::npos
464  || (endc = thermoName.find(',', beg)) != string::npos
465  )
466  {
467  if (endb == string::npos)
468  {
469  end = endc;
470  }
471  else if ((endc = thermoName.find(',', beg)) != string::npos)
472  {
473  end = std::min(endb, endc);
474  }
475  else
476  {
477  end = endb;
478  }
479 
480  if (beg < end)
481  {
482  cmpts[i] = thermoName.substr(beg, end-beg);
483  cmpts[i++].replaceAll(">","");
484 
485  // If the number of number of components in the name
486  // is greater than nCmpt return an empty list
487  if (i == nCmpt)
488  {
489  return wordList::null();
490  }
491  }
492  beg = end + 1;
493  }
494 
495  // If the number of number of components in the name is not equal to nCmpt
496  // return an empty list
497  if (i + 1 != nCmpt)
498  {
499  return wordList::null();
500  }
501 
502  if (beg < thermoName.size())
503  {
504  cmpts[i] = thermoName.substr(beg, string::npos);
505  cmpts[i].replaceAll(">","");
506  }
507 
508  return cmpts;
509 }
510 
511 
513 {
514  return p_;
515 }
516 
517 
519 {
520  return p_;
521 }
522 
523 
525 {
526  return T_;
527 }
528 
529 
531 {
532  return T_;
533 }
534 
535 
537 {
538  return alpha_;
539 }
540 
541 
542 const Foam::scalarField& Foam::basicThermo::alpha(const label patchi) const
543 {
544  return alpha_.boundaryField()[patchi];
545 }
546 
547 
549 {
550  return regIOobject::read();
551 }
552 
553 
554 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::fvPatchField< scalar >
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::fvPatchField::internalField
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:349
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::basicThermo::heBoundaryTypes
wordList heBoundaryTypes()
Return the enthalpy/internal energy field boundary types.
Definition: basicThermo.C:85
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:129
basicThermo.H
Foam::List::null
static const List< T > & null()
Return a null List.
Definition: ListI.H:108
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::basicThermo::~basicThermo
virtual ~basicThermo()
Destructor.
Definition: basicThermo.C:317
Foam::basicThermo::p
virtual volScalarField & p()
Pressure [Pa].
Definition: basicThermo.C:512
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::basicThermo::read
virtual bool read()
Read thermophysical properties dictionary.
Definition: basicThermo.C:548
gradientEnergyFvPatchScalarField.H
thermo
psiReactionThermo & thermo
Definition: createFields.H:28
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::regIOobject::read
virtual bool read()
Read object.
Definition: regIOobjectRead.C:202
dictName
const word dictName("blockMeshDict")
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
fixedJumpAMIFvPatchFields.H
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:65
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::objectRegistry::lookupClass
HashTable< const Type * > lookupClass(const bool strict=false) const
Return all objects with a class satisfying isA<Type>
Foam::basicThermo::heBoundaryBaseTypes
wordList heBoundaryBaseTypes()
Return the enthalpy/internal energy field boundary base types.
Definition: basicThermo.C:54
energyJumpFvPatchScalarField.H
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::Field< scalar >
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:122
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:76
Foam::basicThermo::splitThermoName
static wordList splitThermoName(const word &thermoName, const int nCmpt)
Split name of thermo package into a list of the components names.
Definition: basicThermo.C:451
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionary.H:458
dict
dictionary dict
Definition: searchingEngine.H:14
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
Foam::basicThermo::New
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
energyJumpAMIFvPatchScalarField.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::basicThermo::validate
void validate(const string &app, const word &) const
Check that the thermodynamics package is consistent.
Definition: basicThermo.C:357
fixedEnergyFvPatchScalarField.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::basicThermo::T_
volScalarField & T_
Temperature [K].
Definition: basicThermo.H:84
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
mixedEnergyFvPatchScalarField.H
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::basicThermo::basicThermo
basicThermo(const basicThermo &)
Construct as copy (not implemented)
Foam::objectRegistry::findObject
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:401
he
volScalarField & he
Definition: YEEqn.H:52
Foam::basicThermo::T
virtual const volScalarField & T() const
Temperature [K].
Definition: basicThermo.C:524
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::fvPatchField::db
const objectRegistry & db() const
Return local objectRegistry.
Definition: fvPatchField.C:198
Foam::List< word >
fixedJumpFvPatchFields.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:275
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
Foam::basicThermo::lookupThermo
static Table::iterator lookupThermo(const dictionary &thermoTypeDict, Table *tablePtr, std::initializer_list< const char * > cmptNames, const word &thermoTypeName)
Generic lookup for thermodynamics package thermoTypeName.
Definition: basicThermoTemplates.C:35
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
zeroGradientFvPatchFields.H
Foam::basicThermo::lookupOrConstruct
static volScalarField & lookupOrConstruct(const fvMesh &mesh, const word &, bool &isOwner)
Look up or construct field.
Definition: basicThermo.C:126
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:295
thermos
PtrList< solidThermo > thermos(solidRegions.size())
Foam::IOobject::MUST_READ
Definition: IOobject.H:120