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-2023 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 for cell-set [J/kg]
307  virtual tmp<scalarField> he
308  (
309  const scalarField& T,
310  const labelList& cells
311  ) const = 0;
312 
313  //- Enthalpy/Internal energy for patch [J/kg]
314  virtual tmp<scalarField> he
315  (
316  const scalarField& T,
317  const label patchi
318  ) const = 0;
319 
320  //- Enthalpy/Internal energy for source [J/kg]
321  virtual tmp<scalarField> he
322  (
323  const scalarField& T,
324  const fvSource& source
325  ) const = 0;
326 
327  //- Sensible enthalpy [J/kg]
328  virtual tmp<volScalarField> hs() const = 0;
329 
330  //- Sensible enthalpy
331  // for given pressure and temperature [J/kg]
332  virtual tmp<volScalarField> hs
333  (
334  const volScalarField& p,
335  const volScalarField& T
336  ) const = 0;
337 
338  //- Sensible enthalpy for cell-set [J/kg]
339  virtual tmp<scalarField> hs
340  (
341  const scalarField& T,
342  const labelList& cells
343  ) const = 0;
344 
345  //- Sensible enthalpy for patch [J/kg]
346  virtual tmp<scalarField> hs
347  (
348  const scalarField& T,
349  const label patchi
350  ) const = 0;
351 
352  //- Absolute enthalpy [J/kg]
353  virtual tmp<volScalarField> ha() const = 0;
354 
355  //- Absolute enthalpy
356  // for given pressure and temperature [J/kg]
357  virtual tmp<volScalarField> ha
358  (
359  const volScalarField& p,
360  const volScalarField& T
361  ) const = 0;
362 
363  //- Absolute enthalpy for cell-set [J/kg]
364  virtual tmp<scalarField> ha
365  (
366  const scalarField& T,
367  const labelList& cells
368  ) const = 0;
369 
370  //- Absolute enthalpy for patch [J/kg]
371  virtual tmp<scalarField> ha
372  (
373  const scalarField& T,
374  const label patchi
375  ) const = 0;
376 
377  //- Heat capacity at constant pressure for patch [J/kg/K]
378  virtual tmp<scalarField> Cp
379  (
380  const scalarField& T,
381  const label patchi
382  ) const = 0;
383 
384  //- Heat capacity at constant volume for patch [J/kg/K]
385  virtual tmp<scalarField> Cv
386  (
387  const scalarField& T,
388  const label patchi
389  ) const = 0;
390 
391  //- Heat capacity at constant pressure/volume for patch [J/kg/K]
392  virtual tmp<scalarField> Cpv
393  (
394  const scalarField& T,
395  const label patchi
396  ) const = 0;
397 
398  //- Gamma = Cp/Cv []
399  tmp<volScalarField> gamma() const;
400 
401  //- Gamma = Cp/Cv for patch []
403  (
404  const scalarField& T,
405  const label patchi
406  ) const;
407 
408 
409  // Temperature-energy inversion functions
410 
411  //- Temperature from enthalpy/internal energy
412  virtual tmp<volScalarField> The
413  (
414  const volScalarField& h,
415  const volScalarField& p,
416  const volScalarField& T0 // starting temperature
417  ) 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& T0, // starting temperature
424  const labelList& cells
425  ) const = 0;
426 
427  //- Temperature from enthalpy/internal energy for patch
428  virtual tmp<scalarField> The
429  (
430  const scalarField& h,
431  const scalarField& T0, // starting temperature
432  const label patchi
433  ) const = 0;
434 
435 
436  // Transport state
437 
438  //- Thermal conductivity of mixture [W/m/K]
439  virtual const volScalarField& kappa() const = 0;
440 };
441 
442 
443 /*---------------------------------------------------------------------------*\
444  Class basicThermo::implementation Declaration
445 \*---------------------------------------------------------------------------*/
446 
448 :
449  virtual public basicThermo
450 {
451  // Private Member Data
452 
453  //- Reference to the mesh
454  const fvMesh& mesh_;
455 
456 
457 protected:
458 
459  // Protected data
460 
461  //- Phase-name
462  const word& phaseName_;
463 
464 
465  // Fields
466 
467  //- Temperature [K]
469 
470  //- Thermal conductivity [W/m/K]
472 
473 
474  //- Should the dpdt term be included in the enthalpy equation
475  Switch dpdt_;
476 
477 
478 public:
479 
480  // Constructors
481 
482  //- Construct from dictionary, mesh and phase name
483  implementation(const dictionary&, const fvMesh&, const word&);
484 
485  //- Disallow default bitwise copy construction
486  implementation(const implementation&) = delete;
487 
488 
489 
490  //- Destructor
491  virtual ~implementation();
492 
493 
494  // Member Functions
495 
496  //- Return const access to the mesh
497  virtual const fvMesh& mesh() const
498  {
499  return mesh_;
500  }
501 
502  //- Phase name
503  virtual const word& phaseName() const
504  {
505  return phaseName_;
506  }
507 
508  //- Should the dpdt term be included in the enthalpy equation
509  virtual Switch dpdt() const
510  {
511  return dpdt_;
512  }
513 
514 
515  // Thermodynamic state
516 
517  //- Temperature [K]
518  virtual const volScalarField& T() const;
519 
520  //- Temperature [K]
521  // Non-const access allowed for transport equations
522  virtual volScalarField& T();
523 
524 
525  // Transport state
526 
527  //- Thermal conductivity of mixture [W/m/K]
528  virtual const volScalarField& kappa() const;
529 
530 
531  //- Read thermophysical properties dictionary
532  virtual void read(const dictionary&);
533 
534 
535  // Member Operators
536 
537  //- Disallow default bitwise assignment
538  void operator=(const implementation&) = delete;
539 };
540 
541 
542 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
543 
544 } // End namespace Foam
545 
546 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
547 
548 #ifdef NoRepository
549  #include "basicThermoTemplates.C"
550 #endif
551 
552 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
553 
554 #endif
555 
556 // ************************************************************************* //
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:470
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:474
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:508
virtual ~implementation()
Destructor.
Definition: basicThermo.C:301
virtual const fvMesh & mesh() const
Return const access to the mesh.
Definition: basicThermo.H:496
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:467
const word & phaseName_
Phase-name.
Definition: basicThermo.H:461
virtual void read(const dictionary &)
Read thermophysical properties dictionary.
Definition: basicThermo.C:381
virtual const word & phaseName() const
Phase name.
Definition: basicThermo.H:502
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
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 bool)
Return a word representation of a bool.
Definition: boolIO.C:39
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...