thermo.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::thermo
29 
30 Description
31  Basic thermodynamics type based on the use of fitting functions for
32  cp, h, s obtained from the template argument type thermo. All other
33  properties are derived from these primitive functions.
34 
35 SourceFiles
36  thermoI.H
37  thermo.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef thermo_H
42 #define thermo_H
43 
44 #include "thermodynamicConstants.H"
45 using namespace Foam::constant::thermodynamic;
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 namespace species
52 {
53 
54 // Forward declaration of friend functions and operators
55 
56 template<class Thermo, template<class> class Type> class thermo;
57 
58 template<class Thermo, template<class> class Type>
59 inline thermo<Thermo, Type> operator+
60 (
61  const thermo<Thermo, Type>&,
63 );
64 
65 template<class Thermo, template<class> class Type>
66 inline thermo<Thermo, Type> operator*
67 (
68  const scalar,
70 );
71 
72 template<class Thermo, template<class> class Type>
73 inline thermo<Thermo, Type> operator==
74 (
75  const thermo<Thermo, Type>&,
77 );
78 
79 template<class Thermo, template<class> class Type>
80 Ostream& operator<<
81 (
82  Ostream&,
84 );
85 
86 
87 /*---------------------------------------------------------------------------*\
88  Class thermo Declaration
89 \*---------------------------------------------------------------------------*/
90 
91 template<class Thermo, template<class> class Type>
92 class thermo
93 :
94  public Thermo,
95  public Type<thermo<Thermo, Type>>
96 {
97  // Private data
98 
99  //- Convergence tolerance of energy -> temperature inversion functions
100  static const scalar tol_;
101 
102  //- Max number of iterations in energy->temperature inversion functions
103  static const int maxIter_;
104 
105 
106  // Private Member Functions
107 
108  //- Return the temperature corresponding to the value of the
109  // thermodynamic property f, given the function f = F(p, T)
110  // and dF(p, T)/dT
111  inline scalar T
112  (
113  scalar f,
114  scalar p,
115  scalar T0,
116  scalar (thermo::*F)(const scalar, const scalar) const,
117  scalar (thermo::*dFdT)(const scalar, const scalar) const,
118  scalar (thermo::*limit)(const scalar) const
119  ) const;
120 
121 
122 public:
123 
124  //- The thermodynamics of the individual species'
126 
127 
128  // Constructors
129 
130  //- Construct from components
131  inline thermo(const Thermo& sp);
132 
133  //- Construct from dictionary
134  thermo(const dictionary& dict);
135 
136  //- Construct as named copy
137  inline thermo(const word& name, const thermo&);
138 
139 
140  // Member Functions
141 
142  //- Return the instantiated type name
143  static word typeName()
144  {
145  return
146  Thermo::typeName() + ','
147  + Type<thermo<Thermo, Type>>::typeName();
148  }
149 
150  //- Name of Enthalpy/Internal energy
151  static inline word heName();
152 
153 
154  // Fundamental properties
155  // (These functions must be provided in derived types)
156 
157  // Heat capacity at constant pressure [J/(kg K)]
158  // inline scalar Cp(const scalar p, const scalar T) const;
159 
160  // Sensible enthalpy [J/kg]
161  // inline scalar Hs(const scalar p, const scalar T) const;
162 
163  // Chemical enthalpy [J/kg]
164  // inline scalar Hc() const;
165 
166  // Absolute Enthalpy [J/kg]
167  // inline scalar Ha(const scalar p, const scalar T) const;
168 
169  // Heat capacity at constant volume [J/(kg K)]
170  // inline scalar Cv(const scalar p, const scalar T) const;
171 
172  // Sensible internal energy [J/kg]
173  // inline scalar Es(const scalar p, const scalar T) const;
174 
175  // Absolute internal energy [J/kg]
176  // inline scalar Ea(const scalar p, const scalar T) const;
177 
178  // Entropy [J/(kg K)]
179  // inline scalar S(const scalar p, const scalar T) const;
180 
181 
182  // Mass specific derived properties
183 
184 
185  //- Heat capacity at constant pressure/volume [J/(kg K)]
186  inline scalar Cpv(const scalar p, const scalar T) const;
187 
188  //- Gamma = Cp/Cv []
189  inline scalar gamma(const scalar p, const scalar T) const;
190 
191  //- Ratio of heat capacity at constant pressure to that at
192  // constant pressure/volume []
193  inline scalar CpByCpv(const scalar p, const scalar T) const;
194 
195  //- Enthalpy/Internal energy [J/kg]
196  inline scalar HE(const scalar p, const scalar T) const;
197 
198  //- Gibbs free energy [J/kg]
199  inline scalar G(const scalar p, const scalar T) const;
200 
201  //- Helmholtz free energy [J/kg]
202  inline scalar A(const scalar p, const scalar T) const;
203 
204 
205  // Mole specific derived properties
206 
207  //- Heat capacity at constant pressure [J/(kmol K)]
208  inline scalar cp(const scalar p, const scalar T) const;
209 
210  //- Absolute Enthalpy [J/kmol]
211  inline scalar ha(const scalar p, const scalar T) const;
212 
213  //- Sensible enthalpy [J/kmol]
214  inline scalar hs(const scalar p, const scalar T) const;
215 
216  //- Chemical enthalpy [J/kmol]
217  inline scalar hc() const;
218 
219  //- Entropy [J/(kmol K)]
220  inline scalar s(const scalar p, const scalar T) const;
221 
222  //- Enthalpy/Internal energy [J/kmol]
223  inline scalar he(const scalar p, const scalar T) const;
224 
225  //- Heat capacity at constant volume [J/(kmol K)]
226  inline scalar cv(const scalar p, const scalar T) const;
227 
228  //- Sensible internal energy [J/kmol]
229  inline scalar es(const scalar p, const scalar T) const;
230 
231  //- Absolute internal energy [J/kmol]
232  inline scalar ea(const scalar p, const scalar T) const;
233 
234  //- Gibbs free energy [J/kmol]
235  inline scalar g(const scalar p, const scalar T) const;
236 
237  //- Helmholtz free energy [J/kmol]
238  inline scalar a(const scalar p, const scalar T) const;
239 
240 
241  // Equilibrium reaction thermodynamics
242 
243  //- Equilibrium constant [] i.t.o fugacities
244  // = PIi(fi/Pstd)^nui
245  inline scalar K(const scalar p, const scalar T) const;
246 
247  //- Equilibrium constant [] i.t.o. partial pressures
248  // = PIi(pi/Pstd)^nui
249  // For low pressures (where the gas mixture is near perfect) Kp = K
250  inline scalar Kp(const scalar p, const scalar T) const;
251 
252  //- Equilibrium constant i.t.o. molar concentration
253  // = PIi(ci/cstd)^nui
254  // For low pressures (where the gas mixture is near perfect)
255  // Kc = Kp(pstd/(RR*T))^nu
256  inline scalar Kc(const scalar p, const scalar T) const;
257 
258  //- Equilibrium constant [] i.t.o. mole-fractions
259  // For low pressures (where the gas mixture is near perfect)
260  // Kx = Kp(pstd/p)^nui
261  inline scalar Kx
262  (
263  const scalar p,
264  const scalar T
265  ) const;
266 
267  //- Equilibrium constant [] i.t.o. number of moles
268  // For low pressures (where the gas mixture is near perfect)
269  // Kn = Kp(n*pstd/p)^nui where n = number of moles in mixture
270  inline scalar Kn
271  (
272  const scalar p,
273  const scalar T,
274  const scalar n
275  ) const;
276 
277 
278  // Energy->temperature inversion functions
279 
280  //- Temperature from enthalpy or internal energy
281  // given an initial temperature T0
282  inline scalar THE
283  (
284  const scalar H,
285  const scalar p,
286  const scalar T0
287  ) const;
288 
289  //- Temperature from sensible enthalpy given an initial T0
290  inline scalar THs
291  (
292  const scalar Hs,
293  const scalar p,
294  const scalar T0
295  ) const;
296 
297  //- Temperature from absolute enthalpy
298  // given an initial temperature T0
299  inline scalar THa
300  (
301  const scalar H,
302  const scalar p,
303  const scalar T0
304  ) const;
305 
306  //- Temperature from sensible internal energy
307  // given an initial temperature T0
308  inline scalar TEs
309  (
310  const scalar E,
311  const scalar p,
312  const scalar T0
313  ) const;
314 
315  //- Temperature from absolute internal energy
316  // given an initial temperature T0
317  inline scalar TEa
318  (
319  const scalar E,
320  const scalar p,
321  const scalar T0
322  ) const;
323 
324 
325  // Derivative term used for Jacobian
326 
327  //- Derivative of B (acooding to Niemeyer et al.) w.r.t. temperature
328  inline scalar dKcdTbyKc(const scalar p, const scalar T) const;
329 
330  //- Derivative of cp w.r.t. temperature
331  inline scalar dcpdT(const scalar p, const scalar T) const;
332 
333 
334  // I-O
335 
336  //- Write to Ostream
337  void write(Ostream& os) const;
338 
339 
340  // Member operators
341 
342  inline void operator+=(const thermo&);
343  inline void operator*=(const scalar);
344 
345 
346  // Friend operators
347 
348  friend thermo operator+ <Thermo, Type>
349  (
350  const thermo&,
351  const thermo&
352  );
353 
354  friend thermo operator* <Thermo, Type>
355  (
356  const scalar s,
357  const thermo&
358  );
359 
360  friend thermo operator== <Thermo, Type>
361  (
362  const thermo&,
363  const thermo&
364  );
365 
366 
367  // Ostream Operator
368 
369  friend Ostream& operator<< <Thermo, Type>
370  (
371  Ostream&,
372  const thermo&
373  );
374 };
375 
376 
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378 
379 } // End namespace species
380 } // End namespace Foam
381 
382 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383 
384 #include "thermoI.H"
385 
386 #ifdef NoRepository
387  #include "thermo.C"
388 #endif
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #endif
393 
394 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::constant::universal::G
const dimensionedScalar G
Newtonian constant of gravitation.
Hs
scalar Hs(const scalar p, const scalar T) const
Definition: EtoHthermo.H:17
thermo
psiReactionThermo & thermo
Definition: createFields.H:28
Foam::species::thermo::typeName
static word typeName()
Return the instantiated type name.
Definition: thermo.H:142
H
volScalarField H(IOobject("H", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimLength, Zero))
A
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
F
volVectorField F(fluid.F())
K
CGAL::Exact_predicates_exact_constructions_kernel K
Definition: CGALTriangulation3DKernel.H:58
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::constant::thermodynamic
Thermodynamic scalar constants.
Definition: thermodynamicConstants.C:37
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
g
const uniformDimensionedVectorField & g
Definition: createFluidFields.H:26
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::species::thermo
Definition: thermo.H:55
thermoI.H
thermodynamicConstants.H
Foam::cp
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
Definition: MSwindows.C:802
he
volScalarField & he
Definition: YEEqn.H:52
f
labelList f(nPoints)
gamma
const scalar gamma
Definition: EEqn.H:9
Foam::limit
complex limit(const complex &, const complex &)
Definition: complexI.H:263
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::species::thermo::thermoType
thermo< Thermo, Type > thermoType
The thermodynamics of the individual species'.
Definition: thermo.H:124
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
T0
scalar T0
Definition: createFields.H:22