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-2026 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  // Private Static Member Functions
81 
82  // Convert multiComponent -> multicomponent for backward-compatibility
83  static word mixtureName(const Foam::dictionary& thermoTypeDict);
84 
85  //- Get the constructor iterator for the given thermo dictionary and
86  // entries and constructor iterator table
87  template<class Thermo, class Table>
88  static typename Table::iterator lookupCstrIter
89  (
90  const dictionary& thermoTypeDict,
91  Table* tablePtr,
92  const int nCmpt,
93  const char* cmptNames[],
94  const word& thermoTypeName
95  );
96 
97 
98 protected:
99 
100  // Protected Static Member Functions
101 
102  //- Lookup and the named field, or construct it as MUST-READ if it is
103  // not found, and return a reference
105  (
106  const fvMesh& mesh,
107  const char* name
108  );
109 
110 
111  // Protected Member Functions
112 
113  //- Enthalpy/internal energy field boundary types
114  // by interrogating the temperature field boundary types
116 
117  //- Enthalpy/internal energy field boundary base types
118  // by interrogating the temperature field boundary types
120 
121  //- Enthalpy/internal energy field sources types
122  // by interrogating the temperature field sources types
124 
125 
126 public:
127 
128  // Public Classes
129 
130  //- Forward declare the implementation class
131  class implementation;
132 
133 
134  //- Runtime type information
135  TypeName("basicThermo");
136 
137 
138  //- Declare run-time constructor selection table
140  (
141  autoPtr,
142  basicThermo,
143  fvMesh,
144  (const fvMesh& mesh, const word& phaseName),
145  (mesh, phaseName)
146  );
147 
148 
149  // Static Member Functions
150 
151  //- Name of a property for a given phase
152  static word phasePropertyName(const word& name, const word& phaseName)
153  {
155  }
156 
157  //- Get the constructor iterator for the given thermo dictionary and
158  // constructor iterator table
159  template<class Thermo, class Table>
160  static typename Table::iterator lookupCstrIter
161  (
162  const dictionary& thermoDict,
163  Table* tablePtr
164  );
165 
166  //- Lookup the thermo associated with the given field
167  template<class FieldType>
168  static const basicThermo& lookupThermo(const FieldType& f);
169 
170  //- Split name of thermo package into a list of the components names
172  (
173  const word& thermoName,
174  const int nCmpt
175  );
176 
177  //- Split name of thermo package into a list of named components names
179  (
180  const word& thermoName
181  );
182 
183 
184  // Selectors
185 
186  //- Generic New for each of the related thermodynamics packages
187  template<class Thermo>
188  static autoPtr<Thermo> New
189  (
190  const fvMesh&,
191  const word& phaseName=word::null
192  );
193 
194  //- Specialisation of the Generic New for basicThermo
196  (
197  const fvMesh&,
198  const word& phaseName=word::null
199  );
200 
201 
202  //- Destructor
203  virtual ~basicThermo();
204 
205 
206  // Member Functions
207 
208  //- Properties dictionary
209  virtual const IOdictionary& properties() const = 0;
210 
211  //- Non-const access the properties dictionary
212  virtual IOdictionary& properties() = 0;
213 
214  //- Return const access to the mesh
215  virtual const fvMesh& mesh() const = 0;
216 
217  //- Phase name
218  virtual const word& phaseName() const = 0;
219 
220  //- Name of a property for a given phase
221  word phasePropertyName(const word& name) const
222  {
223  return phasePropertyName(name, phaseName());
224  }
225 
226  //- Check that the thermodynamics package is consistent
227  // with energy forms supported by the application
228  void validate
229  (
230  const string& app,
231  const word&
232  ) const;
233 
234  //- Check that the thermodynamics package is consistent
235  // with energy forms supported by the application
236  void validate
237  (
238  const string& app,
239  const word&,
240  const word&
241  ) const;
242 
243  //- Update properties
244  virtual void correct() = 0;
245 
246  //- Name of the mixture
247  virtual word mixtureName() const = 0;
248 
249  //- Name of the thermo physics
250  virtual word thermoName() const = 0;
251 
252  //- Return true if the equation of state is incompressible
253  // i.e. rho != f(p)
254  virtual bool incompressible() const = 0;
255 
256  //- Return true if the equation of state is isochoric
257  // i.e. rho = const
258  virtual bool isochoric() const = 0;
259 
260  //- Should the dpdt term be included in the enthalpy equation
261  virtual Switch dpdt() const = 0;
262 
263 
264  // Molecular properties
265 
266  //- Molecular weight [kg/kmol]
267  virtual tmp<volScalarField> W() const = 0;
268 
269  //- Molecular weight for patch [kg/kmol]
270  virtual tmp<scalarField> W(const label patchi) const = 0;
271 
272 
273  // Thermodynamic state
274 
275  //- Temperature [K]
276  virtual const volScalarField& T() const = 0;
277 
278  //- Temperature [K]
279  // Non-const access allowed for transport equations
280  virtual volScalarField& T() = 0;
281 
282  //- Enthalpy/Internal energy [J/kg]
283  virtual const volScalarField& he() const = 0;
284 
285  //- Enthalpy/Internal energy [J/kg]
286  // Non-const access allowed for transport equations
287  virtual volScalarField& he() = 0;
288 
289  //- Heat capacity at constant pressure [J/kg/K]
290  virtual const volScalarField& Cp() const = 0;
291 
292  //- Heat capacity at constant volume [J/kg/K]
293  virtual const volScalarField& Cv() const = 0;
294 
295  //- Heat capacity at constant pressure/volume [J/kg/K]
296  virtual const volScalarField& Cpv() const = 0;
297 
298 
299  // Derived Thermodynamic Properties
300 
301  //- Density [kg/m^3]
302  virtual tmp<volScalarField> rho() const = 0;
303 
304  //- Density for patch [kg/m^3]
305  virtual tmp<scalarField> rho(const label patchi) const = 0;
306 
307  //- Enthalpy/Internal energy
308  // for given pressure and temperature [J/kg]
309  virtual tmp<volScalarField> he
310  (
311  const volScalarField& p,
312  const volScalarField& T
313  ) const = 0;
314 
315  //- Enthalpy/Internal energy
316  // for given pressure and temperature [J/kg]
318  (
321  ) const = 0;
322 
323  //- Enthalpy/Internal energy for cell-set [J/kg]
324  virtual tmp<scalarField> he
325  (
326  const scalarField& T,
327  const labelList& cells
328  ) const = 0;
329 
330  //- Enthalpy/Internal energy for patch [J/kg]
331  virtual tmp<scalarField> he
332  (
333  const scalarField& T,
334  const label patchi
335  ) const = 0;
336 
337  //- Enthalpy/Internal energy for source [J/kg]
339  (
341  const fvSource& model,
342  const volScalarField::Internal& source
343  ) const = 0;
344 
345  //- Enthalpy/Internal energy for source [J/kg]
346  virtual tmp<scalarField> he
347  (
348  const scalarField& T,
349  const fvSource& model,
350  const scalarField& source,
351  const labelUList& cells
352  ) const = 0;
353 
354  //- Sensible enthalpy [J/kg]
355  virtual tmp<volScalarField> hs() const = 0;
356 
357  //- Sensible enthalpy
358  // for given pressure and temperature [J/kg]
359  virtual tmp<volScalarField> hs
360  (
361  const volScalarField& p,
362  const volScalarField& T
363  ) const = 0;
364 
365  //- Sensible enthalpy
366  // for given pressure and temperature [J/kg]
368  (
371  ) const = 0;
372 
373  //- Sensible enthalpy for cell-set [J/kg]
374  virtual tmp<scalarField> hs
375  (
376  const scalarField& T,
377  const labelList& cells
378  ) const = 0;
379 
380  //- Sensible enthalpy for patch [J/kg]
381  virtual tmp<scalarField> hs
382  (
383  const scalarField& T,
384  const label patchi
385  ) const = 0;
386 
387  //- Absolute enthalpy [J/kg]
388  virtual tmp<volScalarField> ha() const = 0;
389 
390  //- Absolute enthalpy
391  // for given pressure and temperature [J/kg]
392  virtual tmp<volScalarField> ha
393  (
394  const volScalarField& p,
395  const volScalarField& T
396  ) const = 0;
397 
398  //- Absolute enthalpy
399  // for given pressure and temperature [J/kg]
401  (
404  ) const = 0;
405 
406  //- Absolute enthalpy for cell-set [J/kg]
407  virtual tmp<scalarField> ha
408  (
409  const scalarField& T,
410  const labelList& cells
411  ) const = 0;
412 
413  //- Absolute enthalpy for patch [J/kg]
414  virtual tmp<scalarField> ha
415  (
416  const scalarField& T,
417  const label patchi
418  ) const = 0;
419 
420  //- Heat capacity at constant pressure for patch [J/kg/K]
421  virtual tmp<scalarField> Cp
422  (
423  const scalarField& T,
424  const label patchi
425  ) const = 0;
426 
427  //- Heat capacity at constant volume for patch [J/kg/K]
428  virtual tmp<scalarField> Cv
429  (
430  const scalarField& T,
431  const label patchi
432  ) const = 0;
433 
434  //- Heat capacity at constant pressure/volume for patch [J/kg/K]
435  virtual tmp<scalarField> Cpv
436  (
437  const scalarField& T,
438  const label patchi
439  ) const = 0;
440 
441  //- Gamma = Cp/Cv []
442  tmp<volScalarField> gamma() const;
443 
444  //- Gamma = Cp/Cv for patch []
446  (
447  const scalarField& T,
448  const label patchi
449  ) const;
450 
451 
452  // Temperature-energy inversion functions
453 
454  //- Temperature from enthalpy/internal energy
455  virtual tmp<volScalarField> The
456  (
457  const volScalarField& h,
458  const volScalarField& p,
459  const volScalarField& T0 // starting temperature
460  ) const = 0;
461 
462  //- Temperature from enthalpy/internal energy for cell-set
463  virtual tmp<scalarField> The
464  (
465  const scalarField& h,
466  const scalarField& T0, // starting temperature
467  const labelList& cells
468  ) const = 0;
469 
470  //- Temperature from enthalpy/internal energy for patch
471  virtual tmp<scalarField> The
472  (
473  const scalarField& h,
474  const scalarField& T0, // starting temperature
475  const label patchi
476  ) const = 0;
477 
478 
479  // Transport state
480 
481  //- Thermal conductivity of mixture [W/m/K]
482  virtual const volScalarField& kappa() const = 0;
483 };
484 
485 
486 /*---------------------------------------------------------------------------*\
487  Class basicThermo::implementation Declaration
488 \*---------------------------------------------------------------------------*/
489 
491 :
492  virtual public basicThermo
493 {
494  // Private Data
495 
496  //- Reference to the mesh
497  const fvMesh& mesh_;
498 
499 
500 protected:
501 
502  // Protected data
503 
504  //- Phase-name
505  const word& phaseName_;
506 
507 
508  // Fields
509 
510  //- Temperature [K]
512 
513  //- Thermal conductivity [W/m/K]
515 
516 
517  //- Should the dpdt term be included in the enthalpy equation
518  Switch dpdt_;
519 
520 
521 public:
522 
523  // Constructors
524 
525  //- Construct from dictionary, mesh and phase name
526  implementation(const dictionary&, const fvMesh&, const word&);
527 
528  //- Disallow default bitwise copy construction
529  implementation(const implementation&) = delete;
530 
531 
532 
533  //- Destructor
534  virtual ~implementation();
535 
536 
537  // Member Functions
538 
539  //- Return const access to the mesh
540  virtual const fvMesh& mesh() const
541  {
542  return mesh_;
543  }
544 
545  //- Phase name
546  virtual const word& phaseName() const
547  {
548  return phaseName_;
549  }
550 
551  //- Should the dpdt term be included in the enthalpy equation
552  virtual Switch dpdt() const
553  {
554  return dpdt_;
555  }
556 
557 
558  // Thermodynamic state
559 
560  //- Temperature [K]
561  virtual const volScalarField& T() const;
562 
563  //- Temperature [K]
564  // Non-const access allowed for transport equations
565  virtual volScalarField& T();
566 
567 
568  // Transport state
569 
570  //- Thermal conductivity of mixture [W/m/K]
571  virtual const volScalarField& kappa() const;
572 
573 
574  //- Read thermophysical properties dictionary
575  virtual void read(const dictionary&);
576 
577 
578  // Member Operators
579 
580  //- Disallow default bitwise assignment
581  void operator=(const implementation&) = delete;
582 };
583 
584 
585 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
586 
587 } // End namespace Foam
588 
589 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
590 
591 #ifdef NoRepository
592  #include "basicThermoTemplates.C"
593 #endif
594 
595 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
596 
597 #endif
598 
599 // ************************************************************************* //
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:513
virtual const volScalarField & T() const
Temperature [K].
Definition: basicThermo.C:376
Switch dpdt_
Should the dpdt term be included in the enthalpy equation.
Definition: basicThermo.H:517
virtual const volScalarField & kappa() const
Thermal conductivity of mixture [W/m/K].
Definition: basicThermo.C:388
virtual Switch dpdt() const
Should the dpdt term be included in the enthalpy equation.
Definition: basicThermo.H:551
virtual ~implementation()
Destructor.
Definition: basicThermo.C:314
virtual const fvMesh & mesh() const
Return const access to the mesh.
Definition: basicThermo.H:539
implementation(const dictionary &, const fvMesh &, const word &)
Construct from dictionary, mesh and phase name.
Definition: basicThermo.C:255
volScalarField T_
Temperature [K].
Definition: basicThermo.H:510
const word & phaseName_
Phase-name.
Definition: basicThermo.H:504
virtual void read(const dictionary &)
Read thermophysical properties dictionary.
Definition: basicThermo.C:394
virtual const word & phaseName() const
Phase name.
Definition: basicThermo.H:545
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 word mixtureName() const =0
Name of the mixture.
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:156
wordList heBoundaryTypes()
Enthalpy/internal energy field boundary types.
Definition: basicThermo.C:193
HashTable< word > heSourcesTypes()
Enthalpy/internal energy field sources types.
Definition: basicThermo.C:238
static word phasePropertyName(const word &name, const word &phaseName)
Name of a property for a given phase.
Definition: basicThermo.H:151
wordList heBoundaryBaseTypes()
Enthalpy/internal energy field boundary base types.
Definition: basicThermo.C:175
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:94
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.
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:360
void validate(const string &app, const word &) const
Check that the thermodynamics package is consistent.
Definition: basicThermo.C:321
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:310
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:62
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:98
Base class for finite volume sources.
Definition: fvSource.H:53
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
const scalar T0
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
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...