@@ -4,12 +4,12 @@ package PR
44 extends Modelica.Icons.ExamplesPackage;
55 function CompresseblityFactor
66 extends Modelica.Icons.Function;
7- input Real b[NOC ];
8- input Real aij[NOC, NOC ];
7+ input Real b[Nc ];
8+ input Real aij[Nc, Nc ];
99 input Real P;
1010 input Real T;
11- input Integer NOC ;
12- input Real m[NOC ];
11+ input Integer Nc ;
12+ input Real m[Nc ];
1313 output Real am;
1414 output Real bm;
1515 output Real A;
@@ -20,94 +20,96 @@ package PR
2020 Real C[4 ];
2121 Real ZR[3 , 2 ];
2222 algorithm
23- am := sum ({{m[i] * m[j] * aij[i, j] for i in 1 :NOC } for j in 1 :NOC });
23+ am := sum ({{m[i] * m[j] * aij[i, j] for i in 1 :Nc } for j in 1 :Nc });
2424 bm := sum (b .* m);
2525 A := am * P / (R * T) ^ 2 ;
2626 B := bm * P / (R * T);
2727 C[1 ] := 1 ;
2828 C[2 ] := B - 1 ;
2929 C[3 ] := A - 3 * B ^ 2 - 2 * B;
3030 C[4 ] := B ^ 3 + B ^ 2 - A * B;
31- ZR := Modelica.Math.Vectors.Utilities .roots(C);
31+ ZR := Modelica.Math.Polynomials .roots(C);
3232 Z := {ZR[i, 1 ] for i in 1 :3 };
3333 end CompresseblityFactor;
3434
3535 model PR
36- parameter Simulator.Files.ChemsepDatabase.GeneralProperties comp[NOC ];
37- parameter Integer NOC ;
36+ parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc ];
37+ parameter Integer Nc ;
3838 parameter Real R = 8.314 ;
39- parameter Real kij[NOC, NOC] = Simulator.Files.ThermodynamicFunctions.BIPPR(NOC, comp.name);
40- Real Tr[NOC];
41- Real b[NOC];
42- Real m[NOC];
43- Real q[NOC];
44- Real a[NOC];
45- Real aij[NOC, NOC];
39+ parameter Real kij[Nc, Nc] = Simulator.Files.ThermodynamicFunctions.BIPPR(Nc, C.name);
40+ Real x[Nc];
41+ Real y[Nc];
42+ Real Tr[Nc];
43+ Real b[Nc];
44+ Real m[Nc];
45+ Real q[Nc];
46+ Real a[Nc];
47+ Real aij[Nc, Nc];
4648 Real amL, bmL;
4749 Real AL, BL, Z_L[3 ];
4850 Real ZL;
49- Real sum_xa[NOC ];
50- Real liqfugcoeff[NOC ];
51+ Real sum_xa[Nc ];
52+ Real liqfugcoeff[Nc ];
5153 Real amV, bmV;
5254 Real AV, BV, Z_V[3 ];
5355 Real ZV;
54- Real sum_ya[NOC ];
55- Real vapfugcoeff[NOC ];
56+ Real sum_ya[Nc ];
57+ Real vapfugcoeff[Nc ];
5658 Real P;
5759 Real T(start = 273 );
58- Real Psat[NOC ];
60+ Real Psat[Nc ];
5961 //Bubble and Dew Point Calculation
60- Real Tr_bubl[NOC ];
61- Real a_bubl[NOC ];
62- Real aij_bubl[NOC, NOC ];
63- Real Psat_bubl[NOC ];
62+ Real Tr_bubl[Nc ];
63+ Real a_bubl[Nc ];
64+ Real aij_bubl[Nc, Nc ];
65+ Real Psat_bubl[Nc ];
6466 Real amL_bubl, bmL_bubl;
65- Real AL_bubl, BL_bubl, Z_L_bubl[3 ];
66- Real ZL_bubl;
67- Real sum_xa_bubl[NOC ];
68- Real liqfugcoeff_bubl[NOC ];
69- Real gammaBubl[NOC ];
67+ Real AL_bubl, BL_bubl(start = 0.005 ) , Z_L_bubl[3 ];
68+ Real ZL_bubl ( each start = 0.005 ) ;
69+ Real sum_xa_bubl[Nc ];
70+ Real liqfugcoeff_bubl[Nc ];
71+ Real gammaBubl[Nc ];
7072 Real Tbubl(start = 273 );
7173 equation
72- for i in 1 :NOC loop
73- Psat_bubl[i] = Simulator.Files.ThermodynamicFunctions.Psat(comp [i].VP, Tbubl);
74- Psat[i] = Simulator.Files.ThermodynamicFunctions.Psat(comp [i].VP, T);
74+ for i in 1 :Nc loop
75+ Psat_bubl[i] = Simulator.Files.ThermodynamicFunctions.Psat(C [i].VP, Tbubl);
76+ Psat[i] = Simulator.Files.ThermodynamicFunctions.Psat(C [i].VP, T);
7577 end for ;
76- //Bubble Point and Dew Point Calculation Routine
77- Tr_bubl = Tbubl ./ comp .Tc;
78+ //Bubble Point and Dew Point Calculation Routine
79+ Tr_bubl = Tbubl ./ C .Tc;
7880 a_bubl = q .* (1 .+ m .* (1 .- sqrt (Tr_bubl))) .^ 2 ;
79- aij_bubl = {{(1 - kij[i, j]) * sqrt (a_bubl[i] * a_bubl[j]) for i in 1 :NOC } for j in 1 :NOC };
80- (amL_bubl, bmL_bubl, AL_bubl, BL_bubl, Z_L_bubl) = CompresseblityFactor(b, aij_bubl, P, Tbubl, NOC , x[:]);
81+ aij_bubl = {{(1 - kij[i, j]) * sqrt (a_bubl[i] * a_bubl[j]) for i in 1 :Nc } for j in 1 :Nc };
82+ (amL_bubl, bmL_bubl, AL_bubl, BL_bubl, Z_L_bubl) = CompresseblityFactor(b, aij_bubl, P, Tbubl, Nc , x[:]);
8183 ZL_bubl = min ({Z_L_bubl});
82- sum_xa_bubl = {sum ({x[j] * aij_bubl[i, j] for j in 1 :NOC }) for i in 1 :NOC };
84+ sum_xa_bubl = {sum ({x[j] * aij_bubl[i, j] for j in 1 :Nc }) for i in 1 :Nc };
8385 liqfugcoeff_bubl = exp (AL_bubl / (BL_bubl * sqrt (8 )) * log ((ZL_bubl + 2.4142135 * BL_bubl) / (ZL_bubl - 0.414213 * BL_bubl)) .* (b / bmL_bubl .- 2 * sum_xa_bubl / amL_bubl) .+ (ZL_bubl - 1 ) * (b / bmL_bubl) .- log (ZL_bubl - BL_bubl));
8486 liqfugcoeff_bubl[:] = gammaBubl[:] .* P ./ Psat_bubl[:];
85- P = sum (gammaBubl[:] .* x[:] .* exp (comp [:].VP[2 ] + comp [:].VP[3 ] / Tbubl + comp [:].VP[4 ] * log (Tbubl) + comp [:].VP[5 ] .* Tbubl .^ comp [:].VP[6 ]) ./ liqfugcoeff_bubl[:]);
86- //Calculation of Temperatures at different compositions
87- Tr = T ./ comp .Tc;
88- b = 0.0778 * R * comp .Tc ./ comp .Pc;
89- m = 0.37464 .+ 1.54226 * comp .AF .- 0.26992 * comp .AF .^ 2 ;
90- q = 0.45724 * R ^ 2 * comp .Tc . ^ 2 ./ comp .Pc;
87+ P = sum (gammaBubl[:] .* x[:] .* exp (C [:].VP[2 ] + C [:].VP[3 ] / Tbubl + C [:].VP[4 ] * log (Tbubl) + C [:].VP[5 ] .* Tbubl .^ C [:].VP[6 ]) ./ liqfugcoeff_bubl[:]);
88+ //Calculation of Temperatures at different compositions
89+ Tr = T ./ C .Tc;
90+ b = 0.0778 * R * C .Tc ./ C .Pc;
91+ m = 0.37464 .+ 1.54226 * C .AF .- 0.26992 * C .AF .^ 2 ;
92+ q = 0.45724 * R ^ 2 * C .Tc. ^ ( 2 ) ./ C .Pc;
9193 a = q .* (1 .+ m .* (1 .- sqrt (Tr))) .^ 2 ;
92- aij = {{(1 - kij[i, j]) * sqrt (a[i] * a[j]) for i in 1 :NOC } for j in 1 :NOC };
93- //Liquid Phase Calculation Routine
94- (amL, bmL, AL, BL, Z_L) = CompresseblityFactor(b, aij, P, T, NOC , x[:]);
94+ aij = {{(1 - kij[i, j]) * sqrt (a[i] * a[j]) for i in 1 :Nc } for j in 1 :Nc };
95+ //Liquid Phase Calculation Routine
96+ (amL, bmL, AL, BL, Z_L) = CompresseblityFactor(b, aij, P, T, Nc , x[:]);
9597 ZL = min ({Z_L});
96- sum_xa = {sum ({x[j] * aij[i, j] for j in 1 :NOC }) for i in 1 :NOC };
98+ sum_xa = {sum ({x[j] * aij[i, j] for j in 1 :Nc }) for i in 1 :Nc };
9799 liqfugcoeff = exp (AL / (BL * sqrt (8 )) * log ((ZL + 2.4142135 * BL) / (ZL - 0.414213 * BL)) .* (b / bmL .- 2 * sum_xa / amL) .+ (ZL - 1 ) * (b / bmL) .- log (ZL - BL));
98- //Vapour Phase Calculation Routine
99- (amV, bmV, AV, BV, Z_V) = CompresseblityFactor(b, aij, P, T, NOC , y[:]);
100+ //Vapour Phase Calculation Routine
101+ (amV, bmV, AV, BV, Z_V) = CompresseblityFactor(b, aij, P, T, Nc , y[:]);
100102 ZV = max ({Z_V});
101- sum_ya = {sum ({y[j] * aij[i, j] for j in 1 :NOC }) for i in 1 :NOC };
103+ sum_ya = {sum ({y[j] * aij[i, j] for j in 1 :Nc }) for i in 1 :Nc };
102104 vapfugcoeff = exp (AV / (BV * sqrt (8 )) * log ((ZV + 2.4142135 * BV) / (ZV - 0.414213 * BV)) .* (b / bmV .- 2 * sum_ya / amV) .+ (ZV - 1 ) * (b / bmV) .- log (ZV - BV));
103105 end PR;
104106
105107 model PhaseEquilibria
106108 import data = Simulator.Files.ChemsepDatabase;
107109 parameter data.Ethane eth;
108110 parameter data.Propane prop;
109- extends PR(NOC = 2 , comp = {eth, prop});
110- Real P, T(start = 273 ), K[NOC ], x[NOC ](each start = 0.5 ), y[NOC ], Tbubl(start = 273 );
111+ extends PR(Nc = 2 , C = {eth, prop});
112+ Real P, T(start = 273 ), K[Nc ], x[Nc ](each start = 0.5 ), y[Nc ], Tbubl(start = 273 );
111113 equation
112114 K[:] = liqfugcoeff[:] ./ vapfugcoeff[:];
113115 y[:] = K[:] .* x[:];
@@ -120,13 +122,13 @@ package PR
120122 import data = Simulator.Files.ChemsepDatabase;
121123 parameter data.Ethane eth;
122124 parameter data.Propane prop;
123- parameter Integer NOC = 2 ;
124- parameter Integer N = 2 ;
125- parameter data.GeneralProperties comp[NOC ] = {eth, prop};
126- PhaseEquilibria points[N](each T = 210 , each NOC = NOC , each comp = comp , each T(start = 273 ), each Tbubl(start = 273 ), each x(each start = 0.5 ), each y(each start = 0.5 ));
125+ parameter Integer Nc = 2 ;
126+ parameter Integer N = 10 ;
127+ parameter data.GeneralProperties C[Nc ] = {eth, prop};
128+ PhaseEquilibria points[N](each T = 210 , each Nc = Nc , each C = C , each T(start = 273 ), each Tbubl(start = 273 ), each x(each start = 0.5 ), each y(each start = 0.5 ));
127129 Real x1[N], y1[N], x2[N], y2[N], P[N](each start = 101325 ), Tbubl[N], Temp[N];
128130 equation
129- //Generation of Points to compute Bubble Temperature
131+ //Generation of Points to Compute Bubble Temperature
130132 points[:].x[1 ] = x1[:];
131133 points[:].y[1 ] = y1[:];
132134 points[:].x[2 ] = x2[:];
@@ -148,11 +150,11 @@ package PR
148150 import data = Simulator.Files.ChemsepDatabase;
149151 parameter data.Ethane eth;
150152 parameter data.Propane prop;
151- parameter Integer NOC = 2 ;
152- parameter Integer N = 10 ;
153- parameter data.GeneralProperties comp[NOC ] = {eth, prop};
154- PhaseEquilibria points[N](each P = 101325 , each NOC = NOC , each comp = comp , each T(start = 273 ), each Tbubl(start = 273 ), each x(each start = 0.5 ), each y(each start = 0.5 ));
155- Real x[N, NOC ], y[N, NOC ], T[N], Tbubl[N], T_PR[N];
153+ parameter Integer Nc = 2 ;
154+ parameter Integer N = 21 ;
155+ parameter data.GeneralProperties C[Nc ] = {eth, prop};
156+ PhaseEquilibria points[N](each P = 101325 , each Nc = Nc , each C = C , each T(start = 273 ), each Tbubl(start = 273 ), each x(each start = 0.5 ), each y(each start = 0.5 ));
157+ Real x[N, Nc ], y[N, Nc ], T[N], Tbubl[N], T_PR[N];
156158 equation
157159 points[:].x = x;
158160 points[:].y = y;
@@ -164,7 +166,7 @@ package PR
164166 T_PR[i] = T[i];
165167 end for ;
166168 for i in 1 :N loop
167- x[i, 1 ] = 0 + (i - 1 ) * 0.025 ;
169+ x[i, 1 ] = 0.5 + (i - 1 ) * 0.025 ;
168170 end for ;
169171 end Txy;
170- end PR;
172+ end PR;
0 commit comments