thermoI.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 | Copyright (C) 2011-2016 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 \*---------------------------------------------------------------------------*/
25 
26 #include "thermo.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class Thermo, template<class> class Type>
32 (
33  const Thermo& sp
34 )
35 :
36  Thermo(sp)
37 {}
38 
39 
40 template<class Thermo, template<class> class Type>
42 (
43  scalar f,
44  scalar p,
45  scalar T0,
46  scalar (thermo<Thermo, Type>::*F)(const scalar, const scalar) const,
47  scalar (thermo<Thermo, Type>::*dFdT)(const scalar, const scalar)
48  const,
49  scalar (thermo<Thermo, Type>::*limit)(const scalar) const
50 ) const
51 {
52  scalar Test = T0;
53  scalar Tnew = T0;
54  scalar Ttol = T0*tol_;
55  int iter = 0;
56 
57  do
58  {
59  Test = Tnew;
60  Tnew =
61  (this->*limit)
62  (Test - ((this->*F)(p, Test) - f)/(this->*dFdT)(p, Test));
63 
64  if (iter++ > maxIter_)
65  {
67  << "Maximum number of iterations exceeded"
68  << abort(FatalError);
69  }
70 
71  } while (mag(Tnew - Test) > Ttol);
72 
73  return Tnew;
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
79 template<class Thermo, template<class> class Type>
81 (
82  const word& name,
83  const thermo& st
84 )
85 :
86  Thermo(name, st)
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
91 
92 template<class Thermo, template<class> class Type>
93 inline Foam::word
95 {
96  return Type<thermo<Thermo, Type>>::name();
97 }
98 
99 
100 template<class Thermo, template<class> class Type>
101 inline Foam::scalar
102 Foam::species::thermo<Thermo, Type>::he(const scalar p, const scalar T) const
103 {
104  return Type<thermo<Thermo, Type>>::he(*this, p, T);
105 }
106 
107 
108 template<class Thermo, template<class> class Type>
109 inline Foam::scalar
110 Foam::species::thermo<Thermo, Type>::cv(const scalar p, const scalar T) const
111 {
112  return this->cp(p, T) - this->cpMcv(p, T);
113 }
114 
115 
116 template<class Thermo, template<class> class Type>
117 inline Foam::scalar
118 Foam::species::thermo<Thermo, Type>::cpv(const scalar p, const scalar T) const
119 {
120  return Type<thermo<Thermo, Type>>::cpv(*this, p, T);
121 }
122 
123 
124 template<class Thermo, template<class> class Type>
125 inline Foam::scalar
126 Foam::species::thermo<Thermo, Type>::gamma(const scalar p, const scalar T) const
127 {
128  scalar cp = this->cp(p, T);
129  return cp/(cp - this->cpMcv(p, T));
130 }
131 
132 
133 template<class Thermo, template<class> class Type>
134 inline Foam::scalar
136 (
137  const scalar p,
138  const scalar T
139 ) const
140 {
141  return Type<thermo<Thermo, Type>>::cpBycpv(*this, p, T);
142 }
143 
144 
145 template<class Thermo, template<class> class Type>
146 inline Foam::scalar
147 Foam::species::thermo<Thermo, Type>::es(const scalar p, const scalar T) const
148 {
149  return this->hs(p, T) - p*this->W()/this->rho(p, T);
150 }
151 
152 
153 template<class Thermo, template<class> class Type>
154 inline Foam::scalar
155 Foam::species::thermo<Thermo, Type>::ea(const scalar p, const scalar T) const
156 {
157  return this->ha(p, T) - p*this->W()/this->rho(p, T);
158 }
159 
160 
161 template<class Thermo, template<class> class Type>
162 inline Foam::scalar
163 Foam::species::thermo<Thermo, Type>::g(const scalar p, const scalar T) const
164 {
165  return this->ha(p, T) - T*this->s(p, T);
166 }
167 
168 
169 template<class Thermo, template<class> class Type>
170 inline Foam::scalar
171 Foam::species::thermo<Thermo, Type>::a(const scalar p, const scalar T) const
172 {
173  return this->ea(p, T) - T*this->s(p, T);
174 }
175 
176 
177 template<class Thermo, template<class> class Type>
178 inline Foam::scalar
179 Foam::species::thermo<Thermo, Type>::Cpv(const scalar p, const scalar T) const
180 {
181  return this->cpv(p, T)/this->W();
182 }
183 
184 
185 template<class Thermo, template<class> class Type>
186 inline Foam::scalar
187 Foam::species::thermo<Thermo, Type>::Cp(const scalar p, const scalar T) const
188 {
189  return this->cp(p, T)/this->W();
190 }
191 
192 
193 template<class Thermo, template<class> class Type>
194 inline Foam::scalar
195 Foam::species::thermo<Thermo, Type>::Cv(const scalar p, const scalar T) const
196 {
197  return this->cv(p, T)/this->W();
198 }
199 
200 
201 template<class Thermo, template<class> class Type>
202 inline Foam::scalar
203 Foam::species::thermo<Thermo, Type>::HE(const scalar p, const scalar T) const
204 {
205  return Type<thermo<Thermo, Type>>::HE(*this, p, T);
206 }
207 
208 
209 template<class Thermo, template<class> class Type>
210 inline Foam::scalar
211 Foam::species::thermo<Thermo, Type>::Hs(const scalar p, const scalar T) const
212 {
213  return this->hs(p, T)/this->W();
214 }
215 
216 
217 template<class Thermo, template<class> class Type>
218 inline Foam::scalar
220 {
221  return this->hc()/this->W();
222 }
223 
224 
225 template<class Thermo, template<class> class Type>
226 inline Foam::scalar
227 Foam::species::thermo<Thermo, Type>::Ha(const scalar p, const scalar T) const
228 {
229  return this->ha(p, T)/this->W();
230 }
231 
232 
233 template<class Thermo, template<class> class Type>
234 inline Foam::scalar
235 Foam::species::thermo<Thermo, Type>::S(const scalar p, const scalar T) const
236 {
237  return this->s(p, T)/this->W();
238 }
239 
240 
241 template<class Thermo, template<class> class Type>
242 inline Foam::scalar
243 Foam::species::thermo<Thermo, Type>::E(const scalar p, const scalar T) const
244 {
245  return this->e(p, T)/this->W();
246 }
247 
248 
249 template<class Thermo, template<class> class Type>
250 inline Foam::scalar
251 Foam::species::thermo<Thermo, Type>::Es(const scalar p, const scalar T) const
252 {
253  return this->es(p, T)/this->W();
254 }
255 
256 template<class Thermo, template<class> class Type>
257 inline Foam::scalar
258 Foam::species::thermo<Thermo, Type>::Ea(const scalar p, const scalar T) const
259 {
260  return this->ea(p, T)/this->W();
261 }
262 
263 
264 template<class Thermo, template<class> class Type>
265 inline Foam::scalar
266 Foam::species::thermo<Thermo, Type>::G(const scalar p, const scalar T) const
267 {
268  return this->g(p, T)/this->W();
269 }
270 
271 
272 template<class Thermo, template<class> class Type>
273 inline Foam::scalar
274 Foam::species::thermo<Thermo, Type>::A(const scalar p, const scalar T) const
275 {
276  return this->a(p, T)/this->W();
277 }
278 
279 
280 template<class Thermo, template<class> class Type>
281 inline Foam::scalar
282 Foam::species::thermo<Thermo, Type>::K(const scalar p, const scalar T) const
283 {
284  scalar arg = -this->nMoles()*this->g(Pstd, T)/(RR*T);
285 
286  if (arg < 600.0)
287  {
288  return exp(arg);
289  }
290  else
291  {
292  return VGREAT;
293  }
294 }
295 
296 
297 template<class Thermo, template<class> class Type>
298 inline Foam::scalar
299 Foam::species::thermo<Thermo, Type>::Kp(const scalar p, const scalar T) const
300 {
301  return K(p, T);
302 }
303 
304 
305 template<class Thermo, template<class> class Type>
306 inline Foam::scalar
307 Foam::species::thermo<Thermo, Type>::Kc(const scalar p, const scalar T) const
308 {
309  if (equal(this->nMoles(), SMALL))
310  {
311  return Kp(p, T);
312  }
313  else
314  {
315  return Kp(p, T)*pow(Pstd/(RR*T), this->nMoles());
316  }
317 }
318 
319 
320 template<class Thermo, template<class> class Type>
321 inline Foam::scalar Foam::species::thermo<Thermo, Type>::Kx
322 (
323  const scalar p,
324  const scalar T
325 ) const
326 {
327  if (equal(this->nMoles(), SMALL))
328  {
329  return Kp(p, T);
330  }
331  else
332  {
333  return Kp(p, T)*pow(Pstd/p, this->nMoles());
334  }
335 }
336 
337 
338 template<class Thermo, template<class> class Type>
339 inline Foam::scalar Foam::species::thermo<Thermo, Type>::Kn
340 (
341  const scalar p,
342  const scalar T,
343  const scalar n
344 ) const
345 {
346  if (equal(this->nMoles(), SMALL))
347  {
348  return Kp(p, T);
349  }
350  else
351  {
352  return Kp(p, T)*pow(n*Pstd/p, this->nMoles());
353  }
354 }
355 
356 
357 template<class Thermo, template<class> class Type>
359 (
360  const scalar he,
361  const scalar p,
362  const scalar T0
363 ) const
364 {
365  return Type<thermo<Thermo, Type>>::THE(*this, he, p, T0);
366 }
367 
368 
369 template<class Thermo, template<class> class Type>
371 (
372  const scalar hs,
373  const scalar p,
374  const scalar T0
375 ) const
376 {
377  return T
378  (
379  hs,
380  p,
381  T0,
385  );
386 }
387 
388 
389 template<class Thermo, template<class> class Type>
391 (
392  const scalar ha,
393  const scalar p,
394  const scalar T0
395 ) const
396 {
397  return T
398  (
399  ha,
400  p,
401  T0,
405  );
406 }
407 
408 
409 template<class Thermo, template<class> class Type>
411 (
412  const scalar es,
413  const scalar p,
414  const scalar T0
415 ) const
416 {
417  return T
418  (
419  es,
420  p,
421  T0,
425  );
426 }
427 
428 
429 template<class Thermo, template<class> class Type>
431 (
432  const scalar ea,
433  const scalar p,
434  const scalar T0
435 ) const
436 {
437  return T
438  (
439  ea,
440  p,
441  T0,
445  );
446 }
447 
448 
449 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
450 
451 template<class Thermo, template<class> class Type>
452 inline void Foam::species::thermo<Thermo, Type>::operator+=
453 (
454  const thermo<Thermo, Type>& st
455 )
456 {
457  Thermo::operator+=(st);
458 }
459 
460 
461 template<class Thermo, template<class> class Type>
462 inline void Foam::species::thermo<Thermo, Type>::operator-=
463 (
464  const thermo<Thermo, Type>& st
465 )
466 {
467  Thermo::operator-=(st);
468 }
469 
470 
471 template<class Thermo, template<class> class Type>
473 {
474  Thermo::operator*=(s);
475 }
476 
477 
478 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
479 
480 template<class Thermo, template<class> class Type>
481 inline Foam::species::thermo<Thermo, Type> Foam::species::operator+
482 (
483  const thermo<Thermo, Type>& st1,
484  const thermo<Thermo, Type>& st2
485 )
486 {
487  return thermo<Thermo, Type>
488  (
489  static_cast<const Thermo&>(st1) + static_cast<const Thermo&>(st2)
490  );
491 }
492 
493 
494 template<class Thermo, template<class> class Type>
495 inline Foam::species::thermo<Thermo, Type> Foam::species::operator-
496 (
497  const thermo<Thermo, Type>& st1,
498  const thermo<Thermo, Type>& st2
499 )
500 {
501  return thermo<Thermo, Type>
502  (
503  static_cast<const Thermo&>(st1) - static_cast<const Thermo&>(st2)
504  );
505 }
506 
507 
508 template<class Thermo, template<class> class Type>
509 inline Foam::species::thermo<Thermo, Type> Foam::species::operator*
510 (
511  const scalar s,
512  const thermo<Thermo, Type>& st
513 )
514 {
515  return thermo<Thermo, Type>
516  (
517  s*static_cast<const Thermo&>(st)
518  );
519 }
520 
521 
522 template<class Thermo, template<class> class Type>
523 inline Foam::species::thermo<Thermo, Type> Foam::species::operator==
524 (
525  const thermo<Thermo, Type>& st1,
526  const thermo<Thermo, Type>& st2
527 )
528 {
529  return st2 - st1;
530 }
531 
532 
533 // ************************************************************************* //
scalar TEs(const scalar E, const scalar p, const scalar T0) const
Temperature from sensible internal energy.
Definition: thermoI.H:411
volScalarField & he
Definition: YEEqn.H:56
scalar THa(const scalar H, const scalar p, const scalar T0) const
Temperature from absolute enthalpy.
Definition: thermoI.H:391
scalar cpBycpv(const scalar p, const scalar T) const
Ratio of heat capacity at constant pressure to that at.
Definition: thermoI.H:136
scalar K(const scalar p, const scalar T) const
Equilibrium constant [] i.t.o fugacities.
Definition: thermoI.H:282
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
scalar Kx(const scalar p, const scalar T) const
Equilibrium constant [] i.t.o. mole-fractions.
Definition: thermoI.H:322
scalar Cv(const scalar p, const scalar T) const
Heat capacity at constant volume [J/(kg K)].
Definition: thermoI.H:195
scalar Cpv(const scalar p, const scalar T) const
Heat capacity at constant pressure/volume [J/(kg K)].
Definition: thermoI.H:179
scalar he(const scalar p, const scalar T) const
Enthalpy/Internal energy [J/kmol].
Definition: thermoI.H:102
scalar HE(const scalar p, const scalar T) const
Enthalpy/Internal energy [J/kg].
Definition: thermoI.H:203
CGAL::Exact_predicates_exact_constructions_kernel K
static word heName()
Name of Enthalpy/Internal energy.
Definition: thermoI.H:94
scalar THE(const scalar H, const scalar p, const scalar T0) const
Temperature from enthalpy or internal energy.
Definition: thermoI.H:359
scalar A(const scalar p, const scalar T) const
Helmholtz free energy [J/kg].
Definition: thermoI.H:274
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().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))
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:78
dimensionedScalar exp(const dimensionedScalar &ds)
A class for handling words, derived from string.
Definition: word.H:59
scalar THs(const scalar Hs, const scalar p, const scalar T0) const
Temperature from sensible enthalpy given an initial T0.
Definition: thermoI.H:371
scalar E(const scalar p, const scalar T) const
Internal energy [J/kg].
Definition: thermoI.H:243
const dimensionedScalar Pstd
Standard pressure.
scalar Ha(const scalar p, const scalar T) const
Absolute Enthalpy [J/kg].
Definition: thermoI.H:227
errorManip< error > abort(error &err)
Definition: errorManip.H:131
scalar ea(const scalar p, const scalar T) const
Absolute internal energy [J/kmol].
Definition: thermoI.H:155
scalar Cp(const scalar p, const scalar T) const
Heat capacity at constant pressure [J/(kg K)].
Definition: thermoI.H:187
const volScalarField & cp
const dimensionedVector & g
scalar Kc(const scalar p, const scalar T) const
Equilibrium constant i.t.o. molar concentration.
Definition: thermoI.H:307
const volScalarField & T
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
scalar Kp(const scalar p, const scalar T) const
Equilibrium constant [] i.t.o. partial pressures.
Definition: thermoI.H:299
scalar a(const scalar p, const scalar T) const
Helmholtz free energy [J/kmol].
Definition: thermoI.H:171
scalar cv(const scalar p, const scalar T) const
Heat capacity at constant volume [J/(kmol K)].
Definition: thermoI.H:110
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
scalar Hc() const
Chemical enthalpy [J/kg].
Definition: thermoI.H:219
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
scalar g(const scalar p, const scalar T) const
Gibbs free energy [J/kmol].
Definition: thermoI.H:163
void operator*=(const scalar)
Definition: thermoI.H:472
thermo(const Thermo &sp)
Construct from components.
Definition: thermoI.H:32
scalar S(const scalar p, const scalar T) const
Entropy [J/(kg K)].
Definition: thermoI.H:235
scalar cpv(const scalar p, const scalar T) const
Heat capacity at constant pressure/volume [J/(kmol K)].
Definition: thermoI.H:118
dimensioned< scalar > mag(const dimensioned< Type > &)
const scalar RR
Universal gas constant (default in [J/(kmol K)])
void limit(const RdeltaTType &rDeltaT, const RhoType &rho, const volScalarField &psi, const surfaceScalarField &phi, surfaceScalarField &phiPsi, const SpType &Sp, const SuType &Su, const scalar psiMax, const scalar psiMin, const bool returnCorr)
scalar Ea(const scalar p, const scalar T) const
Absolute internal energy [J/kg].
Definition: thermoI.H:258
scalar Kn(const scalar p, const scalar T, const scalar n) const
Equilibrium constant [] i.t.o. number of moles.
Definition: thermoI.H:340
scalar Hs(const scalar p, const scalar T) const
Sensible enthalpy [J/kg].
Definition: thermoI.H:211
scalar TEa(const scalar E, const scalar p, const scalar T0) const
Temperature from absolute internal energy.
Definition: thermoI.H:431
scalar gamma(const scalar p, const scalar T) const
Gamma = cp/cv [].
Definition: thermoI.H:126
scalar G(const scalar p, const scalar T) const
Gibbs free energy [J/kg].
Definition: thermoI.H:266
scalar es(const scalar p, const scalar T) const
Sensible internal energy [J/kmol].
Definition: thermoI.H:147
scalar Es(const scalar p, const scalar T) const
Sensible internal energy [J/kg].
Definition: thermoI.H:251