1 NTNU Norwegian University of Science and Technology Calculation of Natural Gas Mixture Phase Behavior at Low Temperature Project Work of Subject KP 8108 Advanced Thermodynamics Student : Rahmat Nur Adi Wijaya : Longman Zhang Table of Contents Introduction ..................................................................................................................................... 3 1 Thermodynamics on Equilibrium Phase ................................................................................. 3 1.1 Phase Equilibria................................................................................................................ 3 1.2 Fugacity and Fugacity Coefficient ................................................................................... 5 1.3 Calculation of Fugacity Coefficient ................................................................................. 7 2 Phase Equilibrium by Equation of State ................................................................................. 9 2.1 Cubic Equation of State.................................................................................................... 9 2.2 Mixing Rules .................................................................................................................. 10 2.3 Application of EOS to Phase Equilibrium ..................................................................... 11 3 Phase Equilibria on Flash Calculation .................................................................................. 12 3.1 The K-ratio method ........................................................................................................ 14 3.1.1 Solve the SRK EOS ................................................................................................ 16 3.1.2 Algorithm for the Two Phase TPn (isothermal) flash............................................. 18 3.1.3 Algorithm for the Two Phase TVn (isochoric) flash .............................................. 19 3.2 Freezing Temperature .................................................................................................... 20 3.3 The Newton Method....................................................................................................... 21 3.3.1 TVn Flash Using Newton Method .......................................................................... 21 3.3.2 TPn Flash Using Newton Method........................................................................... 25
46
Embed
Calculation of Natural Gas Mixture Phase Behavior at Low ...folk.ntnu.no/haugwarb/KP8108/Essays/rahmat_nur_adi_wijaya_and... · The isothermal flash calculation, i.e. equilibrium
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
NTNU Norwegian University of Science and Technology
Calculation of Natural Gas Mixture Phase Behavior at Low Temperature
Project Work of Subject
KP 8108 Advanced Thermodynamics
Student : Rahmat Nur Adi Wijaya
: Longman Zhang
Table of Contents Introduction ..................................................................................................................................... 3
1 Thermodynamics on Equilibrium Phase ................................................................................. 3
Substitute eq.(3-17a-3.17f) and eq.(3-39-44c) to eq.(3-38), and substitute eq.(3-36-38) into eq.(3-
35), we can get 2
,i j T V
An n
∂ ∂ ∂
.
Use eq.(14), we can get
, 1 2( )( )n T
A nRT APV V B V c B V c B∂ = − = − + ∂ − + +
(3-45)
21 2
2 2 21 2,
(2 )( ) [( )( )]n T
A V c B c BA nRTV V B V c B V c B
+ +∂= − ∂ − + +
(3-46)
1 2 1 2 1 2
2 21 2
(2 )( )( ) [( ) 2 ]
( ) [( )( )]
V i ii n V Vn
i j j j iji
A A
a n V c B V c B A c c Vb c c BbnRTb
V B V c B V c B
µ = =
+ + − + +−
= +− + +
∑ (3-47)
25
Substitute the above derivatives into eq.(3-26-27), we can calculate the Newton step.
3.3.2 TPn Flash Using Newton Method For the TPn flash using Newton method, the procedure is quite similar to the TVn flash, but in
this case, pressure P is given, can we have to find the volume for the vapour and the liquid. The
given pressure can be expressed as:
0( , , )P T V Pα α =n (3-48)
0( , , )P T V Pβ β =n (3-49)
Where 0P is the specified pressure. Linearization of the two equations can be expressed as:
0VP P V P Pα α α α+ ∆ + ∆ =n n (3-50)
0VP P V P Pβ β β β+ ∆ + ∆ =n n (3-51)
In the TPn flash, we still solve the eq. 3-30 in iteration to update mole amount of each
component in the liquid and vapour phase, and also we can get the update volume of the vapour
and liquid, then by using eq. 3-50 and eq. 3-51, we can update the pressure for vapour and liquid
phase. The new volume for eq 3-30 is calculated from solving the cubic SRK equation for
volume, that is eq 3-18. The algorithm is also shown in Fig 3.
26
Figure 3 TPn vapor liquid flash algorithm using Newton method
Given T, P and feed composition z
Calculate V vapor and V liquid By eq. 3-18
Solve eq. 3-30, get the step for volume and mole amount
, , ,V Vα β α β∆ ∆ ∆ ∆n n
V V VV V V
α α α
β β β
= + ∆
= + ∆
α α α
β β β
= + ∆
= + ∆
n n nn n n
0
0
V
V
P P P V PP P P V P
α α α α
β β β β
= − ∆ − ∆
= − ∆ − ∆n
n
nn
Convergence?
No
Yes
Finish calculation
27
3.4 Result and Discussion
The vapor liquid flash and the freezing temperature calculations are implemented in matlab, the calculation results are shown as follows.
3.4.1 Comparision between Pro.II and TPn K-ratio Method
In this exercise, the vapor liquid equilibrium for given composition of gas, is solved using SRK
EOS. And then the result is compared to the same model SRK provided by commercial software.
Both for the TVn and TPn flash are compared. In this case the commercial software used is Pro
II.
The bubble point line and due point line calculated by ProII for a gas mixture is shown in Fig. 3,
the components and composition of the mixture are shown in table 1. In this work, the PTn flash
calculation of two points in the two phase liquid-vapor region using K ratio method is compared
with the calculation from ProII, and the results are shown in table 1 and table 2.
Figure 4 PT phase diagram of gas mixture calculated by ProII
Temperature, K0 60.0 120.0 180.0 240.0 300.0
Pres
sure
, MPa
0
2.50
5.00
7.50
10.00
12.50
Phase Envelope Curve for stream 'S1', Description :
Full EnvelopeLiquid Mole Fraction : 0.000000Critical PointCricondenbarCricondentherm
28
For given gas composition, and pressure at 1 Mpa and temperature is 170K, the mole fraction for
each phases, compared for calculation using Matlab and Pro. II as follow:
Table 1 Comparision of results between ProII and this work: PTn flash using K ratio methd at 1Mpa, 170K
No. Composition
inlet composition
(zi)
Vapor (yi) Liquid (xi)
Pro.II This work Pro.II This work 1 Methane 0.80000 0.89300 0.88857 0.33660 0.35598 2 Ethane 0.05000 0.01360 0.01403 0.23120 0.23031 3 Propane 0.03000 0.00072 0.00072 0.17600 0.17679 4 Hexane 1.000E-02 8.036E-08 0.000E+00 5.980E-02 6.013E-02 5 N2 0.05000 0.05950 0.05937 0.00251 0.00301 6 CO2 0.06000 0.03310 0.03730 0.19380 0.17378
At higher pressure that the critical point, the consistency of the result for this exercise indicates
slightly differences compared to the Pro. II result. Table 2 Comparision of results between ProII and this work: PTn flash using K ratio methd at 10Mpa, 170K
No. Composition
inlet composition
(zi)
Vapor (yi) Liquid (xi)
Pro.II This work Pro.II This work 1 Methane 0.80000 0.80620 0.80484 0.57370 0.63214 2 Ethane 0.05000 0.04880 0.04897 0.09310 0.08571 3 Propane 0.03000 0.02820 0.02840 0.09750 0.08571 4 Hexane 1.000E-02 6.519E-03 7.305E-03 1.374E-01 1.036E-01 5 N2 0.05000 0.05090 0.05082 0.01880 0.02143 6 CO2 0.06000 0.05950 0.05967 0.07960 0.07143
3.4.2 Verification of TVn flash by TPn flash of K ratio method
In the previous part, it is shown that the TPn flash calculation using K ratio method from this
work is comparable to the result from ProII, also, we can get the total volume from the TPn
flash.
To verify the TVn flash result, we can start the calculation by specifying the given volume
equals the volume we get from the TPn flash, and the temperature and feed composition equals
29
the given condition in the TPn flash calculation, if the implementation of the TVn flash
calculation is collect, we should get the pressure equals the given pressure in the TPn flash, and
the same vapor liquid composition as TPn flash.
Table 3 and table 4 are the results for the verification of the TVn flash by TPn flash, the feed in
table three for both TPn flash and TVn flash are the same as shown in table 4. The results show
that the TVn flash is verified by the TPn flash.
Table 3 Verification of TVn flash by TPn flash at 170K
TPn flash TVn flash Given
condition Temperature (K) 170 170 Pressure (MPa) 1.0000 Total Volume (m3) - 0.0010552
Calculation result
Pressure (MPa) - 1.0000MPa Total Volume (m3) 0.0010552 -
Table 4 Verification of TVn flash by TPn flash: Vapor and Liquid composition at 1MPa, 170K
From the table, the deviation to the experiment result 1-3%, high deviation especially found at
low concentration and high pressure. It indicates that the model could predict the freeze out even
less accurate, but adjustment on the interaction parameter and also on the enthalpy of fusion is
expected to have better result.
Comparison for Liquid-solid phase equilibrium between the model and experimental data (GPA
RR-10 Report) has been done for solid CO2 in liquid of methane. Slight difference on the
prediction can be observed on the curve below.
0
5
10
15
20
160 170 180 190 200 210
Calculation by this work
Experimental data
CO2
mol
%
Temperature (K)
Figure 7 Solubility of CO2 in liquid CH4[2]
4 Conclusion and suggested further work
4.1 Conclusion In this work, the background of the equilibrium calculation is introduced, followed by the
thermodynamic framework of phase equilibrium. To show the practical calculation aspects, both
the TPn and TVn flash calculations are carried out using K ratio and Newton method, as shown
33
in table 6. The calculations are implemented in matlab and the calculation results are verified by
commercial software PROII and also by experimental data.
The prediction of solid-vapor-liquid phase behavior is illustrated through the freeze out
prediction of CH4-CO2 system, the calculation results was reasonable compared to experimental
data. Table 6 Flash calculations in this work
Methods TPn flash TVn flash
K ratio method × ×
Newton mehod × ×
4.2 Suggested further work This project work shows the basic feathers in the calculation of gas mixture phase behavior, but
to make the simulation accurate for real situation, there are still a lot of work left to be done
based on this project, the following topics are suggested to be done to predict the natural gas
mixture phase behavior (include solid phase) at low temperature:
• Implement the stability analysis and multiphase equilibrium algorithm.
• Implement more accurate thermodynamic model, for example, to get the binary
interaction parameters accurate for the cubic EOS, or to implement other thermodynamic
models for the fluid phase such as GERG-2004, and also improve the thermodynamic
model for the solid.
References 1. Soave, G.S., Application of the Redlich-Kwong-Soave Equation of State to Solid-Liquid
Equilibria Calculations. Chemical Engineering Science, 1979. 34(2): p. 225-229. 2. Kurata, F., Research Report RR-10 Solubility of Solid Carbon Dioxide in Pure Light
Hydrocarbons and Mixtures of Light Hydrocarbon. 1974. 3. Le, T.T. and M.A. Trebble, Measurement of carbon dioxide freezing in mixtures of
methane, ethane, and nitrogen in the solid-vapor equilibrium region. Journal of Chemical and Engineering Data, 2007. 52(3): p. 683-686.
34
4. Elliott, J.R. and C.T. Lira, Introductory chemical engineering thermodynamics. Prentice-Hall international series in the physical and chemical engineering sciences. 1999, Upper Saddle River, NJ: Prentice Hall PTR.
5. Prausnitz, J.M., E.G.d. Azevedo, and R.N. Lichtenthaler, Molecular thermodynamics of fluid-phase equilibria. Prentice-Hall international series in the physical and chemical engineering sciences. 2004, Upper Saddle River, NJ: Prentice Hall PTR.
7. Tore Haug-Warberg, Lecture Note- KP8108 Advanced Thermodynamics: with applications to Phase and Reaction Equilibria, October 20, 2008; Department of Chemical Engineering, NTNU
35
Appendix: Source code for TPn Newton flash (The algorithm is shown in fig. 3)
1. Main program % Program for (T,V) flash using Newton Method. % component vector (CH4, C2H6, C3H8, C6H14, N2, CO2); T = 170; % K P0=1.0e+6; % Initial value of the vapor and liquid phase n_vapor =[ 0.7 0.0117 0.0006 0.00000007232679 0.0495 0.0311]; n_liquid =[ 0.1 0.0383 0.0294 0.0100 0.0005 0.0289]; n = n_vapor+n_liquid; Vaporfraction_initial = sum(n_vapor)/sum(n); P_vapor=P0; P_liquid=P0; %----------------------------------------------------------------- % Solve the Newton iteration error= 1000; lhs=zeros(7); rhs=zeros(7,1); delta_step=zeros(7,1); iteration=0; while error > 0.000000001 iteration=iteration+1; V_vapor = GetV(P_vapor,n_vapor,T,-1); V_liquid = GetV(P_liquid,n_liquid,T,1); P_v_vapor=P_V(V_vapor,n_vapor,T); P_v_liquid=P_V(V_liquid,n_liquid,T); P_ni_vapor=P_ni(V_vapor,n_vapor,T); P_ni_liquid=P_ni(V_liquid,n_liquid,T); A_vv_vapor=AVV(V_vapor,n_vapor,T); A_vv_liquid=AVV(V_liquid,n_liquid,T); Mu_v_vapor=MU_V(V_vapor,n_vapor,T); Mu_v_liquid=MU_V(V_liquid,n_liquid,T); A_ninj_vapor=A_NINJ(V_vapor,n_vapor,T); A_ninj_liquid=A_NINJ(V_liquid,n_liquid,T); A_v_vapor=A_V(V_vapor,n_vapor,T); A_v_liquid=A_V(V_liquid,n_liquid,T);
36
Muvapor_minus_Muliquid=Mu_dif(V_liquid,n_liquid,V_vapor,n_vapor,T); lhs(1,1) = A_vv_vapor + A_vv_liquid; lhs(1,2:end) = Mu_v_vapor + Mu_v_liquid; lhs(2:end,1) = Mu_v_vapor + Mu_v_liquid; lhs(2:end,2:end) = A_ninj_vapor + A_ninj_liquid; lhs; rhs(1) = -(A_v_vapor-A_v_liquid); rhs(2:end) = -(Muvapor_minus_Muliquid); rhs; delta_Step_old= delta_step; delta_step=lhs\rhs; error=sum((delta_Step_old-delta_step).^2); P_vapor=P0-P_v_vapor*delta_step(1,1)-sum(P_ni_vapor'.*delta_step(2:end,1)); P_liquid=P0+P_v_liquid*delta_step(1,1)+sum(P_ni_liquid'.*delta_step(2:end,1)); for i=1:6 n_vapor_new(i)=n_vapor(i)+delta_step(i+1,1); n_liquid_new(i)=n_liquid(i)-delta_step(i+1,1); end n_vapor_new; n_liquid_new; while ~(min(n_vapor_new) >= 0 & min(n_liquid_new) >= 0) display('n is negative ,Decrease the step size to 40%'); delta_step=0.4*delta_step; P_vapor=P0-P_v_vapor*delta_step(1,1)-sum(P_ni_vapor.*delta_step(2:end,1)); P_liquid=P0+P_v_liquid*delta_step(1,1)+sum(P_ni_liquid.*delta_step(2:end,1)); for i=1:6 n_vapor_new(i)=n_vapor(i)+delta_step(i+1,1); n_liquid_new(i)=n_liquid(i)-delta_step(i+1,1); end n_vapor_new; n_liquid_new; end n_vapor=n_vapor_new; n_liquid=n_liquid_new; Beta=sum(n_vapor)/sum(n); y= n_vapor/sum(n_vapor); x= n_liquid/sum(n_liquid);
37
P_liquid P_vapor end display ('***************************TVn flash is solved') display ('************ The input:') T n display ('************ The result:') iteration V_vapor V_liquid n_vapor n_liquid y= n_vapor/sum(n_vapor) x= n_liquid/sum(n_liquid) Beta=sum(n_vapor)/sum(n) P_liquid P_vapor
2. Function to calculate the SRK EOS parameters function [n_total,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n) % Step 1: Calculate molor fraction x n_total=sum(n); x=n/sum(n); % Step 2: Input individual critical properties for each component % Critical properties Tcrit=[190.60 305.40 369.80 507.40 126.20 304.20]; Pcrit=[4.599 4.883 4.244 2.968 3.394 7.375]; Omega=[0.0080 0.0980 0.1520 0.2960 0.0400 0.2250]; % Interaction coefficients K_binary=zeros(6,6); K_binary(1,5)=0.02; K_binary(1,6)=0.12; K_binary(2,5)=0.06; K_binary(2,6)=0.15; K_binary(3,5)=0.08; K_binary(3,6)=0.15; K_binary(4,5)=0.08; K_binary(4,6)=0.15;
38
K_binary(5,1)=0.02; K_binary(5,2)=0.06; K_binary(5,3)=0.08; K_binary(5,4)=0.08; K_binary(6,1)=0.12; K_binary(6,2)=0.15; K_binary(6,3)=0.15; K_binary(6,4)=0.15; % Calculate the parameter a and b for individual components and mixture R_gasconstant = 8.314472; % m3*Pa/(K*mol) % a_individual for SRK EOS a_coefficient_individual = (1+(0.48+1.574*Omega- ... 0.176*Omega.^2).*(1-(T./Tcrit).^0.5)).^2; a_individual = 0.42748* ... (((R_gasconstant^2)* ... (Tcrit.^2)./(1000000*Pcrit))).*a_coefficient_individual; b_individual=0.08644 * R_gasconstant * Tcrit./(1000000*Pcrit); a_binary=zeros(6,6); for i=1:6 for j=1:6 a_binary(i,j)=(a_individual(i)*a_individual(j))^0.5*(1-K_binary(i,j)); end end clear i; clear j; a_mixture=0; b_mixture=0; for i=1:6 for j=1:6 a_mixture = a_mixture + x(i)*x(j)* a_binary(i,j); end b_mixture = b_mixture + x(i) * b_individual (i) ; end clear i; clear j; A = (n_total ^ 2)* a_mixture; B = n_total * b_mixture;
39
3. Function to calculate 2
,i j T V
An n
∂ ∂ ∂
function A_ninj=A_NINJ(V,n,T) [n_total,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n); R_gasconstant = 8.314472; c1=1.0; c2=0.0; A_ninj=zeros(6); dFdn=log(V/(V-B)); dFdA=(1/(R_gasconstant*T*B*(c2-c1)))*log((V+c1*B)/(V+c2*B)); for i=1:6 sumpart=0. ; for j=1:6 sumpart=sumpart+a_binary(i,j)*n(j) ; end dA_dni(i)=2*sumpart; end dFdB=(n_total/(V-B))+ ... (A/(R_gasconstant*T*B*(c2-c1)))*( c1/(V+c1*B)-c2/(V+c2*B)) ... - (A*log((V+c1*B)/(V+c2*B)))/(R_gasconstant*T*B*B*(c2-c1)) ; dB_dni= b_individual ; % Calculate the second derivatives d2F_dndnj=b_individual/(V-B); d2F_dAdnj= -b_individual/(R_gasconstant*T*B^2*(c2-c1)) * log((V+c1*B)/(V+c2*B)) + ... (1/(R_gasconstant*T*B*(c2-c1)))* ... (c1*b_individual/(V+c1*B)-c2*b_individual/(V+c2*B)); d2A_dnidnj=2*a_binary; d2B_dnidnj=zeros(6); jsumpart=[0 0 0 0 0 0]; for j=1:6 for k=1:6 jsumpart(j)=jsumpart(j)+a_binary(j,k)*n(k) ; end end d2F_dBdnj_1part=(V-B+n_total*b_individual)/(V-B)^2;
40
d2F_dBdnj_2part= ((2*jsumpart*(R_gasconstant*T*B*(c2-c1))-A*R_gasconstant*T*b_individual*(c2-c1))/ ... (R_gasconstant*T*B*(c2-c1))^2)*(c1/(V+c1*B)-c2/(V+c2*B)); d2F_dBdnj_3part=(A/(R_gasconstant*T*B*(c2-c1)))*(-c1^2*b_individual/(V+c1*B)^2+c2^2*b_individual/(V+c2*B)^2); d2F_dBdnj_4part = -((2*jsumpart*log((V+c1*B)/(V+c2*B)) + A*(c1*b_individual/(V+c1*B)-c2*b_individual/(V+c2*B))) ... * R_gasconstant*T*B^2*(c2-c1)- 2*R_gasconstant*T*B*(c2-c1)*b_individual*A*log((V+c1*B)/(V+c2*B)))/ ... ( R_gasconstant*T*B^2*(c2-c1))^2; d2F_dBdnj= d2F_dBdnj_1part+ d2F_dBdnj_2part+ d2F_dBdnj_3part+ d2F_dBdnj_4part; d2F_dninj=zeros(6); for i=1:6 for j=1:6 d2F_dninj(i,j) = d2F_dndnj(j) + d2F_dAdnj(j)*dA_dni(i)+dFdA*d2A_dnidnj(i,j) + d2F_dBdnj(j)*dB_dni(i) + dFdB*d2B_dnidnj(i,j); end end Kronecker=zeros(6); for j=1:6 Kronecker(j,j)=1; end for i=1:6 for j=1:6 A_ninj(i,j)=R_gasconstant*T*(d2F_dninj(i,j)+(1/n(i))*Kronecker(i,j)); end end
41
4. Function to calculate ,T
AV∂
∂ n
function A_v=A_V(V,n,T) % Function for calculating derivative A with v % step 1: Get the SRK EOS parameters [n_total,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n); R_gasconstant = 8.314472; % Set the parameters for SRK EOS in the general cubic equation c1=1.0; c2=0.0; %--------------------------------------------------------------------- % Step 2: Calculate the derivative A_v= -n_total*R_gasconstant*T/(V-B) ... + A/((V+c1*B)*(V+c2*B));
5. Function to calculate 2
2,T
AV
∂ ∂ n
function A_vv=AVV(V,n,T) % Function for calculating the second derivatives A_VV %-------------------------------------------------------------------------- % step 1: Get the SRK EOS parameters [n_total,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n); R_gasconstant = 8.314472; % Set the parameters for SRK EOS in the general cubic equation c1=1.0; c2=0.0; %--------------------------------------------------------------------- % Step 2: Calculate the derivative A_vv=n_total*R_gasconstant*T/(V-B)^2 ... + (-A*(2*V+c1*B+c2*B))/((V+c1*B)*(V+c2*B))^2;
42
6. Function to calculate volume for SRK EOS function V=GetV(P,n,T,Icon) % Function for calculating V %-------------------------------------------------------------------------- % Get the SRK EOS parameters [n_total,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n); R_gasconstant = 8.314472; % Set the parameters for SRK EOS in the general cubic equation c1=1.0; c2=0.0; % Solve the equation for V and choose V A3=1; A2=-1; A_inter=a_mixture*P/(R_gasconstant*T)^2; B_inter=b_mixture*P/(R_gasconstant*T); A1=A_inter-B_inter-B_inter^2; A0=-A_inter*B_inter; z_cubic_roots=roots([A3 A2 A1 A0]); v=(z_cubic_roots*R_gasconstant*T)/(P); %-------------------------------------------------------------------------- % Determine the stable root % Take out the real roots from v v_imag=imag(v); if sum(v_imag.^2) == 0 ; % the image of v is zero, all three are real roots. v_intermid=v ; else for i=1:3 if imag(v(i))==0 v_intermid=v(i); end end end ; if length(v_intermid)==1 ; % only one real root v_stable=v_intermid ; else % three roots are real roots, we have to choose the stable one, % Only have to choose between the max one and the min one v_max=max(v); v_min=min(v); V1=n_total*v_min; F1_first_term=n_total*log(V1/(V1-B)); F1_second_term=(A/(R_gasconstant*T*B*(c2-c1)))*log((V1+c1*B)/(V1+c2*B)); F1_value=F1_first_term+F1_second_term; Z1=((P)*v_min)/(R_gasconstant*T); G_vmin_reducedres=F1_value+n_total*(Z1-1-log(Z1)); % calculate the v_max coressponding Reduced Resudual Gibbs energy V2=n_total*v_max; F2_first_term=n_total*log(V2/(V2-B)); F2_second_term=(A/(R_gasconstant*T*B*(c2-c1)))*log((V2+c1*B)/(V2+c2*B)); F2_value=F2_first_term+F2_second_term; Z2=((P)*v_max)/(R_gasconstant*T);
43
G_vmax_reducedres=F2_value+n_total*(Z2-1-log(Z2)); if G_vmin_reducedres<G_vmax_reducedres ; v_stable=v_min ; elseif G_vmin_reducedres>G_vmax_reducedres ; v_stable=v_max ; elseif G_vmin_reducedres == G_vmax_reducedres ; display('---------------Return to equilibrium properties') error('choose which liquid or vapor property') if Icon==1 v_stable=v_min else v_stable=v_max end end end ; V=n_total*v_stable ;
7. Function to calculate chemical potential difference between vapor and liquid function Muvapor_minus_Muliquid=Mu_dif(V_liquid,n_liquid,V_vapor,n_vapor,T) % function for calculating the chemical potential difference V-L [n_total_liquid,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n_liquid); R_gasconstant = 8.314472; % Set the parameters for SRK EOS in the general cubic equation c1=1.0; c2=0.0; dFdn=log(V_liquid/max(0.00000000001,(V_liquid-B))); dFdA=(1/(R_gasconstant*T*B*(c2-c1)))*log((V_liquid+c1*B)/(V_liquid+c2*B)); for i=1:6 sumpart=0. ; for j=1:6 sumpart=sumpart+a_binary(i,j)*n_liquid(j) ; end dA_dni(i)=2*sumpart; end dFdB=(n_total_liquid/(V_liquid-B))+ ... (A/(R_gasconstant*T*B*(c2-c1)))*( c1/(V_liquid+c1*B)-c2/(V_liquid+c2*B)) ... - (A*log((V_liquid+c1*B)/(V_liquid+c2*B)))/(R_gasconstant*T*B*B*(c2-c1)) ;
44
dB_dni= b_individual ; dF_dni_liquid=dFdn+dFdA*dA_dni+dFdB*dB_dni; clear a_individual b_individual a_binary a_mixture b_mixture A B [n_total_vapor,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n_vapor); R_gasconstant = 8.314472; c1=1.0; c2=0.0; dFdn=log(V_vapor/(V_vapor-B)); dFdA=(1/(R_gasconstant*T*B*(c2-c1)))*log((V_vapor+c1*B)/(V_vapor+c2*B)); for i=1:6 sumpart=0. ; for j=1:6 sumpart=sumpart+a_binary(i,j)*n_vapor(j) ; end dA_dni(i)=2*sumpart; end dFdB=(n_total_vapor/(V_vapor-B))+ ... (A/(R_gasconstant*T*B*(c2-c1)))*( c1/(V_vapor+c1*B)-c2/(V_vapor+c2*B)) ... - (A*log((V_vapor+c1*B)/(V_vapor+c2*B)))/(R_gasconstant*T*B*B*(c2-c1)) ; dB_dni= b_individual ; dF_dni_vapor=dFdn+dFdA*dA_dni+dFdB*dB_dni; Muvapor_minus_Muliquid = R_gasconstant*T*(dF_dni_vapor+log(n_vapor/V_vapor)) - ... R_gasconstant*T*(dF_dni_liquid+log(n_liquid/V_liquid));
8. Function to calculate Vµ∂∂
function Mu_v=MU_V(V,n,T) % Function for calculating the second derivatives A_Vni [n_total,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n); R_gasconstant = 8.314472; % Set the parameters for SRK EOS in the general cubic equation c1=1.0;
45
c2=0.0; %--------------------------------------------------------------------- % Step 2: Calculate the derivative sum_aijnj=[0 0 0 0 0 0]; for i=1:6 for j=1:6 sum_aijnj(i)=sum_aijnj(i)+a_binary(i,j)*n(j); end end Mu_v=-(R_gasconstant*T*(V-B)+n_total*R_gasconstant*b_individual*T)/(V-B)^2 ... + (2*sum_aijnj*(V+c1*B)* ... (V+c2*B)-A*((c1+c2)*V*b_individual+2*c1*c2*B*b_individual))/ ... ((V+c1*B)*(V+c2*B))^2;
9. Function to calculate i
Pn∂∂
function P_ni=P_ni(V,n,T) % Function for calculating derivative P with ni %-------------------------------------------------------------------------- % step 1: Get the SRK EOS parameters [n_total,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n); R_gasconstant = 8.314472; % Set the parameters for SRK EOS in the general cubic equation c1=1.0; c2=0.0; %--------------------------------------------------------------------- % Step 2: Calculate the derivative aisumpart=[0 0 0 0 0 0]; for i=1:6 for j=1:6 aisumpart(i)=aisumpart(i)+a_binary(i,j)*n(j) ; end end P_ni=(R_gasconstant*T*(V-B)+n_total*R_gasconstant*T*b_individual)/(V-B)^2 ... -(2*aisumpart*(V+c1*B)*(V+c2*B)-A*(V*(c1+c2)*b_individual+2*c1*c2*B*b_individual))/ ... ((V+c1*B)*(V+c2*B))^2;
46
9. Function to calculate PV∂∂
function P_v=P_V(V,n,T) % step 1: Get the SRK EOS parameters [n_total,a_individual,b_individual,a_binary,a_mixture,b_mixture,A,B]=SRK_parameters(T,n); R_gasconstant = 8.314472; % Set the parameters for SRK EOS in the general cubic equation c1=1.0; c2=0.0; % Step 2: Calculate the derivative P_v= -n_total*R_gasconstant*T/(V-B)^2 ... + A*(2*V+c1*B+c2*B)/((V+c1*B)*(V+c2*B))^2;