PengRobinsonGasI.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) 2014-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 "PengRobinsonGas.H"
27 #include "mathematicalConstants.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class Specie>
33 (
34  const Specie& sp,
35  const scalar& Tc,
36  const scalar& Vc,
37  const scalar& Zc,
38  const scalar& Pc,
39  const scalar& omega
40 )
41 :
42  Specie(sp),
43  Tc_(Tc),
44  Vc_(Vc),
45  Zc_(Zc),
46  Pc_(Pc),
47  omega_(omega)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52 
53 template<class Specie>
55 (
56  const word& name,
57  const PengRobinsonGas& pg
58 )
59 :
60  Specie(name, pg),
61  Tc_(pg.Tc_),
62  Pc_(pg.Pc_),
63  Vc_(pg.Vc_),
64  Zc_(pg.Zc_),
65  omega_(pg.omega_)
66 {}
67 
68 
69 template<class Specie>
72 {
74  (
75  new PengRobinsonGas<Specie>(*this)
76  );
77 }
78 
79 
80 template<class Specie>
83 (
84  Istream& is
85 )
86 {
88 }
89 
90 
91 template<class Specie>
94 (
95  const dictionary& dict
96 )
97 {
99  (
101  );
102 }
103 
104 
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 
107 template<class Specie>
108 inline Foam::scalar Foam::PengRobinsonGas<Specie>::rho
109 (
110  scalar p,
111  scalar T
112 ) const
113 {
114  scalar Z = this->Z(p, T);
115  return p/(Z*this->R()*T);
116 }
117 
118 
119 template<class Specie>
120 inline Foam::scalar Foam::PengRobinsonGas<Specie>::h(scalar p, scalar T) const
121 {
122  scalar Pr = p/Pc_;
123  scalar Tr = T/Tc_;
124  scalar B = 0.07780*Pr/Tr;
125  scalar kappa = 0.37464 + 1.54226*omega_ - 0.26992*sqr(omega_);
126  scalar alpha = sqr(1 + kappa*(1 - sqrt(Tr)));
127 
128  scalar Z = this->Z(p, T);
129 
130  return
131  RR*Tc_
132  *(
133  Tr*(Z - 1)
134  - 2.078*(1 + kappa)*sqrt(alpha)
135  *log((Z + 2.414*B)/(Z - 0.414*B))
136  );
137 }
138 
139 
140 template<class Specie>
141 inline Foam::scalar Foam::PengRobinsonGas<Specie>::cp(scalar p, scalar T) const
142 {
143  scalar Tr = T/Tc_;
144  scalar a = 0.45724*sqr(RR*Tc_)/Pc_;
145  scalar b = 0.07780*RR*Tc_/Pc_;
146  scalar kappa = 0.37464 + 1.54226*omega_ - 0.26992*sqr(omega_);
147  scalar alpha = sqr(1 + kappa*(1 - sqrt(Tr)));
148 
149  scalar A = a*alpha*p/sqr(RR*T);
150  scalar B = b*p/(RR*T);
151 
152  scalar Z = this->Z(p, T);
153 
154  scalar ap = kappa*a*(kappa/Tc_ - (1 + kappa)/sqrt(T*Tc_));
155  scalar app = kappa*a*(1 + kappa)/(2*sqrt(pow3(T)*Tc_));
156 
157  scalar M = (sqr(Z) + 2*B*Z - sqr(B))/(Z - B);
158  scalar N = ap*B/(b*RR);
159 
160  const scalar root2 = sqrt(2.0);
161 
162  return
163  app*(T/(2*root2*b))*log((Z + (root2 + 1)*B)/(Z - (root2 - 1)*B))
164  + RR*sqr(M - N)/(sqr(M) - 2*A*(Z + B))
165  - RR;
166 }
167 
168 
169 template<class Specie>
170 inline Foam::scalar Foam::PengRobinsonGas<Specie>::s
171 (
172  scalar p,
173  scalar T
174 ) const
175 {
176  scalar Pr = p/Pc_;
177  scalar Tr = T/Tc_;
178  scalar B = 0.07780*Pr/Tr;
179  scalar kappa = 0.37464 + 1.54226*omega_ - 0.26992*sqr(omega_);
180 
181  scalar Z = this->Z(p, T);
182 
183  return
184  - RR*log(p/Pstd)
185  + RR
186  *(
187  log(Z - B)
188  - 2.078*kappa*((1 + kappa)/sqrt(Tr) - kappa)
189  *log((Z + 2.414*B)/(Z - 0.414*B))
190  );
191 }
192 
193 
194 template<class Specie>
195 inline Foam::scalar Foam::PengRobinsonGas<Specie>::psi
196 (
197  scalar p,
198  scalar T
199 ) const
200 {
201  scalar Z = this->Z(p, T);
202 
203  return 1.0/(Z*this->R()*T);
204 }
205 
206 
207 template<class Specie>
208 inline Foam::scalar Foam::PengRobinsonGas<Specie>::Z
209 (
210  scalar p,
211  scalar T
212 ) const
213 {
214  scalar Tr = T/Tc_;
215  scalar a = 0.45724*sqr(RR*Tc_)/Pc_;
216  scalar b = 0.07780*RR*Tc_/Pc_;
217  scalar kappa = 0.37464 + 1.54226*omega_ - 0.26992*sqr(omega_);
218  scalar alpha = sqr(1 + kappa*(1 - sqrt(Tr)));
219 
220  scalar A = a*alpha*p/sqr(RR*T);
221  scalar B = b*p/(RR*T);
222 
223  scalar a2 = B - 1;
224  scalar a1 = A - 2*B - 3*sqr(B);
225  scalar a0 = -A*B + sqr(B) + pow3(B);
226 
227  scalar Q = (3*a1 - a2*a2)/9.0;
228  scalar Rl = (9*a2*a1 - 27*a0 - 2*a2*a2*a2)/54.0;
229 
230  scalar Q3 = Q*Q*Q;
231  scalar D = Q3 + Rl*Rl;
232 
233  scalar root = -1;
234 
235  if (D <= 0)
236  {
237  scalar th = ::acos(Rl/sqrt(-Q3));
238  scalar qm = 2*sqrt(-Q);
239  scalar r1 = qm*cos(th/3.0) - a2/3.0;
240  scalar r2 = qm*cos((th + 2*constant::mathematical::pi)/3.0) - a2/3.0;
241  scalar r3 = qm*cos((th + 4*constant::mathematical::pi)/3.0) - a2/3.0;
242 
243  root = max(r1, max(r2, r3));
244  }
245  else
246  {
247  // One root is real
248  scalar D05 = sqrt(D);
249  scalar S = pow(Rl + D05, 1.0/3.0);
250  scalar Tl = 0;
251  if (D05 > Rl)
252  {
253  Tl = -pow(mag(Rl - D05), 1.0/3.0);
254  }
255  else
256  {
257  Tl = pow(Rl - D05, 1.0/3.0);
258  }
259 
260  root = S + Tl - a2/3.0;
261  }
262 
263  return root;
264 }
265 
266 
267 template<class Specie>
268 inline Foam::scalar Foam::PengRobinsonGas<Specie>::cpMcv
269 (
270  scalar p,
271  scalar T
272 ) const
273 {
274  scalar Tr = T/Tc_;
275  scalar a = 0.45724*sqr(RR*Tc_)/Pc_;
276  scalar b = 0.07780*RR*Tc_/Pc_;
277  scalar kappa = 0.37464 + 1.54226*omega_ - 0.26992*sqr(omega_);
278  scalar alpha = sqr(1 + kappa*(1 - sqrt(Tr)));
279 
280  scalar A = alpha*a*p/sqr(RR*T);
281  scalar B = b*p/(RR*T);
282 
283  scalar Z = this->Z(p, T);
284 
285  scalar ap = kappa*a*(kappa/Tc_ - (1 + kappa)/sqrt(T*Tc_));
286  scalar M = (sqr(Z) + 2*B*Z - sqr(B))/(Z - B);
287  scalar N = ap*B/(b*RR);
288 
289  return RR*sqr(M - N)/(sqr(M) - 2*A*(Z + B));
290 }
291 
292 
293 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
294 
295 template<class Specie>
296 inline void Foam::PengRobinsonGas<Specie>::operator+=
297 (
298  const PengRobinsonGas<Specie>& pg
299 )
300 {
301  scalar molr1 = this->nMoles();
302  Specie::operator+=(pg);
303 
304  molr1 /= this->nMoles();
305  scalar molr2 = pg.nMoles()/this->nMoles();
306 
307  Tc_ = molr1*Tc_ + molr2*pg.Tc_;
308  Vc_ = molr1*Vc_ + molr2*pg.Vc_;
309  Zc_ = molr1*Zc_ + molr2*pg.Zc_;
310  Pc_ = RR*Zc_*Tc_/Vc_;
311  omega_ = molr1*omega_ + molr2*pg.omega_;
312 }
313 
314 
315 template<class Specie>
316 inline void Foam::PengRobinsonGas<Specie>::operator-=
317 (
318  const PengRobinsonGas<Specie>& pg
319 )
320 {
321  scalar molr1 = this->nMoles();
322 
323  Specie::operator-=(pg);
324 
325  molr1 /= this->nMoles();
326  scalar molr2 = pg.nMoles()/this->nMoles();
327 
328  Tc_ = molr1*Tc_ - molr2*pg.Tc_;
329  Vc_ = molr1*Vc_ - molr2*pg.Vc_;
330  Zc_ = molr1*Zc_ - molr2*pg.Zc_;
331  Pc_ = RR*Zc_*Tc_/Vc_;
332  omega_ = molr1*omega_ - molr2*pg.omega_;
333 }
334 
335 
336 template<class Specie>
337 inline void Foam::PengRobinsonGas<Specie>::operator*=(const scalar s)
338 {
339  Specie::operator*=(s);
340 }
341 
342 
343 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
344 
345 
346 template<class Specie>
347 Foam::PengRobinsonGas<Specie> Foam::operator+
348 (
349  const PengRobinsonGas<Specie>& pg1,
350  const PengRobinsonGas<Specie>& pg2
351 )
352 {
353  scalar nMoles = pg1.nMoles() + pg2.nMoles();
354  scalar molr1 = pg1.nMoles()/nMoles;
355  scalar molr2 = pg2.nMoles()/nMoles;
356 
357  const scalar Tc = molr1*pg1.Tc_ + molr2*pg2.Tc_;
358  const scalar Vc = molr1*pg1.Vc_ + molr2*pg2.Vc_;
359  const scalar Zc = molr1*pg1.Zc_ + molr2*pg2.Zc_;
360 
362  (
363  static_cast<const Specie&>(pg1)
364  + static_cast<const Specie&>(pg2),
365  Tc,
366  Vc,
367  Zc,
368  RR*Zc*Tc/Vc,
369  molr1*pg1.omega_ + molr2*pg2.omega_
370  );
371 }
372 
373 
374 template<class Specie>
375 Foam::PengRobinsonGas<Specie> Foam::operator-
376 (
377  const PengRobinsonGas<Specie>& pg1,
378  const PengRobinsonGas<Specie>& pg2
379 )
380 {
381  scalar nMoles = pg1.nMoles() + pg2.nMoles();
382  scalar molr1 = pg1.nMoles()/nMoles;
383  scalar molr2 = pg2.nMoles()/nMoles;
384 
385  const scalar Tc = molr1*pg1.Tc_ + molr2*pg2.Tc_;
386  const scalar Vc = molr1*pg1.Vc_ + molr2*pg2.Vc_;
387  const scalar Zc = molr1*pg1.Zc_ + molr2*pg2.Zc_;
388 
390  (
391  static_cast<const Specie&>(pg1)
392  - static_cast<const Specie&>(pg2),
393  Tc,
394  Vc,
395  Zc,
396  RR*Zc*Tc/Vc,
397  molr1*pg1.omega_ - molr2*pg2.omega_
398  );
399 }
400 
401 
402 template<class Specie>
403 Foam::PengRobinsonGas<Specie> Foam::operator*
404 (
405  const scalar s,
406  const PengRobinsonGas<Specie>& pg
407 )
408 {
410  (
411  s*static_cast<const Specie&>(pg),
412  pg.Tc_,
413  pg.Vc_,
414  pg.Zc_,
415  pg.Pc_,
416  pg.omega_
417  );
418 }
419 
420 
421 template<class Specie>
422 Foam::PengRobinsonGas<Specie> Foam::operator==
423 (
424  const PengRobinsonGas<Specie>& pg1,
425  const PengRobinsonGas<Specie>& pg2
426 )
427 {
428  return pg2 - pg1;
429 }
430 
431 
432 // ************************************************************************* //
scalar cpMcv(scalar p, scalar T) const
Return (cp - cv) [J/(kmol K].
static autoPtr< PengRobinsonGas > New(Istream &is)
dimensionedScalar Pr("Pr", dimless, laminarTransport)
dictionary dict
dimensionedScalar acos(const dimensionedScalar &ds)
dimensionedScalar log(const dimensionedScalar &ds)
scalar cp(scalar p, scalar T) const
Return cp departure [J/(kmol K].
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
scalar h(const scalar p, const scalar T) const
Return enthalpy departure [J/kmol].
dimensionedScalar sqrt(const dimensionedScalar &ds)
void operator*=(const scalar)
const dimensionedScalar kappa
Coulomb constant: default SI units: [N.m2/C2].
autoPtr< PengRobinsonGas > clone() const
Construct and return a clone.
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))
scalar s(const scalar p, const scalar T) const
Return entropy [J/(kmol K)].
dimensionedScalar cos(const dimensionedScalar &ds)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
A class for handling words, derived from string.
Definition: word.H:59
scalar Z(scalar p, scalar T) const
Return compression factor [-].
scalar rho(scalar p, scalar T) const
Return density [kg/m^3].
PengRobinsonGas gas equation of state.
const dimensionedScalar Pstd
Standard pressure.
PengRobinsonGas(const Specie &sp, const scalar &Tc, const scalar &Vc, const scalar &Zc, const scalar &Pc, const scalar &omega)
Construct from components.
const volScalarField & T
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
dimensionedScalar pow3(const dimensionedScalar &ds)
#define R(A, B, C, D, E, F, K, M)
scalar psi(scalar p, scalar T) const
Return compressibility rho/p [s^2/m^2].
const dimensionedScalar a0
Bohr radius: default SI units: [m].
label N
Definition: createFields.H:22
dimensioned< scalar > mag(const dimensioned< Type > &)
const scalar RR
Universal gas constant (default in [J/(kmol K)])
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
#define M(I)