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