basicThermo.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 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 Class
25  Foam::basicThermo
26 
27 Description
28  Base-class for fluid and solid thermodynamic properties.
29 
30  The basicThermo class is the pure virtual interface, plus static data and
31  functions, including the selection table. It is default-constructable and
32  holds no non-static data.
33 
34  The basicThermo::implementation class contains the class data, non-default
35  construction and other implementation details.
36 
37  This structure allows for arbitrary mixing of the interfaces. Derived
38  levels should implement a similar separation of interface and
39  implementation. All interface classes should be default-constructable, and
40  should be inherited virtually into whatever interfaces are required.
41  Implementation classes should virtually inherit from their corresponding
42  interface class and *not* a lower level implementation class.
43 
44  In derived levels that are complete enough to act as the base of a
45  thermodynamic instantiation, an additional *::composite sub class should be
46  defined, which (non-virtually) inherits from all the *::implementation
47  classes that it needs. This way, the composite class composes an interface
48  for which diamond patterns are resolved by virtual inheritance, whilst also
49  obtaining a single copy of all the implementation classes it needs to form
50  a complete implementation. The use of virtual inheritance does not result
51  in additional constructor calls propagating further down the hierarchy
52  (into BasicThermo and similar) because all virtually inherited interface
53  classes are default constructable.
54 
55 SourceFiles
56  basicThermo.C
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #ifndef basicThermo_H
61 #define basicThermo_H
62 
63 #include "volFields.H"
64 #include "typeInfo.H"
65 #include "physicalProperties.H"
66 #include "autoPtr.H"
67 #include "wordIOList.H"
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 namespace Foam
72 {
73 
74 /*---------------------------------------------------------------------------*\
75  Class basicThermo Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 class basicThermo
79 {
80 protected:
81 
82  // Protected Static Member Functions
83 
84  //- Lookup and the named field, or construct it as MUST-READ if it is
85  // not found, and return a reference
87  (
88  const fvMesh& mesh,
89  const char* name
90  );
91 
92  //- Get the constructor iterator for the given thermo dictionary and
93  // entries and constructor iterator table
94  template<class Thermo, class Table>
95  static typename Table::iterator lookupCstrIter
96  (
97  const dictionary& thermoTypeDict,
98  Table* tablePtr,
99  const int nCmpt,
100  const char* cmptNames[],
101  const word& thermoTypeName
102  );
103 
104  //- Get the constructor iterator for the given thermo dictionary and
105  // constructor iterator table
106  template<class Thermo, class Table>
107  static typename Table::iterator lookupCstrIter
108  (
109  const dictionary& thermoDict,
110  Table* tablePtr
111  );
112 
113 
114  // Protected Member Functions
115 
116  //- Enthalpy/internal energy field boundary types
117  // by interrogating the temperature field boundary types
119 
120  //- Enthalpy/internal energy field boundary base types
121  // by interrogating the temperature field boundary types
123 
124  //- Enthalpy/internal energy field sources types
125  // by interrogating the temperature field sources types
127 
128 
129 public:
130 
131  // Public Classes
132 
133  //- Forward declare the implementation class
134  class implementation;
135 
136 
137  //- Runtime type information
138  TypeName("basicThermo");
139 
140 
141  //- Declare run-time constructor selection table
143  (
144  autoPtr,
145  basicThermo,
146  fvMesh,
147  (const fvMesh& mesh, const word& phaseName),
148  (mesh, phaseName)
149  );
150 
151 
152  // Static Member Functions
153 
154  //- Name of a property for a given phase
155  static word phasePropertyName(const word& name, const word& phaseName)
156  {
158  }
159 
160  //- Lookup the thermo associated with the given field
161  template<class FieldType>
162  static const basicThermo& lookupThermo(const FieldType& f);
163 
164  //- Split name of thermo package into a list of the components names
166  (
167  const word& thermoName,
168  const int nCmpt
169  );
170 
171  //- Split name of thermo package into a list of named components names
173  (
174  const word& thermoName
175  );
176 
177 
178  // Selectors
179 
180  //- Generic New for each of the related thermodynamics packages
181  template<class Thermo>
182  static autoPtr<Thermo> New
183  (
184  const fvMesh&,
185  const word& phaseName=word::null
186  );
187 
188  //- Specialisation of the Generic New for basicThermo
190  (
191  const fvMesh&,
192  const word& phaseName=word::null
193  );
194 
195 
196  //- Destructor
197  virtual ~basicThermo();
198 
199 
200  // Member Functions
201 
202  //- Properties dictionary
203  virtual const IOdictionary& properties() const = 0;
204 
205  //- Non-const access the properties dictionary
206  virtual IOdictionary& properties() = 0;
207 
208  //- Return const access to the mesh
209  virtual const fvMesh& mesh() const = 0;
210 
211  //- Phase name
212  virtual const word& phaseName() const = 0;
213 
214  //- Name of a property for a given phase
215  word phasePropertyName(const word& name) const
216  {
217  return phasePropertyName(name, phaseName());
218  }
219 
220  //- Check that the thermodynamics package is consistent
221  // with energy forms supported by the application
222  void validate
223  (
224  const string& app,
225  const word&
226  ) const;
227 
228  //- Check that the thermodynamics package is consistent
229  // with energy forms supported by the application
230  void validate
231  (
232  const string& app,
233  const word&,
234  const word&
235  ) const;
236 
237  //- Update properties
238  virtual void correct() = 0;
239 
240  //- Name of the thermo physics
241  virtual word thermoName() const = 0;
242 
243  //- Return true if the equation of state is incompressible
244  // i.e. rho != f(p)
245  virtual bool incompressible() const = 0;
246 
247  //- Return true if the equation of state is isochoric
248  // i.e. rho = const
249  virtual bool isochoric() const = 0;
250 
251  //- Should the dpdt term be included in the enthalpy equation
252  virtual Switch dpdt() const = 0;
253 
254 
255  // Molecular properties
256 
257  //- Molecular weight [kg/kmol]
258  virtual tmp<volScalarField> W() const = 0;
259 
260  //- Molecular weight for patch [kg/kmol]
261  virtual tmp<scalarField> W(const label patchi) const = 0;
262 
263 
264  // Thermodynamic state
265 
266  //- Temperature [K]
267  virtual const volScalarField& T() const = 0;
268 
269  //- Temperature [K]
270  // Non-const access allowed for transport equations
271  virtual volScalarField& T() = 0;
272 
273  //- Enthalpy/Internal energy [J/kg]
274  virtual const volScalarField& he() const = 0;
275 
276  //- Enthalpy/Internal energy [J/kg]
277  // Non-const access allowed for transport equations
278  virtual volScalarField& he() = 0;
279 
280  //- Heat capacity at constant pressure [J/kg/K]
281  virtual const volScalarField& Cp() const = 0;
282 
283  //- Heat capacity at constant volume [J/kg/K]
284  virtual const volScalarField& Cv() const = 0;
285 
286  //- Heat capacity at constant pressure/volume [J/kg/K]
287  virtual const volScalarField& Cpv() const = 0;
288 
289 
290  // Derived Thermodynamic Properties
291 
292  //- Density [kg/m^3]
293  virtual tmp<volScalarField> rho() const = 0;
294 
295  //- Density for patch [kg/m^3]
296  virtual tmp<scalarField> rho(const label patchi) const = 0;
297 
298  //- Enthalpy/Internal energy
299  // for given pressure and temperature [J/kg]
300  virtual tmp<volScalarField> he
301  (
302  const volScalarField& p,
303  const volScalarField& T
304  ) const = 0;
305 
306  //- Enthalpy/Internal energy
307  // for given pressure and temperature [J/kg]
309  (
312  ) const = 0;
313 
314  //- Enthalpy/Internal energy for cell-set [J/kg]
315  virtual tmp<scalarField> he
316  (
317  const scalarField& T,
318  const labelList& cells
319  ) const = 0;
320 
321  //- Enthalpy/Internal energy for patch [J/kg]
322  virtual tmp<scalarField> he
323  (
324  const scalarField& T,
325  const label patchi
326  ) const = 0;
327 
328  //- Enthalpy/Internal energy for source [J/kg]
330  (
332  const fvSource& model,
333  const volScalarField::Internal& source
334  ) const = 0;
335 
336  //- Enthalpy/Internal energy for source [J/kg]
337  virtual tmp<scalarField> he
338  (
339  const scalarField& T,
340  const fvSource& model,
341  const scalarField& source,
342  const labelUList& cells
343  ) const = 0;
344 
345  //- Sensible enthalpy [J/kg]
346  virtual tmp<volScalarField> hs() const = 0;
347 
348  //- Sensible enthalpy
349  // for given pressure and temperature [J/kg]
350  virtual tmp<volScalarField> hs
351  (
352  const volScalarField& p,
353  const volScalarField& T
354  ) const = 0;
355 
356  //- Sensible enthalpy
357  // for given pressure and temperature [J/kg]
359  (
362  ) const = 0;
363 
364  //- Sensible enthalpy for cell-set [J/kg]
365  virtual tmp<scalarField> hs
366  (
367  const scalarField& T,
368  const labelList& cells
369  ) const = 0;
370 
371  //- Sensible enthalpy for patch [J/kg]
372  virtual tmp<scalarField> hs
373  (
374  const scalarField& T,
375  const label patchi
376  ) const = 0;
377 
378  //- Absolute enthalpy [J/kg]
379  virtual tmp<volScalarField> ha() const = 0;
380 
381  //- Absolute enthalpy
382  // for given pressure and temperature [J/kg]
383  virtual tmp<volScalarField> ha
384  (
385  const volScalarField& p,
386  const volScalarField& T
387  ) const = 0;
388 
389  //- Absolute enthalpy
390  // for given pressure and temperature [J/kg]
392  (
395  ) const = 0;
396 
397  //- Absolute enthalpy for cell-set [J/kg]
398  virtual tmp<scalarField> ha
399  (
400  const scalarField& T,
401  const labelList& cells
402  ) const = 0;
403 
404  //- Absolute enthalpy for patch [J/kg]
405  virtual tmp<scalarField> ha
406  (
407  const scalarField& T,
408  const label patchi
409  ) const = 0;
410 
411  //- Heat capacity at constant pressure for patch [J/kg/K]
412  virtual tmp<scalarField> Cp
413  (
414  const scalarField& T,
415  const label patchi
416  ) const = 0;
417 
418  //- Heat capacity at constant volume for patch [J/kg/K]
419  virtual tmp<scalarField> Cv
420  (
421  const scalarField& T,
422  const label patchi
423  ) const = 0;
424 
425  //- Heat capacity at constant pressure/volume for patch [J/kg/K]
426  virtual tmp<scalarField> Cpv
427  (
428  const scalarField& T,
429  const label patchi
430  ) const = 0;
431 
432  //- Gamma = Cp/Cv []
433  tmp<volScalarField> gamma() const;
434 
435  //- Gamma = Cp/Cv for patch []
437  (
438  const scalarField& T,
439  const label patchi
440  ) const;
441 
442 
443  // Temperature-energy inversion functions
444 
445  //- Temperature from enthalpy/internal energy
446  virtual tmp<volScalarField> The
447  (
448  const volScalarField& h,
449  const volScalarField& p,
450  const volScalarField& T0 // starting temperature
451  ) const = 0;
452 
453  //- Temperature from enthalpy/internal energy for cell-set
454  virtual tmp<scalarField> The
455  (
456  const scalarField& h,
457  const scalarField& T0, // starting temperature
458  const labelList& cells
459  ) const = 0;
460 
461  //- Temperature from enthalpy/internal energy for patch
462  virtual tmp<scalarField> The
463  (
464  const scalarField& h,
465  const scalarField& T0, // starting temperature
466  const label patchi
467  ) const = 0;
468 
469 
470  // Transport state
471 
472  //- Thermal conductivity of mixture [W/m/K]
473  virtual const volScalarField& kappa() const = 0;
474 };
475 
476 
477 /*---------------------------------------------------------------------------*\
478  Class basicThermo::implementation Declaration
479 \*---------------------------------------------------------------------------*/
480 
482 :
483  virtual public basicThermo
484 {
485  // Private Member Data
486 
487  //- Reference to the mesh
488  const fvMesh& mesh_;
489 
490 
491 protected:
492 
493  // Protected data
494 
495  //- Phase-name
496  const word& phaseName_;
497 
498 
499  // Fields
500 
501  //- Temperature [K]
503 
504  //- Thermal conductivity [W/m/K]
506 
507 
508  //- Should the dpdt term be included in the enthalpy equation
509  Switch dpdt_;
510 
511 
512 public:
513 
514  // Constructors
515 
516  //- Construct from dictionary, mesh and phase name
517  implementation(const dictionary&, const fvMesh&, const word&);
518 
519  //- Disallow default bitwise copy construction
520  implementation(const implementation&) = delete;
521 
522 
523 
524  //- Destructor
525  virtual ~implementation();
526 
527 
528  // Member Functions
529 
530  //- Return const access to the mesh
531  virtual const fvMesh& mesh() const
532  {
533  return mesh_;
534  }
535 
536  //- Phase name
537  virtual const word& phaseName() const
538  {
539  return phaseName_;
540  }
541 
542  //- Should the dpdt term be included in the enthalpy equation
543  virtual Switch dpdt() const
544  {
545  return dpdt_;
546  }
547 
548 
549  // Thermodynamic state
550 
551  //- Temperature [K]
552  virtual const volScalarField& T() const;
553 
554  //- Temperature [K]
555  // Non-const access allowed for transport equations
556  virtual volScalarField& T();
557 
558 
559  // Transport state
560 
561  //- Thermal conductivity of mixture [W/m/K]
562  virtual const volScalarField& kappa() const;
563 
564 
565  //- Read thermophysical properties dictionary
566  virtual void read(const dictionary&);
567 
568 
569  // Member Operators
570 
571  //- Disallow default bitwise assignment
572  void operator=(const implementation&) = delete;
573 };
574 
575 
576 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
577 
578 } // End namespace Foam
579 
580 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
581 
582 #ifdef NoRepository
583  #include "basicThermoTemplates.C"
584 #endif
585 
586 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
587 
588 #endif
589 
590 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic GeometricField class.
An STL-conforming hash table.
Definition: HashTable.H:127
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
static word groupName(Name name, const word &group)
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
volScalarField kappa_
Thermal conductivity [W/m/K].
Definition: basicThermo.H:504
virtual const volScalarField & T() const
Temperature [K].
Definition: basicThermo.C:363
Switch dpdt_
Should the dpdt term be included in the enthalpy equation.
Definition: basicThermo.H:508
virtual const volScalarField & kappa() const
Thermal conductivity of mixture [W/m/K].
Definition: basicThermo.C:375
virtual Switch dpdt() const
Should the dpdt term be included in the enthalpy equation.
Definition: basicThermo.H:542
virtual ~implementation()
Destructor.
Definition: basicThermo.C:301
virtual const fvMesh & mesh() const
Return const access to the mesh.
Definition: basicThermo.H:530
implementation(const dictionary &, const fvMesh &, const word &)
Construct from dictionary, mesh and phase name.
Definition: basicThermo.C:242
volScalarField T_
Temperature [K].
Definition: basicThermo.H:501
const word & phaseName_
Phase-name.
Definition: basicThermo.H:495
virtual void read(const dictionary &)
Read thermophysical properties dictionary.
Definition: basicThermo.C:381
virtual const word & phaseName() const
Phase name.
Definition: basicThermo.H:536
void operator=(const implementation &)=delete
Disallow default bitwise assignment.
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:78
virtual word thermoName() const =0
Name of the thermo physics.
virtual const volScalarField & Cv() const =0
Heat capacity at constant volume [J/kg/K].
virtual tmp< volScalarField > The(const volScalarField &h, const volScalarField &p, const volScalarField &T0) const =0
Temperature from enthalpy/internal energy.
virtual tmp< volScalarField > W() const =0
Molecular weight [kg/kmol].
static const basicThermo & lookupThermo(const FieldType &f)
Lookup the thermo associated with the given field.
static List< Pair< word > > thermoNameComponents(const word &thermoName)
Split name of thermo package into a list of named components names.
Definition: basicThermo.C:143
wordList heBoundaryTypes()
Enthalpy/internal energy field boundary types.
Definition: basicThermo.C:180
HashTable< word > heSourcesTypes()
Enthalpy/internal energy field sources types.
Definition: basicThermo.C:225
static word phasePropertyName(const word &name, const word &phaseName)
Name of a property for a given phase.
Definition: basicThermo.H:154
wordList heBoundaryBaseTypes()
Enthalpy/internal energy field boundary base types.
Definition: basicThermo.C:162
virtual Switch dpdt() const =0
Should the dpdt term be included in the enthalpy equation.
virtual const IOdictionary & properties() const =0
Properties dictionary.
static wordList splitThermoName(const word &thermoName, const int nCmpt)
Split name of thermo package into a list of the components names.
Definition: basicThermo.C:81
virtual const fvMesh & mesh() const =0
Return const access to the mesh.
virtual void correct()=0
Update properties.
virtual const volScalarField & T() const =0
Temperature [K].
virtual const volScalarField & Cp() const =0
Heat capacity at constant pressure [J/kg/K].
virtual const volScalarField & Cpv() const =0
Heat capacity at constant pressure/volume [J/kg/K].
virtual bool incompressible() const =0
Return true if the equation of state is incompressible.
static Table::iterator lookupCstrIter(const dictionary &thermoTypeDict, Table *tablePtr, const int nCmpt, const char *cmptNames[], const word &thermoTypeName)
Get the constructor iterator for the given thermo dictionary and.
virtual const word & phaseName() const =0
Phase name.
virtual bool isochoric() const =0
Return true if the equation of state is isochoric.
tmp< volScalarField > gamma() const
Gamma = Cp/Cv [].
Definition: basicThermo.C:347
void validate(const string &app, const word &) const
Check that the thermodynamics package is consistent.
Definition: basicThermo.C:308
TypeName("basicThermo")
Runtime type information.
virtual tmp< volScalarField > ha() const =0
Absolute enthalpy [J/kg].
virtual tmp< volScalarField > hs() const =0
Sensible enthalpy [J/kg].
virtual ~basicThermo()
Destructor.
Definition: basicThermo.C:297
virtual const volScalarField & he() const =0
Enthalpy/Internal energy [J/kg].
static volScalarField & lookupOrConstruct(const fvMesh &mesh, const char *name)
Lookup and the named field, or construct it as MUST-READ if it is.
Definition: basicThermo.C:49
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
virtual const volScalarField & kappa() const =0
Thermal conductivity of mixture [W/m/K].
declareRunTimeSelectionTable(autoPtr, basicThermo, fvMesh,(const fvMesh &mesh, const word &phaseName),(mesh, phaseName))
Declare run-time constructor selection table.
virtual tmp< volScalarField > rho() const =0
Density [kg/m^3].
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
Base class for finite volume sources.
Definition: fvSource.H:52
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
label patchi
const cellShapeList & cells
const dimensionedScalar h
Planck constant.
Namespace for OpenFOAM.
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
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
labelList f(nPoints)
volScalarField & p
scalar T0
Definition: createFields.H:22
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...