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-2022 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 heThermo 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 
125 public:
126 
127  // Public Classes
128 
129  //- Forward declare the implementation class
130  class implementation;
131 
132 
133  //- Runtime type information
134  TypeName("basicThermo");
135 
136 
137  //- Declare run-time constructor selection table
139  (
140  autoPtr,
141  basicThermo,
142  fvMesh,
143  (const fvMesh& mesh, const word& phaseName),
144  (mesh, phaseName)
145  );
146 
147 
148  // Static Member Functions
149 
150  //- Name of a property for a given phase
151  static word phasePropertyName(const word& name, const word& phaseName)
152  {
153  return IOobject::groupName(name, phaseName);
154  }
155 
156  //- Lookup the thermo associated with the given patch field
157  static const basicThermo& lookupThermo(const fvPatchScalarField& pf);
158 
159  //- Split name of thermo package into a list of the components names
161  (
162  const word& thermoName,
163  const int nCmpt
164  );
165 
166  //- Split name of thermo package into a list of named components names
168  (
169  const word& thermoName
170  );
171 
172 
173  // Selectors
174 
175  //- Generic New for each of the related thermodynamics packages
176  template<class Thermo>
177  static autoPtr<Thermo> New
178  (
179  const fvMesh&,
180  const word& phaseName=word::null
181  );
182 
183  //- Specialisation of the Generic New for basicThermo
185  (
186  const fvMesh&,
187  const word& phaseName=word::null
188  );
189 
190 
191  //- Destructor
192  virtual ~basicThermo();
193 
194 
195  // Member Functions
196 
197  //- Properties dictionary
198  virtual const IOdictionary& properties() const = 0;
199 
200  //- Non-const access the properties dictionary
201  virtual IOdictionary& properties() = 0;
202 
203  //- Phase name
204  virtual const word& phaseName() const = 0;
205 
206  //- Name of a property for a given phase
207  word phasePropertyName(const word& name) const
208  {
209  return phasePropertyName(name, phaseName());
210  }
211 
212  //- Check that the thermodynamics package is consistent
213  // with energy forms supported by the application
214  void validate
215  (
216  const string& app,
217  const word&
218  ) const;
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 word&
227  ) const;
228 
229  //- Update properties
230  virtual void correct() = 0;
231 
232  //- Name of the thermo physics
233  virtual word thermoName() const = 0;
234 
235  //- Return true if the equation of state is incompressible
236  // i.e. rho != f(p)
237  virtual bool incompressible() const = 0;
238 
239  //- Return true if the equation of state is isochoric
240  // i.e. rho = const
241  virtual bool isochoric() const = 0;
242 
243  //- Should the dpdt term be included in the enthalpy equation
244  virtual Switch dpdt() const = 0;
245 
246 
247  // Access to thermodynamic state variables
248 
249  //- Density [kg/m^3]
250  virtual tmp<volScalarField> rho() const = 0;
251 
252  //- Density for patch [kg/m^3]
253  virtual tmp<scalarField> rho(const label patchi) const = 0;
254 
255  //- Old-time density [kg/m^3]
256  virtual tmp<volScalarField> rho0() const = 0;
257 
258  //- Enthalpy/Internal energy [J/kg]
259  // Non-const access allowed for transport equations
260  virtual volScalarField& he() = 0;
261 
262  //- Enthalpy/Internal energy [J/kg]
263  virtual const volScalarField& he() const = 0;
264 
265  //- Enthalpy/Internal energy
266  // for given pressure and temperature [J/kg]
267  virtual tmp<volScalarField> he
268  (
269  const volScalarField& p,
270  const volScalarField& T
271  ) const = 0;
272 
273  //- Enthalpy/Internal energy for cell-set [J/kg]
274  virtual tmp<scalarField> he
275  (
276  const scalarField& T,
277  const labelList& cells
278  ) const = 0;
279 
280  //- Enthalpy/Internal energy for patch [J/kg]
281  virtual tmp<scalarField> he
282  (
283  const scalarField& T,
284  const label patchi
285  ) const = 0;
286 
287  //- Sensible enthalpy [J/kg]
288  virtual tmp<volScalarField> hs() const = 0;
289 
290  //- Sensible enthalpy
291  // for given pressure and temperature [J/kg]
292  virtual tmp<volScalarField> hs
293  (
294  const volScalarField& p,
295  const volScalarField& T
296  ) const = 0;
297 
298  //- Sensible enthalpy for cell-set [J/kg]
299  virtual tmp<scalarField> hs
300  (
301  const scalarField& T,
302  const labelList& cells
303  ) const = 0;
304 
305  //- Sensible enthalpy for patch [J/kg]
306  virtual tmp<scalarField> hs
307  (
308  const scalarField& T,
309  const label patchi
310  ) const = 0;
311 
312  //- Absolute enthalpy [J/kg]
313  virtual tmp<volScalarField> ha() const = 0;
314 
315  //- Absolute enthalpy
316  // for given pressure and temperature [J/kg]
317  virtual tmp<volScalarField> ha
318  (
319  const volScalarField& p,
320  const volScalarField& T
321  ) const = 0;
322 
323  //- Absolute enthalpy for cell-set [J/kg]
324  virtual tmp<scalarField> ha
325  (
326  const scalarField& T,
327  const labelList& cells
328  ) const = 0;
329 
330  //- Absolute enthalpy for patch [J/kg]
331  virtual tmp<scalarField> ha
332  (
333  const scalarField& T,
334  const label patchi
335  ) const = 0;
336 
337  //- Enthalpy of formation [J/kg]
338  virtual tmp<volScalarField> hc() const = 0;
339 
340  //- Temperature from enthalpy/internal energy
341  virtual tmp<volScalarField> THE
342  (
343  const volScalarField& h,
344  const volScalarField& p,
345  const volScalarField& T0 // starting temperature
346  ) const = 0;
347 
348  //- Temperature from enthalpy/internal energy for cell-set
349  virtual tmp<scalarField> THE
350  (
351  const scalarField& h,
352  const scalarField& T0, // starting temperature
353  const labelList& cells
354  ) const = 0;
355 
356  //- Temperature from enthalpy/internal energy for patch
357  virtual tmp<scalarField> THE
358  (
359  const scalarField& h,
360  const scalarField& T0, // starting temperature
361  const label patchi
362  ) const = 0;
363 
364  //- Heat capacity at constant pressure [J/kg/K]
365  virtual const volScalarField& Cp() const = 0;
366 
367  //- Heat capacity at constant volume [J/kg/K]
368  virtual const volScalarField& Cv() const = 0;
369 
370 
371  // Access to transport state variables
372 
373  //- Thermal conductivity of mixture [W/m/K]
374  virtual const volScalarField& kappa() const = 0;
375 
376 
377  // Fields derived from thermodynamic state variables
378 
379  //- Temperature [K]
380  virtual const volScalarField& T() const = 0;
381 
382  //- Temperature [K]
383  // Non-const access allowed for transport equations
384  virtual volScalarField& T() = 0;
385 
386  //- Heat capacity at constant pressure for patch [J/kg/K]
387  virtual tmp<scalarField> Cp
388  (
389  const scalarField& T,
390  const label patchi
391  ) const = 0;
392 
393  //- Heat capacity at constant volume for patch [J/kg/K]
394  virtual tmp<scalarField> Cv
395  (
396  const scalarField& T,
397  const label patchi
398  ) const = 0;
399 
400  //- Heat capacity at constant pressure/volume [J/kg/K]
401  virtual tmp<volScalarField> Cpv() const = 0;
402 
403  //- Heat capacity at constant pressure/volume for patch [J/kg/K]
404  virtual tmp<scalarField> Cpv
405  (
406  const scalarField& T,
407  const label patchi
408  ) const = 0;
409 
410 
411  // Fields derived from transport state variables
412 
413  //- Thermal diffusivity of energy of mixture [kg/m/s]
414  virtual tmp<volScalarField> alphahe() const = 0;
415 
416  //- Thermal diffusivity of energy of mixture for patch [kg/m/s]
417  virtual tmp<scalarField> alphahe(const label patchi) const = 0;
418 };
419 
420 
421 /*---------------------------------------------------------------------------*\
422  Class basicThermo::implementation Declaration
423 \*---------------------------------------------------------------------------*/
426 :
427  virtual public basicThermo,
428  public physicalProperties
429 {
430 protected:
431 
432  // Protected data
433 
434  //- Phase-name
435  const word& phaseName_;
436 
437 
438  // Fields
439 
440  //- Temperature [K]
441  volScalarField T_;
442 
443  //- Thermal conductivity [W/m/K]
444  volScalarField kappa_;
445 
446 
447  //- Should the dpdt term be included in the enthalpy equation
448  Switch dpdt_;
449 
450 
451 public:
452 
453  // Static Member data
454 
455  //- Name of the thermophysical properties dictionary
456  using physicalProperties::typeName;
457 
458 
459  // Constructors
460 
461  //- Construct from mesh and phase name
462  implementation(const fvMesh&, const word& phaseName);
463 
464  //- Disallow default bitwise copy construction
465  implementation(const implementation&) = delete;
466 
467 
468 
469  //- Destructor
470  virtual ~implementation();
471 
472 
473  // Member Functions
474 
475  //- Properties dictionary
476  virtual const IOdictionary& properties() const
477  {
478  return *this;
479  }
480 
481  //- Non-const access the properties dictionary
482  virtual IOdictionary& properties()
483  {
484  return *this;
485  }
486 
487  //- Phase name
488  virtual const word& phaseName() const
489  {
490  return phaseName_;
491  }
492 
493  //- Should the dpdt term be included in the enthalpy equation
494  virtual Switch dpdt() const
495  {
496  return dpdt_;
497  }
498 
499 
500  // Fields derived from thermodynamic state variables
501 
502  //- Temperature [K]
503  virtual const volScalarField& T() const;
504 
505  //- Temperature [K]
506  // Non-const access allowed for transport equations
507  virtual volScalarField& T();
508 
509 
510  // Access to transport state variables
511 
512  //- Thermal conductivity of mixture [W/m/K]
513  virtual const volScalarField& kappa() const;
514 
515 
516  //- Read thermophysical properties dictionary
517  virtual bool read();
518 
519 
520  // Member Operators
521 
522  //- Disallow default bitwise assignment
523  void operator=(const implementation&) = delete;
524 };
525 
526 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
527 
528 } // End namespace Foam
529 
530 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
531 
532 #ifdef NoRepository
533  #include "basicThermoTemplates.C"
534 #endif
535 
536 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
537 
538 #endif
539 
540 // ************************************************************************* //
virtual ~basicThermo()
Destructor.
Definition: basicThermo.C:334
TypeName("basicThermo")
Runtime type information.
Base-class for fluid and solid thermodynamic properties.
Definition: basicThermo.H:77
static word phasePropertyName(const word &name, const word &phaseName)
Name of a property for a given phase.
Definition: basicThermo.H:150
virtual tmp< volScalarField > rho() const =0
Density [kg/m^3].
virtual tmp< volScalarField > THE(const volScalarField &h, const volScalarField &p, const volScalarField &T0) const =0
Temperature from enthalpy/internal energy.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
An abstract base class for physical properties.
virtual word thermoName() const =0
Name of the thermo physics.
virtual tmp< volScalarField > alphahe() const =0
Thermal diffusivity of energy of mixture [kg/m/s].
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
fvMesh & mesh
static autoPtr< Thermo > New(const fvMesh &, const word &phaseName=word::null)
Generic New for each of the related thermodynamics packages.
const dimensionedScalar h
Planck constant.
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].
virtual const volScalarField & Cp() const =0
Heat capacity at constant pressure [J/kg/K].
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
virtual tmp< volScalarField > rho0() const =0
Old-time density [kg/m^3].
virtual const IOdictionary & properties() const =0
Properties dictionary.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
virtual Switch dpdt() const =0
Should the dpdt term be included in the enthalpy equation.
virtual const word & phaseName() const =0
Phase name.
wordList heBoundaryBaseTypes()
Enthalpy/internal energy field boundary base types.
Definition: basicThermo.C:200
const cellShapeList & cells
static wordList splitThermoName(const word &thermoName, const int nCmpt)
Split name of thermo package into a list of the components names.
Definition: basicThermo.C:119
A class for handling words, derived from string.
Definition: word.H:59
static word groupName(Name name, const word &group)
wordList heBoundaryTypes()
Enthalpy/internal energy field boundary types.
Definition: basicThermo.C:228
static const word null
An empty word.
Definition: word.H:77
virtual const volScalarField & kappa() const =0
Thermal conductivity of mixture [W/m/K].
virtual tmp< volScalarField > hc() const =0
Enthalpy of formation [J/kg].
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
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 volScalarField & Cv() const =0
Heat capacity at constant volume [J/kg/K].
label patchi
virtual const volScalarField & T() const =0
Temperature [K].
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
static const basicThermo & lookupThermo(const fvPatchScalarField &pf)
Lookup the thermo associated with the given patch field.
Definition: basicThermo.C:83
virtual tmp< volScalarField > hs() const =0
Sensible enthalpy [J/kg].
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
virtual bool isochoric() const =0
Return true if the equation of state is isochoric.
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
virtual void correct()=0
Update properties.
void validate(const string &app, const word &) const
Check that the thermodynamics package is consistent.
Definition: basicThermo.C:345
virtual tmp< volScalarField > ha() const =0
Absolute enthalpy [J/kg].
virtual bool incompressible() const =0
Return true if the equation of state is incompressible.
static List< Pair< word > > thermoNameComponents(const word &thermoName)
Split name of thermo package into a list of named components names.
Definition: basicThermo.C:181
Namespace for OpenFOAM.
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:51
scalar T0
Definition: createFields.H:22