UNIQUAC Matlab Code
UNIQUAC Matlab Code
UNIQUAC Matlab Code
On
Submitted by
Gaurav Tiwari
Under the guidance of
Prof.Kannan M. Moudgalya
Chemical Engineering Department
IIT Bombay
July 7, 2019
Acknowledgment
I wish to express my deepest gratitude to my internship guide Dr. Kannan M.
Moudgalya, Professor, Department of Chemical Engineering, IIT Bombay for his
continuous support and supervision throughout the internship. I would also like to
express my profound and heart felt thanks to our mentors Priyam Nayak,
Department of Chemical Engineering, IIT Bombay, A. S. Rahul, Department of
Chemical Engineering IIT Bombay, our college professor Dr. P. R. Naren, SCBT,
SASTRA Deemed University, and the FOSSEE team for their timely help and
guidance.
1
Contents
1 Introduction 3
2 Background 4
3 Entropy Function 5
3.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.4 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4 Extended UNIQUAC 8
4.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.2 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3 Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.4 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5 Conclusion 11
6 OpenModelica Code 13
2
Chapter 1
Introduction
3
Chapter 2
Background
4
Chapter 3
Entropy Function
3.1 Description
We can think of Entropy as a measure of randomness or disorder in an isolated
system. Entropy can be measured in two possible ways i.e. absolute entropy
and relative entropy. Absolute entropy can be measured using statistical method,
whereas the relative entropy is more related with the heat involved in the process,
thus making it a thermodynamic process. Entropy is a state function just like
Enthalpy,Internal Energy, thus independent of path. Entropy of a system is maxi-
mum when it reaches equilibrium, thus the change in entropy becomes zero. Under
isothermal conditions, the total entropy of a system in reversible process is zero
while in an irreversible process it is never zero,this is not the case with change in
Internal Energy which remains zero for both processes.
3.2 Equations
Entropy equation for an ideal gas can be derived using the first law of thermody-
namics
dU = dq + dw
at constant volume, W = 0
thus
5
R Tf Tf
∆Uv = 32 pV Ti
dT
T
= 32 pV ln Ti
dUT = dw = −pdV
Substituting equation of state and integrating the above equation we get,
RV V
∆UT = −nRT Vif dV V
= −nRT ln Vfi
∆UT = ∆w = −T ∆ST
∆S = ∆Sv + ∆ST
∆Q = T ∆S
Finally,
∆Q
∆S = T
6
3.3 Development
The equation is basically obtained from Maxwell’s relations
RT
Sm(T, P ) = Sm(T0 , P0 )+ T0 Cpm
T
dT − Rln(P/P0 )
3.4 Table
7
Chapter 4
Extended UNIQUAC
4.1 Description
Extended UNIQUAC (Universal QuasiChemical) is a thermodynamic (activity co-
efficient) model, specially designed for electrolyte solutions (both aqueous solutions
and mixed solvents). The model has proven itself applicable for calculations of
vapor-liquid-liquid-solid equilibria and of thermal properties in aqueous solutions
containing electrolytes and non-electrolytes. The extended UNIQUAC model con-
sists of three terms: a combinatorial or entropic term, a residual or enthalpic term
and an electrostatic term. The combinatorial and the residual terms are identical
to the terms used in the traditional UNIQUAC equation (ref 3 and 4). The elec-
trostatic term corresponds to the extended Debye-Hückel law. The combinatorial,
entropic term is independent of temperature and only depends on the relative sizes
of the species.
4.2 Equations
As said earlier, the extended UNIQUAC model consists of three terms: a combina-
torial or entropic term, a residual or enthalpic term and an electrostatic term. They
are:
Gex = Gex ex ex
combinatorial + Gresidual + GExtendedDebye−Huckel
Gex
combinatorial
X φi z X φi
= xi ln − qi xi ln
RT xi 2 θi
xi ri xi q i
φi = P ; θi = P
j xj rj j xj q j
Gex
residual
X X
=− (xi qi ln( θj ψji ))
RT i j
8
uji = uij = u0ij + uTij (T − 298.15)
φi φi z φi φi
lnγiC = ln +1− − q[ln + 1 − ]
xi xi 2 θi θi
X X θi φij
lnγiR = qi [1 − ln( θj ψji ) − P ]
j j k θ k ψ kj
ri ri z ri q w ri q w
lnγiC∞ = ln +1− − qi [ln +1− ]
rw rw 2 rw q i rw q i
2 3 1
lnγwDH = Mw AI 2 σ(bI 2 )
3
3 1
σ(x) = 3
1+x− − 2ln(1 + x)
x 1+x
√
∗DH 2 A I
lnγi = −Zi √
1+b I
γiC γiR
lnγi∗ = ln C∞
+ ln R∞
+ lnγi∗DH
γi γi
4.3 Development
This model is quite similar to the UNIQUAC model when we consider the resid-
ual and combinatorial terms in the model, and in addition to that we have used
an electrostatic term which is also called as Debye-Huckel Law term. This term
is used for calling out the interaction parameters of the ionic elements which will
be used during the simulation for instance a two component system containing
water − N a+ orN a+ − I − for which interaction parameters are completely different
from that of other compounds(organic mostly) and thus the need of Debye-Huckel
Law arises.
If at all the compounds contain organic/water elements then the system would basi-
cally call out the UNIQUAC interaction parameters. Thus, in OpenModelica we will
use the UNIQUAC interaction parameters only as for now since we don’t have the
ionic element database and their corresponding parameters.Here, the mixture will
comprise of water and organic compound because of which the interaction param-
eters of the mixture will become zero, this will cause residual term in the activity
9
coefficient to become zero, as of now we are not using ionic compounds thus the
Debye-Huckel term will also cease to exist. Hence, we will be left with only com-
binatorial term which will give us the activity coefficient and hence the fugacity
coefficient.
4.4 Table
10
Chapter 5
Conclusion
Entropy function contains liquid and gas entropy equations, out of which the liquid
equation was missing the liquid density correction factor which was forced upon
in DWSIM, we added that term to the liquid entropy formula and figured out the
output values in OpenModelica as well as DWSIM and compared them.
There was an erroneous routine followed in the calculation of the residual term
in UNIQUAC thermodynamic model which was giving inaccurate values of fugacity
coefficients that was also solved.
11
Reference
• B. Sander; P. Rasmussen and Aa. Fredenslund, “Calculation of Solid-Liquid
Equilibria in Aqueous Solutions of Nitrate Salts Using an Extended UNIQUAC
Equation”. Chemical Engineering Science, 41(1986)1197-1202
12
Chapter 6
OpenModelica Code
13
39 Svap := Entr − R ∗ l o g (P / P r e f ) − R ∗ l o g ( y ) ;
40 e l s e i f y == 0 then
41 S l i q := Entr − R ∗ l o g (P / P r e f ) − R ∗ l o g ( x ) − HV(HOV, Tc, T) / T + P
/1000/ P h a s e D e n s i t y /T ;
42 Svap := 0 ;
43 else
44 S l i q := 0 ;
45 Svap := 0 ;
46 end i f ;
47
48 end SId FuncENTROPY ;
14
41 / / R e a l PCF dew [ NOC ] ” P o y n t i n g C o r r e c t i o n F a c t o r ” ;
42 // Bubble P o i n t C a l c u l a t i o n V a r i a b l e s
43 / / I n t e r m e d i a t e v a r i a b l e s t o c a l c u l a t e t h e c o m b i n a t o r i a l and r e s i d u a l
part of a c t i v i t y c o e f f i c i e n t at bubble point
44 / / R e a l r b u b l ( s t a r t =2) , q b u b l ( s t a r t =2) ;
45 / / R e a l t e t a b u b l [ NOC ] ;
46 / / R e a l S b u b l [ NOC ] ;
47 / / R e a l s u m b u b l [ NOC ] ;
48 // A c t i v i t y C o e f f i c i e n t s
49 / / R e a l g a m m a c b u b l [ NOC ] ( e a c h s t a r t = 2 ) ” C o m b i n a t o r i a l P a r t o f a c t i v i t y
c o e f f i c e n t at bubble point ”;
50 / / R e a l g a m m a r b u b l [ NOC ] ( e a c h s t a r t = 1 ) ” R e s i d u a l p a r t o f a c t i v i t y
c o e f f i c e n t at bubble point ”;
51 / / R e a l g a m m a B u b l o l d [ NOC ] ( e a c h s t a r t = 1 ) ” C o m b i n a t o r i a l P a r t o f
a c t i v i t y c o e f f i c e n t ( without c o r r e c t i o n ) ”;
52 Real gammaBubl [NOC] ( each s t a r t = 1 ) ” A c t i v i t y c o e f f i c e n t a t bubble p o i n t
”;
53 // F u g a c i t y coefficient
54 Real l i q f u g c o e f f b u b l [NOC ] ;
55 / / R e a l p h i l b u b l [ NOC ] ( e a c h s t a r t = 0 . 5 ) ” L i q u i d P h a s e F u g a c i t y
c o e f f i c i e n t ”;
56 / / R e a l P C F b u b l [ NOC ] ” P o y n t i n g C o r r e c t i o n F a c t o r ” ;
57 // Phase E n v e l o p e
58 Real Psat [NOC] ( each u n i t = ”Pa” ) ” S a t u r a t e d Vapour P r e s s u r e a t t h e
input temperature ” ;
59 Real PCF[NOC] ” Poynting c o r r e c t i o n f a c t o r ” ;
60 Real K[NOC] ( each s t a r t = 0 . 7 ) ” D i s t r i b u t i o n C o e f f i c i e n t ” ;
61 // R e s i d u a l Energy P a r a m e t e r s
62 Real resMolSpHeat [ 3 ] , resMolEnth [ 3 ] , resMolEntr [ 3 ] ;
63 // T r a n s p o r t Properties at the input conditions
64 Real D e n s i t y [NOC] ( each u n i t = ” kmol /mˆ3 ” ) ;
65 Real A[NOC ] , B [NOC ] , D[NOC ] , E [NOC ] , Ff [NOC ] ;
66 Real C [NOC ] ;
67 // R e a l A b u b l [ NOC ] , B b u b l [ NOC ] , C b u b l [ NOC ] , D b u b l [ NOC ] , E b u b l [ NOC ] ,
F b u b l [ NOC ] ;
68 // R e a l A dew [ NOC ] , B dew [ NOC ] , C dew [ NOC ] , D dew [ NOC ] , E dew [ NOC ] , F dew [ NOC
];
69 //
====================================================================================
70 // E q u a t i o n Section
71 equation
72 // F u g a c i t y c o e f f i c i e n t s set to 1 s i n c e t h e model type is Activity
Coefficient
73 f o r i in 1 :NOC loop
74 gammaBubl [ i ] = 1 ;
75 gammaDew [ i ] = 1 ;
76 liqfugcoeff bubl [ i ] = 1;
77 vapfugcoeff dew [ i ] = 1;
78 end f o r ;
79
80
81
82 / / C a l c u l a t i o n o f I n t e r m e d i a t e p a r a m e t e r s t o e v a l u a t e c o m b i n a t o r i a l and
r e s i d u a l part of the a c t i v i t y c o e f f i c i e n t
83 // Note : compMolFrac i s t h e r e f e r e n c e d from ” M a t e r i a l Stream ” model
84
85 r = sum ( compMolFrac [ 2 , : ] .∗ R[ : ] ) ;
86 q = sum ( compMolFrac [ 2 , : ] .∗ Q[ : ] ) ;
87
88 // C a l c u l a t i o n o f Energy i n t e r a c t i o n p a r a m e t e r a t t h e input tempetraure
89 / / F u n c t i o n : Tow UNIQUAC i s u s e d t o i n s t a n t i a t e d
90 tow = Simulator.Files.Thermodynamic Functions.Tow UNIQUAC (NOC, a , T) ;
91 // C a l c u l a t i o n of C o m b i n a t o r i a l and R e s i d u a l Activity coefficient
15
92
93 f o r i in 1 :NOC loop
94 i f ( q>0) then
95 t e t a [ i ] = compMolFrac [ 2 , i ] ∗ Q[ i ] ∗ ( 1 / q ) ;
96 e l s e i f ( q<0) then
97 teta [ i ]=0;
98 else
99 teta [ i ]=0;
100 end i f ;
101 end f o r ;
102
103 f o r i in 1 :NOC loop
104 if ( t e t a [ i ]==0) then
105 S [ i ]=1;
106 else
107 S [ i ] = sum ( t e t a [ : ] . ∗ tow [ i , :]) ;
108 end i f ;
109
110 i f ( S [ i ]==1) then
111 sum [ i ]=sum ( t e t a [ : ] . ∗ tow [ i , : ] ) ;
112 else
113 sum [ i ] = sum ( t e t a [ : ] . ∗ tow [ i , : ] . / S [ : ] ) ;
114 end i f ;
115 end f o r ;
116
117 f o r i in 1 :NOC loop
118
119 i f ( S [ i ]==1) then
120 C[ i ] = 0 ;
121 e l s e i f ( S [ i ] >0 and S [ i ]<>1) then
122 C[ i ] = l o g (S [ i ] ) ;
123 else
124 C[ i ]=0;
125 end i f ;
126
127 ( gammar [ i ] ) = exp (Q[ i ] ∗ ( 1 − C [ i ] − sum [ i ] ) ) ;
128 end f o r ;
129 / / //===================================================================
130 // equation
131
132 f o r i in 1 :NOC loop
133 i f ( r >0) then
134 D[ i ] = R[ i ] / r ;
135 e l s e i f ( r <=0) then
136 D[ i ] =0;
137 else
138 D[ i ] = 0 ;
139 end i f ;
140
141 i f ( q>0) then
142 E [ i ] = Q[ i ] / q ;
143 e l s e i f ( q<=0) then
144 E[ i ] = 0;
145 else
146 E[ i ] = 0;
147 end i f ;
148
149 i f (E [ i ]==0 or D[ i ]==0) then
150 Ff [ i ] = 0 ;
151 else
152 Ff [ i ] = D[ i ] / E [ i ] ;
153 end i f ;
154
155
16
156 i f (D[ i ] >0) then
157 A[ i ] =l o g (D[ i ] ) ;
158 e l s e i f (D[ i ]==1) then
159 A[ i ] = 0 ;
160 else
161 A[ i ] = 0 ;
162 end i f ;
163
164 i f ( Ff [ i ] > 0 . 5 ) then
165 B [ i ] =l o g ( Ff [ i ] ) ;
166 e l s e i f ( Ff [ i ]==1) then
167 B[ i ]=0;
168 else
169 B[ i ]=0;
170 end i f ;
171
172 l o g ( gammac [ i ] ) =1−D[ i ] + A[ i ] + (−Z / 2 ∗ Q[ i ] ∗ ( 1 − Ff [ i ] + B [ i ] ) ) ;
173
174 (gamma [ i ] ) = ( gammac [ i ] ) ; / / ( gammar [ i ] ) ;
175 end f o r ;
176 //
========================================================================================
17
[ 3 ] ( each s t a r t = 0 , each min = 0 ) ” Average M o l e c u l a r w e i g h t o f Phases
”;
12 Real compMolFrac [ 3 , NOC] ( each min = 0 , each max = 1 , each s t a r t = 1 / (
NOC + 1 ) ) ”Component mole f r a c t i o n ” , compMasFrac [ 3 , NOC] ( each s t a r t =
1 / (NOC + 1 ) , each min = 0 , each max = 1 ) ”Component Mass f r a c t i o n ”
, compMolFlo [ 3 , NOC] ( each s t a r t = 1 0 0 , each min = 0 ) ”Component Molar
f l o w ” , compMasFlo [ 3 , NOC] ( each min = 0 , each s t a r t = 1 0 0 ) ”Component
Mass F r a c t i o n ” ;
13 Real phasMolSpHeat [ 3 ] ” phase Molar S p e c i f i c Heat ” , compMolSpHeat [ 3 , NOC]
”Component Molar S p e c i f i c Heat ” ;
14 Real phasMolEnth [ 3 ] ” Phase Molar Enthalpy ” , compMolEnth [ 3 , NOC] ”
Component Molar Enthalpy ” ;
15 Real phasMolEntr [ 3 ] ” Phase Molar Entropy ” , compMolEntr [ 3 , NOC] ”Component
Molar Entropy ” ;
16 Real L i q u i d P h a s e D e n s i t y ;
17 Real LiqDens [NOC ] ;
18 S i m u l a t o r . F i l e s . C o n n e c t i o n . m a t C o n n i n l e t (connNOC = NOC) annotation (
19 Placement ( v i s i b l e = t r u e , t r a n s f o r m a t i o n ( o r i g i n = {−100, 0 } , e x t e n t =
{{−10, −10}, { 1 0 , 1 0 } } , r o t a t i o n = 0 ) , i c o n T r a n s f o r m a t i o n ( o r i g i n =
{−100, 0 } , e x t e n t = {{−10, −10}, { 1 0 , 1 0 } } , r o t a t i o n = 0 ) ) ) ;
20 S i m u l a t o r . F i l e s . C o n n e c t i o n . m a t C o n n o u t l e t (connNOC = NOC) annotation (
21 Placement ( v i s i b l e = t r u e , t r a n s f o r m a t i o n ( o r i g i n = { 1 0 0 , 0 } , e x t e n t =
{{−10, −10}, { 1 0 , 1 0 } } , r o t a t i o n = 0 ) , i c o n T r a n s f o r m a t i o n ( o r i g i n =
{ 1 0 0 , 0 } , e x t e n t = {{−10, −10}, { 1 0 , 1 0 } } , r o t a t i o n = 0 ) ) ) ;
22 equation
23 // C o n n e c t o r equations
24 i n l e t . P = P;
25 i n l e t . T = T;
26 inlet.mixMolFlo = totMolFlo [ 1 ] ;
27 i n l e t . m i x M o l E n t h = phasMolEnth [ 1 ] ;
28 i n l e t . m i x M o l E n t r = phasMolEntr [ 1 ] ;
29 i n l e t . m i x M o l F r a c = compMolFrac ;
30 i n l e t . v a p P h a s M o l F r a c = vapPhasMolFrac ;
31 outlet.P = P;
32 o u t l e t . T = T;
33 outlet.mixMolFlo = totMolFlo [ 1 ] ;
34 o u t l e t . m i x M o l E n t h = phasMolEnth [ 1 ] ;
35 o u t l e t . m i x M o l E n t r = phasMolEntr [ 1 ] ;
36 o u t l e t . m i x M o l F r a c = compMolFrac ;
37 o u t l e t . v a p P h a s M o l F r a c = vapPhasMolFrac ;
38 //
=====================================================================================
39 // Mole B a l a n c e
40 totMolFlo [ 1 ] = totMolFlo [ 2 ] + totMolFlo [ 3 ] ;
41 compMolFrac [ 1 , : ] . ∗ t o t M o l F l o [ 1 ] = compMolFrac [ 2 , : ] . ∗ totMolFlo [ 2 ] +
compMolFrac [ 3 , : ] . ∗ t o t M o l F l o [ 3 ] ;
42 / / c o m p o n e n t m o l a r and m a s s f l o w s
43 f o r i in 1 :NOC loop
44 compMolFlo [ : , i ] = compMolFrac [ : , i ] . ∗ totMolFlo [ : ] ;
45 end f o r ;
46 i f P >= Pbubl then
47 // below b u b b l e point region
48 compMasFrac [ 3 , : ] = z e r o s (NOC) ;
49 compMasFlo [ 1 , : ] = compMasFrac [ 1 , : ] . ∗ totMasFlo [ 1 ] ;
50 compMasFrac [ 2 , : ] = compMasFrac [ 1 , : ] ;
51 e l s e i f P >= Pdew then
52 f o r i in 1 :NOC loop
53 compMasFlo [ : , i ] = compMasFrac [ : , i ] . ∗ totMasFlo [ : ] ;
54 end f o r ;
55 else
56 / / a b o v e dew p o i n t region
57 compMasFrac [ 2 , : ] = z e r o s (NOC) ;
58 compMasFlo [ 1 , : ] = compMasFrac [ 1 , : ] . ∗ totMasFlo [ 1 ] ;
18
59 compMasFrac [ 3 , : ] = compMasFrac [ 1 , :];
60 end i f ;
61 / / p h a s e m o l a r and m a s s fractions
62 liqPhasMolFrac = totMolFlo [ 2 ] / totMolFlo [1];
63 vapPhasMolFrac = totMolFlo [ 3 ] / totMolFlo [1];
64 liqPhasMasFrac = totMasFlo [ 2 ] / totMasFlo [1];
65 vapPhasMasFrac = totMasFlo [ 3 ] / totMasFlo [1];
66 / / C o n v e r s i o n b e t w e e n m o l e and m a s s f l o w
67 f o r i in 1 :NOC loop
68 compMasFlo [ : , i ] = compMolFlo [ : , i ] ∗ comp [ i ] .MW;
69 end f o r ;
70 totMasFlo [ : ] = t o t M o l F l o [ : ] . ∗ MW[ : ] ;
71 // Energy B a l a n c e
72 f o r i in 1 :NOC loop
73 // S p e c i f i c H e a t and E n t h a l p y calculation
74 compMolSpHeat [ 2 , i ] = Thermodynamic Functions.LiqCpId ( comp [ i ] . LiqCp, T)
;
75 compMolSpHeat [ 3 , i ] = Thermodynamic Functions.VapCpId ( comp [ i ] . VapCp, T)
;
76 compMolEnth [ 2 , i ] = Thermodynamic Functions.HLiqId ( comp [ i ] . SH, comp [ i ] .
VapCp, comp [ i ] . HOV, comp [ i ] . Tc, T) ;
77 compMolEnth [ 3 , i ] = Thermodynamic Functions.HVapId ( comp [ i ] . SH, comp [ i ] .
VapCp, comp [ i ] . HOV, comp [ i ] . Tc, T) ;
78 ( compMolEntr [ 2 , i ] , compMolEntr [ 3 , i ] ) = Thermodynamic Functions.SId (
comp [ i ] . AS, comp [ i ] . VapCp, comp [ i ] . HOV, comp [ i ] . Tb, comp [ i ] . Tc, T,
P, compMolFrac [ 2 , i ] , compMolFrac [ 3 , i ] , L i q u i d P h a s e D e n s i t y ) ;
79 end f o r ;
80 f o r i in 2 : 3 loop
81 phasMolSpHeat [ i ] = sum ( compMolFrac [ i , : ] . ∗ compMolSpHeat [ i , : ] ) +
resMolSpHeat [ i ] ;
82 phasMolEnth [ i ] = sum ( compMolFrac [ i , : ] . ∗ compMolEnth [ i , : ] ) +
resMolEnth [ i ] ;
83 phasMolEntr [ i ] = sum ( compMolFrac [ i , : ] . ∗ compMolEntr [ i , : ] ) +
resMolEntr [ i ] ;
84 end f o r ;
85 phasMolSpHeat [ 1 ] = l i q P h a s M o l F r a c ∗ phasMolSpHeat [ 2 ] + vapPhasMolFrac ∗
phasMolSpHeat [ 3 ] ;
86 compMolSpHeat [ 1 , : ] = compMolFrac [ 1 , : ] . ∗ phasMolSpHeat [ 1 ] ;
87 phasMolEnth [ 1 ] = l i q P h a s M o l F r a c ∗ phasMolEnth [ 2 ] + vapPhasMolFrac ∗
phasMolEnth [ 3 ] ;
88 compMolEnth [ 1 , : ] = compMolFrac [ 1 , : ] . ∗ phasMolEnth [ 1 ] ;
89 phasMolEntr [ 1 ] = l i q P h a s M o l F r a c ∗ phasMolEntr [ 2 ] + vapPhasMolFrac ∗
phasMolEntr [ 3 ] ;
90 compMolEntr [ 1 , : ] = compMolFrac [ 1 , : ] ∗ phasMolEntr [ 1 ] ;
91 // Bubble p o i n t calculation
92 Pbubl = sum ( gammaBubl [ : ] . ∗ compMolFrac [ 1 , : ] . ∗ exp ( comp [ : ] . VP [ 2 ] + comp
[ : ] . VP [ 3 ] / T + comp [ : ] . VP [ 4 ] ∗ l o g (T) + comp [ : ] . VP [ 5 ] . ∗ T . ˆ comp
[ : ] . VP [ 6 ] ) . / l i q f u g c o e f f b u b l [ : ] ) ;
93 / / Dew p o i n t calculation
94 Pdew = 1 / sum ( compMolFrac [ 1 , : ] . / (gammaDew [ : ] . ∗ exp ( comp [ : ] . VP [ 2 ] +
comp [ : ] . VP [ 3 ] / T + comp [ : ] . VP [ 4 ] ∗ l o g (T) + comp [ : ] . VP [ 5 ] . ∗ T . ˆ
comp [ : ] . VP [ 6 ] ) ) . ∗ v a p f u g c o e f f d e w [ : ] ) ;
95 i f P >= Pbubl then
96 // below b u b b l e point region
97 compMolFrac [ 3 , : ] = z e r o s (NOC) ;
98 sum ( compMolFrac [ 2 , : ] ) = 1 ;
99 e l s e i f P >= Pdew then
100 / /VLE r e g i o n
101 f o r i in 1 :NOC loop
102 compMolFrac [ 3 , i ] = K[ i ] ∗ compMolFrac [ 2 , i ] ;
103 end f o r ;
104 sum ( compMolFrac [ 3 , : ] ) = 1 ;
105 / / sum y = 1
106 else
19
107 / / a b o v e dew p o i n t region
108 compMolFrac [ 2 , : ] = z e r o s (NOC) ;
109 sum ( compMolFrac [ 3 , : ] ) = 1 ;
110 end i f ;
111 algorithm
112 f o r i in 1 :NOC loop
113 MW[ : ] := MW[ : ] + comp [ i ] .MW ∗ compMolFrac [ : , i ] ;
114 end f o r ;
115 LiqDens [ : ] := T h e r m o d y n a m i c F u n c t i o n s . D e n s i t y R a c k e t (NOC, T, P, comp [ : ] .
P c , comp [ : ] . Tc, comp [ : ] . Racketparam, comp [ : ] . AF, comp [ : ] . MW, Psat
[:]) ;
116
117 L i q u i d P h a s e D e n s i t y := 1 / sum ( compMasFrac [ 2 , : ] . / LiqDens [ : ] ) / MW[ 2 ] ;
118
119 end Mat Stream ;
20
;
38 // F u g a c i t y coefficient
39 Real v a p f u g c o e f f d e w [NOC] ” Vapour F u g a c i t y c o e f f i c i e n t a t dew p o i n t ” ;
40 Real p h i l d e w [NOC] ( each s t a r t = 0 . 5 ) ;
41 Real PCF dew [NOC] ” Poynting C o r r e c t i o n F a c t o r ” ;
42 // Bubble P o i n t C a l c u l a t i o n V a r i a b l e s
43 / / I n t e r m e d i a t e v a r i a b l e s t o c a l c u l a t e t h e c o m b i n a t o r i a l and residual
part of a c t i v i t y c o e f f i c i e n t at bubble point
44 Real r b u b l ( s t a r t =2) , q b u b l ( s t a r t =2) ;
45 Real t e t a b u b l [NOC ] ;
46 Real S b u b l [NOC ] ;
47 Real sum bubl [NOC ] ;
48 // A c t i v i t y Coefficients
49 Real gammac bubl [NOC] ( each s t a r t = 2 ) ” C o m b i n a t o r i a l Part o f a c t i v i t y
c o e f f i c e n t a t bubble p o i n t ” ;
50 Real gammar bubl [NOC] ( each s t a r t = 1 ) ” R e s i d u a l p a r t o f a c t i v i t y
c o e f f i c e n t a t bubble p o i n t ” ;
51 Real gammaBubl old [NOC] ( each s t a r t = 1 ) ” C o m b i n a t o r i a l Part o f a c t i v i t y
c o e f f i c e n t ( without c o r r e c t i o n ) ” ;
52 Real gammaBubl [NOC] ( each s t a r t = 1 ) ” A c t i v i t y c o e f f i c e n t a t bubble
point ” ;
53 // F u g a c i t y coefficient
54 Real l i q f u g c o e f f b u b l [NOC ] ;
55 Real p h i l b u b l [NOC] ( each s t a r t = 0 . 5 ) ” L i q u i d Phase F u g a c i t y
coefficient”;
56 Real PCF bubl [NOC] ” Poynting C o r r e c t i o n F a c t o r ” ;
57 // Phase E n v e l o p e
58 Real Psat [NOC] ( each u n i t = ”Pa” ) ” S a t u r a t e d Vapour P r e s s u r e a t t h e
input temperature ” ;
59 Real PCF[NOC] ” Poynting c o r r e c t i o n f a c t o r ” ;
60 Real K[NOC] ( each s t a r t = 0 . 7 ) ” D i s t r i b u t i o n C o e f f i c i e n t ” ;
61 // R e s i d u a l Energy P a r a m e t e r s
62 Real resMolSpHeat [ 3 ] , resMolEnth [ 3 ] , resMolEntr [ 3 ] ;
63 // T r a n s p o r t Properties at the input conditions
64 Real D e n s i t y [NOC] ( each u n i t = ” kmol /mˆ3 ” ) ;
65 Real A[NOC ] , B [NOC ] , D[NOC ] , E [NOC ] , Ff [NOC ] ;
66 Real C [NOC ] ;
67 Real A bubl [NOC ] , B bubl [NOC ] , C bubl [NOC ] , D bubl [NOC ] , E bubl [NOC ] , F bubl
[NOC ] ;
68 Real A dew [NOC ] , B dew [NOC ] , C dew [NOC ] , D dew [NOC ] , E dew [NOC ] , F dew [NOC ] ;
69 //
====================================================================================
70 // E q u a t i o n Section
71 equation
72 // F u g a c i t y c o e f f i c i e n t s set to 1 s i n c e t h e model type is Activity
Coefficient
73 f o r i in 1 :NOC loop
74 liqfugcoeff bubl [ i ] = 1;
75 vapfugcoeff dew [ i ] = 1;
76 end f o r ;
77 / / C a l c u l a t i o n o f I n t e r m e d i a t e p a r a m e t e r s t o e v a l u a t e c o m b i n a t o r i a l and
r e s i d u a l part of the a c t i v i t y c o e f f i c i e n t
78 // Note : compMolFrac i s t h e r e f e r e n c e d from ” M a t e r i a l Stream ” model
79
80 r = sum ( compMolFrac [ 2 , : ] .∗ R[ : ] ) ;
81 q = sum ( compMolFrac [ 2 , : ] .∗ Q[ : ] ) ;
82
83 // C a l c u l a t i o n o f Energy i n t e r a c t i o n p a r a m e t e r a t t h e input tempetraure
84 / / F u n c t i o n : Tow UNIQUAC i s u s e d t o i n s t a n t i a t e d
85 tow = Simulator.Files.Thermodynamic Functions.Tow UNIQUAC (NOC, a , T) ;
86 // C a l c u l a t i o n of C o m b i n a t o r i a l and R e s i d u a l Activity coefficient
87
88 f o r i in 1 :NOC loop
21
89 i f ( q>0) then
90 t e t a [ i ] = compMolFrac [ 2 , i ] ∗ Q[ i ] ∗ ( 1 / q ) ;
91 e l s e i f ( q<0) then
92 teta [ i ]=0;
93 else
94 teta [ i ]=0;
95 end i f ;
96 end f o r ;
97
98 f o r i in 1 :NOC loop
99 if ( t e t a [ i ]==0) then
100 S [ i ]=1;
101 else
102 S [ i ] = sum ( t e t a [ : ] . ∗ tow [ i , :]) ;
103 end i f ;
104
105 i f ( S [ i ]==1) then
106 sum [ i ] = 0 ;
107 else
108 sum [ i ] = sum ( t e t a [ : ] . ∗ tow [ i , : ] ./ S [ : ] ) ;
109 end i f ;
110 end f o r ;
111
112 f o r i in 1 :NOC loop
113
114 i f ( S [ i ]==1) then
115 C[ i ] = 0 ;
116 e l s e i f ( S [ i ] >0) then
117 C[ i ] = l o g (S [ i ] ) ;
118 else
119 C[ i ]=0;
120 end i f ;
121
122 ( gammar [ i ] ) = exp (Q[ i ] ∗ ( 1 − C [ i ] − sum [ i ] ) ) ;
123 end f o r ;
124 / / //===================================================================
125 // equation
126
127 f o r i in 1 :NOC loop
128 i f ( r >0) then
129 D[ i ] = R[ i ] / r ;
130 e l s e i f ( r <=0) then
131 D[ i ] =0;
132 else
133 D[ i ] = 0 ;
134 end i f ;
135
136 i f ( q>0) then
137 E [ i ] = Q[ i ] / q ;
138 e l s e i f ( q<=0) then
139 E[ i ] = 0;
140 else
141 E[ i ] = 0;
142 end i f ;
143
144 i f (E [ i ]==0 or D[ i ]==0) then
145 Ff [ i ] = 0 ;
146 else
147 Ff [ i ] = D[ i ] / E [ i ] ;
148 end i f ;
149
150
151 i f (D[ i ] >0) then
152 A[ i ] =l o g (D[ i ] ) ;
22
153 e l s e i f (D[ i ]==1) then
154 A[ i ] = 0 ;
155 else
156 A[ i ] = 0 ;
157 end i f ;
158
159 i f ( Ff [ i ] >1) then
160 B [ i ] =l o g ( Ff [ i ] ) ;
161 e l s e i f ( Ff [ i ]==1) then
162 B[ i ]=0;
163 else
164 B[ i ]=0;
165 end i f ;
166
167 l o g ( gammac [ i ] ) =1−D[ i ] + A[ i ] + (−Z / 2 ∗ Q[ i ] ∗ ( 1 − Ff [ i ] + B [ i ] ) ) ;
168
169 (gamma [ i ] ) = ( gammac [ i ] ) ∗ ( gammar [ i ] ) ;
170 end f o r ;
171 //
========================================================================================
23
204 else
205 t e t a d e w [ i ] = dewLiqMolFrac [ i ] ∗ Q[ i ] ∗ ( 1 / q dew ) ;
206 end i f ;
207 i f ( t e t a d e w [ i ]==0) then
208 S dew [ i ] =1;
209 else
210 S dew [ i ] = sum ( t e t a d e w [ : ] . ∗ tow [ i , : ] ) ;
211 end i f ;
212 end f o r ;
213 //
=======================================================================================
214
215 f o r i in 1 :NOC loop
216 i f ( S dew [ i ]==1) then
217 sum dew [ i ] = 0 ;
218 else
219 sum dew [ i ] = sum ( t e t a d e w [ : ] . ∗ tow [ i , : ] . / ( S dew [ : ] ) ) ;
220 end i f ;
221
222
223 i f ( S dew [ i ]==1) then
224 C dew [ i ] = 0 ;
225 e l s e i f ( S dew [ i ] >0) then
226 C dew [ i ] =l o g ( S dew [ i ] ) ;
227 else
228 C dew [ i ] = 0 ;
229 end i f ;
230
231 ( gammar dew [ i ] ) = exp (Q[ i ] ∗ ( 1 − C dew [ i ] − sum dew [ i ] ) ) ;
232 end f o r ;
233 //
========================================================================================
234
235 f o r i in 1 :NOC loop
236 i f ( r dew==0) then
237 D dew [ i ] =0;
238 else
239 D dew [ i ] = R[ i ] / r dew ;
240 end i f ;
241
242 i f ( q dew==0) then
243 E dew [ i ] = 0 ;
244 else
245 E dew [ i ] = Q[ i ] / q dew ;
246 end i f ;
247
248 i f ( E dew [ i ]==0) then
249 F dew [ i ] = 0 ;
250 else
251 F dew [ i ] = D dew [ i ] / E dew [ i ] ;
252 end i f ;
253
254
255 i f ( D dew [ i ] >0) then
256 A dew [ i ] =l o g ( D dew [ i ] ) ;
257 e l s e i f ( D dew [ i ]==1) then
258 A dew [ i ] = 0 ;
259 else
260 A dew [ i ] = 0 ;
261 end i f ;
262
263 i f ( F dew [ i ] >0) then
24
264 B dew [ i ] =l o g ( F dew [ i ] ) ;
265 e l s e i f ( F dew [ i ]==1) then
266 B dew [ i ] = 0 ;
267 else
268 B dew [ i ] = 0 ;
269 end i f ;
270
271 l o g ( gammac dew [ i ] ) =1−D dew [ i ] + A dew [ i ] + (−Z / 2 ∗ Q[ i ] ∗ ( 1 −
F dew [ i ] + B dew [ i ] ) ) ;
272
273 ( gammaDew old [ i ] ) = ( gammac dew [ i ] ) ∗ ( gammar dew [ i ] ) ;
274 end f o r ;
275
276 f o r i in 1 :NOC loop
277 i f ( Pdew==0) then
278 phil dew [ i ]=1;
279 gammaDew [ i ] = 1 ;
280
281 else
282
283 phil d e w [ i ] = gammaDew old [ i ] . ∗ Psat [ i ] . / Pdew . ∗ PCF dew [ i ] ;
284 phil d e w [ i ] = gammaDew [ i ] . ∗ Psat [ i ] . / Pdew ;
285 end if ;
286 end for ;
287 / / The same c a l c u l a t i o n routine is followed at the Bubble Point
288 // Bubble P o i n t
289 r b u b l = sum ( compMolFrac [ 1 , : ] . ∗ R [ : ] ) ;
290 q b u b l = sum ( compMolFrac [ 1 , : ] . ∗ Q [ : ] ) ;
291 f o r i in 1 :NOC loop
292 i f ( compMolFrac [ 1 , i ]==0) then
293 teta bubl [ i ]=0;
294 else
295 t e t a b u b l [ i ] = compMolFrac [ 1 , i ] ∗ Q[ i ] ∗ ( 1 / q b u b l ) ;
296 end i f ;
297
298 i f ( t e t a b u b l [ i ]==0) then
299 S b u b l [ i ] =1;
300 else
301 S b u b l [ i ] = sum ( t e t a b u b l [ : ] . ∗ tow [ i , :]) ;
302 end i f ;
303
304 i f ( S b u b l [ i ]==1) then
305 sum bubl [ i ] = 0 ;
306 else
307 sum bubl [ i ] = sum ( t e t a b u b l [ : ] . ∗ tow [ i , : ] . / S bubl [ : ] ) ;
308 end i f ;
309
310
311 i f ( S b u b l [ i ]==1) then
312 C bubl [ i ] =0 ;
313 e l s e i f ( S b u b l [ i ] >0) then
314 C bubl [ i ]= l o g ( S b u b l [ i ] ) ;
315 else
316 C bubl [ i ] = 0 ;
317 end i f ;
318 l o g ( gammar bubl [ i ] ) = Q[ i ] ∗ ( 1 − C bubl [ i ] − sum bubl [ i ] ) ;
319 //
========================================================================================
320
321 i f ( r b u b l ==0) then
322 D bubl [ i ] =0;
323 else
324 D bubl [ i ] = R[ i ] / r b u b l ;
25
325 end i f ;
326
327 i f ( q b u b l ==0) then
328 E bubl [ i ] = 0 ;
329 else
330 E bubl [ i ] = Q[ i ] / q b u b l ;
331 end i f ;
332
333 i f ( E bubl [ i ]==0) then
334 F bubl [ i ] = 0 ;
335 else
336 F bubl [ i ] = D bubl [ i ] / E bubl [ i ] ;
337 end i f ;
338
339
340 i f ( D bubl [ i ] >0) then
341 A bubl [ i ] =l o g ( D bubl [ i ] ) ;
342 e l s e i f ( D bubl [ i ]==1) then
343 A bubl [ i ] = 0 ;
344 else
345 A bubl [ i ] = 0 ;
346 end i f ;
347
348 i f ( F bubl [ i ] >0) then
349 B bubl [ i ] =l o g ( F bubl [ i ] ) ;
350 e l s e i f ( F bubl [ i ]==1) then
351 B bubl [ i ] = 0 ;
352 else
353 B bubl [ i ] = 0 ;
354 end i f ;
355
356 l o g ( gammac bubl [ i ] ) =1−D bubl [ i ] + A bubl [ i ] + (−Z / 2 ∗ Q[ i ] ∗ ( 1 −
F bubl [ i ] + B bubl [ i ] ) ) ;
357
358 ( gammaBubl old [ i ] ) = ( gammac bubl [ i ] ) ∗ ( gammar bubl [ i ] ) ;
359 end f o r ;
360
361 f o r i in 1 :NOC loop
362 i f ( Pbubl==0) then
363 phil bubl [ i ]=1;
364 gammaBubl [ i ] = 1 ;
365 else
366 p h i l b u b l [ i ] = gammaBubl old [ i ] . ∗ Psat [ i ] . / Pbubl . ∗ PCF bubl [ i ] ;
367 p h i l b u b l [ i ] = gammaBubl [ i ] . ∗ Psat [ i ] . / Pbubl ;
368 end i f ;
369 end f o r ;
370 end UNIQUAC Correction ;
26