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  {
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  //- Return const access to the mesh
204  virtual const fvMesh& mesh() const = 0;
205 
206  //- Phase name
207  virtual const word& phaseName() const = 0;
208 
209  //- Name of a property for a given phase
210  word phasePropertyName(const word& name) const
211  {
212  return phasePropertyName(name, phaseName());
213  }
214 
215  //- Check that the thermodynamics package is consistent
216  // with energy forms supported by the application
217  void validate
218  (
219  const string& app,
220  const word&
221  ) const;
222 
223  //- Check that the thermodynamics package is consistent
224  // with energy forms supported by the application
225  void validate
226  (
227  const string& app,
228  const word&,
229  const word&
230  ) const;
231 
232  //- Update properties
233  virtual void correct() = 0;
234 
235  //- Name of the thermo physics
236  virtual word thermoName() const = 0;
237 
238  //- Return true if the equation of state is incompressible
239  // i.e. rho != f(p)
240  virtual bool incompressible() const = 0;
241 
242  //- Return true if the equation of state is isochoric
243  // i.e. rho = const
244  virtual bool isochoric() const = 0;
245 
246  //- Should the dpdt term be included in the enthalpy equation
247  virtual Switch dpdt() const = 0;
248 
249 
250  // Access to thermodynamic state variables
251 
252  //- Density [kg/m^3]
253  virtual tmp<volScalarField> rho() const = 0;
254 
255  //- Density for patch [kg/m^3]
256  virtual tmp<scalarField> rho(const label patchi) 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  //- Heat capacity at constant pressure/volume [J/kg/K]
371  virtual const volScalarField& Cpv() const = 0;
372 
373 
374  // Access to transport state variables
375 
376  //- Thermal conductivity of mixture [W/m/K]
377  virtual const volScalarField& kappa() const = 0;
378 
379 
380  // Fields derived from thermodynamic state variables
381 
382  //- Temperature [K]
383  virtual const volScalarField& T() const = 0;
384 
385  //- Temperature [K]
386  // Non-const access allowed for transport equations
387  virtual volScalarField& T() = 0;
388 
389  //- Heat capacity at constant pressure for patch [J/kg/K]
390  virtual tmp<scalarField> Cp
391  (
392  const scalarField& T,
393  const label patchi
394  ) const = 0;
395 
396  //- Heat capacity at constant volume for patch [J/kg/K]
397  virtual tmp<scalarField> Cv
398  (
399  const scalarField& T,
400  const label patchi
401  ) 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 
412 /*---------------------------------------------------------------------------*\
413  Class basicThermo::implementation Declaration
414 \*---------------------------------------------------------------------------*/
415 
417 :
418  virtual public basicThermo,
419  public physicalProperties
420 {
421  // Private Member Data
422 
423  //- Reference to the mesh
424  const fvMesh& mesh_;
425 
426 
427 protected:
428 
429  // Protected data
430 
431  //- Phase-name
432  const word& phaseName_;
433 
434 
435  // Fields
436 
437  //- Temperature [K]
439 
440  //- Thermal conductivity [W/m/K]
442 
443 
444  //- Should the dpdt term be included in the enthalpy equation
445  Switch dpdt_;
446 
447 
448 public:
449 
450  // Static Member data
451 
452  //- Name of the thermophysical properties dictionary
453  using physicalProperties::typeName;
454 
455 
456  // Constructors
457 
458  //- Construct from mesh and phase name
459  implementation(const fvMesh&, const word& phaseName);
460 
461  //- Disallow default bitwise copy construction
462  implementation(const implementation&) = delete;
463 
464 
465 
466  //- Destructor
467  virtual ~implementation();
468 
469 
470  // Member Functions
471 
472  //- Properties dictionary
473  virtual const IOdictionary& properties() const
474  {
475  return *this;
476  }
477 
478  //- Non-const access the properties dictionary
479  virtual IOdictionary& properties()
480  {
481  return *this;
482  }
483 
484  //- Return const access to the mesh
485  virtual const fvMesh& mesh() const
486  {
487  return mesh_;
488  }
489 
490  //- Phase name
491  virtual const word& phaseName() const
492  {
493  return phaseName_;
494  }
495 
496  //- Should the dpdt term be included in the enthalpy equation
497  virtual Switch dpdt() const
498  {
499  return dpdt_;
500  }
501 
502 
503  // Fields derived from thermodynamic state variables
504 
505  //- Temperature [K]
506  virtual const volScalarField& T() const;
507 
508  //- Temperature [K]
509  // Non-const access allowed for transport equations
510  virtual volScalarField& T();
511 
512 
513  // Access to transport state variables
514 
515  //- Thermal conductivity of mixture [W/m/K]
516  virtual const volScalarField& kappa() const;
517 
518 
519  //- Read thermophysical properties dictionary
520  virtual bool read();
521 
522 
523  // Member Operators
524 
525  //- Disallow default bitwise assignment
526  void operator=(const implementation&) = delete;
527 };
528 
529 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
530 
531 } // End namespace Foam
532 
533 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
534 
535 #ifdef NoRepository
536  #include "basicThermoTemplates.C"
537 #endif
538 
539 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
540 
541 #endif
542 
543 // ************************************************************************* //
Generic GeometricField class.
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:440
virtual const volScalarField & T() const
Temperature [K].
Definition: basicThermo.C:369
implementation(const fvMesh &, const word &phaseName)
Construct from mesh and phase name.
Definition: basicThermo.C:264
Switch dpdt_
Should the dpdt term be included in the enthalpy equation.
Definition: basicThermo.H:444
virtual const volScalarField & kappa() const
Thermal conductivity of mixture [W/m/K].
Definition: basicThermo.C:381
virtual Switch dpdt() const
Should the dpdt term be included in the enthalpy equation.
Definition: basicThermo.H:496
virtual ~implementation()
Destructor.
Definition: basicThermo.C:324
virtual const fvMesh & mesh() const
Return const access to the mesh.
Definition: basicThermo.H:484
virtual const IOdictionary & properties() const
Properties dictionary.
Definition: basicThermo.H:472
volScalarField T_
Temperature [K].
Definition: basicThermo.H:437
const word & phaseName_
Phase-name.
Definition: basicThermo.H:431
virtual const word & phaseName() const
Phase name.
Definition: basicThermo.H:490
void operator=(const implementation &)=delete
Disallow default bitwise assignment.
virtual bool read()
Read thermophysical properties dictionary.
Definition: basicThermo.C:387
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].
static const basicThermo & lookupThermo(const fvPatchScalarField &pf)
Lookup the thermo associated with the given patch field.
Definition: basicThermo.C:81
static List< Pair< word > > thermoNameComponents(const word &thermoName)
Split name of thermo package into a list of named components names.
Definition: basicThermo.C:179
wordList heBoundaryTypes()
Enthalpy/internal energy field boundary types.
Definition: basicThermo.C:216
virtual volScalarField & he()=0
Enthalpy/Internal energy [J/kg].
static word phasePropertyName(const word &name, const word &phaseName)
Name of a property for a given phase.
Definition: basicThermo.H:150
wordList heBoundaryBaseTypes()
Enthalpy/internal energy field boundary base types.
Definition: basicThermo.C:198
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:117
virtual tmp< volScalarField > THE(const volScalarField &h, const volScalarField &p, const volScalarField &T0) const =0
Temperature from enthalpy/internal energy.
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.
void validate(const string &app, const word &) const
Check that the thermodynamics package is consistent.
Definition: basicThermo.C:331
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:320
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].
virtual tmp< volScalarField > hc() const =0
Enthalpy of formation [J/kg].
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:160
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:87
An abstract base class for physical properties.
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 complex &)
Return a string representation of a complex.
Definition: complex.C:47
volScalarField & p
scalar T0
Definition: createFields.H:22