Ticket #4482: post.mo

File post.mo, 23.5 KB (added by pravinkumar.dalve@…, 9 years ago)

problem is commented at the end of column1 model.

Line 
1package Post
2 package Chemsep_Database
3 model General_Properties
4 parameter Integer SN;
5 parameter String name;
6 parameter Real Tc;
7 parameter Real Pc;
8 parameter Real Vc;
9 parameter Real Cc;
10 parameter Real Tb;
11 parameter Real Tm;
12 parameter Real TT;
13 parameter Real TP;
14 parameter Real MW;
15 parameter Real LVB;
16 parameter Real AF;
17 parameter Real SP;
18 parameter Real DM;
19 parameter Real SH;
20 parameter Real IGHF;
21 parameter Real GEF;
22 parameter Real AS;
23 parameter Real HFMP;
24 parameter Real HOC;
25 parameter Real UniquacR;
26 parameter Real UniquacQ;
27 parameter Real LiqDen[6];
28 parameter Real VP[6];
29 parameter Real LiqCp[6];
30 parameter Real HOV[6];
31 parameter Real VapCp[6];
32 parameter Real LiqVis[6];
33 parameter Real VapVis[6];
34 parameter Real LiqK[6];
35 parameter Real VapK[6];
36 parameter Real Racketparam;
37end General_Properties;
38
39 model Benzene
40 extends General_Properties(SN = 125, name = "Benzene", Tc = 562.05, Pc = 4895000, Vc = 0.256, Cc = 0.268, Tb = 353.24, Tm = 278.68, TT = 278.68, TP = 4764.22, MW = 78.114, LVB = 0.08941, AF = 0.209, SP = 18700, DM = 0, SH = 49073013.1279, IGHF = 8.288E+07, GEF = 1.296E+08, AS = 269300, HFMP = 9866000, HOC = -3.136E+09, LiqDen = {105, 0.99938, 0.26348, 562.05, 0.27856, 0}, VP = {101, 88.368, -6712.9, -10.022, 0.000007694, 2}, LiqCp = {16, 111460, -1854.3, 22.399, -0.028936, 0.000028991}, HOV = {106, 4.881E+07, 0.61066, -0.25882, 0.032238, 0.022475}, VapCp = {16, 34010.24, -588.0978, 12.81777, -0.000197306, 5.142899E-08}, LiqVis = {101, -24.61, 1576.5, 2.1698, -0.0000051366, 2}, VapVis = {102, 3.1366E-08, 0.9675, 8.0285, -35.629, 0}, LiqK = {16, 0.049539, -177.97, 0.19475, -0.0073805, 0.0000027938}, VapK = {102, 0.0000049549, 1.4519, 154.14, 26202, 0}, Racketparam = 0.2696, UniquacR = 3.1878, UniquacQ = 2.4);
41 end Benzene;
42
43 model Toluene
44 extends General_Properties(SN = 140, name = "Toluene", Tc = 591.75, Pc = 4108000, Vc = 0.316, Cc = 0.264, Tb = 383.79, Tm = 178.18, TT = 178.18, TP = 0.0475285, MW = 92.141, LVB = 0.10687, AF = 0.264, SP = 18250, DM = 1.2E-30, SH = 12079609.7184, IGHF = 5.017E+07, GEF = 1.222E+08, AS = 320990, HFMP = 6636000, HOC = -3.734E+09, LiqDen = {105, 0.89799, 0.27359, 591.75, 0.30006, 0}, VP = {101, 32.89891, -5013.81, -1.348918, -1.869928E-06, 2}, LiqCp = {16, 28291, 48.171, 10.912, 0.0020542, 8.7875E-07}, HOV = {106, 5.3752E+07, 0.50341, 0.24755, -0.72898, 0.37794}, VapCp = {16, 47225, -565.85, 12.856, 0.000005535, -1.998E-08}, LiqVis = {101, -152.84, 5644.6, 22.826, -0.000040987, 2}, VapVis = {102, 8.5581E-07, 0.49514, 307.82, 1891.6, 0}, LiqK = {16, -0.072922, -23.153, -1.0277, -0.0017074, 3.6787E-07}, VapK = {102, 0.000006541, 1.4227, 190.97, 21890, 0}, Racketparam = 0.2646, UniquacR = 3.9228, UniquacQ = 2.968);
45 end Toluene;
46
47 end Chemsep_Database;
48
49 function Psat
50 /*Returns vapor pressure at given temperature*/
51 input Real VP[6] "from chemsep database";
52 input Real T(unit = "K") "Temperature";
53 output Real Vp(unit = "Pa") "Vapor pressure";
54algorithm
55 Vp := exp(VP[2] + VP[3] / T + VP[4] * log(T) + VP[5] .* T .^ VP[6]);
56end Psat;
57
58 function LiqCpId
59 /*Calculates specific heat of liquid at given Temperature*/
60 input Real LiqCp[6] "from chemsep database";
61 input Real T(unit = "K") "Temperature";
62 output Real Cp(unit = "J/mol") "Specific heat of liquid";
63 algorithm
64 Cp := (LiqCp[2] + exp(LiqCp[3] / T + LiqCp[4] + LiqCp[5] * T + LiqCp[6] * T ^ 2)) / 1000;
65 end LiqCpId;
66
67
68 function VapCpId
69 /*Calculates Vapor Specific Heat*/
70 input Real VapCp[6] "from chemsep database";
71 input Real T(unit = "K") "Temperature";
72 output Real Cp(unit = "J/mol.K") "specific heat";
73 algorithm
74 Cp := (VapCp[2] + exp(VapCp[3] / T + VapCp[4] + VapCp[5] * T + VapCp[6] * T ^ 2)) / 1000;
75 end VapCpId;
76
77 function HV
78 /*Returns Heat of Vaporization*/
79 input Real HOV[6] "from chemsep database";
80 input Real Tc(unit = "K") "Critical Temperature";
81 input Real T(unit = "K") "Temperature";
82 output Real Hv(unit = "J/mol") "Heat of Vaporization";
83 protected
84 Real Tr = T / Tc;
85 algorithm
86 Hv := HOV[2] * (1 - Tr) ^ (HOV[3] + HOV[4] * Tr + HOV[5] * Tr ^ 2 + HOV[6] * Tr ^ 3) / 1000;
87 end HV;
88
89
90
91
92 function HLiqId
93 /* Calculates Enthalpy of Ideal Liquid*/
94 input Real SH(unit = "J/kmol") "from chemsep database std. Heat of formation";
95 input Real VapCp[6] "from chemsep database";
96 input Real HOV[6] "from chemsep database";
97 input Real Tc "critical temp, from chemsep database";
98 input Real T(unit = "K") "Temperature";
99 output Real Ent(unit = "J/mol") "Molar Enthalpy";
100 algorithm
101 Ent := HVapId(SH, VapCp, HOV, Tc, T) - HV(HOV, Tc, T);
102 end HLiqId;
103
104
105
106
107
108
109
110 function HVapId
111 /* Calculates enthalpy of ideal vapor */
112 input Real SH(unit = "J/kmol") "from chemsep database std. Heat of formation";
113 input Real VapCp[6] "from chemsep database";
114 input Real HOV[6] "from chemsep database";
115 input Real Tc "critical temp, from chemsep database";
116 input Real T(unit = "K") "Temperature";
117 output Real Ent(unit = "J/mol") "Molar Enthalpy";
118 protected
119 Real Temp = 298.15;
120 algorithm
121 Ent := 0;
122 if T > 298.15 then
123 while Temp < T loop
124 Ent := Ent + VapCpId(VapCp, Temp) * 0.01;
125 Temp := Temp + 0.01;
126 end while;
127 Ent := Ent;
128 else
129 while Temp > T loop
130 Ent := Ent + VapCpId(VapCp, Temp) * 0.01;
131 Temp := Temp - 0.01;
132 end while;
133 Ent := -Ent;
134 end if;
135 end HVapId;
136
137 model Raoults_Law
138 import Simulator.Files.Thermodynamic_Functions.*;
139 Real K[NOC](each min = 0), resMolSpHeat[3], resMolEnth[3], resMolEntr[3];
140 equation
141 for i in 1:NOC loop
142 K[i] = Psat(comp[i].VP, T) / P;
143 end for;
144 resMolSpHeat[:] = zeros(3);
145 resMolEnth[:] = zeros(3);
146 resMolEntr = zeros(3);
147 end Raoults_Law;
148
149 package Connection
150 connector matConn
151 Real P, T, mixMolFlo, mixMolEnth, mixMolEntr, mixMolFrac[connNOC](each min = 0, each max = 1), vapPhasMolFrac(min = 0, max = 1);
152 parameter Integer connNOC;
153 annotation(Icon(coordinateSystem(initialScale = 0.1), graphics = {Rectangle(fillColor = {175, 175, 175}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}})}));
154 end matConn;
155
156
157 connector enConn
158 Real enFlo;
159 annotation(Icon(coordinateSystem(initialScale = 0.1), graphics = {Rectangle(fillColor = {255, 255, 33}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}})}));
160 end enConn;
161
162
163
164 connector trayConn
165 Real mixMolFlo, mixMolEnth, mixMolFrac[connNOC](each min = 0, each max = 1);
166 parameter Integer connNOC;
167 annotation(Icon(coordinateSystem(initialScale = 0.1), graphics = {Rectangle(fillColor = {8, 184, 211}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}})}));
168 end trayConn;
169
170 end Connection;
171
172 model Condensor1
173 extends Raoults_Law;
174 parameter Integer NOC = 2;
175 parameter Chemsep_Database.General_Properties comp[NOC];
176 Real P, T;
177 Real feedMolFlo(min = 0), sideDrawMolFlo(min = 0), inVapMolFlo(min = 0), outLiqMolFlo(min = 0), feedMolFrac[NOC](each min = 0, each max = 1), sideDrawMolFrac[NOC](each min = 0 , each max = 1), inVapCompMolFrac[NOC](each min = 0, each max = 1), outLiqCompMolFrac[NOC](each min = 0, each max = 1), feedMolEnth, inVapMolEnth, outLiqMolEnth, outVapCompMolEnth[NOC], outLiqCompMolEnth[NOC], heatLoad, sideDrawMolEnth;
178
179 parameter String condType"Partial or Total";
180 Connection.matConn feed(connNOC = NOC) annotation(
181 Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
182 Connection.matConn side_draw(connNOC = NOC) annotation(
183 Placement(visible = true, transformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
184 Connection.trayConn liquid_outlet(connNOC = NOC) annotation(
185 Placement(visible = true, transformation(origin = {-50, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-50, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
186 Connection.trayConn vapor_inlet(connNOC = NOC) annotation(
187 Placement(visible = true, transformation(origin = {50, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {50, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
188 Connection.enConn heat_load annotation(
189 Placement(visible = true, transformation(origin = {100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
190equation
191//connector equation
192 feed.mixMolFrac = feedMolFrac;
193 feed.mixMolEnth = feedMolEnth;
194 feed.mixMolFlo = feedMolFlo;
195
196 side_draw.P = P;
197 side_draw.T = T;
198 side_draw.mixMolFrac = sideDrawMolFrac;
199 side_draw.mixMolFlo = sideDrawMolFlo;
200 side_draw.mixMolEnth = sideDrawMolEnth;
201
202 liquid_outlet.mixMolFlo = outLiqMolFlo;
203 liquid_outlet.mixMolEnth = outLiqMolEnth;
204 liquid_outlet.mixMolFrac[:] = outLiqCompMolFrac[:];
205
206 vapor_inlet.mixMolFlo = inVapMolFlo;
207 vapor_inlet.mixMolEnth = inVapMolEnth;
208 vapor_inlet.mixMolFrac[:] = inVapCompMolFrac[:];
209
210 heat_load.enFlo = heatLoad;
211//molar balance
212 //feedMolFlo + inVapMolFlo = sideDrawMolFlo + outLiqMolFlo;
213 feedMolFlo .* feedMolFrac[:] + inVapMolFlo .* inVapCompMolFrac[:] = sideDrawMolFlo .* sideDrawMolFrac[:] + outLiqMolFlo .* outLiqCompMolFrac[:];
214//equillibrium
215 if (condType == "Partial") then
216 sideDrawMolFrac[:] = K[:] .* outLiqCompMolFrac[:];
217 sideDrawMolEnth = sum(sideDrawMolFrac[:] .* outVapCompMolEnth[:]) + resMolEnth[3];
218 elseif (condType == "Total") then
219 sideDrawMolFrac[:] = outLiqCompMolFrac[:];
220 sideDrawMolEnth = sum(sideDrawMolFrac[:] .* outLiqCompMolEnth[:]) + resMolEnth[2];
221 end if;
222//summation equation
223 sum(outLiqCompMolFrac[:]) = 1;
224 //sum(sideDrawMolFrac[:]) = 1;
225// Enthalpy balance
226 feedMolFlo * feedMolEnth + inVapMolFlo * inVapMolEnth = sideDrawMolFlo * sideDrawMolEnth + outLiqMolFlo * outLiqMolEnth + heatLoad;
227
228//enthalpy calculation
229 for i in 1:NOC loop
230 outLiqCompMolEnth[i] = HLiqId(comp[i].SH, comp[i].VapCp, comp[i].HOV, comp[i].Tc, T);
231 outVapCompMolEnth[i] = HVapId(comp[i].SH, comp[i].VapCp, comp[i].HOV, comp[i].Tc, T);
232 end for;
233 outLiqMolEnth = sum(outLiqCompMolFrac[:] .* outLiqCompMolEnth[:]) + resMolEnth[2];
234// outVapMolEnth = sum(inVapCompMolFrac[:] .* outVapCompMolEnth[:]) + resMolEnth[3];
235
236
237
238
239
240 annotation(
241 Diagram(coordinateSystem(extent = {{-100, -40}, {100, 40}})),
242 Icon(coordinateSystem(extent = {{-100, -40}, {100, 40}})),
243 __OpenModelica_commandLineOptions = "");
244end Condensor1;
245
246
247
248
249
250model Reboiler1
251 extends Raoults_Law;
252 parameter Integer NOC = 2;
253 parameter Chemsep_Database.General_Properties comp[NOC];
254 Real P, T;
255 Real feedMolFlo(min = 0), sideDrawMolFlo(min = 0), outVapMolFlo(min = 0), inLiqMolFlo(min = 0), feedMolFrac[NOC](each min = 0, each max = 1), sideDrawMolFrac[NOC](each min = 0, each max = 1), outVapCompMolFrac[NOC](each min = 0, each max = 1), inLiqCompMolFrac[NOC](each min = 0, each max = 1), feedMolEnth, outVapMolEnth, inLiqMolEnth, outVapCompMolEnth[NOC], sideDrawCompMolEnth[NOC], heatLoad, sideDrawMolEnth;
256
257 Connection.matConn feed(connNOC = NOC) annotation(
258 Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
259 Connection.matConn side_draw(connNOC = NOC) annotation(
260 Placement(visible = true, transformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
261 Connection.trayConn liquid_inlet(connNOC = NOC) annotation(
262 Placement(visible = true, transformation(origin = {-50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
263 Connection.trayConn vapor_outlet(connNOC = NOC) annotation(
264 Placement(visible = true, transformation(origin = {50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
265 Connection.enConn heat_load annotation(
266 Placement(visible = true, transformation(origin = {100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
267 equation
268 //connector equation
269 feed.mixMolFrac = feedMolFrac;
270 feed.mixMolEnth = feedMolEnth;
271 feed.mixMolFlo = feedMolFlo;
272
273 side_draw.P = P;
274 side_draw.T = T;
275 side_draw.mixMolFrac = sideDrawMolFrac;
276 side_draw.mixMolFlo = sideDrawMolFlo;
277 side_draw.mixMolEnth = sideDrawMolEnth;
278
279 liquid_inlet.mixMolFlo = inLiqMolFlo;
280 liquid_inlet.mixMolEnth = inLiqMolEnth;
281 liquid_inlet.mixMolFrac[:] = inLiqCompMolFrac[:];
282
283 vapor_outlet.mixMolFlo = outVapMolFlo;
284 vapor_outlet.mixMolEnth = outVapMolEnth;
285 vapor_outlet.mixMolFrac[:] = outVapCompMolFrac[:];
286
287 heat_load.enFlo = heatLoad;
288//molar balance
289feedMolFlo + inLiqMolFlo = sideDrawMolFlo + outVapMolFlo;
290
291 // feedMolFlo .* feedMolFrac[:] + inLiqMolFlo .* inLiqCompMolFrac[:] = sideDrawMolFlo .* sideDrawMolFrac[:] + outVapMolFlo .* outVapCompMolFrac[:];
292
293//equillibrium
294 outVapCompMolFrac[:] = K[:] .* sideDrawMolFrac[:];
295//summation equation
296 sum(outVapCompMolFrac[:]) = 1;
297 sum(sideDrawMolFrac[:]) = 1;
298// Enthalpy balance
299 feedMolFlo * feedMolEnth + inLiqMolFlo * inLiqMolEnth = sideDrawMolFlo * sideDrawMolEnth + outVapMolFlo * outVapMolEnth + heatLoad;
300//enthalpy calculation
301 for i in 1:NOC loop
302 sideDrawCompMolEnth[i] =HLiqId(comp[i].SH, comp[i].VapCp, comp[i].HOV, comp[i].Tc, T);
303 outVapCompMolEnth[i] = HVapId(comp[i].SH, comp[i].VapCp, comp[i].HOV, comp[i].Tc, T);
304 end for;
305 sideDrawMolEnth = sum(sideDrawMolFrac[:] .* sideDrawCompMolEnth[:]) + resMolEnth[2];
306 outVapMolEnth = sum(outVapCompMolFrac[:] .* outVapCompMolEnth[:]) + resMolEnth[3];
307 annotation(
308 Diagram(coordinateSystem(extent = {{-100, -40}, {100, 40}})),
309 Icon(coordinateSystem(extent = {{-100, -40}, {100, 40}})),
310 __OpenModelica_commandLineOptions = "");
311end Reboiler1;
312
313
314
315
316
317model distillTray1
318extends Raoults_Law;
319 parameter Integer NOC = 2;
320 parameter Chemsep_Database.General_Properties comp[NOC];
321 Real P, T(start = (min(comp[:].Tb) + max(comp[:].Tb)) / NOC);
322 Real feedMolFlo(min = 0), sideDrawMolFlo(min = 0), vapMolFlo[2](each min = 0), liqMolFlo[2](each min = 0), feedMolFrac[NOC](each min = 0, each max = 1), sideDrawMolFrac[NOC](each min = 0, each max = 1), vapCompMolFrac[2, NOC](each min = 0, each max = 1), liqCompMolFrac[2, NOC](each min = 0, each max = 1), feedMolEnth, vapMolEnth[2], liqMolEnth[2], outVapCompMolEnth[NOC], outLiqCompMolEnth[NOC], heatLoad, sideDrawMolEnth;
323 String sideDrawType(start = "Null");
324 //L or V
325 Connection.matConn feed(connNOC = NOC) annotation(
326 Placement(visible = true, transformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
327 Connection.matConn side_draw(connNOC = NOC) annotation(
328 Placement(visible = true, transformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
329 Connection.trayConn liquid_inlet(connNOC = NOC) annotation(
330 Placement(visible = true, transformation(origin = {-50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
331 Connection.trayConn liquid_outlet(connNOC = NOC) annotation(
332 Placement(visible = true, transformation(origin = {-50, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-50, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
333 Connection.trayConn vapor_outlet(connNOC = NOC) annotation(
334 Placement(visible = true, transformation(origin = {50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {50, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
335 Connection.trayConn vapor_inlet(connNOC = NOC) annotation(
336 Placement(visible = true, transformation(origin = {50, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {50, -40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
337 Connection.enConn heat_load annotation(
338 Placement(visible = true, transformation(origin = {100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
339equation
340//connector equation
341 feed.mixMolFrac = feedMolFrac;
342 feed.mixMolEnth = feedMolEnth;
343 feed.mixMolFlo = feedMolFlo;
344
345 side_draw.P = P;
346 side_draw.T = T;
347 side_draw.mixMolFrac = sideDrawMolFrac;
348 side_draw.mixMolFlo = sideDrawMolFlo;
349 side_draw.mixMolEnth = sideDrawMolEnth;
350
351 liquid_inlet.mixMolFlo = liqMolFlo[1];
352 liquid_inlet.mixMolEnth = liqMolEnth[1];
353 liquid_inlet.mixMolFrac[:] = liqCompMolFrac[1, :];
354
355 liquid_outlet.mixMolFlo = liqMolFlo[2];
356 liquid_outlet.mixMolEnth = liqMolEnth[2];
357 liquid_outlet.mixMolFrac[:] = liqCompMolFrac[2, :];
358
359 vapor_inlet.mixMolFlo = vapMolFlo[1];
360 vapor_inlet.mixMolEnth = vapMolEnth[1];
361 vapor_inlet.mixMolFrac[:] = vapCompMolFrac[1, :];
362
363 vapor_outlet.mixMolFlo = vapMolFlo[2];
364 vapor_outlet.mixMolEnth = vapMolEnth[2];
365 vapor_outlet.mixMolFrac[:] = vapCompMolFrac[2, :];
366
367 heat_load.enFlo = heatLoad;
368//molar balance
369//feedMolFlo + vapMolFlo[1] + liqMolFlo[1] = sideDrawMolFlo + vapMolFlo[2] + liqMolFlo[2];
370 feedMolFlo .* feedMolFrac[:] + vapMolFlo[1] .* vapCompMolFrac[1, :] + liqMolFlo[1] .* liqCompMolFrac[1, :] = sideDrawMolFlo .* sideDrawMolFrac[:] + vapMolFlo[2] .* vapCompMolFrac[2, :] + liqMolFlo[2] .* liqCompMolFrac[2, :];
371//equillibrium
372vapCompMolFrac[2, :] = K[:] .* liqCompMolFrac[2, :];
373//summation equation
374 sum(liqCompMolFrac[2, :]) = 1;
375 sum(vapCompMolFrac[2, :]) = 1;
376// Enthalpy balance
377 feedMolFlo * feedMolEnth + vapMolFlo[1] * vapMolEnth[1] + liqMolFlo[1] * liqMolEnth[1] = sideDrawMolFlo * sideDrawMolEnth + vapMolFlo[2] * vapMolEnth[2] + liqMolFlo[2] * liqMolEnth[2] + heatLoad;
378//enthalpy calculation
379 for i in 1:NOC loop
380 outLiqCompMolEnth[i] = HLiqId(comp[i].SH, comp[i].VapCp, comp[i].HOV, comp[i].Tc, T);
381 outVapCompMolEnth[i] = HVapId(comp[i].SH, comp[i].VapCp, comp[i].HOV, comp[i].Tc, T);
382 end for;
383 liqMolEnth[2] = sum(liqCompMolFrac[2, :] .* outLiqCompMolEnth[:]) + resMolEnth[2];
384 vapMolEnth[2] = sum(vapCompMolFrac[2, :] .* outVapCompMolEnth[:]) + resMolEnth[3];
385//sidedraw calculation
386 if sideDrawType == "L" then
387 sideDrawMolFrac[:] = liqCompMolFrac[2, :];
388 elseif sideDrawType == "V" then
389 sideDrawMolFrac[:] = vapCompMolFrac[2, :];
390 else
391 sideDrawMolFrac[:] = zeros(NOC);
392 end if;
393 annotation(
394 Diagram(coordinateSystem(extent = {{-100, -40}, {100, 40}})),
395 Icon(coordinateSystem(extent = {{-100, -40}, {100, 40}})),
396 __OpenModelica_commandLineOptions = "");
397end distillTray1;
398
399
400
401
402model column1
403 import data = Post.Chemsep_Database;
404 //instantiation of chemsep database
405 parameter data.Benzene benz;
406 parameter data.Toluene tol;
407 parameter Integer NOC = 2;
408 parameter data.General_Properties comp[NOC] = {benz, tol};
409 parameter String condType = "Total";
410 parameter Integer noOfStages = 3, noOfFeeds = 1, feedStages[noOfFeeds] = {1}, noOfSideDraws = 0, sideDrawStages[noOfSideDraws], noOfHeatLoads = 1, heatLoadStages[noOfHeatLoads] = {1};
411
412 distillTray1 tray[noOfStages - 2](each NOC = NOC,each comp = comp, T(start = 370), liquid_outlet.mixMolFlo(start = 81.3864), vapor_outlet.mixMolFlo(start = 100.999));
413 Condensor1 condensor(NOC = NOC, comp = comp, condType = condType, liquid_outlet.mixMolFlo(start = 50.999));
414 Reboiler1 reboiler(NOC = NOC, comp = comp, vapor_outlet.mixMolFlo(start = 31.3864));
415
416 //Connection.matConn feed[noOfFeeds](each connNOC = NOC);
417 //Connection.enConn heat_load[noOfHeatLoads];
418
419 equation
420 //connector equation
421 connect(tray[1].liquid_inlet, condensor.liquid_outlet);
422 connect(tray[1].vapor_outlet, condensor.vapor_inlet);
423 connect(tray[noOfStages - 2].liquid_outlet, reboiler.liquid_inlet);
424 connect(tray[noOfStages - 2].vapor_inlet, reboiler.vapor_outlet);
425 //tray equation
426 tray[1].sideDrawType = "Null";
427 tray[1].heat_load.enFlo = 0;
428 tray[1].P = 101325;
429 tray[1].feed.mixMolFlo = 100;
430 tray[1].feed.mixMolEnth = -2584.65;
431 tray[1].feed.mixMolFrac = {0.5, 0.5};
432 tray[1].side_draw.mixMolFlo = 0;
433 tray[1].side_draw.mixMolEnth = 0;
434 tray[1].side_draw.mixMolEntr = 0;
435 tray[1].side_draw.vapPhasMolFrac = 0;
436
437 //condensor equation
438 condensor.P = 101325;
439 condensor.side_draw.mixMolFlo = 50;
440 condensor.side_draw.T = 351.1855;
441 condensor.side_draw.mixMolEntr = 0;
442 condensor.side_draw.vapPhasMolFrac = 0;
443
444
445 //Reboiler equation
446 reboiler.P = 101325;
447 reboiler.side_draw.mixMolFlo = 50;
448 reboiler.side_draw.T = 370.076;
449 reboiler.side_draw.mixMolEntr = 0;
450 reboiler.side_draw.vapPhasMolFrac = 0;
451
452
453 algorithm
454 //feed equation
455 for i in 1:(noOfStages - 2) loop
456 for j in 1:noOfFeeds loop
457 if (feedStages[j] == i) then
458 tray[i].feed.P := 101325;
459 tray[i].feed.T := 370;
460 tray[i].feed.mixMolEntr := 0;
461 tray[i].feed.vapPhasMolFrac := 0;
462 break;
463 else
464 tray[i].feed.P := 0;
465 tray[i].feed.T := 0;
466 tray[i].feed.mixMolEntr := 0;
467 tray[i].feed.vapPhasMolFrac := 0;
468 end if;
469 end for;
470 end for;
471
472 for j in 1:noOfFeeds loop
473 if (feedStages[j] == (noOfStages - 1)) then
474 reboiler.feed.P := 0;
475 reboiler.feed.T := 0;
476 reboiler.feed.mixMolFlo := 0;
477 reboiler.feed.mixMolEnth := 0;
478 reboiler.feed.mixMolEntr := 0;
479// reboiler.feed.mixMolFrac[:] := zeros(NOC);
480 reboiler.feed.vapPhasMolFrac := 0;
481 break;
482 else
483 reboiler.feed.P := 0;
484 reboiler.feed.T := 0;
485 reboiler.feed.mixMolFlo := 0;
486 reboiler.feed.mixMolEnth := 0;
487 reboiler.feed.mixMolEntr := 0;
488// reboiler.feed.mixMolFrac[:] := zeros(NOC);
489 reboiler.feed.vapPhasMolFrac := 0;
490 end if;
491 end for;
492
493 for j in 1:noOfFeeds loop
494 if (feedStages[j] == noOfStages) then
495 condensor.feed.P := 0;
496 condensor.feed.T := 0;
497 condensor.feed.mixMolFlo := 0;
498 condensor.feed.mixMolEnth := 0;
499 condensor.feed.mixMolEntr := 0;
500 condensor.feed.mixMolFrac[:] := zeros(NOC);
501 condensor.feed.vapPhasMolFrac := 0;
502 break;
503 else
504 condensor.feed.P := 0;
505 condensor.feed.T := 0;
506 condensor.feed.mixMolFlo := 0;
507 condensor.feed.mixMolEnth := 0;
508 condensor.feed.mixMolEntr := 0;
509 condensor.feed.mixMolFrac[:] := zeros(NOC);
510 condensor.feed.vapPhasMolFrac := 0;
511 end if;
512 end for;
513
514 reboiler.feed.mixMolFrac := {0, 0};
515 //condensor.feed.mixMolFrac := {0, 0};
516
517 //Condensor and reboiler feed.mixMolFrac is creating a problem. If I directly giving value in algorithm it works. It gives error when ran inside if-else statement.
518end column1;
519
520
521
522
523
524
525end Post;