Skip to content

Commit aab20ac

Browse files
authored
Merge pull request #59 from biananino/update-to-new-frontend
Update to new frontend
2 parents 2bdd624 + 1bef7cd commit aab20ac

46 files changed

Lines changed: 325 additions & 228 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Simulator/BinaryPhaseEnvelope/NRTL.mo

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,58 @@ package NRTL
44
extends Modelica.Icons.ExamplesPackage;
55
model NRTLmodel
66
import Simulator.Files.ThermodynamicFunctions.*;
7-
gammaNRTLmodel Gamma(NOC = NOC, comp = comp, molFrac = x[:], T = T);
8-
Real density[NOC], BIPS[NOC, NOC, 2];
7+
parameter Integer Nc "Number of components";
8+
parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array";
9+
gammaNRTLmodel Gamma(Nc = Nc, C = C, molFrac = x[:], T = T);
10+
Real gamma[Nc];
11+
Real x[Nc];
12+
Real T(start = 300);
13+
Real P;
14+
Real K[Nc];
15+
Real density[Nc], BIPS[Nc, Nc, 2];
916
equation
1017
gamma = Gamma.gamma;
1118
BIPS = Gamma.BIPS;
12-
for i in 1:NOC loop
13-
density[i] = Dens(comp[i].LiqDen, comp[i].Tc, T, P);
19+
for i in 1:Nc loop
20+
density[i] = Dens(C[i].LiqDen, C[i].Tc, T, P);
1421
end for;
15-
for i in 1:NOC loop
16-
K[i] = gamma[i] * Psat(comp[i].VP, T) / P;
22+
for i in 1:Nc loop
23+
K[i] = gamma[i] * Psat(C[i].VP, T) / P;
1724
end for;
1825
end NRTLmodel;
1926

2027
model gammaNRTLmodel
21-
parameter Integer NOC;
22-
parameter Simulator.Files.ChemsepDatabase.GeneralProperties comp[NOC];
23-
Real molFrac[NOC], T;
24-
Real gamma[NOC];
25-
Real tau[NOC, NOC], G[NOC, NOC], alpha[NOC, NOC], A[NOC, NOC], BIPS[NOC, NOC, 2];
26-
Real sum1[NOC], sum2[NOC];
28+
parameter Integer Nc "Number of components";
29+
parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array";
30+
Real molFrac[Nc], T(start = 300);
31+
Real gamma[Nc];
32+
Real tau[Nc, Nc], G[Nc, Nc], alpha[Nc, Nc], A[Nc, Nc], BIPS[Nc, Nc, 2];
33+
Real sum1[Nc], sum2[Nc];
2734
constant Real R = 1.98721;
2835
equation
2936
A = BIPS[:, :, 1];
3037
alpha = BIPS[:, :, 2];
3138
tau = A ./ (R * T);
32-
for i in 1:NOC loop
33-
for j in 1:NOC loop
39+
for i in 1:Nc loop
40+
for j in 1:Nc loop
3441
G[i, j] = exp(-alpha[i, j] * tau[i, j]);
3542
end for;
3643
end for;
37-
for i in 1:NOC loop
44+
for i in 1:Nc loop
3845
sum1[i] = sum(molFrac[:] .* G[:, i]);
3946
sum2[i] = sum(molFrac[:] .* tau[:, i] .* G[:, i]);
4047
end for;
41-
for i in 1:NOC loop
48+
for i in 1:Nc loop
4249
log(gamma[i]) = sum(molFrac[:] .* tau[:, i] .* G[:, i]) / sum(molFrac[:] .* G[:, i]) + sum(molFrac[:] .* G[i, :] ./ sum1[:] .* (tau[i, :] .- sum2[:] ./ sum1[:]));
4350
end for;
4451
end gammaNRTLmodel;
4552

4653
model base
47-
import data = Simulator.Files.ChemsepDatabase;
48-
parameter Integer NOC;
49-
parameter Real BIP[NOC, NOC, 2];
50-
parameter data.GeneralProperties comp[NOC];
54+
parameter Integer Nc;
55+
parameter Real BIP[Nc, Nc, 2];
56+
parameter Simulator.Files.ChemsepDatabase.GeneralProperties C[Nc] "Component instances array";
5157
extends NRTLmodel(BIPS = BIP);
52-
Real P, T(start = 300), gamma[NOC], K[NOC], x[NOC](each start = 0.5), y[NOC];
58+
Real P, T(start = 300), gamma[Nc], K[Nc], x[Nc](each start = 0.5), y[Nc];
5359
equation
5460
y[:] = K[:] .* x[:];
5561
sum(x[:]) = 1;
@@ -61,11 +67,11 @@ package NRTL
6167
import data = Simulator.Files.ChemsepDatabase;
6268
parameter data.Onehexene ohex;
6369
parameter data.Acetone acet;
64-
parameter Integer NOC = 2;
65-
parameter Real BIP[NOC, NOC, 2] = Simulator.Files.ThermodynamicFunctions.BIPNRTL(NOC, comp.CAS);
66-
parameter data.GeneralProperties comp[NOC] = {ohex, acet};
67-
base points[41](each P = 1013250, each NOC = NOC, each comp = comp, each BIP = BIP);
68-
Real x[41, NOC], y[41, NOC], T[41];
70+
parameter Integer Nc = 2;
71+
parameter Real BIP[Nc, Nc, 2] = Simulator.Files.ThermodynamicFunctions.BIPNRTL(Nc, C.CAS);
72+
parameter data.GeneralProperties C[Nc] = {ohex, acet};
73+
base points[41](each P = 1013250, each Nc = Nc, each C = C, each BIP = BIP);
74+
Real x[41, Nc], y[41, Nc], T[41];
6975
equation
7076
points[:].x = x;
7177
points[:].y = y;
@@ -80,11 +86,11 @@ package NRTL
8086
import data = Simulator.Files.ChemsepDatabase;
8187
parameter data.Onehexene ohex;
8288
parameter data.Acetone acet;
83-
parameter Integer NOC = 2;
84-
parameter Real BIP[NOC, NOC, 2] = Simulator.Files.ThermodynamicFunctions.BIPNRTL(NOC, comp.CAS);
85-
parameter data.GeneralProperties comp[NOC] = {ohex, acet};
86-
base points[41](each T = 424, each NOC = NOC, each comp = comp, each BIP = BIP);
87-
Real x[41, NOC], y[41, NOC], P[41];
89+
parameter Integer Nc = 2;
90+
parameter Real BIP[Nc, Nc, 2] = Simulator.Files.ThermodynamicFunctions.BIPNRTL(Nc, C.CAS);
91+
parameter data.GeneralProperties C[Nc] = {ohex, acet};
92+
base points[41](each T = 424, each Nc = Nc, each C = C, each BIP = BIP);
93+
Real x[41, Nc], y[41, Nc], P[41];
8894
equation
8995
points[:].x = x;
9096
points[:].y = y;
@@ -93,4 +99,4 @@ package NRTL
9399
x[i, 1] = 0 + (i - 1) * 0.025;
94100
end for;
95101
end Pxy;
96-
end NRTL;
102+
end NRTL;

Simulator/BinaryPhaseEnvelope/PR.mo

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

Simulator/BinaryPhaseEnvelope/UNIFAC.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package UNIFAC
77
//Libraries
88
import Simulator.*;
99
//Extension of Chemsep Database
10-
Simulator.Files.ChemsepDatabase data;
10+
import data = Simulator.Files.ChemsepDatabase;
1111
//Parameter Section
1212
//Selection of compounds
1313
parameter data.Methylethylketone meth;
@@ -135,7 +135,7 @@ package UNIFAC
135135
//Libraries
136136
import Simulator.*;
137137
//Extension of Chemsep Database
138-
Simulator.Files.ChemsepDatabase data;
138+
import data = Simulator.Files.ChemsepDatabase;
139139
//Parameter Section
140140
//Selection of compounds
141141
parameter data.Methylethylketone meth;
@@ -177,7 +177,7 @@ package UNIFAC
177177
//Mole Fractions (x-axis) of the T-x-y plot
178178
Real z1[N + 1], z2[N + 1];
179179
//Bubble Temperature
180-
Real T[N + 1](unit = "K", each start = 300);
180+
Real T[N + 1](each unit = "K", each start = 300);
181181
//Distribution coefficient
182182
Real K1[N + 1];
183183
//Vapour Phase Mole Fraction
@@ -264,4 +264,4 @@ package UNIFAC
264264
end Txy;
265265

266266
//================================================================================================================
267-
end UNIFAC;
267+
end UNIFAC;

0 commit comments

Comments
 (0)