basicThermo.H
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-2017 OpenFOAM Foundation
9  Copyright (C) 2017-2023 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 Class
28  Foam::basicThermo
29 
30 Description
31  Abstract base-class for fluid and solid thermodynamic properties
32 
33  An important concept is that the thermo can share an existing T
34  (similar to p) in which case it will not try to update it. This gets
35  triggered purely on construction order - the first one to register
36  T is responsible for updating it. Note that the mechanism also means
37  that if multiple thermos are running on the same mesh, only the first one
38  will update the temperature. The behaviour can be overridden using the
39  'updateT' dictionary entry.
40 
41 SourceFiles
42  basicThermo.C
43 
44 \*---------------------------------------------------------------------------*/
45 
46 #ifndef Foam_basicThermo_H
47 #define Foam_basicThermo_H
48 
49 #include "volFields.H"
50 #include "typeInfo.H"
51 #include "IOdictionary.H"
52 #include "autoPtr.H"
53 #include "wordIOList.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 
60 /*---------------------------------------------------------------------------*\
61  Class basicThermo Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class basicThermo
65 :
66  public IOdictionary
67 {
68  // Private Data
69 
70  //- Components names/order
71  static const wordList componentHeader4;
72 
73  //- Components names/order
74  static const wordList componentHeader7;
75 
76 
77  // Private Member Functions
78 
79  //- Construct name of thermo package from dictionary components
80  static word makeThermoName
81  (
82  const dictionary& dict,
83  const wordList*& cmptHeaderPtr
84  );
85 
86  //- Look up field from registry or construct and store
87  static volScalarField& lookupOrConstruct
88  (
89  const fvMesh& mesh,
90  const word& fieldName,
91  bool& isOwner
92  );
93 
94  //- Generic lookup for thermodynamics package thermoTypeName
95  // \return constructor pointer, or FatalError
96  template<class Thermo, class ThermoConstructTable>
97  static typename ThermoConstructTable::mapped_type
98  getThermoOrDie
99  (
100  const dictionary& thermoTypeDict,
101  ThermoConstructTable& thermoTable,
102  const word& thermoTypeName,
103  const wordList& cmptNames
104  );
105 
106  //- Generic lookup for each of the related thermodynamics packages
107  // \return constructor pointer, or FatalError
108  template<class Thermo, class ThermoConstructTable>
109  static typename ThermoConstructTable::mapped_type
110  getThermoOrDie
111  (
112  const dictionary& thermoDict,
113  ThermoConstructTable& thermoTable
114  );
115 
116 
117 protected:
118 
119  // Protected Data
120 
121  //- Phase-name
122  const word& phaseName_;
123 
124  //- Pressure created and stored by this instance
125  bool pOwner_;
126 
127  //- Temperature created and stored by this instance
128  bool TOwner_;
129 
130  //- Include dpdt term in the enthalpy equation?
131  bool dpdt_;
132 
134  // Fields
135 
136  //- Pressure [Pa]
139  //- Temperature [K]
141 
142  //- Laminar thermal diffusivity [kg/m/s]
144 
145 
146  // Protected Member Functions
147 
148  //- Return the enthalpy/internal energy field boundary types
149  //- by interrogating the temperature field boundary types
151 
152  //- Return the enthalpy/internal energy field boundary base types
153  //- by interrogating the temperature field boundary types
155 
156  //- No copy construct
157  basicThermo(const basicThermo&) = delete;
158 
159 
160 public:
162  //- Runtime type information
163  TypeName("basicThermo");
164 
165 
166  //- Declare run-time constructor selection table
168  (
169  autoPtr,
170  basicThermo,
171  fvMesh,
172  (const fvMesh& mesh, const word& phaseName),
173  (mesh, phaseName)
174  );
175 
176 
177  //- Declare run-time constructor selection table for dictionary based
179  (
180  autoPtr,
181  basicThermo,
182  fvMeshDictPhase,
183  (const fvMesh& mesh, const word& phaseName, const word& dictName),
184  (mesh, phaseName, dictName)
185  );
186 
187 
188  // Constructors
189 
190  //- Construct from mesh and phase name
192  (
193  const fvMesh&,
194  const word& phaseName
195  );
196 
197  //- Construct from mesh, dictionary and phase name
199  (
200  const fvMesh&,
201  const dictionary&,
202  const word& phaseName
203  );
204 
205  //- Construct from mesh, phase name and explicit naming of the
206  //- dictionary (so it can be shared amongst phases).
208  (
209  const fvMesh&,
210  const word& phaseName,
211  const word& dictionaryName
212  );
213 
214 
215  // Selectors
216 
217  //- Generic New for each of the related thermodynamics packages
218  template<class Thermo>
219  static autoPtr<Thermo> New
220  (
221  const fvMesh&,
222  const word& phaseName = word::null
223  );
224 
225  //- Generic New for each of the related thermodynamics packages
226  template<class Thermo>
227  static autoPtr<Thermo> New
228  (
229  const fvMesh&,
230  const dictionary&,
231  const word& phaseName = word::null
232  );
233 
234  //- Generic New for each of the related thermodynamics packages
235  template<class Thermo>
236  static autoPtr<Thermo> New
237  (
238  const fvMesh&,
239  const word& phaseName,
240  const word& dictName
241  );
242 
243  //- Specialisation of the Generic New for basicThermo
245  (
246  const fvMesh&,
247  const word& phaseName = word::null
248  );
249 
250 
251  //- Destructor
252  virtual ~basicThermo();
253 
254 
255  // Member Functions
256 
257  //- The dictionary name ("thermophysicalProperties")
258  static const word dictName;
259 
260  //- The phase property name as property.phase
261  //- \sa IOobject::groupName
262  static word phasePropertyName(const word& name, const word& phaseName)
263  {
264  return IOobject::groupName(name, phaseName);
265  }
266 
267  //- The phase property name as property.phase (using phaseName_)
268  //- \sa IOobject::groupName
269  word phasePropertyName(const word& name) const
270  {
272  }
273 
274  //- The phase property name scoped as scope:property.phase
275  //- \sa IOobject::groupName and \sa IOobject::scopedName
276  word phaseScopedName(const std::string& scope, const word& name) const
277  {
278  return IOobject::groupName
279  (
280  IOobject::scopedName(scope, name),
281  phaseName_
282  );
283  }
284 
285  static const basicThermo& lookupThermo(const fvPatchScalarField& pf);
286 
287  //- Print (filtered) table of thermo names, splits on \c " ,<>"
288  static Ostream& printThermoNames
289  (
290  Ostream& os,
291  const wordList& cmptNames,
292  const wordList& thermoNames
293  );
294 
295  //- Check that the thermodynamics package is consistent
296  // with energy forms supported by the application
297  void validate
298  (
299  const string& app,
300  const word&
301  ) const;
302 
303  //- Check that the thermodynamics package is consistent
304  // with energy forms supported by the application
305  void validate
306  (
307  const string& app,
308  const word&,
309  const word&
310  ) const;
312  //- Check that the thermodynamics package is consistent
313  // with energy forms supported by the application
314  void validate
315  (
316  const string& app,
317  const word&,
318  const word&,
319  const word&
320  ) const;
321 
322  //- Check that the thermodynamics package is consistent
323  // with energy forms supported by the application
324  void validate
325  (
326  const string& app,
327  const word&,
328  const word&,
329  const word&,
330  const word&
331  ) const;
332 
333  //- Split thermo package name into a list of components names
334  // Splits on \c " ,<>"
335  // \return empty list if the split name does not have the
336  // expected number of components (non-zero).
338  (
339  const std::string& thermoName,
340  const int nExpectedCmpts
341  );
342 
343  //- Update properties
344  virtual void correct() = 0;
345 
346  //- Return the name of the thermo physics
347  virtual word thermoName() const = 0;
348 
349  //- Return true if the equation of state is incompressible
350  // i.e. rho != f(p)
351  virtual bool incompressible() const = 0;
352 
353  //- Return true if the equation of state is isochoric
354  // i.e. rho = const
355  virtual bool isochoric() const = 0;
356 
357  //- True if dpdt term should be included in enthalpy equation
358  bool dpdt() const noexcept
359  {
360  return dpdt_;
361  }
362 
363  //- True if T should be updated
364  bool updateT() const noexcept
365  {
366  return TOwner_;
367  }
368 
369 
370  // Access to thermodynamic state variables
371 
372  //- Pressure [Pa]
373  // Non-const access allowed for transport equations
374  virtual volScalarField& p();
375 
376  //- Pressure [Pa]
377  virtual const volScalarField& p() const;
378 
379  //- Density [kg/m^3]
380  virtual tmp<volScalarField> rho() const = 0;
381 
382  //- Density for patch [kg/m^3]
383  virtual tmp<scalarField> rho(const label patchi) const = 0;
384 
385  //- Enthalpy/Internal energy [J/kg]
386  // Non-const access allowed for transport equations
387  virtual volScalarField& he() = 0;
388 
389  //- Enthalpy/Internal energy [J/kg]
390  virtual const volScalarField& he() const = 0;
391 
392  //- Enthalpy/Internal energy
393  // for given pressure and temperature [J/kg]
394  virtual tmp<volScalarField> he
395  (
396  const volScalarField& p,
397  const volScalarField& T
398  ) const = 0;
399 
400  //- Enthalpy/Internal energy for cell-set [J/kg]
401  virtual tmp<scalarField> he
402  (
403  const scalarField& p,
404  const scalarField& T,
405  const labelList& cells
406  ) const = 0;
407 
408  //- Enthalpy/Internal energy for patch [J/kg]
409  virtual tmp<scalarField> he
410  (
411  const scalarField& p,
412  const scalarField& T,
413  const label patchi
414  ) const = 0;
415 
416  //- Chemical enthalpy [J/kg]
417  virtual tmp<volScalarField> hc() const = 0;
418 
419  //- Temperature from enthalpy/internal energy for cell-set
420  virtual tmp<scalarField> THE
421  (
422  const scalarField& h,
423  const scalarField& p,
424  const scalarField& T0, // starting temperature
425  const labelList& cells
426  ) const = 0;
427 
428  //- Temperature from enthalpy/internal energy for patch
429  virtual tmp<scalarField> THE
430  (
431  const scalarField& h,
432  const scalarField& p,
433  const scalarField& T0, // starting temperature
434  const label patchi
435  ) const = 0;
436 
437 
438  // Fields derived from thermodynamic state variables
439 
440  //- Temperature [K]
441  virtual const volScalarField& T() const;
442 
443  //- Temperature [K]
444  // Non-const access allowed for transport equations
445  virtual volScalarField& T();
447  //- Heat capacity at constant pressure [J/kg/K]
448  virtual tmp<volScalarField> Cp() const = 0;
449 
450  //- Heat capacity at constant pressure for patch [J/kg/K]
451  virtual tmp<scalarField> Cp
452  (
453  const scalarField& p,
454  const scalarField& T,
455  const label patchi
456  ) const = 0;
457 
458  //- Heat capacity using pressure and temperature [J/kg/K]
459  virtual tmp<scalarField> Cp
460  (
461  const scalarField& p,
462  const scalarField& T,
463  const labelList& cells
464  ) const = 0;
465 
466  //- Heat capacity at constant volume [J/kg/K]
467  virtual tmp<volScalarField> Cv() const = 0;
468 
469  //- Heat capacity at constant volume for patch [J/kg/K]
470  virtual tmp<scalarField> Cv
471  (
472  const scalarField& p,
473  const scalarField& T,
474  const label patchi
475  ) const = 0;
476 
477  //- Density from pressure and temperature from EoS
478  virtual tmp<scalarField> rhoEoS
479  (
480  const scalarField& p,
481  const scalarField& T,
482  const labelList& cells
483  ) const = 0;
484 
485  //- Gamma = Cp/Cv []
486  virtual tmp<volScalarField> gamma() const = 0;
487 
488  //- Gamma = Cp/Cv for patch []
489  virtual tmp<scalarField> gamma
490  (
491  const scalarField& p,
492  const scalarField& T,
493  const label patchi
494  ) const = 0;
495 
496  //- Heat capacity at constant pressure/volume [J/kg/K]
497  virtual tmp<volScalarField> Cpv() const = 0;
498 
499  //- Heat capacity at constant pressure/volume for patch [J/kg/K]
500  virtual tmp<scalarField> Cpv
501  (
502  const scalarField& p,
503  const scalarField& T,
504  const label patchi
505  ) const = 0;
506 
507  //- Heat capacity ratio []
508  virtual tmp<volScalarField> CpByCpv() const = 0;
509 
510  //- Heat capacity ratio for patch []
511  virtual tmp<scalarField> CpByCpv
512  (
513  const scalarField& p,
514  const scalarField& T,
515  const label patchi
516  ) const = 0;
517 
518  //- Molecular weight [kg/kmol]
519  virtual tmp<volScalarField> W() const = 0;
520 
521 
522  // Access to transport state variables
523 
524  //- Thermal diffusivity for enthalpy of mixture [kg/m/s]
525  virtual const volScalarField& alpha() const;
526 
527  //- Thermal diffusivity for enthalpy of mixture for patch [kg/m/s]
528  virtual const scalarField& alpha
529  (
530  const label patchi
531  ) const;
532 
533 
534  // Fields derived from transport state variables
535 
536  //- Thermal diffusivity for temperature of mixture [J/m/s/K]
537  virtual tmp<volScalarField> kappa() const = 0;
538 
539  //- Thermal diffusivity for temperature
540  // of mixture for patch [J/m/s/K]
541  virtual tmp<scalarField> kappa
542  (
543  const label patchi
544  ) const = 0;
545 
546  //- Thermal diffusivity for energy of mixture [kg/m/s]
547  virtual tmp<volScalarField> alphahe() const = 0;
548 
549  //- Thermal diffusivity for energy of mixture for patch [kg/m/s]
550  virtual tmp<scalarField> alphahe(const label patchi) const = 0;
551 
552  //- Effective thermal diffusivity for temperature
553  // of mixture [J/m/s/K]
555  (
556  const volScalarField&
557  ) const = 0;
558 
559  //- Effective thermal diffusivity for temperature
560  // of mixture for patch [J/m/s/K]
561  virtual tmp<scalarField> kappaEff
562  (
563  const scalarField& alphat,
564  const label patchi
565  ) const = 0;
566 
567  //- Effective thermal diffusivity of mixture [kg/m/s]
569  (
570  const volScalarField& alphat
571  ) const = 0;
572 
573  //- Effective thermal diffusivity of mixture for patch [kg/m/s]
574  virtual tmp<scalarField> alphaEff
575  (
576  const scalarField& alphat,
577  const label patchi
578  ) const = 0;
579 
580 
581  //- Read thermophysical properties dictionary
582  virtual bool read();
583 };
584 
585 
586 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
587 
588 } // End namespace Foam
589 
590 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
591 
592 #ifdef NoRepository
593  #include "basicThermoTemplates.C"
594 #endif
595 
596 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
597 
598 #endif
599 
600 // ************************************************************************* //
virtual tmp< scalarField > rhoEoS(const scalarField &p, const scalarField &T, const labelList &cells) const =0
Density from pressure and temperature from EoS.
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
virtual tmp< volScalarField > kappaEff(const volScalarField &) const =0
Effective thermal diffusivity for temperature.
virtual ~basicThermo()
Destructor.
Definition: basicThermo.C:431
dictionary dict
TypeName("basicThermo")
Runtime type information.
virtual tmp< volScalarField > kappa() const =0
Thermal diffusivity for temperature of mixture [J/m/s/K].
virtual tmp< scalarField > THE(const scalarField &h, const scalarField &p, const scalarField &T0, const labelList &cells) const =0
Temperature from enthalpy/internal energy for cell-set.
Abstract base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:59
static word phasePropertyName(const word &name, const word &phaseName)
The phase property name as property.phase.
Definition: basicThermo.H:317
virtual tmp< volScalarField > rho() const =0
Density [kg/m^3].
bool updateT() const noexcept
True if T should be updated.
Definition: basicThermo.H:454
virtual tmp< volScalarField > alphaEff(const volScalarField &alphat) const =0
Effective thermal diffusivity of mixture [kg/m/s].
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static Ostream & printThermoNames(Ostream &os, const wordList &cmptNames, const wordList &thermoNames)
Print (filtered) table of thermo names, splits on " ,<>".
Definition: basicThermo.C:68
virtual tmp< volScalarField > Cv() const =0
Heat capacity at constant volume [J/kg/K].
virtual word thermoName() const =0
Return the name of the thermo physics.
virtual tmp< volScalarField > alphahe() const =0
Thermal diffusivity for energy of mixture [kg/m/s].
virtual const volScalarField & alpha() const
Thermal diffusivity for enthalpy of mixture [kg/m/s].
Definition: basicThermo.C:625
virtual const volScalarField & T() const
Temperature [K].
Definition: basicThermo.C:613
bool pOwner_
Pressure created and stored by this instance.
Definition: basicThermo.H:138
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
virtual tmp< volScalarField > Cpv() const =0
Heat capacity at constant pressure/volume [J/kg/K].
declareRunTimeSelectionTable(autoPtr, basicThermo, fvMesh,(const fvMesh &mesh, const word &phaseName),(mesh, phaseName))
Declare run-time constructor selection table.
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
virtual volScalarField & p()
Pressure [Pa].
Definition: basicThermo.C:601
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
bool dpdt_
Include dpdt term in the enthalpy equation?
Definition: basicThermo.H:148
const word & phaseName_
Phase-name.
Definition: basicThermo.H:133
static word groupName(StringType base, const word &group)
Create dot-delimited name.group string.
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Definition: IOobjectI.H:40
dynamicFvMesh & mesh
wordList heBoundaryBaseTypes()
Return the enthalpy/internal energy field boundary base types by interrogating the temperature field ...
Definition: basicThermo.C:157
const cellShapeList & cells
basicThermo(const basicThermo &)=delete
No copy construct.
static wordList splitThermoName(const std::string &thermoName, const int nExpectedCmpts)
Split thermo package name into a list of components names.
Definition: basicThermo.C:571
fvPatchField< scalar > fvPatchScalarField
volScalarField & p_
Pressure [Pa].
Definition: basicThermo.H:156
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
bool dpdt() const noexcept
True if dpdt term should be included in enthalpy equation.
Definition: basicThermo.H:446
wordList heBoundaryTypes()
Return the enthalpy/internal energy field boundary types by interrogating the temperature field bound...
Definition: basicThermo.C:191
static const word null
An empty word.
Definition: word.H:84
const dictionary & thermoDict
Definition: EEqn.H:16
virtual tmp< volScalarField > hc() const =0
Chemical enthalpy [J/kg].
const word & name() const
Name function is needed to disambiguate those inherited from regIOobject and dictionary.
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
virtual tmp< volScalarField > Cp() const =0
Heat capacity at constant pressure [J/kg/K].
const dimensionedScalar h
Planck constant.
List< word > wordList
List of word.
Definition: fileName.H:59
volScalarField alpha_
Laminar thermal diffusivity [kg/m/s].
Definition: basicThermo.H:166
bool TOwner_
Temperature created and stored by this instance.
Definition: basicThermo.H:143
word phaseScopedName(const std::string &scope, const word &name) const
The phase property name scoped as scope:property.phase.
Definition: basicThermo.H:335
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual tmp< volScalarField > gamma() const =0
Gamma = Cp/Cv [].
virtual bool read()
Read thermophysical properties dictionary.
Definition: basicThermo.C:637
virtual tmp< volScalarField > W() const =0
Molecular weight [kg/kmol].
static const basicThermo & lookupThermo(const fvPatchScalarField &pf)
Definition: basicThermo.C:448
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual bool isochoric() const =0
Return true if the equation of state is isochoric.
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50
virtual void correct()=0
Update properties.
void validate(const string &app, const word &) const
Check that the thermodynamics package is consistent.
Definition: basicThermo.C:477
virtual bool incompressible() const =0
Return true if the equation of state is incompressible.
virtual tmp< volScalarField > CpByCpv() const =0
Heat capacity ratio [].
volScalarField & T_
Temperature [K].
Definition: basicThermo.H:161
Namespace for OpenFOAM.
scalar T0
Definition: createFields.H:22