Calculation of partial derivatives of the GERG

advertisement
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
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 Intended use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Scope of this report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
2
2
3
2 Description of the GERG-2004 equation of state
4
3 Derivatives of A with respect to V and N
3.1 Negative pressure and chemical potential . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Derivatives of αr , αroi and αrij with respect to δ and xi . . . . . . . . . . . . . . . . .
7
7
7
4 Implementation in MATLAB, results
4.1 Rearranging expressions for αroi and αrij . . . .
4.2 Importing parameters for the equation of state
4.3 MATLAB call hierarchy . . . . . . . . . . . . .
4.4 Differences between report and MATLAB code
4.5 Results . . . . . . . . . . . . . . . . . . . . . . .
4.6 Initializing flash calculations . . . . . . . . . . .
.
.
.
.
.
.
9
9
9
9
10
10
12
5 Conclusions and future work
5.1 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16
16
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 Helmholtz
energy, A(T, V, N ). It is intended as a reference equation of state for natural gas applications, over a
wide range of temperature and density. The equation of state was developed at the Ruhr-Universität
Bochum with support from the Groupe Européen de Recherches Gazières or GERG for short.
In this project work, the volume and mole number derivatives of the equation are coded in
Matlab. This exercise is part of the course KP8108 Advanced Thermodynamics With Applications
to 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 mole
numbers
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 cubic
equations of state like the widely used Soave-Redlich-Kwong EOS [2]. The motivation for using such
complex equations of state is the need for very accurate calculations (especially of density) in the
low-temperature region. This is very important for example in the LNG business, where one needs
to 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 using
other equations of state for calculation of different thermodynamic properties. A reference of good
quality over a large range of temperatures and pressures, for all relevant components, can be used
to assess the quality of other, simpler equations of state. According to [1] this was an important
motivation 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 problems
related to processes for liquefaction of natural gas. Regardless of choice of process, one has to deal
with heat transfer at low temperatures (as low as 114K, which is the boiling point of methane at
atmospheric pressure) and with small temperature differences. A typical problem to study is the
steady-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 blue
receives 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 exchanger
is typically carried out by discretizing the entire exchanger into a finite number of intervals, and
performing a heat balance calculation over each interval. The heat transferred in each interval will
depend 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 calculations
have to be performed. Whether this happens at given volume or given pressure again depends on
the model formulation.
Regardless of formulation, it is obvious that an inaccurate EOS can cause large errors when
one is operating with small temperature differences - especially when operating close to the JouleThompson inversion temperature of the gas. It is therefore in our interest to carry out calculations
on a model of the system shown in figure 1 using the GERG-2004 EOS, and compare the results to
those 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 intended
to do the following:
1. To present the equation of state in a clear way, and show how to calculate the most important
derivatives
2. To describe the working process and the assumptions behind the MATLAB code which is the
main result of this project
3. To show some simple calculations that will give an indication of the difficulty of applying the
GERG-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 α =
where n is the total mole number. We have the following expression 1 :
α(δ, τ, x) = α0 (ρ, T, x) + αr (δ, τ, x)
A
nRT
(1)
The ideal part, α0 , is equal to
α0 (ρ, T, x) =
N
X
i=1
xi α0oi (ρ, T ) + ln xi
(2)
The residual part, αr , is given by the following expression:
αr (δ, τ, x) =
N
X
xi αroi (δ, τ ) +
i=1
N−1
X
N
X
xi xj Fij αrij (δ, τ )
(3)
i=1 j=i+1
The variables δ and τ are defined as δ = ρρr and τ = TTr respectively, with ρr and Tr being
functions of x.
The form of the functions αroi (δ, τ ) and αrij (δ, τ ) 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:
ρ
Tc,i
Tc,i
R∗
0
0
0
=
log
+ noi,1 + noi,2
+ noi,3 log
R
ρc,i
T
T


X
R∗  X 0
T
T
c,i
c,i
0
0

+
noi,k log sinh υoi,k
−
n0oi,k log cosh υoi,k
R
T
T
α0oi (ρ, T )
k=4,6
(4)
k=5,7
The GERG-2004 equation of state uses the same general form for the residual Helmholtz energies
of the individual components as the one suggested by Span and Wagner [4] - it can be written on
the form
αroi (δ, τ ) =
K
P ol
X
KExp
npol,oi,k δ dpol,oi,k τ tpol,oi,k +
k=1
X
nexp,oi,k δ dexp,oi,k τ texp,oi,k e−δ
cexp,oi,k
(5)
k=1
KP ol,ij +KExp,ij
αrij (δ, τ )
=
X
nij,k δ dij,k τ tij,k e−ηij,k (δ−εij,k )
2
−βij,k (δ−γij,k )
(6)
k=1
For the KP ol,ij first terms, the parameters η, ε, β and γ in equation 6 are all zero. This is due
to 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 sums
like 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:
N
N−1
N
X
X X
1
1
xi + xj 1
=
x2i
+
2xi xj βν,ij γν,ij 2
ρr (x)
ρc,i
βν,ij xi + xj 8
i=1
Tr (x) =
N
X
i=1
1 Notice
i=1 j=i+1
x2i Tc,i +
N−1
X
N
X
2xi xj βT ,ij γT ,ij
i=1 j=i+1
that ρ here means molar density - in [1] they use the unit
4
1
1/3
ρc,i
+
1
1/3
ρc,j
!3
xi + xj
0.5
(Tc,i · Tc,j )
βT2 ,ij xi + xj
mol
dm3
(7)
(8)
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 450
K, 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 (in
the cold end of the main heat exchanger) to 350 K (at compressor outlets). This means that the
EOS 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 simpler
equations of state. For example, the SRK EOS uses only three parameters for single-component
calculations (critical pressure and temperature plus acentric factor). The GERG-2004 EOS has got
more than 100 parameters per component as well as a large number of parameters for component
pairs. The total number of components for which parameters have been estimated is 18. Table 1
shows the number of parameters per component and table 2 the number of parameters per component
pair.3
Table 1: Number of coefficients per component
Coefficient name Number of coefficients Used in equation
n0oi
7
4
0
υoi
7
4
npol,oi
7
5
dpol,oi
7
5
tpol,oi
7
5
nexp,oi
18
5
dexp,oi
18
5
texp,oi
18
5
cexp,oi
18
5
ρc
1
4, 7
Tc
1
4, 8
Total
109
N/A
Table 2: Number of coefficients per component pair
Coefficient name Number of coefficients Used in equation
nij
12
6
dij
12
6
tij
12
6
ηij
12
6
εij
12
6
βij
12
6
γij
12
6
Fij
1
3
βν,ij
1
7
γν,ij
1
7
βT ,ij
1
8
γT ,ij
1
8
Total
89
N/A
If we consider a system with 5 components, where all 10 possible pairs have nonzero Fij entries, we
get no less than 2007 parameters, including critical temperature and density (but this also includes
2 The fraction R∗ is included to correct for the fact that when the mixture model was developed, the developers
R
used a different value for the molar gas constant R - see page 104 in [1].
3 The coefficients used in equation 6 only apply to 15 component pairs, because only 15 elements of F
ij 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 when
importing the parameters into any application.
6
Derivatives of A with respect to V and N
3
∂A
)T ,n and µ = ( ∂A
In order to do equilibrium calculations, we need the derivatives −p = ( ∂V
∂n )T ,V .
Since the equation of state is expressed in terms of δ, τ and x we need the partial derivatives of
these 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
∂τ
∂A
, we have (remember, ∂V
is obviously zero since τ does not
For negative pressure, defined as ∂V
depend on V ):
r ∂A
∂α0
∂(ρ/ρc,i )
∂δ
∂α
= ntot RT
+
(9)
∂V
∂(ρ/ρc,i ) T
∂V
∂δ τ ∂V n
x
The derivatives with respect to δ and xi are common for the −p and µ expressions and are
summarized in section 3.2. The remaining derivatives are (∂ρ/∂V )n and (∂δ/∂V )n , which are both
quite simple:
∂(ρ/ρc,i )
ntot
1
ρ
1
=− 2 ·
=− ·
(10)
∂V
V
ρ
V
ρ
c,i
c,i
x
When differentiating with respect to V , the reducing function for density, ρr , is constant since
it is a function of x only.
∂δ
ntot 1
ρ 1
=− 2 ·
=− ·
(11)
∂V x
V
ρr
V ρr
The partial derivative of ideal Helmholtz energy with respect to density is very simple, since only
one term in this expression contains the density (as can be seen from equation 4).
∂α0
R∗ ρc,i
=
·
(12)
∂(ρ/ρc,i ) T
R
ρ
For the chemical potentials, we have (with ∂ntot /∂ni = 1 and recalling that A = RT · ntot α):
∂A
∂nα
= RT
(13)
∂ni T ,V,nj
∂ni T ,V,nj
Splitting nα in its ideal and residual parts and differentiating each with respect to ni gives that
r
∂nα
∂α
= α0oi (ρ, T ) + 1 + ln xi + αr + ntot
(14)
∂ni T ,V,nj
∂ni T ,V,nj
Being able to calculate the fugacity coefficient (ϕi ) may also be necessary when doing equilibrium
calculations. The fugacity coefficient of component i can be expressed in the following way:
r ∂α
∂nαr
ln ϕi =
− ln 1 + δ
(15)
∂ni T ,V,nj
∂δ τ
3.2
Derivatives of αr , αroi and αrij with respect to δ and xi
In this section, the derivatives needed to express the pressure, chemical potential and fugacity
coefficients are shown. The exception is the derivatives of the reducing functions Tr and ρr with
respect to mole numbers, these are shown in appendix A.4
4 αr
xi
=
“
∂αr
∂xi
”
τ,δ,xj
7
n
∂αr
∂ni
=
δαrδ
T ,V,nj
"
1
1−
·n
ρr
∂ρr
∂ni
#
+
τ αrτ
nj
1
·n
Tr
The derivatives of reducing functions with respect to ni (n
∂Tr
∂ni
∂ρr
∂ni
+ αrxi −
nj
nj
∂αr
∂δ
∂αr
∂xi
=
τ,x
N
X
= αroi +
τ,δ,xj
xi
i=1
N
X
xk αrxk
(16)
k=1
and n
in appendix A.
From equation 3 we get the derivatives of αr with respect to δ and xi :
N
X
xk Fik αrik
∂Tr
∂ni
nj
) are shown
(17)
k=1,k6=i
∂αroi
∂δ
+
τ
N−1
X
N
X
i=1 j=i+1
xi xj Fij
∂αrij
∂δ
(18)
τ
Equations 17 and 18 are quite simple because αroi and αrij are not functions of x.
Now we just need the derivatives of αroi and αrij with respect to δ. They are obtained by
differentiating equations 5 and 6. By doing this, we get the following expression for the individual
components (equation 19) and component pairs(equation 20):
∂αroi
∂δ
KP ol,i
X
=
τ
KExp
npoloi,k dpoloi,k δ
(dpoloi,k −1) tpoloi,k
τ
k=1
+
X
nexpoi,k τ texpoi,k δ (dexpoi,k −1) (dexpoi,k − cexpoi,k δ cexpoi,k )e−δ
k=1
∂αrij
∂δ
=
τ
KP ol,ij +KExp,ij
X
k=1
(19)
nij,k δ
dij,k tij,k
τ
dij,k
− 2ηij,k (δ − εij,k ) − βij,k
exp −ηij,k (δ − εij,k ) − βij,k (δ − γij,k )
δ
2
(20)
8
cexpoi,k
4
Implementation in MATLAB, results
4.1
Rearranging expressions for αroi and αrij
In [1], equations 5 and 6 are both written as two sums - one from 1 to Kpol and one from Kpol + 1
to Kpol + Kexp . Since the values of Kpol and Kexp varies from component to component (and from
component pair to component pair), it was considered better to rewrite both in a simpler form, as
they are shown in section 2. The reason for letting equation
5 remain split, was that there is no
cexp,oi,k
general choice of the parameter cexp,oi which will make e−δ
= 1 for the Kpol first terms of the
sum. This is easily done for equation 6, by setting η, ε, β and γ equal to zero for the polynomial
terms.
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 are
listed 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 of
the 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 saved
in .csv format
2. This resulted in one table per component for equations 4 and two per component for 5 (for
exponential and polynomial coefficients), one table per component pair for equation 6 as well
as tables of critical parameters, a table representing the Fij matrix of equation 3, and tables
of 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 of
Kpol for each component). This was done in a way that would ensure that where the original
formulation had fewer terms, the last terms would be zero, but at the same time avoiding
divisions by zero.
4.3
MATLAB call hierarchy
The MATLAB implementation of the equation of state is relatively simple, and consists of three
MATLAB m-files.
1. loadsort.m: Takes an 18-element vector of mole numbers as input (the total number of
components for which coefficients are listed is 18. This file loads each of the .csv tables into the
MATLAB workspace, identifies those who correspond to nonzero mole numbers, and arrange
these in arrays of size (ncoeff × ncomp ). Then the file outputs these arrays in a structure called
par.
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 are
pressure, 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. Within
this script, the temperature, molar numbers and volume are defined, loadsort.m is run to load
the 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 5
are not written with one expression per component; instead, they are written by element-wise operations on the coefficient matrices, and then the sum is taken over the dimension corresponding to the
coefficients. 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 )), and
after 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 ) + ln x
(21)
αr (δ, τ, x) = xT αroi (δ, τ ) + xT (Fij ⊗ αrij (δ, τ ))x
α0oi (ρ, T ),
αroi (δ, τ )
In equations 21 and 22,
ln x and
and ⊗ symbolizes multiplication element by element.
4.5
are vectors, Fij and
(22)
αrij (δ, τ )
are matrices
Results
The figures following show various isotherms for pure methane and for a mixture of methane, nitrogen, 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 critical
temperature of methane is 190.5640K). The non-cubic behaviour of the equation of state becomes
clearly visible at the lowest temperature, where we observe that the curve has two distinct local
minima. When the temperature is further lowered, these minima become more distinct and the
curve 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 equation
of state and the Soave-Redlich-Kwong (SRK) EOS. The data used for the SRK equation of state
are taken from [5]. To further illustrate the difference between the cubic SRK equation and the
GERG-2004 equation at intermediate molar volumes, the isotherms for 180K are also included, see
figure 4. Finally, isotherms for a mixture consisting of 40 % methane, 10 % nitrogen, 40 % ethane
and 10 % propane are shown for four temperatures in the range from 225K to 262.5K - see figure 5.
5
10
T = 180 K
T = 185 K
T = 190 K
Pressure
(kPa)
T = 195 K
4
10
2
10
Volume (dm3)
Figure 2: Isotherms for pure methane at 180, 185, 190 and 195 K
10
GERG−2004
SRK
5
10
Pressure
(kPa)
4
10
2
10
Volume (dm3)
Figure 3: Critical isotherms for methane
GERG−2004
SRK
5
10
Pressure
(kPa)
4
10
2
10
Volume (dm3)
Figure 4: GERG-2004 and SRK isotherms at 180 K
11
225K
237.5K
250K
262.5K
5
10
Pressure
(kPa)
4
10
3
10
2
10
Volume (dm3)
Figure 5: Isotherms at 225, 237.5, 250 and 262.5 K for a mixture of methane, ethane, propane and
nitrogen
In figure 6, a plot of ln ϕ versus P is shown. As one would expect from the shape of the pressurevolume curve (figure 4), the curve crosses itself several times. Figure 7 shows a similar plot for
the chemical potential (µ). If one traces both graphs from the right (high pressure) towards the
left, the point at which the curve first crosses itself is at the same pressure in the two figures. It
corresponds to the fugacity coefficient (or chemical potential) at the point where vapour and liquid
are in equilibrium with each other.
If the temperature is lowered further, the p−µ curve crosses itself even more times, as can be seen
in figure 8. In this plot one can spot six solutions to the equilibrium problem p1 = p2 , µ1 = µ2 . Only
one of these will correspond to a true vapour-liquid equilibrium. The pressure and volume values
at the six intersections in figure 8 are shown in table 3, in the order they appear when the curve is
traced from small volumes (large pressures). For illustrative purposes, figure 9 shows the volumes
and pressure for the point marked 1 in figure 8. For the point 2-6, corresponding pressure-volume
curves are included in appendix ??.
Table 3: Intersections in figure 8, pressure and volume values
p (kPa) V1 (dm3 ) V2 (dm3 )
2777
54.35
95.51
2336
55.19
100.8
2258
55.36
125.6
2559
76.43
138.2
2894
78.17
301.0
2861
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 see
from figure 8, at 175K there are 6 solutions to this problem, even for a single component where it
12
−0.05
−0.1
−0.15
−0.2
−0.25
ln(phi) −0.3
−0.35
−0.4
−0.45
−0.5
−0.55
2000
2500
3000
3500
4000
4500
Pressure (kPa)
Figure 6: ln ϕ versus P for methane at 180 K
3900
3800
3700
mu (J/mol)
3600
3500
3400
3300
2000
2500
3000
3500
4000
4500
Pressure (kPa)
Figure 7: Chemical potential for methane (µCH4 ) versus pressure at 180 K
13
3500
3450
3400
5
6
4
3350
3
3300
1
2
Chemical potential
(J/mol)
3250
3200
3150
3100
3050
3000
1000
1500
2000
2500
3000
3500
Pressure (kPa)
Figure 8: µ against P for methane at 175 K
5
10
Volumes corresponding
to the
point
labeled "1" in p−mu plot
4
10
3
10
2
3
10
10
Volume (dm3)
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 initial
guess for any iterative solution of the flash problem. [1] do not address this problem directly, but for
the problem where density is to be calculated at given pressure (where the non-monotonic nature of
the isotherm causes similar problems) they suggest using the Peng-Robinson EOS to provide initial
guesses. In their report, they have included comparisons of GERG-2004, Peng-Robinson and other
equations of state to experimental data, and densities calculated by the Peng-Robinson equations
of state are shown to be somewhat higher than those calculated by GERG-2004.
15
5
5.1
Conclusions and future work
Conclusions
A simple implementation of the GERG-2004 equation of state has been carried out in Matlab and
tested by plotting isotherms for different components and temperatures. The most time-consuming
job was to make the tables containing the coefficients of equations 4-8 workable. Some effort has
also been made in writing some of the equations in a simpler form within Matlab than the form they
are formulated here (for example, many sum expressions were possible to replace with matrix-vector
multiplication).
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 of
state 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 (figure
7) indicate that flash calculations may be difficult, as there are multiple solutions (at constant
temperature, equilibrium is defined by equal pressure and equal chemical potential in the phases
that are present).
5.2
Future work
It is a goal of future work to include the reference equation of state in steady-state models of
LNG plants, to compare with the results one obtains using cubic equations of state (typically SoaveRedlich-Kwong, Peng-Robinson). Liquefaction processes for natural gas involve phase transfer at low
temperatures (down to 116K which is the boiling temperature of CH4 at atmospheric pressure). At
these temperatures, which are also close to the Joule-Thompson inversion temperature of methane in
the pressure range of interest, it is crucial to have an accurate thermodynamic model. Carrying out
simulations with a model especially made for this type of systems, will give a better understanding
of 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 heat
exchangers, where heat exchange between more than two two-phase streams takes place at small
temperature differences (∆Tmin ≈ 1K). With this small temperature differences, small differences
in the flash calculation can be significant.
16
References
[1] Kunz, O., Klimeck, R., Wagner, W., Jaeschke, M.: ”The GERG-2004 Wide-Range
Equation of State for Natural Gases and Other Mixtures”
[2] Soave, G.: ”Equilibrium constants from a modified Redlich-Kwong equation of
state”, 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. Results
for Nonpolar Fluids”, Int. Journ. of Thermophysics, Vol. 24, No. 1, January 2003
[5] Green, Don W,; Perry, Robert H.: ”Perry’s Chemical Engineers Handbook (8th
Edition)”, McGraw-Hill (2007)
17
A
Derivatives of reducing functions with respect to mole
numbers
n
∂ρr
∂ni
=
nj
∂ρr
∂xi
−
∂Tr
∂ni
n
N
X
xj
xk
k=1
nj
=
∂ρr
∂xk
, with
∂Tr
∂xi
−
xj
xj
N
X
k=1
xk
∂ρr
∂xk
∂Tr
∂xk
= −ρ2r
xj
∂(1/ρr )
∂xk
(24)
xj
(25)
xj
Next are the individual derivatives with respect to xk - these are quite complex:
∂Yr
∂xi
xj
= 2xi Yc,i +
i−1
X
k=1
cY,ki
N
X
∂fY,ki (xk , xi )
∂fY,ik (xi , xk )
+
cY,ik
∂xi
∂xi
(26)
k=i+1
x +x
j
In this equation, fY,ij (xi , xj ) = xi xj β2 i xi+x
and cY,ij = 2βY,ij γY,ij Yc,ij where Yc,ij is either
j
Y,ij
3
0.5
1
1
1
or (Tc,i · Tc,j ) .
1/3 + 1/3
8
ρc,i
ρc,j
We now need to express the partial derivatives inside equation 26 in terms of xi and xj .
!
∂fY,ki (xk , xi )
xk + xi
1
xk + xi
= xk 2
+ xk xi 2
1− 2
∂xi
βY,ki xk + xi
βY,kixk + xi
βY,ki xk + xi
xk
!
xk + xi
1
xk + xi
∂fY,ik (xi , xk )
2
= xk 2
+ xi xk 2
1 − βY,ik 2
∂xi
βY,ik xi + xk
βY,ik xi + xk
βY,ik xi + xk
xk
(27)
(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 reducing
function. 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 that
we remain above the main diagonal.
18
B
1
2
3
MATLAB m-code
function [p ln fi mu] = gergdiffs(V,T,N,par)
%negp Calculate −p(V,T,N1,...) = (@A/@V) t ,n1,... from the GERG
%equation of state. Output will be in kPa.
4
5
6
7
8
%
%
%
%
Input:
Volume (in dm3)
Temperature (in K)
Mole numbers (in mol)
%
%
%
%
This file takes V, T and the 18−element vector N and calculates the
volume derivative of the Helmholtz energy A. This involves calculation of
the reducing functions Tr and Rhor, as well as pertial derivatives of the
individual contributions to A.
9
10
11
12
13
14
15
%Calculate molar fractions
16
17
18
N=N(:) ;
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
27
28
Tc = par.Tc ;
mw = par.mw; %#ok<NASGU>
rhoc = par.rhoc;
29
30
31
n ideal = par.n ideal ;
upsilon ideal = par.upsilon ideal;
32
33
34
35
36
nexp
cexp
dexp
texp
=
=
=
=
par.nexp;
par.cexp;
par.dexp;
par.texp;
37
38
39
40
npol = par.npol;
dpol = par.dpol;
tpol = par.tpol;
41
42
43
44
45
46
47
48
49
F = par.F ;
dij = par.dij ;
tij = par.tij ;
nij = par.nij ;
etaij = par.etaij ;
epsilonij = par.epsilonij ;
betaij = par.betaij ;
gammaij = par.gammaij ;
50
51
52
53
54
beta vij = par.beta vij;
beta tij = par.beta tij;
gamma vij = par.gamma vij;
gamma tij = par.gamma tij;
55
56
57
R = par.R ;
Rmod = par.Rmod ;
58
59
%Now, calculate reducing functions (Tr, rhor)
60
61
62
rr = (x.ˆ2)'*(1./rhoc) ; % "ii" contribution to reducing density
Tr = (x.ˆ2)'*Tc ;
63
64
if length(x) > 1
19
65
66
67
68
69
70
71
72
73
74
75
76
77
for i=1:(length(x)−1)
for j=(i+1):length(x)
rr ij = 2*x(i)*x(j)* beta vij(i,j)* gamma vij(i,j)*((x(i)+x(j))/...
((beta vij(i,j)ˆ2)*x(i)+x(j)))*(1/8)*(1/(rhoc(i)ˆ(1/3)) + ...
1/(rhoc(j)ˆ(1/3)))ˆ3 ;
Tr ij = 2*x(i)*x(j)* beta tij(i,j)* gamma tij(i,j)*((x(i)+x(j))/...
((beta tij(i,j)ˆ2)*x(i)+x(j)))*(Tc(i)*Tc(j))ˆ0.5 ;
rr = rr+rr ij ; % Add contribution from pair ij to total
Tr = Tr + Tr ij ;
end
end
end
%Calculate reduced temperature and reduced density
78
79
80
81
rho = sum(N)/V ; % Molar density in mol/dm3
= rho*rr ;
tau = Tr/T ;
∆
82
83
84
%Calculate the derivatives of ideal and residual Helmholtz energy
% as well as derivatives of ∆ and rho
85
86
87
drhoi dV = −(rho./rhoc)/V ; % rhoi = rho/rhoc
d∆ dv = −∆/V ;
88
89
%Calculate ideal Helmholtz energy, alfa id, and residual Helmholtz energy, alfar
90
91
92
93
94
95
alfa id i = (Rmod/R)*(log(rho./rhoc)' + n ideal(1,:) + n ideal(2,:).*(Tc/T)' + ...
n ideal(3,:).*log(Tc/T)' + n ideal(4,:).*(log(sinh(upsilon ideal(4,:).*(Tc/T)'))) ...
+ n ideal(6,:).*(log(sinh(upsilon ideal(6,:).*(Tc/T)'))) − ...
n ideal(5,:).*(log(cosh(upsilon ideal(5,:).*(Tc/T)'))) − ...
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
100
101
102
alfar oi = sum((npol.*(∆.ˆdpol).*tau.ˆtpol),1) + ...
sum(nexp.*(tau.ˆtexp).*(∆.ˆdexp).*(exp(−∆.ˆcexp)),1);
alfar ij = sum(((nij.*(∆.ˆdij).*tau.ˆtij).*exp(−etaij.*((∆ − epsilonij).ˆ2) ...
− 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
113
114
115
dalfar oi d∆ = sum((npol.*dpol.*(∆.ˆ(dpol−1)).*tau.ˆtpol),1)+...
sum(nexp.*(tau.ˆtexp).*(∆.ˆ(dexp−1)).*((dexp − cexp.*∆.ˆcexp).*(exp(−∆.ˆcexp))),1) ;
% Do the calculation element−wise, then for each component take the sum of the corresponding column.
%The result is a vector of length ncomp
116
117
118
% Derivative of residual Helmholtz energy departure function a r ij w.r.t.
% ∆
119
120
121
122
dalfar ij d∆ = sum(((nij.*(∆.ˆdij).*tau.ˆtij).*exp(−etaij.*((∆ − epsilonij).ˆ2)...
− betaij.*(∆ − gammaij)).*(dij./∆ − 2*etaij.*(∆ − epsilonij)−betaij)),3) ;
% Same as above − the result is a matrix of size ncomp*ncomp
123
124
125
126
dalfa dV = (x'*(dalfa 0 drhoi. *drhoi dV)) + ((dalfar oi d∆.*d∆ dv)*x)...
+ (x'*(F.* dalfar ij d∆.*d∆ dv)*x) ; % Sum together contributions
%dalfa dV ideal = (x'*(dalfa 0 drhoi. * drhoi dV)) ;
127
128
129
130
dA dV = sum(N)*Rmod*T* dalfa dV ; % Unit: kPa
p = −dA dV ;
%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
134
135
%calculate first derivatives with respect to mole numbers. This means we
%also need first derivatives of residual Helmholtz energy with respect to
%mole numbers/ fractions.
136
137
138
139
140
dalfar oi dtau = sum((npol.*tpol.*(∆.ˆdpol).*tau.ˆ(tpol−1)),1) + ...
sum(nexp.*texp.*(tau.ˆ(texp−1)).*(∆.ˆdexp),1) ;
dalfar ij dtau = sum(((nij.*(∆.ˆdij).*tij.*(tau.ˆ(tij−1))).*...
exp(−etaij.*((∆ − epsilonij).ˆ2) − betaij.*(∆ − gammaij))),3) ;
141
142
143
144
dalfar d∆ = dalfar oi d∆*x + x'*(F.* dalfar ij d∆)*x ;
dalfar dtau = dalfar oi dtau *x + x'*(F.* dalfar ij dtau)*x ;
dalfar dx = alfar oi' + (F.* alfar ij)*x ;
145
146
147
% Exception; If we have one component only, we don't need the composition
% derivatives.
148
149
150
151
152
if length(x) < 2
ln fi = (alfar + ∆* dalfar d∆) − log(1+∆*dalfar d∆) ;
mu = R*T*((alfa id i + 1)+(alfar + ∆* dalfar d∆)) ; %Residual chemical potential
elseif length(x) ≥ 2
153
154
155
% If we have two components or more, we need to calculate derivatives of rr
% and Tr with respect to composition.
156
157
%Calculate the ugly, ugly derivatives from table 7.10
158
159
160
dTr dx = 2*x.*Tc ;
d invrr dx = (2*x).*(1./rhoc) ;
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
for i=1:length(x)
if i == 1 % If at first component, only the last sum is needed
for j=(i+1):length(x)
dTr dx(i) = dTr dx(i) + 2* beta tij(i,j)* gamma tij(i,j)*((Tc(i)*Tc(j))ˆ0.5)...
*(x(j)*(x(i)+x(j))/(beta tij(i,j)ˆ2*x(i) + x(j)) +(x(i)*x(j)*...
1/(beta tij(i,j)ˆ2*x(i) + x(j)))*(1 − beta tij(i,j)ˆ2*(x(i)+x(j))/...
(beta tij(i,j)ˆ2*x(i) + x(j)))) ; % Add j'th term
d invrr dx(i) = d invrr dx(i) + 2*beta vij(i,j)*gamma vij(i,j)*...
((1/8)*(1/(rhoc(i)ˆ(1/3)) + 1/(rhoc(j)ˆ(1/3)))ˆ3)*...
(x(j)*(x(i)+x(j))/(beta vij(i,j)ˆ2*x(i) + x(j)) +...
(x(i)*x(j)*1/(beta vij(i,j)ˆ2*x(i) + x(j)))*(1 − beta vij(i,j)ˆ2*...
(x(i)+x(j))/(beta vij(i,j)ˆ2*x(i) + x(j)))) ; %Add j'th term
end
elseif i>1 && i<length(x) % If not at the first or last component, we must sum both below and above i
for j = 1:(i−1)
dTr dx(i) = dTr dx(i) + (2* beta tij(j,i))* gamma tij(j,i)*((Tc(i)*Tc(j))ˆ0.5)...
*(x(j)*(x(i)+x(j))/(beta tij(j,i)ˆ2*x(j) + x(i)) +(x(j)*x(i)...
*1/(beta tij(j,i)ˆ2*x(j)+ x(i)))*(1 − (x(j)+x(i))/...
(beta tij(j,i)ˆ2*x(j) + x(i)))) ; % Add j'th term
d invrr dx(i) = d invrr dx(i) + (2*beta vij(j,i))*gamma vij(j,i)*...
((1/8)*(1/(rhoc(i)ˆ(1/3)) + 1/(rhoc(j)ˆ(1/3)))ˆ3)*...
(x(j)*(x(i)+x(j))/(beta vij(j,i)ˆ2*x(j) + x(i))...
+(x(j)*x(i)*1/(beta vij(j,i)ˆ2*x(j) + x(i)))*...
(1 − (x(j)+x(i))/(beta vij(j,i)ˆ2*x(j) + x(i)))); %Add j'th term
end
for j = (i+1):length(x)
dTr dx(i) = dTr dx(i) + 2* beta tij(i,j)* gamma tij(i,j)*((Tc(i)*Tc(j))ˆ0.5)...
*(x(j)*(x(i)+x(j))/(beta tij(i,j)ˆ2*x(i) + x(j)) +(x(i)*x(j)*...
1/(beta tij(i,j)ˆ2*x(i)+ x(j)))*(1 − beta tij(i,j)ˆ2*(x(i)+x(j))/...
(beta tij(i,j)ˆ2*x(i) + x(j)))) ; % Add j'th term
d invrr dx(i) = d invrr dx(i) + 2*beta vij(i,j)*gamma vij(i,j)*...
((1/8)*(1/(rhoc(i)ˆ(1/3))+ 1/(rhoc(j)ˆ(1/3)))ˆ3)*...
(x(j)*(x(i)+x(j))/(beta vij(i,j)ˆ2*x(i) + x(j))...
+(x(i)*x(j)*1/(beta vij(i,j)ˆ2*x(i) + x(j)))*...
(1 − beta vij(i,j)ˆ2*(x(i)+x(j))/(beta vij(i,j)ˆ2*x(i) + x(j)))) ; %Add j'th term
end
198
199
200
elseif i == length(x)
for j = 1:(i−1)
21
dTr dx(i) = dTr dx(i) + (2* beta tij(j,i))* gamma tij(j,i)*...
((Tc(i)*Tc(j))ˆ0.5)*(x(j)*(x(i)+x(j))/(beta tij(j,i)ˆ2*x(j) + x(i))...
+(x(j)*x(i)*1/(beta tij(j,i)ˆ2*x(j) + x(i)))*(1 − (x(j)+x(i))/...
(beta tij(j,i)ˆ2*x(j) + x(i)))) ; % Add j'th term
d invrr dx(i) = d invrr dx(i) + (2*beta vij(j,i))*gamma vij(j,i)*...
((1/8)*(1/(rhoc(i)ˆ(1/3))+ 1/(rhoc(j)ˆ(1/3)))ˆ3)*(x(j)*(x(i)+x(j))/...
(beta vij(j,i)ˆ2*x(j) + x(i))+(x(j)*x(i)*1/(beta vij(j,i)ˆ2*x(j) + x(i)))...
*(1 − (x(j)+x(i))/(beta vij(j,i)ˆ2*x(j) + x(i) ))); %Add j'th term
201
202
203
204
205
206
207
208
209
210
211
end
end %End of "if" loop
end %End of outer "for" loop
212
213
214
215
d rr dx = −(1/rrˆ2)* d invrr dx ;
n drr dn = d rr dx − x'* d rr dx ;
n dTr dn = dTr dx − x'* dTr dx ;
216
217
218
219
220
221
n dalfar dni = zeros(length(x),1);
for i=1:length(x)
n dalfar dni(i) = ∆* dalfar d∆*(1−rr* n drr dn(i)) + ...
tau* dalfar dtau*(1/Tr)* n dTr dn(i) + dalfar dx(i) − x'* dalfar dx ;
end
222
223
224
dn alfa0 dni = alfa id i' + 1 + log(x) ;
dnalfar dni = alfar + n dalfar dni ;
225
226
227
228
mu = R*T*(dn alfa0 dni + dnalfar dni) ; %Vector of chemical potentials
ln fi = dnalfar dni − log(1+∆* dalfar d∆) ; %Vector of ln fugacity coefficients
end
229
230
end
22
1
%Create isotherms of the GERG equation of state and (if desired) SRK equation of state
2
3
4
5
% par.CH4.Tc = 190.564;
% par.CH4.Pc = 4.59e6 ;
% par.CH4.acentric = 0.0115 ;
6
7
8
close all
clear all
9
10
11
T = 180.5640 ; % Tc ch4 − 10 K
Ntot = 1000 ; % mol
;
12
13
14
15
16
ind = [1 2 4 5] ; % Methane, nitrogen, ethane, propane
x = [1 0 0 0] ;
N=zeros(18,1);
N(ind) = Ntot*x ;
17
18
par = loadsort(N) ;
19
20
21
V = logspace(1.5,3.5,1000);
p=zeros(length(T),length(V));
22
23
24
25
if nnz(x) ==1 % We want potential and ln fi if we have single component
mu = zeros(length(T),length(V)) ;
ln fi = zeros(length(T),length(V)) ;
26
27
28
29
30
31
32
33
34
35
36
37
38
%psrk=p ;
for i = 1:length(T)
for j = 1:length(V)
[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
%psrk(i,j) = p srk(V(j),T(i),N,par.CH4) ; % Only valid for pure methane
end
end
figure(2), plot(p,ln fi) ;
figure(3), plot(p,mu) ;
else
for i = 1:length(T)
for j = 1:length(V)
39
40
[p(i,j)] = gergdiffs(V(j),T(i),N,par) ; % For multicomponent, retrieve pressure only
41
42
43
44
45
%psrk(i,j) = p srk(V(j),T(i),N,par.CH4) ; % Only valid for pure methane
end
end
end %End of IF loop
46
47
48
49
50
51
if min(min(p)) < 0
figure(1),plot(V,p) ;
else
figure(1), loglog(V,p);
end
23
C
Miscellaneous plots
5
10
Volumes corresponding
to the
point
labeled "2" in p−mu plot
Pressure
(kPa)
4
10
3
10
2
3
10
10
Volume (dm3)
Figure 10: Pressure-volume curve at 175 K with point 2 shown
24
4
10
Volumes corresponding
to the point labeled
"3" in p−mu plot
Pressure
(kPa)
3
10
2
3
10
10
Volume (dm3)
Figure 11: Pressure-volume curve at 175 K with point 3 shown
5
10
Volumes corresponding
to the point labeled
"4" in p−mu plot
Pressure
(kPa)
4
10
3
10
2
3
10
10
Volume (dm3)
Figure 12: Pressure-volume curve at 175 K with point 4 shown
25
5
10
Volumes corresponding
to the point labeled
"5" in p−mu plot
Pressure
(kPa)
4
10
3
10
2
3
10
10
Volume (dm3)
Figure 13: Pressure-volume curve at 175 K with point 5 shown
5
10
Volumes corresponding
to the point labeled
"6" in p−mu plot
Pressure
(kPa)
4
10
3
10
2
3
10
10
Volume (dm3)
Figure 14: Pressure-volume curve at 175 K with point 6 shown
26
Download