Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

UNIQUAC Matlab Code

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Summer Fellowship Report

On

Development of Thermodynamic Models and Functions in


OpenModelica

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

“OpenModelica” is a free and open-source modelling environment that uses “Model-


ica” modelling language. It follows equation oriented approach. OpenModelica can
be used for modelling, simulation, optimization and analysis of complex steady state
and dynamic systems. Modelica modelling language allows users to express a system
in the form of equations. OpenModelica complies expressions, equations, functions
and algorithms into efficient C code. The generated C code is combined with a
library of utility functions, a run-time library, and a numerical Differential-Algebric
Equation (DAE) solver. OpenModelica Connection Editor, called as OMEdit is the
integrated Graphical User Interface (GUI) in OpenModelica for graphical modelling
and editing. OMEdit consists of several libraries for various domains like Electrical,
Magnetic, Math, Thermal, etc. It provides various user friendly features like repre-
sentation of a model in the form of block diagrams. OMEdit can be used for creating
custom models and for editing or drawing connections between the model interfaces.
It also allows users to plot graphs between parameters of the model simulated.

3
Chapter 2

Background

OMEdit, the integrated Graphical User Interface (GUI) of OpenModelica consists


of libraries across various domains such as Electrical, Thermal, Math, Mechanics,
etc. that can be used to develop models of a physical system or process. However,
OMEdit does not contain libraries for modelling of chemical process systems. This
limits the use of OpenModelica for modelling chemical process systems. Hence, it
becomes necessary to build models or packages that aids in modelling of chemi-
cal process systems. An essential requirement is the availability of thermodynamic
packages to estimate fluid properties. The main aim of this work is to develop stan-
dard thermodynamic packages in OpenModelica. In this work, a thermodynamic
package, namely ”Extended UNIQUAC developed in OpenModelica. Inorder to
develop thermodynamic packages in OpenModelica, properties such as critical tem-
perature, critical pressure, acentric factor, molecular weight, etc. of the components
that constitutes the system are required. For now, we are not using the electrolytes
present in DWSIM but relying only on the current database of OpenModelica. The
developed thermodynamic packages can be used to calculate fugacity coefficient and
activity coefficient of solutions. This package was designed for the use of electrolytic
solutions which involve water as well as some limited number of ionic compounds.

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

dUv = dqv = ncv dT


Assuming a monoatomic gas, where only translational energies are present ,
3
cv = R
2
here, R can be substituted with equation of state for ideal gases and thus
3 dT
dUv = pV
2 T
Integrating the equation gives,

5
R Tf Tf
∆Uv = 32 pV Ti
dT
T
= 32 pV ln Ti

Employing equation of state in the above equation,


Tf
∆Uv = ncv T ln
Ti
This equation contains the expression of entropy for constant volume.
T
∆Sv = ncv ln Tfi

Internal Energy then,

∆Uv = ∆qv = T ∆Sv

At constant temperature the heat term is zero,

dUT = dw = −pdV
Substituting equation of state and integrating the above equation we get,
RV V
∆UT = −nRT Vif dV V
= −nRT ln Vfi

Hence, the expression of entropy for constant temperature


V
∆ST = nRln Vfi

Thus, internal energy becomes,

∆UT = ∆w = −T ∆ST

∆UT = ∆qv + ∆w = ∆Uv + ∆UT = T ∆Sv − T ∆ST = T (∆SV − ∆ST )

∆Q = ∆qv − ∆w = T ∆Sv − (−T ∆ST ) = T (∆Sv + ∆ST )

Summing the two parts,

∆S = ∆Sv + ∆ST

Heat equation then,

∆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 )

Cpm = Cp0 + Cp1 ∗ T + Cp2 ∗ T 2 + Cp3 ∗ T 3


The routine of this equation was basically referred from the DWSIM source
code, which is available on GitHub as well as on Visual Studio. The code previously
developed on OpenModelica had two separate equations for entropy. The equations
involved are liquid phase entropy and gas phase entropy out of which the liquid
phase entropy had a correction term missing. After searching through the code of
entropy function in visual basic we across a term which involved liquid density as
well as temperature and pressure. This term was added to the previous equation
of liquid phase entropy equation and there was a significant improvement in the
accuracy of the values obtained.

3.4 Table

Compound OpenModelica (kJ/kg K) DWSIM (kJ/kg K) Error Percentage


Benzene -
-1.32887 -1.3284 0.04%
Toluene
Acetone -
-2.10373 -2.1037 0.00%
1-Propanol
N-Octane -
-1.14877 -1.14862 0.01%
N-Nonane

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

ψji = exp−(uji −uii )/T

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

lnγiR∞ = qi [1 − lnψwi − ψiw ]

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

A = [1.131 + 1.335 ∗ 10−03 (T − 273.15) + 1.164 ∗ 10−05 (T − 273.15)2 ](kg/kmol)

lnγw = lnγwC + lnγwR + lnγwDH

γ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

Activity Coefficient Fugacity Coefficient


OpenModelica DWSIM OpenModelica DWSIM Error %age
Methanol 1.04062 1.0694536 1.71366 1.90565 11.20350595
Ethanol 1.07305 1.119691256 1.03971 1.18511 13.9846688
Water 1.25837 1.2065084 0.539727 0.556549 3.116760881

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.

Extended UNIQUAC model is used for electrolytic compounds to obtain activity


coefficients and fugacity coefficients respectively. If we use compounds other than
ions, provided they contain water we can still use the model. But there will be a
difference between the Extended UNIQUAC and UNIQUAC results. This difference
is due to the reduction of the residual term in Extended model when we use organic
compounds with water and ions are not present.We have implemented the same in
the OpenModelica.

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

• Thomsen, K., Aqueous electrolytes: model parameters and process simulation,


Ph.D. Thesis, Department of Chemical Engineering, Technical University of
Denmark, 1997.

• GitHub - Source Code DWSIM

12
Chapter 6

OpenModelica Code

1 function SId FuncENTROPY


2
3 import M o d e l i c a . C o n s t a n t s . ∗ ;
4
5 input Real AS ;
6 input Real VapCp [ 6 ] ;
7 input Real HOV[ 6 ] ;
8 input Real Tb ;
9 input Real Tc ;
10 input Real T ;
11 input Real P ;
12 input Real x ;
13 input Real y ;
14 input Real P h a s e D e n s i t y ;
15 output Real S l i q , Svap ;
16 protected
17 parameter Real T r e f = 2 9 8 . 1 5 , P r e f = 1 0 1 3 2 5 ;
18 Real E n t r , Cp [ n − 1 ] ;
19 parameter I n t e g e r n = 1 0 ;
20
21 algorithm
22 Entr := 0 ;
23 f o r i in 1 : n − 1 loop
24 Cp [ i ] := S i m u l a t o r . F i l e s . T h e r m o d y n a m i c F u n c t i o n s . V a p C p I d ( VapCp, 2 9 8 . 1 5
+ i ∗ (T − 2 9 8 . 1 5 ) / n ) / ( 2 9 8 . 1 5 + i ∗ (T − 2 9 8 . 1 5 ) / n ) ;
25 end f o r ;
26 i f T >= T r e f then
27 Entr := (T − 2 9 8 . 1 5 ) ∗ ( S i m u l a t o r . F i l e s . T h e r m o d y n a m i c F u n c t i o n s . V a p C p I d
( VapCp, T) / ( 2 ∗ T) + sum (Cp [ : ] ) +
S i m u l a t o r . F i l e s . T h e r m o d y n a m i c F u n c t i o n s . V a p C p I d ( VapCp, 2 9 8 . 1 5 ) / ( 2
∗ 298.15) ) / n ;
28 else
29 Entr := −(T − 2 9 8 . 1 5 ) ∗ (
S i m u l a t o r . F i l e s . T h e r m o d y n a m i c F u n c t i o n s . V a p C p I d ( VapCp, T) / ( 2 ∗ T)
+ sum (Cp [ : ] ) + S i m u l a t o r . F i l e s . T h e r m o d y n a m i c F u n c t i o n s . V a p C p I d (
VapCp, 2 9 8 . 1 5 ) / ( 2 ∗ 2 9 8 . 1 5 ) ) / n ;
30 end i f ;
31 i f x > 0 and y > 0 then
32 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 ;
33 Svap := Entr − R ∗ l o g (P / P r e f ) − R ∗ l o g ( y ) ;
34 e l s e i f x <= 0 and y <= 0 then
35 S l i q := 0 ;
36 Svap := 0 ;
37 e l s e i f x == 0 then
38 S l i q := 0 ;

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 ;

1 model EXT UNIQUAC


2 // L i b r a r i e s
3 import S i m u l a t o r . F i l e s . ∗ ;
4 // Parameter S e c t i o n
5 // B i n a r y I n t e r a c t i o n P a r a m e t e r s
6 / / F u n c t i o n : BIP UNIQUAC i s u s e d t o obtain the interaction parameters
7 parameter Real a [ NOC, NOC] = Thermodynamic Functions.BIP UNIQUAC (NOC,
comp.name ) ;
8 / / U n i q u a c P a r a m e t e r s R and Q c a l l e d f r o m Chemsep D a t a b a s e
9 parameter Real R[NOC] = comp.UniquacR ;
10 parameter Real Q[NOC] = comp.UniquacQ ;
11 parameter I n t e g e r Z = 10 ” C o m p r e s s e b l i t y − F a c t o r ” ;
12 // V a r i a b l e Section
13 Real tow [ NOC, NOC] ” Energy i n t e r a c t i o n parameter ” ;
14 / / 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 the input c o n d i t i o n s
15 Real r ( each s t a r t =2, min=0,max=1) , q ( each s t a r t =2) ;
16 Real t e t a [NOC ] ;
17 Real S [NOC] ( each s t a r t = 1 ) ;
18 Real sum [NOC ] ;
19 // A c t i v i t y Coefficients
20 Real gammac [NOC] ( each s t a r t = 1 . 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 at input c o n d i t i o n s ” ;
21 Real gammar [NOC] ( each s t a r t = 1 . 2 ) ” 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 i e n t at input c o n d i t i o n s ” ;
22 Real gamma new [NOC] ( each s t a r t = 1 . 2 ) ;
23 Real gamma [NOC] ( each s t a r t = 1 . 2 ) ” A c t i v i t y c o e f f i c i e n t with Poynting
correction ” ;
24 // F u g a c i t y coefficient
25 Real p h i l [NOC] ( each s t a r t = 0 . 5 ) ” F u g a c i t y c o e f f i c i e n t a t t h e i n p u t
conditions ” ;
26 / / Dew 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
27 / / R e a l d e w L i q M o l F r a c [ NOC ] ( e a c h s t a r t = 0 . 5 , e a c h min = 0 , e a c h max =1) ;
28 / / 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
p a r t o f a c t i v i t y c o e f f i c i e n t a t dew p o i n t
29 / / R e a l r d e w ( s t a r t =2) , q d e w ( s t a r t =2) ;
30 / / R e a l t e t a d e w [ NOC ] ( e a c h s t a r t =2) ;
31 // R e a l S d e w [ NOC ] ( e a c h s t a r t = 1 ) ;
32 / / R e a l sum dew [ NOC ] ( e a c h s t a r t =2) ;
33 // A c t i v i t y C o e f f i c i e n t s
34 / / R e a l gammac dew [ NOC ] ( e a c h s t a r t = 5 ) ” 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 a t dew p o i n t ” ;
35 / / R e a l gammar dew [ NOC ] ( e a c h s t a r t = 2 . 5 ) ” 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 i e n t a t dew p o i n t ” ;
36 // R e a l gammaDew old [ NOC ] ( e a c h s t a r t = 2 . 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 ( without c o r r e c t i o n ) ”;
37 Real gammaDew [NOC] ( each s t a r t = 2 . 2 ) ” A c t i v i t y c o e f f i c e n t a t dew p o i n t ”
;
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 ] ( e a c h start = 0.5) ;

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 //
========================================================================================

177 // E x c e s s Energy p a r a m e t e r s are set to 0 s i n c e the c a l c u l a t i o n mode i s Ideal


178 resMolSpHeat [ : ] = z e r o s ( 3 ) ;
179 resMolEnth [ : ] = z e r o s ( 3 ) ;
180 resMolEntr [ : ] = z e r o s ( 3 ) ;
181 // C a l c u l a t i o n of Saturated vapour p r e s s u r e and D e n s i t y at the given input
condition
182 f o r i in 1 :NOC loop
183 Psat [ i ] = S i m u l a t o r . F i l e s . T h e r m o d y n a m i c F u n c t i o n s . P s a t ( comp [ i ] . VP, T)
;
184 D e n s i t y [ i ] = S i m u l a t o r . F i l e s . 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 ( comp [ i ] .
LiqDen, comp [ i ] . Tc, T, P) ∗ 1E−3 ;
185 end f o r ;
186 // C a l c u l a t i o n o f P o y n t i n g c o r r e c t i o n F a c t o r a t i n p u t c o n d i t i o n s , B u b b l e
P o i n t and Dew P o i n t
187 // F u n c t i o n : Poynting CF i s c a l l e d from t h e S i m u l a t o r Package
188 PCF [ : ] = Thermodynamic Functions.PoyntingCF (NOC, comp [ : ] . P c , comp [ : ] .
Tc, comp [ : ] . Racketparam, comp [ : ] . AF, comp [ : ] . MW, T, P, gamma [ : ] ,
Psat [ : ] , D e n s i t y [ : ] ) ;
189 p h i l [ : ] = gamma [ : ] . ∗ Psat [ : ] . / P . ∗ PCF [ : ] ;
190 p h i l [ : ] = gamma new [ : ] . ∗ Psat [ : ] . / P ;
191 K [ : ] = gamma new [ : ] . ∗ Psat [ : ] . / P ;
192 end EXT UNIQUAC;

1 model Mat Stream


2
3 // 1 − Mixture, 2 − Liquid p h a s e , 3 − Gas P h a s e
4 extends M o d e l i c a . I c o n s . S o u r c e s P a c k a g e ;
5 import S i m u l a t o r . F i l e s . ∗ ;
6 parameter I n t e g e r NOC;
7 parameter S i m u l a t o r . F i l e s . C h e m s e p D a t a b a s e . G e n e r a l P r o p e r t i e s comp [NOC ] ;
8 Real P( min = 0 , s t a r t = 1 0 1 3 2 5 ) ” P r e s s u r e ” , T( s t a r t = 2 7 3 ) ” Temperature ” ;
9 Real Pbubl ( min = 0 , s t a r t = sum ( comp [ : ] . Pc ) / NOC) ” Bubble p o i n t p r e s s u r e
” , Pdew ( min = 0 , s t a r t = sum ( comp [ : ] . Pc ) / NOC) ”dew p o i n t p r e s s u r e ” ;
10 Real l i q P h a s M o l F r a c ( s t a r t = 0 . 5 , min = 0 , max = 1 ) ” L i q u i d Phase mole
f r a c t i o n ” , vapPhasMolFrac ( s t a r t = 0 . 5 , min = 0 , max = 1 ) ” Vapor Phase
mole f r a c t i o n ” , liqPhasMasFrac ( s t a r t = 0 . 5 , min = 0 , max = 1 ) ”
L i q u i d Phase mass f r a c t i o n ” , vapPhasMasFrac ( s t a r t = 0 . 5 , min = 0 , max
= 1 ) ” Vapor Phase Mass f r a c t i o n ” ;
11 Real t o t M o l F l o [ 3 ] ( each min = 0 , each s t a r t = 1 0 0 ) ” T o t a l molar f l o w ” ,
totMasFlo [ 3 ] ( each min = 0 , each s t a r t = 1 0 0 ) ” T o t a l Mass Flow ” , MW

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 ;

1 model UNIQUAC Correction


2 // L i b r a r i e s
3 import S i m u l a t o r . F i l e s . ∗ ;
4 // Parameter S e c t i o n
5 // B i n a r y I n t e r a c t i o n P a r a m e t e r s
6 / / F u n c t i o n : BIP UNIQUAC i s u s e d t o obtain the interaction parameters
7 parameter Real a [ NOC, NOC] = Thermodynamic Functions.BIP UNIQUAC (NOC,
comp.name ) ;
8 / / U n i q u a c P a r a m e t e r s R and Q c a l l e d f r o m Chemsep D a t a b a s e
9 parameter Real R[NOC] = comp.UniquacR ;
10 parameter Real Q[NOC] = comp.UniquacQ ;
11 parameter I n t e g e r Z = 10 ” C o m p r e s s e b l i t y − F a c t o r ” ;
12 // V a r i a b l e Section
13 Real tow [ NOC, NOC] ” Energy i n t e r a c t i o n parameter ” ;
14 / / 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 the input c o n d i t i o n s
15 Real r ( each s t a r t =2, min=0,max=1) , q ( each s t a r t =2) ;
16 Real t e t a [NOC ] ;
17 Real S [NOC] ( each s t a r t = 1 ) ;
18 Real sum [NOC ] ;
19 // A c t i v i t y Coefficients
20 Real gammac [NOC] ( each s t a r t = 1 . 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 at input c o n d i t i o n s ” ;
21 Real gammar [NOC] ( each s t a r t = 1 . 2 ) ” 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 i e n t at input c o n d i t i o n s ” ;
22 Real gamma new [NOC] ( each s t a r t = 1 . 2 ) ;
23 Real gamma [NOC] ( each s t a r t = 1 . 2 ) ” A c t i v i t y c o e f f i c i e n t with Poynting
correction ” ;
24 // F u g a c i t y coefficient
25 Real p h i l [NOC] ( each s t a r t = 0 . 5 ) ” F u g a c i t y c o e f f i c i e n t a t t h e i n p u t
conditions ” ;
26 / / Dew P o i n t Calculation Variables
27 Real dewLiqMolFrac [NOC] ( each s t a r t = 0 . 5 , each min=0, each max=1) ;
28 / / 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
p a r t o f a c t i v i t y c o e f f i c i e n t a t dew p o i n t
29 Real r dew ( s t a r t =2) , q dew ( s t a r t =2) ;
30 Real t e t a d e w [NOC] ( each s t a r t =2) ;
31 Real S dew [NOC] ( each s t a r t = 1 ) ;
32 Real sum dew [NOC] ( each s t a r t =2) ;
33 // A c t i v i t y Coefficients
34 Real gammac dew [NOC] ( each s t a r t = 5 ) ” 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 dew p o i n t ” ;
35 Real gammar dew [NOC] ( each s t a r t = 2 . 5 ) ” 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 i e n t a t dew p o i n t ” ;
36 Real gammaDew old [NOC] ( each s t a r t = 2 . 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 ( without c o r r e c t i o n ) ” ;
37 Real gammaDew [NOC] ( each s t a r t = 2 . 2 ) ” A c t i v i t y c o e f f i c e n t a t dew p o i n t ”

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 //
========================================================================================

172 // E x c e s s Energy p a r a m e t e r s are set to 0 s i n c e the c a l c u l a t i o n mode i s Ideal


173 resMolSpHeat [ : ] = z e r o s ( 3 ) ;
174 resMolEnth [ : ] = z e r o s ( 3 ) ;
175 resMolEntr [ : ] = z e r o s ( 3 ) ;
176 // C a l c u l a t i o n of Saturated vapour p r e s s u r e and D e n s i t y at the given input
condition
177 f o r i in 1 :NOC loop
178 Psat [ i ] = S i m u l a t o r . F i l e s . T h e r m o d y n a m i c F u n c t i o n s . P s a t ( comp [ i ] . VP, T)
;
179 D e n s i t y [ i ] = S i m u l a t o r . F i l e s . 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 ( comp [ i ] .
LiqDen, comp [ i ] . Tc, T, P) ∗ 1E−3 ;
180 end f o r ;
181 // C a l c u l a t i o n o f P o y n t i n g c o r r e c t i o n F a c t o r a t i n p u t c o n d i t i o n s , B u b b l e
P o i n t and Dew P o i n t
182 // F u n c t i o n : Poynting CF i s c a l l e d from t h e S i m u l a t o r Package
183 PCF [ : ] = Thermodynamic Functions.PoyntingCF (NOC, comp [ : ] . P c , comp [ : ] .
Tc, comp [ : ] . Racketparam, comp [ : ] . AF, comp [ : ] . MW, T, P, gamma [ : ] ,
Psat [ : ] , D e n s i t y [ : ] ) ;
184 PCF bubl [ : ] = Thermodynamic Functions.PoyntingCF (NOC, comp [ : ] . P c , comp
[ : ] . Tc, comp [ : ] . Racketparam, comp [ : ] . AF, comp [ : ] . MW, T, P b u b l ,
gamma [ : ] , Psat [ : ] , D e n s i t y [ : ] ) ;
185 PCF dew [ : ] = Thermodynamic Functions.PoyntingCF (NOC, comp [ : ] . P c , comp
[ : ] . Tc, comp [ : ] . Racketparam, comp [ : ] . AF, comp [ : ] . MW, T, Pdew, gamma
[ : ] , Psat [ : ] , D e n s i t y [ : ] ) ;
186 // C a l c u l a t i o n of Fugacity coefficient with Poynting correction
187 p h i l [ : ] = gamma [ : ] . ∗ Psat [ : ] . / P . ∗ PCF [ : ] ;
188 p h i l [ : ] = gamma new [ : ] . ∗ Psat [ : ] . / P ;
189 // C a l c u l a t i o n of Distribution coefficient
190 K [ : ] = gamma new [ : ] . ∗ Psat [ : ] ./ P;
191 // B i n a r y Phase E n v e l o p e
192 / / The same c a l c u l a t i o n r o u t i n e is followed a t t h e DewPoint
193 / / Dew P o i n t
194 r dew = sum ( dewLiqMolFrac [ : ] . ∗ R [ : ] ) ;
195 q dew = sum ( dewLiqMolFrac [ : ] . ∗ Q [ : ] ) ;
196 f o r i in 1 :NOC loop
197 i f ( q dew==0 or compMolFrac [ 1 , i ]==0) then
198 dewLiqMolFrac [ i ] = 0 ;
199 else
200 dewLiqMolFrac [ i ] = compMolFrac [ 1 , i ] ∗ Pdew / (gammaDew [ i ] ∗ Psat [ i ] )
;
201 end i f ;
202 i f ( q dew==0 or dewLiqMolFrac [ i ]==0) then
203 teta dew [ i ]=0;

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

You might also like