KP8108 project work: Calculation of partial derivatives of the
GERG-2004 equation of state using Matlab
Magnus G. Jacobsen
December 17, 2009
Contents
Contents 1
1 Introduction 2
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Intended use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 Scope of this report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Description of the GERG-2004 equation of state 4
3 Derivatives of A with respect to V and N 7
3.1 Negative pressure and chemical potential . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Derivatives of αr , αr
oi and αrij with respect to δ and xi . . . . . . . . . . . . . . . . . 7
4 Implementation in MATLAB, results 9
4.1 Rearranging expressions for αroi and αr
ij . . . . . . . . . . . . . . . . . . . . . . . . . 94.2 Importing parameters for the equation of state . . . . . . . . . . . . . . . . . . . . . 94.3 MATLAB call hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94.4 Differences between report and MATLAB code . . . . . . . . . . . . . . . . . . . . . 104.5 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.6 Initializing flash calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5 Conclusions and future work 16
5.1 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165.2 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
References 17
A Derivatives of reducing functions with respect to mole numbers 18
B MATLAB m-code 19
C Miscellaneous plots 24
1
1 Introduction
The GERG-2004 equation of state [1] is an equation of state (EOS) expressed in terms of Helmholtzenergy, A(T, V, N). It is intended as a reference equation of state for natural gas applications, over awide range of temperature and density. The equation of state was developed at the Ruhr-UniversitatBochum with support from the Groupe Europeen de Recherches Gazieres or GERG for short.
In this project work, the volume and mole number derivatives of the equation are coded inMatlab. This exercise is part of the course KP8108 Advanced Thermodynamics With Applicationsto Phase and Reaction Equilibria. The report contains the following:
1. A description of the equation of state and its derivatives with respect to volume and molenumbers
2. A description of how it has been implemented in MATLAB
3. Plots of various properties for given T and N
1.1 Background
The GERG-2004 equation of state is a rather complex equation of state, especially compared to cubicequations of state like the widely used Soave-Redlich-Kwong EOS [2]. The motivation for using suchcomplex equations of state is the need for very accurate calculations (especially of density) in thelow-temperature region. This is very important for example in the LNG business, where one needsto know the density of the liquefied natural gas to set the price correctly.
Having a very accurate equation of state available as a reference is also useful when one is usingother equations of state for calculation of different thermodynamic properties. A reference of goodquality over a large range of temperatures and pressures, for all relevant components, can be usedto assess the quality of other, simpler equations of state. According to [1] this was an importantmotivation for the work undertaken by the authors of [1].
1.2 Intended use
Within our group, we intend to use the GERG-2004 equation of state to study various problemsrelated to processes for liquefaction of natural gas. Regardless of choice of process, one has to dealwith heat transfer at low temperatures (as low as 114K, which is the boiling point of methane atatmospheric pressure) and with small temperature differences. A typical problem to study is thesteady-state solution of a multi-stream heat exchanger like the one shown in figure 1.
Figure 1: Typical three-stream heat exchanger with expansion valve
2
Here, the streams shown in red are the streams that reject heat whereas the stream in bluereceives heat. The ”warm” refrigerant typically enters at the same temperature as the natural gas,and has a similar temperature profile. In the valve, the refrigerant is let down to a smaller pressure,providing the desired temperature decrease. Solving the steady-state model of the heat exchangeris typically carried out by discretizing the entire exchanger into a finite number of intervals, andperforming a heat balance calculation over each interval. The heat transferred in each interval willdepend on the temperature in each stream within that interval, or at the boundaries of the interval(depending on the exact model formulation). Since phase transfer goes on throughout the exchanger,a number of flash calculations need to be carried out. Say the exchanger is discretized in 10 intervals,and the model is solved by iterating on temperatures. Then, at each iteration, 30 flash calculationshave to be performed. Whether this happens at given volume or given pressure again depends onthe model formulation.
Regardless of formulation, it is obvious that an inaccurate EOS can cause large errors whenone is operating with small temperature differences - especially when operating close to the Joule-Thompson inversion temperature of the gas. It is therefore in our interest to carry out calculationson a model of the system shown in figure 1 using the GERG-2004 EOS, and compare the results tothose obtained when using a cubic EOS like SRK or Peng-Robinson [3].
1.3 Scope of this report
This report, which is written as part of the course KP8108 Advanced Thermodynamics, is intendedto do the following:
1. To present the equation of state in a clear way, and show how to calculate the most importantderivatives
2. To describe the working process and the assumptions behind the MATLAB code which is themain result of this project
3. To show some simple calculations that will give an indication of the difficulty of applying theGERG-2004 EOS to the problem outlined above
3
2 Description of the GERG-2004 equation of state
The GERG-2004 equation of state is expressed in terms of the reduced Helmholtz energy α = AnRT
where n is the total mole number. We have the following expression 1:
α(δ, τ, x) = α0(ρ, T, x) + αr(δ, τ, x) (1)
The ideal part, α0, is equal to
α0(ρ, T, x) =
N∑
i=1
xi
[
α0oi(ρ, T ) + lnxi
]
(2)
The residual part, αr, is given by the following expression:
αr(δ, τ, x) =
N∑
i=1
xiαroi(δ, τ ) +
N−1∑
i=1
N∑
j=i+1
xixjFijαrij(δ, τ ) (3)
The variables δ and τ are defined as δ = ρρr
and τ = Tr
T respectively, with ρr and Tr beingfunctions of x.
The form of the functions αroi(δ, τ ) and αr
ij(δ, τ ) as well as the reducing functions Tr(x) and ρr(x)are given in equations 5, 6, 7 and 8.
The ideal Helmholtz energy of each component, α0oi, is given by the following expression:
α0oi(ρ, T ) =
R∗
R
[
log
(
ρ
ρc,i
)
+ n0oi,1 + n0
oi,2
(
Tc,i
T
)
+ n0oi,3 log
(
Tc,i
T
)]
+R∗
R
∑
k=4,6
n0oi,k log
(
sinh
(
υ0oi,k
Tc,i
T
))
−
∑
k=5,7
n0oi,k log
(
cosh
(
υ0oi,k
Tc,i
T
))
(4)
The GERG-2004 equation of state uses the same general form for the residual Helmholtz energiesof the individual components as the one suggested by Span and Wagner [4] - it can be written onthe form
αroi(δ, τ ) =
KP ol∑
k=1
npol,oi,kδdpol,oi,kτ tpol,oi,k +
KExp∑
k=1
nexp,oi,kδdexp,oi,kτ texp,oi,ke−δcexp,oi,k(5)
αrij(δ, τ ) =
KPol,ij+KExp,ij∑
k=1
nij,kδdij,kτ tij,ke−ηij,k(δ−εij,k)2−βij,k(δ−γij,k) (6)
For the KPol,ij first terms, the parameters η, ε, β and γ in equation 6 are all zero. This is dueto a slight modification of the parameter lists given in [1], where the number of coefficients (Kpol,Kexp) vary from component to component. Originally, equation 6 is also formulated as two sumslike equation 5. This is more closely explained in section 4.1.
To fully describe the system, we also need the expressions for the reducing functions:
1
ρr(x)=
N∑
i=1
x2i
1
ρc,i+
N−1∑
i=1
N∑
j=i+1
2xixjβν,ijγν,ijxi + xj
β2ν,ijxi + xj
1
8
(
1
ρ1/3c,i
+1
ρ1/3c,j
)3
(7)
Tr(x) =
N∑
i=1
x2i Tc,i +
N−1∑
i=1
N∑
j=i+1
2xixjβT,ijγT,ijxi + xj
β2T,ijxi + xj
(Tc,i · Tc,j)0.5
(8)
1Notice that ρ here means molar density - in [1] they use the unit moldm3
4
All parameters used in equations 3-8 are listed in [1]. 2
The developers of the equation of state claim that the normal range of validity is from 80 K to 450K, and for pressures up to 35 MPa. This covers more than the area necessary for LNG applications,where the pressures rarely exceed 4 MPa, and temperatures are usually in the range from 110 K (inthe cold end of the main heat exchanger) to 350 K (at compressor outlets). This means that theEOS is supposed to be accurate enough in the relevant range of temperatures and pressures.
As can be seen from the above equations, the model has many parameters compared to simplerequations of state. For example, the SRK EOS uses only three parameters for single-componentcalculations (critical pressure and temperature plus acentric factor). The GERG-2004 EOS has gotmore than 100 parameters per component as well as a large number of parameters for componentpairs. The total number of components for which parameters have been estimated is 18. Table 1shows the number of parameters per component and table 2 the number of parameters per componentpair.3
Table 1: Number of coefficients per componentCoefficient name Number of coefficients Used in equation
n0oi 7 4
υ0oi 7 4
npol,oi 7 5dpol,oi 7 5tpol,oi 7 5nexp,oi 18 5dexp,oi 18 5texp,oi 18 5cexp,oi 18 5
ρc 1 4, 7Tc 1 4, 8
Total 109 N/A
Table 2: Number of coefficients per component pairCoefficient name Number of coefficients Used in equation
nij 12 6dij 12 6tij 12 6ηij 12 6εij 12 6βij 12 6γij 12 6Fij 1 3βν,ij 1 7γν,ij 1 7βT,ij 1 8γT,ij 1 8Total 89 N/A
If we consider a system with 5 components, where all 10 possible pairs have nonzero Fij entries, weget no less than 2007 parameters, including critical temperature and density (but this also includes
2The fraction R∗
Ris included to correct for the fact that when the mixture model was developed, the developers
used a different value for the molar gas constant R - see page 104 in [1].3The coefficients used in equation 6 only apply to 15 component pairs, because only 15 elements of Fij in equation
3 are nonzero. For the reducing functions, all 153 possible pairs are taken into account
5
the zeros and ones used to fill in the tables). It is therefore important to be very systematic whenimporting the parameters into any application.
6
3 Derivatives of A with respect to V and N
In order to do equilibrium calculations, we need the derivatives −p = ( ∂A∂V )T,n and µ = (∂A
∂n )T,V .Since the equation of state is expressed in terms of δ, τ and x we need the partial derivatives ofthese with respect to V and N as well. Some of these partial derivatives are quite nasty, since δ andτ depend on x in a nonlinear manner.
3.1 Negative pressure and chemical potential
For negative pressure, defined as ∂A∂V
, we have (remember, ∂τ∂V
is obviously zero since τ does notdepend on V ):
∂A
∂V= ntotRT
[(
∂α0
∂(ρ/ρc,i)
)
T
(
∂(ρ/ρc,i)
∂V
)
x
+
(
∂αr
∂δ
)
τ
(
∂δ
∂V
)
n
]
(9)
The derivatives with respect to δ and xi are common for the −p and µ expressions and aresummarized in section 3.2. The remaining derivatives are (∂ρ/∂V )n and (∂δ/∂V )n, which are bothquite simple:
(
∂(ρ/ρc,i)
∂V
)
x
= −ntot
V 2·
1
ρc,i= −
ρ
V·
1
ρc,i(10)
When differentiating with respect to V , the reducing function for density, ρr, is constant sinceit is a function of x only.
(
∂δ
∂V
)
x
= −ntot
V 2·
1
ρr= −
ρ
V·
1
ρr(11)
The partial derivative of ideal Helmholtz energy with respect to density is very simple, since onlyone term in this expression contains the density (as can be seen from equation 4).
(
∂α0
∂(ρ/ρc,i)
)
T
=R∗
R·ρc,i
ρ(12)
For the chemical potentials, we have (with ∂ntot/∂ni = 1 and recalling that A = RT · ntotα):
(
∂A
∂ni
)
T,V,nj
= RT
(
∂nα
∂ni
)
T,V,nj
(13)
Splitting nα in its ideal and residual parts and differentiating each with respect to ni gives that
(
∂nα
∂ni
)
T,V,nj
= α0oi(ρ, T ) + 1 + lnxi + αr + ntot
(
∂αr
∂ni
)
T,V,nj
(14)
Being able to calculate the fugacity coefficient (ϕi) may also be necessary when doing equilibriumcalculations. The fugacity coefficient of component i can be expressed in the following way:
lnϕi =
(
∂nαr
∂ni
)
T,V,nj
− ln
[
1 + δ
(
∂αr
∂δ
)
τ
]
(15)
3.2 Derivatives of αr, αroi and αr
ij with respect to δ and xi
In this section, the derivatives needed to express the pressure, chemical potential and fugacitycoefficients are shown. The exception is the derivatives of the reducing functions Tr and ρr withrespect to mole numbers, these are shown in appendix A.4
4αrxi
=“
∂αr
∂xi
”
τ,δ,xj
7
n
(
∂αr
∂ni
)
T,V,nj
= δαrδ
[
1 −1
ρr· n
(
∂ρr
∂ni
)
nj
]
+ ταrτ
1
Tr· n
(
∂Tr
∂ni
)
nj
+ αrxi
−
N∑
k=1
xkαrxk
(16)
The derivatives of reducing functions with respect to ni (n(
∂ρr
∂ni
)
nj
and n(
∂Tr
∂ni
)
nj
) are shown
in appendix A.From equation 3 we get the derivatives of αr with respect to δ and xi:
(
∂αr
∂xi
)
τ,δ,xj
= αroi +
N∑
k=1,k 6=i
xkFikαrik (17)
(
∂αr
∂δ
)
τ,x
=
N∑
i=1
xi
(
∂αroi
∂δ
)
τ
+
N−1∑
i=1
N∑
j=i+1
xixjFij
(
∂αrij
∂δ
)
τ
(18)
Equations 17 and 18 are quite simple because αroi and αr
ij are not functions of x.Now we just need the derivatives of αr
oi and αrij with respect to δ. They are obtained by
differentiating equations 5 and 6. By doing this, we get the following expression for the individualcomponents (equation 19) and component pairs(equation 20):
(
∂αroi
∂δ
)
τ
=
KP ol,i∑
k=1
npoloi,kdpoloi,kδ(dpoloi,k−1)τ tpoloi,k +
KExp∑
k=1
nexpoi,kτ texpoi,kδ(dexpoi,k−1)(dexpoi,k − cexpoi,kδcexpoi,k)e−δcexpoi,k
(19)
(
∂αrij
∂δ
)
τ
=
KP ol,ij+KExp,ij∑
k=1
nij,kδdij,kτ tij,k exp(
−ηij,k(δ − εij,k)2 − βij,k(δ − γij,k))
[
dij,k
δ− 2ηij,k(δ − εij,k) − βij,k
]
(20)
8
4 Implementation in MATLAB, results
4.1 Rearranging expressions for αroi and αr
ij
In [1], equations 5 and 6 are both written as two sums - one from 1 to Kpol and one from Kpol + 1to Kpol + Kexp. Since the values of Kpol and Kexp varies from component to component (and fromcomponent pair to component pair), it was considered better to rewrite both in a simpler form, asthey are shown in section 2. The reason for letting equation 5 remain split, was that there is nogeneral choice of the parameter cexp,oi which will make e−δcexp,oi,k
= 1 for the Kpol first terms of thesum. This is easily done for equation 6, by setting η, ε, β and γ equal to zero for the polynomialterms.
4.2 Importing parameters for the equation of state
This was the most time-consuming task of the project; in [1], the parameters for equations 4-8 arelisted in a relatively compact form. Wherever possible, components with the same number of terms(equal Kpol and Kexp) have been joined into one table. As a result of this, the overall structure ofthe parameter list is not straight-forward. Therefore, a stepwise procedure was carried out:
1. The tables were copied manually from the PDF document into Excel spreadsheets and savedin .csv format
2. This resulted in one table per component for equations 4 and two per component for 5 (forexponential and polynomial coefficients), one table per component pair for equation 6 as wellas tables of critical parameters, a table representing the Fij matrix of equation 3, and tablesof the parameters for the reducing functions (equations 7 and 8)
3. Wherever necessary, the tables were filled in with zeros (in order to get the same value ofKpol for each component). This was done in a way that would ensure that where the originalformulation had fewer terms, the last terms would be zero, but at the same time avoidingdivisions by zero.
4.3 MATLAB call hierarchy
The MATLAB implementation of the equation of state is relatively simple, and consists of threeMATLAB m-files.
1. loadsort.m: Takes an 18-element vector of mole numbers as input (the total number ofcomponents for which coefficients are listed is 18. This file loads each of the .csv tables into theMATLAB workspace, identifies those who correspond to nonzero mole numbers, and arrangethese in arrays of size (ncoeff ×ncomp). Then the file outputs these arrays in a structure calledpar.
2. gergdiffs.m: This is the file which produces the derivatives. The inputs are temperature T,volume V, mole numbers N and the structure par produced by loadsort.m. The outputs arepressure, chemical potentials µi and the natural logarithm of the fugacity coefficients (lnϕi).
3. isotherm.m: This is a script used to produce plots of the outputs from gergdiffs.m. Withinthis script, the temperature, molar numbers and volume are defined, loadsort.m is run to loadthe coefficients and parameters, and gergdiffs.m is run for each combination of temperature,volume and mole numbers.
The files gergdiffs.m and isotherm.m are shown in appendix B.
9
4.4 Differences between report and MATLAB code
Some of the equations shown in this report are not written in exactly the same way inside gergdiffs.m;this is because there are more efficient ways of carrying out these calculations. For example, 4 and 5are not written with one expression per component; instead, they are written by element-wise opera-tions on the coefficient matrices, and then the sum is taken over the dimension corresponding to thecoefficients. The result is a vector of size ncomp. For equation 6 things are slightly more complex;instead of matrices we have three-dimensional arrays of size (ncomp × ncomp × (Kpol + Kexp)), andafter summation we get a matrix of size (ncomp × ncomp).
Also, equations 2 and 3 are expressed by matrix-vector multiplication instead of summation.
α0(ρ, T, x) = xT[
α0oi(ρ, T ) + lnx
]
(21)
αr(δ, τ, x) = xT αroi(δ, τ ) + xT (Fij ⊗ αr
ij(δ, τ ))x (22)
In equations 21 and 22, α0oi(ρ, T ), lnx and αr
oi(δ, τ ) are vectors, Fij and αrij(δ, τ ) are matrices
and ⊗ symbolizes multiplication element by element.
4.5 Results
The figures following show various isotherms for pure methane and for a mixture of methane, nitro-gen, ethane and propane. All are for a total mole number of 1 kmol.
Figure 2 shows isotherms for pure methane at temperatures from 180K to 195K (the criticaltemperature of methane is 190.5640K). The non-cubic behaviour of the equation of state becomesclearly visible at the lowest temperature, where we observe that the curve has two distinct localminima. When the temperature is further lowered, these minima become more distinct and thecurve will eventually go below zero provided the temperature is low enough.
Figure 3 shows a comparison of the critical isotherm for methane for the GERG-2004 equationof state and the Soave-Redlich-Kwong (SRK) EOS. The data used for the SRK equation of stateare taken from [5]. To further illustrate the difference between the cubic SRK equation and theGERG-2004 equation at intermediate molar volumes, the isotherms for 180K are also included, seefigure 4. Finally, isotherms for a mixture consisting of 40 % methane, 10 % nitrogen, 40 % ethaneand 10 % propane are shown for four temperatures in the range from 225K to 262.5K - see figure 5.
102
104
105
Volume (dm3)
Pressure (kPa)
T = 180 K
T = 185 K
T = 190 K
T = 195 K
Figure 2: Isotherms for pure methane at 180, 185, 190 and 195 K
10
102
104
105
Volume (dm3)
Pressure (kPa)
GERG−2004
SRK
Figure 3: Critical isotherms for methane
102
104
105
Volume (dm3)
Pressure (kPa)
GERG−2004
SRK
Figure 4: GERG-2004 and SRK isotherms at 180 K
11
102
103
104
105
Volume (dm3)
Pressure(kPa)
225K
237.5K
250K
262.5K
Figure 5: Isotherms at 225, 237.5, 250 and 262.5 K for a mixture of methane, ethane, propane andnitrogen
In figure 6, a plot of lnϕ versus P is shown. As one would expect from the shape of the pressure-volume curve (figure 4), the curve crosses itself several times. Figure 7 shows a similar plot forthe chemical potential (µ). If one traces both graphs from the right (high pressure) towards theleft, the point at which the curve first crosses itself is at the same pressure in the two figures. Itcorresponds to the fugacity coefficient (or chemical potential) at the point where vapour and liquidare in equilibrium with each other.
If the temperature is lowered further, the p−µ curve crosses itself even more times, as can be seenin figure 8. In this plot one can spot six solutions to the equilibrium problem p1 = p2, µ1 = µ2. Onlyone of these will correspond to a true vapour-liquid equilibrium. The pressure and volume valuesat the six intersections in figure 8 are shown in table 3, in the order they appear when the curve istraced from small volumes (large pressures). For illustrative purposes, figure 9 shows the volumesand pressure for the point marked 1 in figure 8. For the point 2-6, corresponding pressure-volumecurves are included in appendix ??.
Table 3: Intersections in figure 8, pressure and volume valuesp (kPa) V1 (dm3) V2 (dm3)
2777 54.35 95.512336 55.19 100.82258 55.36 125.62559 76.43 138.22894 78.17 301.02861 94.68 309.2
4.6 Initializing flash calculations
When carrying out a two-phase flash calculation at given (T, V, N), the equilibrium conditions are:
p1 = p2
(µ1) = (µ2)(23)
Here, µ is a vector of chemical potentials and 1 and 2 refer to the two phases. As we can seefrom figure 8, at 175K there are 6 solutions to this problem, even for a single component where it
12
2000 2500 3000 3500 4000 4500−0.55
−0.5
−0.45
−0.4
−0.35
−0.3
−0.25
−0.2
−0.15
−0.1
−0.05
Pressure (kPa)
ln(phi)
Figure 6: lnϕ versus P for methane at 180 K
2000 2500 3000 3500 4000 45003300
3400
3500
3600
3700
3800
3900
Pressure (kPa)
mu (J/mol)
Figure 7: Chemical potential for methane (µCH4) versus pressure at 180 K
13
1000 1500 2000 2500 3000 3500
3000
3050
3100
3150
3200
3250
3300
3350
3400
3450
3500
Pressure (kPa)
Chemical potential (J/mol)
1
46
5
32
Figure 8: µ against P for methane at 175 K
102
103
103
104
105
Volume (dm3)
Volumes correspondingto thepointlabeled "1" in p−mu plot
Figure 9: Pressure-volume curve at 175 K with point 1 shown
14
is obvious that there is only one possible solution. This means it is critical to have a good initialguess for any iterative solution of the flash problem. [1] do not address this problem directly, but forthe problem where density is to be calculated at given pressure (where the non-monotonic nature ofthe isotherm causes similar problems) they suggest using the Peng-Robinson EOS to provide initialguesses. In their report, they have included comparisons of GERG-2004, Peng-Robinson and otherequations of state to experimental data, and densities calculated by the Peng-Robinson equationsof state are shown to be somewhat higher than those calculated by GERG-2004.
15
5 Conclusions and future work
5.1 Conclusions
A simple implementation of the GERG-2004 equation of state has been carried out in Matlab andtested by plotting isotherms for different components and temperatures. The most time-consumingjob was to make the tables containing the coefficients of equations 4-8 workable. Some effort hasalso been made in writing some of the equations in a simpler form within Matlab than the form theyare formulated here (for example, many sum expressions were possible to replace with matrix-vectormultiplication).
For pure methane, the chemical potential (µ) and the logarithm of the fugacity coefficient (lnϕ)have been plotted against pressure, and the isotherms calculated by the GERG-2004 equation ofstate have been compared to isotherms calculated using the Soave-Redlich-Kwong equation of state.
The presence of multiple crossings in the plots of chemical potential against pressure (figure7) indicate that flash calculations may be difficult, as there are multiple solutions (at constanttemperature, equilibrium is defined by equal pressure and equal chemical potential in the phasesthat are present).
5.2 Future work
It is a goal of future work to include the reference equation of state in steady-state models ofLNG plants, to compare with the results one obtains using cubic equations of state (typically Soave-Redlich-Kwong, Peng-Robinson). Liquefaction processes for natural gas involve phase transfer at lowtemperatures (down to 116K which is the boiling temperature of CH4 at atmospheric pressure). Atthese temperatures, which are also close to the Joule-Thompson inversion temperature of methane inthe pressure range of interest, it is crucial to have an accurate thermodynamic model. Carrying outsimulations with a model especially made for this type of systems, will give a better understandingof how precise (or imprecise) the far simpler cubic equations of state are.
An especially interesting problem could be heat curve generation for the cold end of LNG heatexchangers, where heat exchange between more than two two-phase streams takes place at smalltemperature differences (∆Tmin ≈ 1K). With this small temperature differences, small differencesin the flash calculation can be significant.
16
References
[1] Kunz, O., Klimeck, R., Wagner, W., Jaeschke, M.: ”The GERG-2004 Wide-RangeEquation of State for Natural Gases and Other Mixtures”
[2] Soave, G.: ”Equilibrium constants from a modified Redlich-Kwong equation ofstate”, Chemical Engineering Science, 1972, vol. 27, pp. 1197-1203.
[3] Y. Peng, D. B. Robinson: ” A New Two-Constant Equation of State”, Ind. Eng.Chem. Fundam. 15 (1976) p. 59
[4] Span, R., Wagner, W.: ”Equations of State for Technical Applications. II. Resultsfor Nonpolar Fluids”, Int. Journ. of Thermophysics, Vol. 24, No. 1, January 2003
[5] Green, Don W,; Perry, Robert H.: ”Perry’s Chemical Engineers Handbook (8thEdition)”, McGraw-Hill (2007)
17
A Derivatives of reducing functions with respect to mole
numbers
n
(
∂ρr
∂ni
)
nj
=
(
∂ρr
∂xi
)
xj
−
N∑
k=1
xk
(
∂ρr
∂xk
)
xj
, with
(
∂ρr
∂xk
)
xj
= −ρ2r
(
∂(1/ρr)
∂xk
)
xj
(24)
n
(
∂Tr
∂ni
)
nj
=
(
∂Tr
∂xi
)
xj
−
N∑
k=1
xk
(
∂Tr
∂xk
)
xj
(25)
Next are the individual derivatives with respect to xk - these are quite complex:
(
∂Yr
∂xi
)
xj
= 2xiYc,i +
i−1∑
k=1
cY,ki∂fY,ki(xk, xi)
∂xi+
N∑
k=i+1
cY,ik∂fY,ik(xi, xk)
∂xi(26)
In this equation, fY,ij(xi, xj) = xixjxi+xj
β2
Y,ijxi+xjand cY,ij = 2βY,ijγY,ijYc,ij where Yc,ij is either
18
(
1
ρ1/3
c,i
+ 1
ρ1/3
c,j
)3
or (Tc,i · Tc,j)0.5
.
We now need to express the partial derivatives inside equation 26 in terms of xi and xj.
(
∂fY,ki(xk, xi)
∂xi
)
xk
= xkxk + xi
β2Y,kixk + xi
+ xkxi1
β2Y,kixk + xi
(
1 −xk + xi
β2Y,kixk + xi
)
(27)
(
∂fY,ik(xi, xk)
∂xi
)
xk
= xkxk + xi
β2Y,ikxi + xk
+ xixk1
β2Y,ikxi + xk
(
1 − β2Y,ik
xk + xi
β2Y,ikxi + xk
)
(28)
The different parameters βY,ij and γY,ij used in equations 7, 8 and 26-28 are also given in [1].The index Y is replaced by ν for the density reducing function and T for the temperature reducingfunction. It is important to notice that we are doing summation over upper triangular matrices -when we are dealing with both (xi, xj) and (xj, xi, as in the above equations, i and j are such thatwe remain above the main diagonal.
18
B MATLAB m-code
1 function [p ln fi mu] = gergdiffs(V,T,N,par)
2 %negp Calculate −p(V,T,N1,...) = (@A/@V) t,n1,... from the GERG
3 %equation of state. Output will be in kPa.
4
5 % Input:
6 % Volume (in dm3)
7 % Temperature (in K)
8 % Mole numbers (in mol)
9
10 % This file takes V, T and the 18−element vector N and calculates the
11 % volume derivative of the Helmholtz energy A. This involves calculation of
12 % the reducing functions Tr and Rhor, as well as pertial derivatives of the
13 % individual contributions to A.
14
15 %Calculate molar fractions
16
17 N=N(:) ;
18 x = N/sum(N) ;
19
20 %Identify the nonzero elements of N
21
22 [i x j x xnz] = find(x) ; % Get the indices for the nonzero molar amounts
23
24 x = xnz ; %From here on, work with only nonzero elements of z
25
26 Tc = par.Tc ;
27 mw = par.mw; %#ok<NASGU>
28 rhoc = par.rhoc;
29
30 n ideal = par.n ideal ;
31 upsilon ideal = par.upsilon ideal;
32
33 nexp = par.nexp;
34 cexp = par.cexp;
35 dexp = par.dexp;
36 texp = par.texp;
37
38 npol = par.npol;
39 dpol = par.dpol;
40 tpol = par.tpol;
41
42 F = par.F ;
43 dij = par.dij ;
44 tij = par.tij ;
45 nij = par.nij ;
46 etaij = par.etaij ;
47 epsilonij = par.epsilonij ;
48 betaij = par.betaij ;
49 gammaij = par.gammaij ;
50
51 beta vij = par.beta vij;
52 beta tij = par.beta tij;
53 gamma vij = par.gamma vij;
54 gamma tij = par.gamma tij;
55
56 R = par.R ;
57 Rmod = par.Rmod ;
58
59 %Now, calculate reducing functions (Tr, rhor)
60
61 rr = (x.ˆ2)'*(1./rhoc) ; % "ii" contribution to reducing density
62 Tr = (x.ˆ2)'*Tc ;
63
64 if length(x) > 1
19
65 for i=1:(length(x)−1)
66 for j=(i+1):length(x)
67 rr ij = 2*x(i)*x(j)*beta vij(i,j)*gamma vij(i,j)*((x(i)+x(j))/...
68 ((beta vij(i,j)ˆ2)*x(i)+x(j)))*(1/8)*(1/(rhoc(i)ˆ(1/3)) + ...
69 1/(rhoc(j)ˆ(1/3)))ˆ3 ;
70 Tr ij = 2*x(i)*x(j)*beta tij(i,j)*gamma tij(i,j)*((x(i)+x(j))/...
71 ((beta tij(i,j)ˆ2)*x(i)+x(j)))*(Tc(i)*Tc(j))ˆ0.5 ;
72 rr = rr+rr ij ; % Add contribution from pair ij to total
73 Tr = Tr + Tr ij ;
74 end
75 end
76 end
77 %Calculate reduced temperature and reduced density
78
79 rho = sum(N)/V ; % Molar density in mol/dm3
80 ∆ = rho*rr ;
81 tau = Tr/T ;
82
83 %Calculate the derivatives of ideal and residual Helmholtz energy
84 % as well as derivatives of ∆ and rho
85
86 drhoi dV = −(rho./rhoc)/V ; % rhoi = rho/rhoc
87 d∆ dv = −∆/V ;
88
89 %Calculate ideal Helmholtz energy, alfa id, and residual Helmholtz energy, alfar
90
91 alfa id i = (Rmod/R)*(log(rho./rhoc)' + n ideal(1,:) + n ideal(2,:).*(Tc/T)' + ...
92 n ideal(3,:).*log(Tc/T)' + n ideal(4,:).*(log(sinh(upsilon ideal(4,:).*(Tc/T)'))) ...
93 + n ideal(6,:).*(log(sinh(upsilon ideal(6,:).*(Tc/T)'))) − ...
94 n ideal(5,:).*(log(cosh(upsilon ideal(5,:).*(Tc/T)'))) − ...
95 n ideal(7,:).*(log(cosh(upsilon ideal(7,:).*(Tc/T)')))) ;
96
97 %alfa id = (alfa id i+log(x)')*x ; % Ideal Helmholtz energy for the mixture
98
99 alfar oi = sum((npol.*(∆.ˆdpol).*tau.ˆtpol),1) + ...
100 sum(nexp.*(tau.ˆtexp).*(∆.ˆdexp).*(exp(−∆.ˆcexp)),1);
101 alfar ij = sum(((nij.*(∆.ˆdij).*tau.ˆtij).*exp(−etaij.*((∆ − epsilonij).ˆ2) ...
102 − betaij.*(∆ − gammaij))),3) ;
103
104 alfar = alfar oi*x + x'*(F.*alfar ij)*x;
105
106 %Derivative of ideal Helmholtz energy w.r.t. density
107
108 dalfa 0 drhoi = (Rmod*rhoc/(R*rho)) ;
109
110 % Derivative of residual Helmholtz energy for individual components a r oi
111
112 dalfar oi d∆ = sum((npol.*dpol.*(∆.ˆ(dpol−1)).*tau.ˆtpol),1)+...
113 sum(nexp.*(tau.ˆtexp).*(∆.ˆ(dexp−1)).*((dexp − cexp.*∆.ˆcexp).*(exp(−∆.ˆcexp))),1) ;
114 % Do the calculation element−wise, then for each component take the sum of the corresponding column.
115 %The result is a vector of length ncomp
116
117 % Derivative of residual Helmholtz energy departure function a r ij w.r.t.
118 % ∆
119
120 dalfar ij d∆ = sum(((nij.*(∆.ˆdij).*tau.ˆtij).*exp(−etaij.*((∆ − epsilonij).ˆ2)...
121 − betaij.*(∆ − gammaij)).*(dij./∆ − 2*etaij.*(∆ − epsilonij)−betaij)),3) ;
122 % Same as above − the result is a matrix of size ncomp*ncomp
123
124 dalfa dV = (x'*(dalfa 0 drhoi.*drhoi dV)) + ((dalfar oi d∆.*d∆ dv)*x)...
125 + (x'*(F.*dalfar ij d∆.*d∆ dv)*x) ; % Sum together contributions
126 %dalfa dV ideal = (x'*(dalfa 0 drhoi.*drhoi dV)) ;
127
128 dA dV = sum(N)*Rmod*T*dalfa dV ; % Unit: kPa
129 p = −dA dV ;
130 %dA dV ideal = sum(N)*Rmod*T*dalfa dV ideal ; % Unit: kPa
131
132 %Now to the slightly more ugly stuff. For fugacity coefficients, we must
20
133 %calculate first derivatives with respect to mole numbers. This means we
134 %also need first derivatives of residual Helmholtz energy with respect to
135 %mole numbers/ fractions.
136
137 dalfar oi dtau = sum((npol.*tpol.*(∆.ˆdpol).*tau.ˆ(tpol−1)),1) + ...
138 sum(nexp.*texp.*(tau.ˆ(texp−1)).*(∆.ˆdexp),1) ;
139 dalfar ij dtau = sum(((nij.*(∆.ˆdij).*tij.*(tau.ˆ(tij−1))).*...
140 exp(−etaij.*((∆ − epsilonij).ˆ2) − betaij.*(∆ − gammaij))),3) ;
141
142 dalfar d∆ = dalfar oi d∆*x + x'*(F.*dalfar ij d∆)*x ;
143 dalfar dtau = dalfar oi dtau*x + x'*(F.*dalfar ij dtau)*x ;
144 dalfar dx = alfar oi' + (F.*alfar ij)*x ;
145
146 % Exception; If we have one component only, we don't need the composition
147 % derivatives.
148
149 if length(x) < 2
150 ln fi = (alfar + ∆*dalfar d∆) − log(1+∆*dalfar d∆) ;
151 mu = R*T*((alfa id i + 1)+(alfar + ∆*dalfar d∆)) ; %Residual chemical potential
152 elseif length(x) ≥ 2
153
154 % If we have two components or more, we need to calculate derivatives of rr
155 % and Tr with respect to composition.
156
157 %Calculate the ugly, ugly derivatives from table 7.10
158
159 dTr dx = 2*x.*Tc ;
160 d invrr dx = (2*x).*(1./rhoc) ;
161
162 for i=1:length(x)
163 if i == 1 % If at first component, only the last sum is needed
164 for j=(i+1):length(x)
165 dTr dx(i) = dTr dx(i) + 2*beta tij(i,j)*gamma tij(i,j)*((Tc(i)*Tc(j))ˆ0.5)...
166 *(x(j)*(x(i)+x(j))/(beta tij(i,j)ˆ2*x(i) + x(j)) +(x(i)*x(j)*...
167 1/(beta tij(i,j)ˆ2*x(i) + x(j)))*(1 − beta tij(i,j)ˆ2*(x(i)+x(j))/...
168 (beta tij(i,j)ˆ2*x(i) + x(j)))) ; % Add j'th term
169 d invrr dx(i) = d invrr dx(i) + 2*beta vij(i,j)*gamma vij(i,j)*...
170 ((1/8)*(1/(rhoc(i)ˆ(1/3)) + 1/(rhoc(j)ˆ(1/3)))ˆ3)*...
171 (x(j)*(x(i)+x(j))/(beta vij(i,j)ˆ2*x(i) + x(j)) +...
172 (x(i)*x(j)*1/(beta vij(i,j)ˆ2*x(i) + x(j)))*(1 − beta vij(i,j)ˆ2*...
173 (x(i)+x(j))/(beta vij(i,j)ˆ2*x(i) + x(j)))) ; %Add j'th term
174 end
175 elseif i>1 && i<length(x) % If not at the first or last component, we must sum both below and above i
176 for j = 1:(i−1)
177 dTr dx(i) = dTr dx(i) + (2*beta tij(j,i))*gamma tij(j,i)*((Tc(i)*Tc(j))ˆ0.5)...
178 *(x(j)*(x(i)+x(j))/(beta tij(j,i)ˆ2*x(j) + x(i)) +(x(j)*x(i)...
179 *1/(beta tij(j,i)ˆ2*x(j)+ x(i)))*(1 − (x(j)+x(i))/...
180 (beta tij(j,i)ˆ2*x(j) + x(i)))) ; % Add j'th term
181 d invrr dx(i) = d invrr dx(i) + (2*beta vij(j,i))*gamma vij(j,i)*...
182 ((1/8)*(1/(rhoc(i)ˆ(1/3)) + 1/(rhoc(j)ˆ(1/3)))ˆ3)*...
183 (x(j)*(x(i)+x(j))/(beta vij(j,i)ˆ2*x(j) + x(i))...
184 +(x(j)*x(i)*1/(beta vij(j,i)ˆ2*x(j) + x(i)))*...
185 (1 − (x(j)+x(i))/(beta vij(j,i)ˆ2*x(j) + x(i)))); %Add j'th term
186 end
187 for j = (i+1):length(x)
188 dTr dx(i) = dTr dx(i) + 2*beta tij(i,j)*gamma tij(i,j)*((Tc(i)*Tc(j))ˆ0.5)...
189 *(x(j)*(x(i)+x(j))/(beta tij(i,j)ˆ2*x(i) + x(j)) +(x(i)*x(j)*...
190 1/(beta tij(i,j)ˆ2*x(i)+ x(j)))*(1 − beta tij(i,j)ˆ2*(x(i)+x(j))/...
191 (beta tij(i,j)ˆ2*x(i) + x(j)))) ; % Add j'th term
192 d invrr dx(i) = d invrr dx(i) + 2*beta vij(i,j)*gamma vij(i,j)*...
193 ((1/8)*(1/(rhoc(i)ˆ(1/3))+ 1/(rhoc(j)ˆ(1/3)))ˆ3)*...
194 (x(j)*(x(i)+x(j))/(beta vij(i,j)ˆ2*x(i) + x(j))...
195 +(x(i)*x(j)*1/(beta vij(i,j)ˆ2*x(i) + x(j)))*...
196 (1 − beta vij(i,j)ˆ2*(x(i)+x(j))/(beta vij(i,j)ˆ2*x(i) + x(j)))) ; %Add j'th term
197 end
198
199 elseif i == length(x)
200 for j = 1:(i−1)
21
201 dTr dx(i) = dTr dx(i) + (2*beta tij(j,i))*gamma tij(j,i)*...
202 ((Tc(i)*Tc(j))ˆ0.5)*(x(j)*(x(i)+x(j))/(beta tij(j,i)ˆ2*x(j) + x(i))...
203 +(x(j)*x(i)*1/(beta tij(j,i)ˆ2*x(j) + x(i)))*(1 − (x(j)+x(i))/...
204 (beta tij(j,i)ˆ2*x(j) + x(i)))) ; % Add j'th term
205 d invrr dx(i) = d invrr dx(i) + (2*beta vij(j,i))*gamma vij(j,i)*...
206 ((1/8)*(1/(rhoc(i)ˆ(1/3))+ 1/(rhoc(j)ˆ(1/3)))ˆ3)*(x(j)*(x(i)+x(j))/...
207 (beta vij(j,i)ˆ2*x(j) + x(i))+(x(j)*x(i)*1/(beta vij(j,i)ˆ2*x(j) + x(i)))...
208 *(1 − (x(j)+x(i))/(beta vij(j,i)ˆ2*x(j) + x(i) ))); %Add j'th term
209 end
210 end %End of "if" loop
211 end %End of outer "for" loop
212
213 d rr dx = −(1/rrˆ2)*d invrr dx ;
214 n drr dn = d rr dx − x'*d rr dx ;
215 n dTr dn = dTr dx − x'*dTr dx ;
216
217 n dalfar dni = zeros(length(x),1);
218 for i=1:length(x)
219 n dalfar dni(i) = ∆*dalfar d∆*(1−rr*n drr dn(i)) + ...
220 tau*dalfar dtau*(1/Tr)*n dTr dn(i) + dalfar dx(i) − x'*dalfar dx ;
221 end
222
223 dn alfa0 dni = alfa id i' + 1 + log(x) ;
224 dnalfar dni = alfar + n dalfar dni ;
225
226 mu = R*T*(dn alfa0 dni + dnalfar dni) ; %Vector of chemical potentials
227 ln fi = dnalfar dni − log(1+∆*dalfar d∆) ; %Vector of ln fugacity coefficients
228 end
229
230 end
22
1 %Create isotherms of the GERG equation of state and (if desired) SRK equation of state
2
3 % par.CH4.Tc = 190.564;
4 % par.CH4.Pc = 4.59e6 ;
5 % par.CH4.acentric = 0.0115 ;
6
7 close all
8 clear all
9
10 T = 180.5640 ; % Tc ch4 − 10 K ;
11 Ntot = 1000 ; % mol
12
13 ind = [1 2 4 5] ; % Methane, nitrogen, ethane, propane
14 x = [1 0 0 0] ;
15 N=zeros(18,1);
16 N(ind) = Ntot*x ;
17
18 par = loadsort(N) ;
19
20 V = logspace(1.5,3.5,1000);
21 p=zeros(length(T),length(V));
22
23 if nnz(x) ==1 % We want potential and ln fi if we have single component
24 mu = zeros(length(T),length(V)) ;
25 ln fi = zeros(length(T),length(V)) ;
26
27 %psrk=p ;
28 for i = 1:length(T)
29 for j = 1:length(V)
30 [p(i,j) ln fi(i,j) mu(i,j)] = gergdiffs(V(j),T(i),N,par) ; %Ask for fi and mu if one component only
31 %psrk(i,j) = p srk(V(j),T(i),N,par.CH4) ; % Only valid for pure methane
32 end
33 end
34 figure(2), plot(p,ln fi) ;
35 figure(3), plot(p,mu) ;
36 else
37 for i = 1:length(T)
38 for j = 1:length(V)
39
40 [p(i,j)] = gergdiffs(V(j),T(i),N,par) ; % For multicomponent, retrieve pressure only
41
42 %psrk(i,j) = p srk(V(j),T(i),N,par.CH4) ; % Only valid for pure methane
43 end
44 end
45 end %End of IF loop
46
47 if min(min(p)) < 0
48 figure(1),plot(V,p) ;
49 else
50 figure(1), loglog(V,p);
51 end
23
C Miscellaneous plots
102
103
103
104
105
Volume (dm3)
Pressure (kPa)
Volumes correspondingto thepointlabeled "2" in p−mu plot
Figure 10: Pressure-volume curve at 175 K with point 2 shown
24
102
103
103
104
Volume (dm3)
Pressure (kPa)
Volumes correspondingto the point labeled "3" in p−mu plot
Figure 11: Pressure-volume curve at 175 K with point 3 shown
102
103
103
104
105
Volume (dm3)
Pressure (kPa)
Volumes correspondingto the point labeled "4" in p−mu plot
Figure 12: Pressure-volume curve at 175 K with point 4 shown
25
102
103
103
104
105
Volume (dm3)
Pressure (kPa)
Volumes correspondingto the point labeled "5" in p−mu plot
Figure 13: Pressure-volume curve at 175 K with point 5 shown
102
103
103
104
105
Volume (dm3)
Pressure (kPa)
Volumes correspondingto the point labeled "6" in p−mu plot
Figure 14: Pressure-volume curve at 175 K with point 6 shown
26