-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistillationPackage.mo
More file actions
1025 lines (1005 loc) · 61.2 KB
/
DistillationPackage.mo
File metadata and controls
1025 lines (1005 loc) · 61.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package DistillationPackage
connector sensor
Real var;
annotation(Diagram(graphics = {Ellipse(origin = {-1, 1}, fillColor = {65, 252, 255}, fillPattern = FillPattern.Solid, extent = {{-67, 65}, {67, -65}}, endAngle = 360)}), Icon(graphics = {Ellipse(origin = {-4, -1}, fillColor = {255, 85, 0}, fillPattern = FillPattern.Solid, extent = {{-60, 61}, {60, -61}}, endAngle = 360)}, coordinateSystem(initialScale = 0.1)));
end sensor;
connector port
parameter Integer NOC = 4;
Real moleflow;
Real pressure;
Real temperature;
Real molefrac[NOC];
Real liquidmoleflow, vapormoleflow;
Real liquidmolefrac[NOC], vapormolefrac[NOC];
Real enthalpy;
annotation(Diagram(graphics = {Ellipse(origin = {-1, 1}, fillColor = {65, 252, 255}, fillPattern = FillPattern.Solid, extent = {{-67, 65}, {67, -65}}, endAngle = 360)}), Icon(graphics = {Ellipse(origin = {-4, -1}, fillColor = {81, 253, 248}, fillPattern = FillPattern.Solid, extent = {{-60, 61}, {60, -61}}, endAngle = 360)}));
end port;
model valve
parameter Real coeff(fixed = false) "Coeff for valve", valveCv = 0.4 "valve Cv if not control valve";
parameter Boolean Control = false;
parameter Boolean OutletPfixed = false;
parameter Real OutletPressure = 1e5 "used only when OutletPfixed is true";
Real flowrate, Cv, outletP, delP;
sensor sensor1 annotation(Placement(visible = true, transformation(origin = {1, 77}, extent = {{-19, -19}, {19, 19}}, rotation = 0), iconTransformation(origin = {2, 56}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
port port1 annotation(Placement(visible = true, transformation(origin = {-80, -4}, extent = {{-18, -18}, {18, 18}}, rotation = 0), iconTransformation(origin = {-82, -2}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
port port2 annotation(Placement(visible = true, transformation(origin = {79, 1}, extent = {{-17, -17}, {17, 17}}, rotation = 0), iconTransformation(origin = {82, 2}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
equation
if Control == false then
sensor1.var = 0;
end if;
if Control == true then
Cv = sensor1.var;
else
Cv = valveCv;
end if;
flowrate = coeff * Cv * delP ^ 0.5;
port1.moleflow = flowrate;
port1.moleflow = port2.moleflow;
if OutletPfixed == true then
outletP = OutletPressure;
port2.pressure = outletP;
end if;
if OutletPfixed == false then
outletP = 0;
end if;
delP = port1.pressure - port2.pressure;
port2.temperature = port1.temperature;
port2.molefrac[:] = port1.molefrac[:];
port2.liquidmoleflow = port1.liquidmoleflow;
port2.vapormoleflow = port1.vapormoleflow;
port2.liquidmolefrac[:] = port1.liquidmolefrac[:];
port2.vapormolefrac[:] = port1.vapormolefrac[:];
port2.enthalpy = port1.enthalpy;
annotation(Icon(graphics = {Polygon(origin = {-48.26, -2.99}, fillColor = {85, 170, 255}, fillPattern = FillPattern.Solid, points = {{-47.7381, 48.9887}, {-47.7381, -49.0113}, {48.2619, 2.98874}, {48.2619, 2.98874}, {-47.7381, 48.9887}}), Polygon(origin = {49.25, -4.98}, fillColor = {85, 170, 255}, fillPattern = FillPattern.Solid, points = {{-47.2509, 4.98071}, {46.7491, 48.9807}, {46.7491, -49.0193}, {-47.2509, 4.98071}}), Rectangle(origin = {1, 35}, fillColor = {85, 170, 255}, fillPattern = FillPattern.Solid, extent = {{-15, 35}, {15, -35}})}, coordinateSystem(initialScale = 0.1)));
end valve;
model MaterialStream
parameter Integer NOC = 4;
parameter Chemsep_Database.Toluene comp1;
parameter Chemsep_Database.Hydrogen comp2;
parameter Chemsep_Database.Benzene comp3;
parameter Chemsep_Database.Methane comp4;
parameter String Name = "MS1";
parameter Chemsep_Database.General_Properties comp[NOC] = {comp1, comp2, comp3, comp4};
parameter Real Flowrate = 100, Pressure = 1e5, Temperature = 300, molefraction[NOC] = zeros(NOC);
parameter Boolean unspecified = true;
parameter Boolean stepchange = false;
parameter Real stepchangetime = 0.01;
parameter Real step_value = 1;
Real kf[NOC], zl[NOC](each min = 0, each max = 1, start = {0.5, 1e-18, 0.5, 0}), zv[NOC](each min = 0, each max = 1, start = {0, 0.25, 0, 0.75}), Fl(min = 0, start = 100), Fv(min = 0, start = 140), Tbf(start = 62), Tdf(start = 495.5), Psat_Tdf[NOC], Psat_Tbf[NOC], Psat_Tf[NOC], Pf, Tf, z[NOC], F;
Real Hvf[NOC], Hlf[NOC], H;
port port2 annotation(Placement(visible = true, transformation(origin = {80, -4}, extent = {{-18, -18}, {18, 18}}, rotation = 0), iconTransformation(origin = {85, 1}, extent = {{-21, -21}, {21, 21}}, rotation = 0)));
port port1 annotation(Placement(visible = true, transformation(origin = {-80, -4}, extent = {{-18, -18}, {18, 18}}, rotation = 0), iconTransformation(origin = {-82, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
equation
if unspecified == false then
if stepchange == true then
if time < stepchangetime then
port1.moleflow = Flowrate;
else
port1.moleflow = Flowrate + step_value;
end if;
else
port1.moleflow = Flowrate;
end if;
port1.pressure = Pressure;
port1.temperature = Temperature;
port1.molefrac[:] = molefraction[:];
port1.liquidmolefrac[:] = zl[:];
port1.vapormolefrac[:] = zv[:];
port1.liquidmoleflow = Fl;
port1.vapormoleflow = Fv;
port1.enthalpy = H;
end if;
if unspecified == true then
port1.liquidmolefrac[:] = zl[:];
port1.vapormolefrac[:] = zv[:];
port1.liquidmoleflow = Fl;
port1.vapormoleflow = Fv;
port1.enthalpy = H;
end if;
if unspecified == false then
Pf = Pressure;
z[:] = molefraction[:];
Tf = Temperature;
F = port1.moleflow;
else
Pf = port1.pressure;
z[:] = port1.molefrac[:];
Tf = port1.temperature;
F = port1.moleflow;
end if;
//flash calculations
sum(Pf * z[:] ./ Psat_Tdf[:]) = 1;
sum(Psat_Tbf[:] ./ Pf .* z[:]) = 1;
if Tf < Tbf then
zl[:] = z[:];
zv = zeros(NOC);
Fl = F;
Fv = 0;
kf = zeros(NOC);
elseif Tf > Tdf then
zv[:] = z[:];
zl = zeros(NOC);
Fl = 0;
Fv = F;
kf = zeros(NOC);
else
sum(zl[:]) = 1;
sum(zv[:]) = 1;
zv[:] = kf[:] .* zl[:];
kf[:] = Psat_Tf[:] ./ Pf;
F = Fl + Fv;
for i in 1:NOC - 1 loop
F * z[i] = Fl * zl[i] + Fv * zv[i];
end for;
end if;
H = Fl * sum(zl[:] .* Hlf[:]) + Fv * sum(zv[:] .* Hvf[:]);
for i in 1:NOC loop
Psat_Tbf[i] = Functions.Psat(comp[i].VP, Tbf);
Psat_Tdf[i] = Functions.Psat(comp[i].VP, Tdf);
Psat_Tf[i] = Functions.Psat(comp[i].VP, Tf);
Hlf[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, Tf);
Hvf[i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, Tf);
end for;
port2.moleflow = F;
port2.pressure = port1.pressure;
port2.temperature = port1.temperature;
port2.molefrac[:] = port1.molefrac[:];
port2.liquidmolefrac[:] = zl[:];
port2.vapormolefrac[:] = zv[:];
port2.liquidmoleflow = Fl;
port2.vapormoleflow = Fv;
port2.enthalpy = H;
annotation(Icon(graphics = {Rectangle(origin = {-10, 3}, fillColor = {255, 0, 0}, fillPattern = FillPattern.Solid, extent = {{-90, 45}, {90, -45}}), Text(origin = {-17, -1}, extent = {{-51, 27}, {51, -27}}, textString = "MS1")}, coordinateSystem(initialScale = 0.1)));
end MaterialStream;
model Distillation
parameter Chemsep_Database.Benzene comp1 annotation(Dialog(tab = "General", group = "compounds"));
parameter Chemsep_Database.Toluene comp2 annotation(Dialog(tab = "General", group = "compounds"));
parameter Chemsep_Database.General_Properties comp[2] = {comp1, comp2} annotation(Dialog(tab = "General", group = "compounds"));
parameter Integer N_Trays = 20 "No. of trays without condensor and reboiler" annotation(Dialog(tab = "General", group = "Trays"));
parameter Integer NOC = 2 "No. of compounds" annotation(Dialog(tab = "General", group = "compounds"));
parameter Integer N_Feed = 10 "Feed tray location" annotation(Dialog(tab = "General", group = "Trays"));
parameter Real M_eff[N_Trays, NOC] = fill(0.99, N_Trays, NOC) "Murfy's efficiency of trays" annotation(Dialog(tab = "General", group = "Efficiency"));
parameter Real Pressure_drop = 2432 "Pressure Drop per tray, Pa" annotation(Dialog(tab = "General", group = "Pressure Profile"));
parameter Real P_condenser = 101350 "Pressure in Condensor" annotation(Dialog(tab = "General", group = "Pressure Profile"));
constant Real R = 8.314 "Gas Constant";
parameter Real A_active = 1 "Active area of Tray, sq.m" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real h_weir = 0.01 "Height of weir, m" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real d_weir = 0.8 "Diameter of weir, m" annotation(Dialog(tab = "dynamic", group = "Tray data"));
type spec1 = enumeration(CondensorHeatLoad, ProductMolarFlow, CompoundMolarFlow, CompoundFractionInStream, RefluxRatio, Temperature) "condensor";
type spec2 = enumeration(ReboilerHeatLoad, ProductMolarFlow, CompoundMolarFlow, CompoundFractionInStream, BoilUpRatio, Temperature) "reboiler";
parameter spec1 specification1;
parameter Real specification1_value = 1;
parameter spec2 specification2;
parameter Real specification2_value = 1;
parameter Real Tray_volume = 0.1 annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real pi1 = -12.55 "constant for calculationg froth density, phi" annotation(Dialog(tab = "dynamic", group = "vapor flow"));
parameter Real pi2 = 0.91 "constant for calculationg froth density, phi" annotation(Dialog(tab = "dynamic", group = "vapor flow"));
Real y[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)), x[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)), y_eq[N_Trays, NOC], Tf[N_Trays];
Real V[N_Trays](each start = 70), L[N_Trays](each start = 100);
Real T[N_Trays](start = linspace(386, 354, N_Trays)), TC(start = 368), TB(start = 377), L0(start = 50), VNT, D, B, xc[NOC], xr[NOC], QC, QB;
Real Keq[N_Trays, NOC], Psat[N_Trays, NOC], PsatC[NOC], PsatB[NOC];
Real yNT[NOC], M[N_Trays](each start = 1), den[N_Trays, NOC];
Real hv[N_Trays, NOC] annotation(each HideResult = true), hl[N_Trays, NOC] annotation(each HideResult = true), hf[N_Trays, NOC] annotation(each HideResult = true), hv_B[NOC] annotation(each HideResult = true), hl_B[NOC] annotation(each HideResult = true), hl_C[NOC] annotation(each HideResult = true);
Real P[N_Trays], Ks[N_Trays] annotation(each HideResult = true);
Real dx[N_Trays, NOC], dM[N_Trays], dhl[N_Trays, NOC];
Real F[N_Trays](each start = 0) annotation(each HideResult = true), z[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)) annotation(each HideResult = true);
port port1 annotation(Placement(visible = true, transformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
port port2 annotation(Placement(visible = true, transformation(origin = {92, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {92, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial equation
for i in 1:N_Trays loop
//M[i] = M0[i];
der(M[i]) = 0;
//der(x[i,1]) = 0;
//dM[i] = 0;
dhl[i, 1] = 0;
//dx[i,1] = 0;
end for;
equation
// port1.pressure = P[N_Feed]; "should be automatic"
for i in 1:N_Trays loop
if i == N_Feed then
F[i] = port1.moleflow;
else
F[i] = 0;
end if;
Tf[i] = port1.temperature;
z[i, 1] = port1.molefrac[3];
z[i, 2] = port1.molefrac[1];
end for;
//functions required
for i in 1:NOC loop
for j in 1:N_Trays loop
Psat[j, i] = Functions.Psat(comp[i].VP, T[j]);
hv[j, i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hl[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hf[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, Tf[j]);
den[j, i] = Functions.Density(comp[i].LiqDen, comp[i].Tc, T[j], P[j]);
end for;
hv_B[i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_B[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_C[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TC);
PsatC[i] = Functions.Psat(comp[i].VP, TC);
PsatB[i] = Functions.Psat(comp[i].VP, TB);
end for;
for i in 1:N_Trays loop
Ks[i] = V[i] * R * T[i] / (A_active * P[i] * 10 ^ (-3)) * (P[i] * 10 ^ (-3) / (R * T[i] * (sum(x[i, :] .* den[i, :]) - P[i] * 10 ^ (-3) / (R * T[i]))));
end for;
//defining state variables!
for i in 1:N_Trays loop
dx[i, :] = der(x[i, :]);
dM[i] = der(M[i]);
dhl[i, :] = der(hl[i, :]);
end for;
//tray mass balance
xr[:] = x[1, :];
yNT[:] = xr[:];
L[1] - VNT - B = 0;
//when time>0 then
for i in 1:N_Trays loop
M[i] = A_active * sum(x[i, :] .* den[i, :]) * (exp(pi1 * Ks[i] ^ pi2) * h_weir + 44300 * 10 ^ (-3) * (L[i] / (sum(x[i, :] .* den[i, :]) * d_weir * 1000 * 3600)) ^ 0.704);
end for;
//end when;
M[1] * dx[1, :] + x[1, :] * dM[1] = VNT .* yNT[:] + L[2] .* x[2, :] - V[1] .* y[1, :] - L[1] .* x[1, :] + F[1] .* z[1, :];
//M0[1] = Tray_volume * sum(x[1,:].*den[1,:]);
//L[1] = L0 + (M[1]-M0[1])/taul;
//M[1] = A_active * sum(x[1,:].*den[1,:])*(exp(pi1*Ks[1]^pi2)*h_weir + 44300*(L[1]/(sum(x[1,:].*den[1,:]) * 0.5* d_weir))^0.704);
for i in 2:N_Trays - 1 loop
dM[i] * x[i, :] + dx[i, :] * M[i] = V[i - 1] .* y[i - 1, :] + L[i + 1] .* x[i + 1, :] - V[i] .* y[i, :] - L[i] .* x[i, :] + F[i] .* z[i, :];
//L[i] = L0 + (M[i]-M0[i])/taul;
//M0[i] = Tray_volume * sum(x[i,:].*den[i,:]);
end for;
M[N_Trays] * dx[N_Trays, :] + x[N_Trays, :] * dM[N_Trays] = V[N_Trays - 1] .* y[N_Trays - 1, :] + L0 .* xc[:] - V[N_Trays] .* y[N_Trays, :] - L[N_Trays] .* x[N_Trays, :] + F[N_Trays] .* z[N_Trays, :];
//M0[N_Trays] = Tray_volume * sum(x[N_Trays,:].*den[N_Trays,:]);
//L[N_Trays] = L0 + (M[N_Trays]-M0[N_Trays])/taul;
//M[N_Trays] = A_active * sum(x[N_Trays,:].*den[N_Trays,:])*(exp(pi1*Ks[N_Trays]^pi2)*h_weir + 44300*(L[N_Trays]/(sum(x[N_Trays,:].*den[N_Trays,:]) * 0.5* d_weir))^0.704);
V[N_Trays] - L0 - D = 0;
y[N_Trays, :] = xc[:];
//energy balance
VNT * sum(yNT[:] .* hv_B[:]) - V[1] * sum(y[1, :] .* hv[1, :]) + L[2] * sum(x[2, :] .* hl[2, :]) - L[1] * sum(x[1, :] .* hl[1, :]) + F[1] * sum(z[1, :] .* hf[1, :]) = M[1] * x[1, :] * dhl[1, :] + M[1] * dx[1, :] * hl[1, :] + dM[1] * x[1, :] * hl[1, :];
for i in 2:N_Trays - 1 loop
V[i - 1] * sum(y[i - 1, :] .* hv[i - 1, :]) - V[i] * sum(y[i, :] .* hv[i, :]) + L[i + 1] * sum(x[i + 1, :] .* hl[i + 1, :]) - L[i] * sum(x[i, :] .* hl[i, :]) + F[i] * sum(z[i, :] .* hf[i, :]) = M[i] * x[i, :] * dhl[i, :] + M[i] * dx[i, :] * hl[i, :] + dM[i] * x[i, :] * hl[i, :];
end for;
V[N_Trays - 1] * sum(y[N_Trays - 1, :] .* hv[N_Trays - 1, :]) - V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) + L0 * sum(xc[:] .* hl_C[:]) - L[N_Trays] * sum(x[N_Trays, :] .* hl[N_Trays, :]) + F[N_Trays] * sum(z[N_Trays, :] .* hf[N_Trays, :]) = dM[N_Trays] * x[N_Trays, :] * hl[N_Trays, :] + M[N_Trays] * dx[N_Trays, :] * hl[N_Trays, :] + M[N_Trays] * x[N_Trays, :] * dhl[N_Trays, :];
V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) - (L0 + D) * sum(xc[:] .* hl_C[:]) = QC;
L[1] * sum(x[1, :] .* hl[1, :]) - B * sum(xr[:] .* hl_B[:]) - VNT * sum(xr[:] .* hv_B[:]) = QB;
//pressure
for i in 1:N_Trays loop
P[i] = P_condenser + (N_Trays - i + 1) * Pressure_drop;
end for;
//Equilibrium
for i in 1:N_Trays loop
Keq[i, :] = Psat[i, :] ./ P[i];
y_eq[i, :] = Keq[i, :] .* x[i, :];
M_eff[i, :] = (y[i, :] - y[i - 1, :]) ./ (y_eq[i, :] - y[i - 1, :]);
sum(x[i, :]) = 1;
sum(y_eq[i, :]) = 1;
end for;
sum(y[N_Trays, :] .* PsatC[:] / P_condenser) = 1;
//sum(xc[:]) =1
sum(x[1, :] .* (P[1] + Pressure_drop) ./ PsatB[:]) = 1;
//sum(yNT[:]) =1;
// D = 0.5 * L0;
// B = 61.1;
port2.moleflow = D;
port2.molefrac = {xc[2], 0, xc[1], 0};
port2.temperature = TC;
port2.pressure = P_condenser;
/* port3.moleflow = B;
port3.molefrac = {xr[2], 0, xr[1], 0};
port3.temperature = TB;
port3.pressure = P_condenser + Pressure_drop * (N_Trays + 1); */
//Equations for Specification
if Integer(specification1) == 1 then
QC = specification1_value;
elseif Integer(specification1) == 2 then
D = specification1_value;
elseif Integer(specification1) == 3 then
xc[1] * D = specification1_value;
//yet to modify
elseif Integer(specification1) == 4 then
xc[1] = specification1_value;
//yet to modify
elseif Integer(specification1) == 5 then
L0 = specification1_value * D;
else
TC = specification1_value;
end if;
if Integer(specification2) == 1 then
QB = specification2_value;
elseif Integer(specification2) == 2 then
B = specification2_value;
elseif Integer(specification2) == 3 then
xr[1] * D = specification2_value;
//yet to modify
elseif Integer(specification2) == 4 then
xc[1] = specification2_value;
//yet to modify
elseif Integer(specification2) == 5 then
VNT = specification2_value * B;
else
TB = specification2_value;
end if;
annotation(Icon(graphics = {Rectangle(origin = {-2, -1}, fillColor = {0, 85, 127}, fillPattern = FillPattern.VerticalCylinder, extent = {{-94, 95}, {94, -95}})}), Documentation(info = "<HTML> <p> This is a generalized model for distilation column </p> </HTML>"));
end Distillation;
model test1
Distillation distillation1(specification1 = DistillationPackage.Distillation.spec1.RefluxRatio, specification1_value = 2, specification2 = DistillationPackage.Distillation.spec2.ProductMolarFlow, specification2_value = 61.5) annotation(Placement(visible = true, transformation(origin = {-3, -7}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
MaterialStream materialStream1(Flowrate = 97.5, Pressure = 1e5, Temperature = 360, molefraction = {0.45, 0, 0.55, 0}, stepchange = false, unspecified = false) annotation(Placement(visible = true, transformation(origin = {-70, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
MaterialStream materialStream2 annotation(Placement(visible = true, transformation(origin = {50, 16}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(distillation1.port2, materialStream2.port1) annotation(Line(points = {{14, 8}, {24, 8}, {24, 18}, {42, 18}, {42, 16}}));
connect(materialStream1.port2, distillation1.port1) annotation(Line(points = {{-62, -8}, {-20, -8}, {-20, -6}, {-20, -6}}));
end test1;
model DistillationC
parameter Chemsep_Database.Benzene comp1 annotation(Dialog(tab = "General", group = "compounds"));
parameter Chemsep_Database.Toluene comp2 annotation(Dialog(tab = "General", group = "compounds"));
parameter Chemsep_Database.General_Properties comp[2] = {comp1, comp2} annotation(Dialog(tab = "General", group = "compounds"));
parameter Integer N_Trays = 20 "No. of trays without condensor and reboiler" annotation(Dialog(tab = "General", group = "Trays"));
parameter Integer NOC = 2 "No. of compounds" annotation(Dialog(tab = "General", group = "compounds"));
parameter Integer N_Feed = 10 "Feed tray location" annotation(Dialog(tab = "General", group = "Trays"));
parameter Real M_eff[N_Trays, NOC] = fill(1, N_Trays, NOC) "Murfy's efficiency of trays" annotation(Dialog(tab = "General", group = "Efficiency"));
parameter Real Pressure_drop = 2432 "Pressure Drop per tray, Pa" annotation(Dialog(tab = "General", group = "Pressure Profile"));
parameter Real P_condenser = 101350 "Pressure in Condensor" annotation(Dialog(tab = "General", group = "Pressure Profile"));
constant Real R = 8.314 "Gas Constant";
parameter Real A_active = 1 "Active area of Tray, sq.m" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real h_weir = 0.01 "Height of weir, m" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real d_weir = 0.8 "Diameter of weir, m" annotation(Dialog(tab = "dynamic", group = "Tray data"));
type spec1 = enumeration(CondensorHeatLoad, ProductMolarFlow, CompoundMolarFlow, CompoundFractionInStream, RefluxRatio, Temperature) "condensor";
type spec2 = enumeration(ReboilerHeatLoad, ProductMolarFlow, CompoundMolarFlow, CompoundFractionInStream, BoilUpRatio, Temperature) "reboiler";
parameter spec1 specification1;
parameter Real specification1_value = 1;
parameter spec2 specification2;
parameter Real specification2_value = 1;
parameter Real Tray_volume = 0.1 annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real pi1 = -12.55 "constant for calculationg froth density, phi" annotation(Dialog(tab = "dynamic", group = "vapor flow"));
parameter Real pi2 = 0.91 "constant for calculationg froth density, phi" annotation(Dialog(tab = "dynamic", group = "vapor flow"));
/*variables*/
Real y[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)) "vapor molefraction", x[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)) "liquid molefraction", y_eq[N_Trays, NOC] "equilibrium vapor molefraction", Tf[N_Trays] "temperature of feed";
Real V[N_Trays](each start = 70) "vapor flowrates", L[N_Trays](each start = 100) "Liquid flowrates";
Real T[N_Trays](start = linspace(386, 354, N_Trays)) "Temperature of trays", TC(start = 368) "Temperature of condenser", TB(start = 377) "Temeprature of reboiler", L0(start = 50) "", VNT "Boil up", D "Distillate", B "Bottoms", xc[NOC] "composition in condenser", xr[NOC] "composition in reboiler", QC "Condenser heat load", QB "Reboiler heat load";
Real Keq[N_Trays, NOC], Psat[N_Trays, NOC], PsatC[NOC], PsatB[NOC];
Real yNT[NOC], M[N_Trays](each start = 1) "moles of liquid in tray", den[N_Trays, NOC] "density of component in tray";
Real hv[N_Trays, NOC] annotation(each HideResult = true), hl[N_Trays, NOC] annotation(each HideResult = true), hf[N_Trays, NOC] annotation(each HideResult = true), hv_B[NOC] annotation(each HideResult = true), hl_B[NOC] annotation(each HideResult = true), hl_C[NOC] annotation(each HideResult = true);
Real P[N_Trays], Ks[N_Trays] annotation(each HideResult = true);
Real dx[N_Trays, NOC], dM[N_Trays], dhl[N_Trays, NOC];
Real F[N_Trays](each start = 0) annotation(each HideResult = true), z[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)) annotation(each HideResult = true);
/*ports*/
port port1 annotation(Placement(visible = true, transformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
port port2 annotation(Placement(visible = true, transformation(origin = {92, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {92, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
port port3 annotation(Placement(visible = true, transformation(origin = {94, -74}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {94, -74}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial equation
for i in 1:N_Trays loop
//M[i] = M0[i];
der(M[i]) = 0;
//der(x[i,1]) = 0;
//dM[i] = 0;
dhl[i, 1] = 0;
//dx[i,1] = 0;
end for;
equation
// port1.pressure = P[N_Feed];
for i in 1:N_Trays loop
if i == N_Feed then
F[i] = port1.moleflow;
else
F[i] = 0;
end if;
Tf[i] = port1.temperature;
z[i, 1] = port1.molefrac[3];
z[i, 2] = port1.molefrac[1];
end for;
//functions required
for i in 1:NOC loop
for j in 1:N_Trays loop
Psat[j, i] = Functions.Psat(comp[i].VP, T[j]);
hv[j, i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hl[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hf[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, Tf[j]);
den[j, i] = Functions.Density(comp[i].LiqDen, comp[i].Tc, T[j], P[j]);
end for;
hv_B[i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_B[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_C[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TC);
PsatC[i] = Functions.Psat(comp[i].VP, TC);
PsatB[i] = Functions.Psat(comp[i].VP, TB);
end for;
for i in 1:N_Trays loop
Ks[i] = V[i] * R * T[i] / (A_active * P[i] * 10 ^ (-3)) * (P[i] * 10 ^ (-3) / (R * T[i] * (sum(x[i, :] .* den[i, :]) - P[i] * 10 ^ (-3) / (R * T[i]))));
end for;
//defining state variables!
for i in 1:N_Trays loop
dx[i, :] = der(x[i, :]);
dM[i] = der(M[i]);
dhl[i, :] = der(hl[i, :]);
end for;
//tray mass balance
//equation for moles on trays
for i in 1:N_Trays loop
M[i] = A_active * sum(x[i, :] .* den[i, :]) * (exp(pi1 * Ks[i] ^ pi2) * h_weir + 44300 * 10 ^ (-3) * (L[i] / (sum(x[i, :] .* den[i, :]) * d_weir * 1000 * 3600)) ^ 0.704);
end for;
//mass balance for tray 1
M[1] * dx[1, :] + x[1, :] * dM[1] = VNT .* yNT[:] + L[2] .* x[2, :] - V[1] .* y[1, :] - L[1] .* x[1, :] + F[1] .* z[1, :];
//mass balance for trays in between
for i in 2:N_Trays - 1 loop
dM[i] * x[i, :] + dx[i, :] * M[i] = V[i - 1] .* y[i - 1, :] + L[i + 1] .* x[i + 1, :] - V[i] .* y[i, :] - L[i] .* x[i, :] + F[i] .* z[i, :];
end for;
//mass balance for top tray
M[N_Trays] * dx[N_Trays, :] + x[N_Trays, :] * dM[N_Trays] = V[N_Trays - 1] .* y[N_Trays - 1, :] + L0 .* xc[:] - V[N_Trays] .* y[N_Trays, :] - L[N_Trays] .* x[N_Trays, :] + F[N_Trays] .* z[N_Trays, :];
//mass balance for condenser
V[N_Trays] - L0 - D = 0;
y[N_Trays, :] = xc[:];
//mass balance for reboiler
xr[:] = x[1, :];
yNT[:] = xr[:];
L[1] - VNT - B = 0;
//energy balance
//at tray 1 (from bottom)
VNT * sum(yNT[:] .* hv_B[:]) - V[1] * sum(y[1, :] .* hv[1, :]) + L[2] * sum(x[2, :] .* hl[2, :]) - L[1] * sum(x[1, :] .* hl[1, :]) + F[1] * sum(z[1, :] .* hf[1, :]) = M[1] * x[1, :] * dhl[1, :] + M[1] * dx[1, :] * hl[1, :] + dM[1] * x[1, :] * hl[1, :];
// for trays in between
for i in 2:N_Trays - 1 loop
V[i - 1] * sum(y[i - 1, :] .* hv[i - 1, :]) - V[i] * sum(y[i, :] .* hv[i, :]) + L[i + 1] * sum(x[i + 1, :] .* hl[i + 1, :]) - L[i] * sum(x[i, :] .* hl[i, :]) + F[i] * sum(z[i, :] .* hf[i, :]) = M[i] * x[i, :] * dhl[i, :] + M[i] * dx[i, :] * hl[i, :] + dM[i] * x[i, :] * hl[i, :];
end for;
//at top tray
V[N_Trays - 1] * sum(y[N_Trays - 1, :] .* hv[N_Trays - 1, :]) - V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) + L0 * sum(xc[:] .* hl_C[:]) - L[N_Trays] * sum(x[N_Trays, :] .* hl[N_Trays, :]) + F[N_Trays] * sum(z[N_Trays, :] .* hf[N_Trays, :]) = dM[N_Trays] * x[N_Trays, :] * hl[N_Trays, :] + M[N_Trays] * dx[N_Trays, :] * hl[N_Trays, :] + M[N_Trays] * x[N_Trays, :] * dhl[N_Trays, :];
//condenser
V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) - (L0 + D) * sum(xc[:] .* hl_C[:]) = QC;
//reboiler
L[1] * sum(x[1, :] .* hl[1, :]) - B * sum(xr[:] .* hl_B[:]) - VNT * sum(xr[:] .* hv_B[:]) = QB;
//pressure
for i in 1:N_Trays loop
P[i] = P_condenser + (N_Trays - i + 1) * Pressure_drop;
end for;
//Equilibrium
for i in 1:N_Trays loop
Keq[i, :] = Psat[i, :] ./ P[i];
y_eq[i, :] = Keq[i, :] .* x[i, :];
M_eff[i, :] = (y[i, :] - y[i - 1, :]) ./ (y_eq[i, :] - y[i - 1, :]);
sum(x[i, :]) = 1;
sum(y_eq[i, :]) = 1;
end for;
sum(y[N_Trays, :] .* PsatC[:] / P_condenser) = 1;
//sum(xc[:]) =1
sum(x[1, :] .* (P[1] + Pressure_drop) ./ PsatB[:]) = 1;
//sum(yNT[:]) =1;
/*sending data to ports*/
port2.moleflow = D;
port2.molefrac = {xc[2], 0, xc[1], 0};
port2.temperature = TC;
port2.pressure = P_condenser;
port3.moleflow = B;
port3.molefrac = {xr[2], 0, xr[1], 0};
port3.temperature = TB;
port3.pressure = P_condenser + Pressure_drop * (N_Trays + 1);
//Equations for Specification
if Integer(specification1) == 1 then
QC = specification1_value;
elseif Integer(specification1) == 2 then
D = specification1_value;
elseif Integer(specification1) == 3 then
xc[1] * D = specification1_value;
//yet to modify
elseif Integer(specification1) == 4 then
xc[1] = specification1_value;
//yet to modify
elseif Integer(specification1) == 5 then
L0 = specification1_value * D;
else
TC = specification1_value;
end if;
if Integer(specification2) == 1 then
QB = specification2_value;
elseif Integer(specification2) == 2 then
B = specification2_value;
elseif Integer(specification2) == 3 then
xr[1] * D = specification2_value;
//yet to modify
elseif Integer(specification2) == 4 then
xc[1] = specification2_value;
//yet to modify
elseif Integer(specification2) == 5 then
VNT = specification2_value * B;
else
TB = specification2_value;
end if;
annotation(Icon(graphics = {Rectangle(origin = {-2, -1}, fillColor = {0, 85, 127}, fillPattern = FillPattern.VerticalCylinder, extent = {{-94, 95}, {94, -95}})}));
end DistillationC;
model Distillationwithsizing
parameter Chemsep_Database.Benzene comp1 annotation(Dialog(tab = "General", group = "compounds"));
parameter Chemsep_Database.Toluene comp2 annotation(Dialog(tab = "General", group = "compounds"));
parameter Chemsep_Database.General_Properties comp[2] = {comp1, comp2} annotation(Dialog(tab = "General", group = "compounds"));
parameter Integer N_Trays = 20 "No. of trays without condensor and reboiler" annotation(Dialog(tab = "General", group = "Trays"));
parameter Integer NOC = 2 "No. of compounds" annotation(Dialog(tab = "General", group = "compounds"));
parameter Integer N_Feed = 10 "Feed tray location" annotation(Dialog(tab = "General", group = "Trays"));
parameter Real M_eff = 0.99 "Murfy's efficiency of trays" annotation(Dialog(tab = "General", group = "Efficiency"), each HideResult = true);
parameter Real Pressure_drop(unit = "atm") = 0.1 "Pressure Drop per tray" annotation(Dialog(tab = "General", group = "Pressure Profile"));
parameter Real P_condenser(unit = "atm") = 1 "Pressure in Condensor" annotation(Dialog(tab = "General", group = "Pressure Profile"));
constant Real R = 8.314 "Gas Constant";
parameter Real Active_area(unit = "m2") = 1 "Active area of Tray" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real Weir_diameter(unit = "m") = 0.8 "Diameter of weir" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real A_active(unit = "m2", fixed = false, start = 0.6);
parameter Real d_weir(unit = "m", fixed = false);
parameter Boolean Override_Sizing_Calculations;
parameter Real Kv(unit = "ft/s") = 0.3 "constant for calculating max velocity permissible, ft/s" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real h_weir(unit = "m") = 0.01 "Height of weir" annotation(Dialog(tab = "dynamic", group = "Tray data"));
type spec1 = enumeration(CondensorHeatLoad, ProductMolarFlow, CompoundMolarFlow, CompoundFractionInStream, RefluxRatio, Temperature) "condensor";
type spec2 = enumeration(ReboilerHeatLoad, ProductMolarFlow, CompoundMolarFlow, CompoundFractionInStream, BoilUpRatio, Temperature) "reboiler";
parameter spec1 specification1 "condensor";
parameter Real specification1_value = 1;
parameter spec2 specification2 "reboiler";
parameter Real specification2_value = 1;
parameter Real Tray_volume(unit = "m3") = 0.1 annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real pi1 = -12.55 "constant for calculationg froth density, phi" annotation(Dialog(tab = "dynamic", group = "vapor flow"));
parameter Real pi2 = 0.91 "constant for calculationg froth density, phi" annotation(Dialog(tab = "dynamic", group = "vapor flow"));
Real y[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)), x[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)), y_eq[N_Trays, NOC], Tf[N_Trays](each unit = "K")annotation(each HideResult = true);
Real V[N_Trays](each unit = "mol/s", each start = 70), L[N_Trays](each unit = "mol/s", each start = 100);
Real T[N_Trays](each unit = "K", start = linspace(386, 354, N_Trays)), TC(unit = "K", start = 368), TB(unit = "K", start = 377), L0(unit = "mol/s", start = 50), VNT(unit = "mol/s"), D(unit = "mol/s"), B(unit = "mol/s"), xc[NOC], xr[NOC], QC(unit = "J/s"), QB(unit = "J/s");
Real Keq[N_Trays, NOC]annotation(each HideResult = true), Psat[N_Trays, NOC](each unit = "Pa"), PsatC[NOC](each unit = "Pa"), PsatB[NOC](each unit = "Pa");
Real yNT[NOC], M[N_Trays](each unit = "mol", each start = 1), den[N_Trays, NOC](each unit = "kmol/m3");
Real hv[N_Trays, NOC](each unit = "J/mol") annotation(each HideResult = true), hl[N_Trays, NOC](each unit = "J/mol") annotation(each HideResult = true), hf[N_Trays, NOC](each unit = "J/mol") annotation(each HideResult = true), hv_B[NOC](each unit = "J/mol") annotation(each HideResult = true), hl_B[NOC](each unit = "J/mol") annotation(each HideResult = true), hl_C[NOC](each unit = "J/mol") annotation(each HideResult = true);
Real P[N_Trays](each unit = "Pa"), Ks[N_Trays] annotation(each HideResult = true);
Real dx[N_Trays, NOC], dM[N_Trays], dhl[N_Trays, NOC];
Real F[N_Trays](each start = 0) annotation(each HideResult = true), z[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)) annotation(each HideResult = true);
port port1 annotation(Placement(visible = true, transformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial equation
/*sizing*/
if Override_Sizing_Calculations == false then
Kv * 0.3048 * ((den[1, :] * x[1, :] - P[1] / (R * T[1] * 1000)) * (P[1] / (R * T[1] * 1000))) ^ 0.5 * 1000* A_active = max(V);
d_weir = (A_active * 4 / 3.14) ^ 0.5;
else
A_active = Active_area;
d_weir = Weir_diameter;
end if;
for i in 1:N_Trays loop
//M[i] = M0[i];
der(M[i]) = 0;
//der(x[i,1]) = 0;
//dM[i] = 0;
dhl[i, 1] = 0;
//dx[i,1] = 0;
end for;
equation
// port1.pressure = P[N_Feed]; "should be automatic"
for i in 1:N_Trays loop
if i == N_Feed then
F[i] = port1.moleflow;
else
F[i] = 0;
end if;
Tf[i] = port1.temperature;
z[i, 1] = port1.molefrac[3];
z[i, 2] = port1.molefrac[1];
end for;
//functions required
for i in 1:NOC loop
for j in 1:N_Trays loop
Psat[j, i] = Functions.Psat(comp[i].VP, T[j]);
hv[j, i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hl[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hf[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, Tf[j]);
den[j, i] = Functions.Density(comp[i].LiqDen, comp[i].Tc, T[j], P[j]);
end for;
hv_B[i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_B[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_C[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TC);
PsatC[i] = Functions.Psat(comp[i].VP, TC);
PsatB[i] = Functions.Psat(comp[i].VP, TB);
end for;
for i in 1:N_Trays loop
Ks[i] = (V[i] * R * T[i] / (A_active * P[i] )) * (P[i] / (R * T[i] * ((1000*sum(x[i, :] .* den[i, :])) - P[i] / (R * T[i]))))^0.5;
end for;
//defining state variables!
for i in 1:N_Trays loop
dx[i, :] = der(x[i, :]);
dM[i] = der(M[i]);
dhl[i, :] = der(hl[i, :]);
end for;
//tray mass balance
xr[:] = x[1, :];
yNT[:] = xr[:];
L[1] - VNT - B = 0;
for i in 1:N_Trays loop
M[i] = A_active * sum(x[i, :] .* den[i, :])*1000 * (exp(pi1 * Ks[i] ^ pi2) * h_weir + 44300 * 10 ^ (-3) * (L[i] / (sum(x[i, :] .* den[i, :]) * 1000 * d_weir * 1000)) ^ 0.704);
end for;
M[1] * dx[1, :] + x[1, :] * dM[1] = VNT .* yNT[:] + L[2] .* x[2, :] - V[1] .* y[1, :] - L[1] .* x[1, :] + F[1] .* z[1, :];
for i in 2:N_Trays - 1 loop
dM[i] * x[i, :] + dx[i, :] * M[i] = V[i - 1] .* y[i - 1, :] + L[i + 1] .* x[i + 1, :] - V[i] .* y[i, :] - L[i] .* x[i, :] + F[i] .* z[i, :];
end for;
M[N_Trays] * dx[N_Trays, :] + x[N_Trays, :] * dM[N_Trays] = V[N_Trays - 1] .* y[N_Trays - 1, :] + L0 .* xc[:] - V[N_Trays] .* y[N_Trays, :] - L[N_Trays] .* x[N_Trays, :] + F[N_Trays] .* z[N_Trays, :];
V[N_Trays] - L0 - D = 0;
y[N_Trays, :] = xc[:];
//energy balance
VNT * sum(yNT[:] .* hv_B[:]) - V[1] * sum(y[1, :] .* hv[1, :]) + L[2] * sum(x[2, :] .* hl[2, :]) - L[1] * sum(x[1, :] .* hl[1, :]) + F[1] * sum(z[1, :] .* hf[1, :]) = M[1] * x[1, :] * dhl[1, :] + M[1] * dx[1, :] * hl[1, :] + dM[1] * x[1, :] * hl[1, :];
for i in 2:N_Trays - 1 loop
V[i - 1] * sum(y[i - 1, :] .* hv[i - 1, :]) - V[i] * sum(y[i, :] .* hv[i, :]) + L[i + 1] * sum(x[i + 1, :] .* hl[i + 1, :]) - L[i] * sum(x[i, :] .* hl[i, :]) + F[i] * sum(z[i, :] .* hf[i, :]) = M[i] * x[i, :] * dhl[i, :] + M[i] * dx[i, :] * hl[i, :] + dM[i] * x[i, :] * hl[i, :];
end for;
V[N_Trays - 1] * sum(y[N_Trays - 1, :] .* hv[N_Trays - 1, :]) - V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) + L0 * sum(xc[:] .* hl_C[:]) - L[N_Trays] * sum(x[N_Trays, :] .* hl[N_Trays, :]) + F[N_Trays] * sum(z[N_Trays, :] .* hf[N_Trays, :]) = dM[N_Trays] * x[N_Trays, :] * hl[N_Trays, :] + M[N_Trays] * dx[N_Trays, :] * hl[N_Trays, :] + M[N_Trays] * x[N_Trays, :] * dhl[N_Trays, :];
V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) - (L0 + D) * sum(xc[:] .* hl_C[:]) = QC;
L[1] * sum(x[1, :] .* hl[1, :]) - B * sum(xr[:] .* hl_B[:]) - VNT * sum(xr[:] .* hv_B[:]) = QB;
//pressure
for i in 1:N_Trays loop
P[i] =( P_condenser + (N_Trays - i + 1) * Pressure_drop)*101325;
end for;
//Equilibrium
for i in 1:N_Trays loop
Keq[i, :] = Psat[i, :] ./ P[i];
y_eq[i, :] = Keq[i, :] .* x[i, :];
{M_eff, M_eff} = (y[i, :] - y[i - 1, :]) ./ (y_eq[i, :] - y[i - 1, :]);
sum(x[i, :]) = 1;
sum(y_eq[i, :]) = 1;
end for;
sum(y[N_Trays, :] .* PsatC[:] / (P_condenser*101325)) = 1;
//sum(xc[:]) =1
sum(x[1, :] .* (P[1] + (Pressure_drop*101325)) ./ PsatB[:]) = 1;
//sum(yNT[:]) =1;
// D = 0.5 * L0;
// B = 61.1;
/* port2.moleflow = D;
port2.molefrac = {xc[2], 0, xc[1], 0};
port2.temperature = TC;
port2.pressure = P_condenser * 101325;
/* port3.moleflow = B;
port3.molefrac = {xr[2], 0, xr[1], 0};
port3.temperature = TB;
port3.pressure = (P_condenser + Pressure_drop * (N_Trays + 1)) * 101325; */
//Equations for Specification
if Integer(specification1) == 1 then
QC = specification1_value;
elseif Integer(specification1) == 2 then
D = specification1_value;
elseif Integer(specification1) == 3 then
xc[1] * D = specification1_value;
//yet to modify
elseif Integer(specification1) == 4 then
xc[1] = specification1_value;
//yet to modify
elseif Integer(specification1) == 5 then
L0 = specification1_value * D;
else
TC = specification1_value;
end if;
if Integer(specification2) == 1 then
QB = specification2_value;
elseif Integer(specification2) == 2 then
B = specification2_value;
elseif Integer(specification2) == 3 then
xr[1] * D = specification2_value;
//yet to modify
elseif Integer(specification2) == 4 then
xc[1] = specification2_value;
//yet to modify
elseif Integer(specification2) == 5 then
VNT = specification2_value * B;
else
TB = specification2_value;
end if;
annotation(Icon(graphics = {Rectangle(origin = {-2, -1}, fillColor = {0, 85, 127}, fillPattern = FillPattern.VerticalCylinder, extent = {{-94, 95}, {94, -95}})}), Documentation(info = "<HTML> <p> This is a generalized model for distilation column </p> </HTML>"));
end Distillationwithsizing;
model Distillationwithsizingtest
DistillationPackage.Distillationwithsizing distillation1(Override_Sizing_Calculations = false, Pressure_drop = 0.01, specification1 = DistillationPackage.Distillation.spec1.RefluxRatio, specification1_value = 2, specification2 = DistillationPackage.Distillation.spec2.ProductMolarFlow, specification2_value = 41) annotation(Placement(visible = true, transformation(origin = {-3, -9}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
MaterialStream materialStream1(Flowrate = 80, Pressure = 1e5, Tdf(start = 370), Temperature = 360, molefraction = {0.45, 0, 0.55, 0}, step_value = 2, stepchange = true, unspecified = false) annotation(Placement(visible = true, transformation(origin = {-70, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(materialStream1.port2, distillation1.port1) annotation(Line(points = {{-62, -8}, {-20, -8}, {-20, -9}}));
annotation(experiment(StartTime = 0, StopTime = 0, Tolerance = 1e-06, Interval = 0));
end Distillationwithsizingtest;
model materialtest
MaterialStream materialStream1(Flowrate = 61.1, Pressure = 152422, Temperature = 391.5, molefraction = {0.704, 0, 0.296, 0}, unspecified = false) annotation(Placement(visible = true, transformation(origin = {-22, 8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
annotation(experiment(StartTime = 0, StopTime = 0, Tolerance = 1e-06, Interval = 0));
end materialtest;
model DistillationwithsizingtestRK
DistillationPackage.Distillationwithsizing distillation1(Override_Sizing_Calculations = false, Pressure_drop = 0.01, specification1 = DistillationPackage.Distillation.spec1.RefluxRatio, specification1_value = 2, specification2 = DistillationPackage.Distillation.spec2.ProductMolarFlow, specification2_value = 41) annotation(Placement(visible = true, transformation(origin = {-3, -9}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
MaterialStream materialStream1(Flowrate = 80, Pressure = 1e5, Tdf(start = 370), Temperature = 360, molefraction = {0.45, 0, 0.55, 0}, step_value = 2, stepchange = true, unspecified = false) annotation(Placement(visible = true, transformation(origin = {-70, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(materialStream1.port2, distillation1.port1) annotation(Line(points = {{-62, -8}, {-20, -8}, {-20, -9}}));
annotation(experiment(StartTime = 0, StopTime = 0, Tolerance = 1e-06, Interval = 0));
end DistillationwithsizingtestRK;
model DistillationNew
parameter Chemsep_Database.Benzene comp1 annotation(Dialog(tab = "General", group = "compounds"));
parameter Chemsep_Database.Toluene comp2 annotation(Dialog(tab = "General", group = "compounds"));
parameter Chemsep_Database.General_Properties comp[2] = {comp1, comp2} annotation(Dialog(tab = "General", group = "compounds"));
parameter Integer N_Trays = 20 "No. of trays without condensor and reboiler" annotation(Dialog(tab = "General", group = "Trays"));
parameter Integer NOC = 2 "No. of compounds" annotation(Dialog(tab = "General", group = "compounds"));
parameter Integer N_Feed = 10 "Feed tray location" annotation(Dialog(tab = "General", group = "Trays"));
parameter Real M_eff = 0.99 "Murfy's efficiency of trays" annotation(Dialog(tab = "General", group = "Efficiency"), each HideResult = true);
parameter Real Pressure_drop(unit = "atm") = 0.1 "Pressure Drop per tray" annotation(Dialog(tab = "General", group = "Pressure Profile"));
parameter Real P_condenser(unit = "atm") = 1 "Pressure in Condensor" annotation(Dialog(tab = "General", group = "Pressure Profile"));
constant Real R = 8.314 "Gas Constant";
parameter Real Active_area(unit = "m2") = 1 "Active area of Tray" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real Weir_diameter(unit = "m") = 0.8 "Diameter of weir" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real A_active(unit = "m2", fixed = false, start = 0.6);
parameter Real d_weir(unit = "m", fixed = false);
parameter Boolean Override_Sizing_Calculations;
parameter Real Kv(unit = "ft/s") = 0.3 "constant for calculating max velocity permissible, ft/s" annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real h_weir(unit = "m") = 0.1 "Height of weir" annotation(Dialog(tab = "dynamic", group = "Tray data"));
type spec1 = enumeration(CondensorHeatLoad, ProductMolarFlow, CompoundMolarFlow, CompoundFractionInStream, RefluxRatio, Temperature) "condensor";
type spec2 = enumeration(ReboilerHeatLoad, ProductMolarFlow, CompoundMolarFlow, CompoundFractionInStream, BoilUpRatio, Temperature) "reboiler";
parameter spec1 specification1 "condensor";
parameter Real specification1_value = 1;
parameter spec2 specification2 "reboiler";
parameter Real specification2_value = 1;
parameter Real Tray_volume(unit = "m3") = 0.1 annotation(Dialog(tab = "dynamic", group = "Tray data"));
parameter Real pi1 = -12.55 "constant for calculationg froth density, phi" annotation(Dialog(tab = "dynamic", group = "vapor flow"));
parameter Real pi2 = 0.91 "constant for calculationg froth density, phi" annotation(Dialog(tab = "dynamic", group = "vapor flow"));
Real y[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)), x[N_Trays, NOC](start = fill(0.5, N_Trays, NOC), each nominal = 1e-1), y_eq[N_Trays, NOC], Tf[N_Trays](each unit = "K")annotation(each HideResult = true);
Real V[N_Trays](each unit = "mol/s", each start = 70), L[N_Trays](each unit = "mol/s", each start = 100);
Real T[N_Trays](each unit = "K", start = linspace(386, 354, N_Trays), each nominal = 1e2), TC(unit = "K", start = 368), TB(unit = "K", start = 377), L0(unit = "mol/s", start = 50), VNT(unit = "mol/s"), D(unit = "mol/s"), B(unit = "mol/s"), xc[NOC], xr[NOC], QC(unit = "J/s", nominal = 1e6), QB(unit = "J/s", nominal = 1e6);
Real Keq[N_Trays, NOC]annotation(each HideResult = true), Psat[N_Trays, NOC](each unit = "Pa") annotation(each HideResult = true), PsatC[NOC](each unit = "Pa"), PsatB[NOC](each unit = "Pa");
Real yNT[NOC], M[N_Trays](each unit = "mol", each start = 2000), den[N_Trays, NOC](each unit = "kmol/m3") annotation(each HideResult = true);
Real hv[N_Trays, NOC](each unit = "J/mol", each nominal = 1e3) annotation(each HideResult = true), hl[N_Trays, NOC](each unit = "J/mol", each nominal = 1e4)annotation(each HideResult = true) , hf[N_Trays, NOC](each unit = "J/mol") annotation(each HideResult = true), hv_B[NOC](each unit = "J/mol") annotation(each HideResult = true), hl_B[NOC](each unit = "J/mol") annotation(each HideResult = true), hl_C[NOC](each unit = "J/mol") annotation(each HideResult = true);
Real P[N_Trays](each unit = "Pa"), Ks[N_Trays] annotation(each HideResult = true);
Real F[N_Trays](each start = 0) annotation(each HideResult = true), z[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)) annotation(each HideResult = true);
DistillationPackage.port port1 annotation(Placement(visible = true, transformation(origin = {-82, 2}, extent = {{-18, -18}, {18, 18}}, rotation = 0), iconTransformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial equation
/*sizing*/
if Override_Sizing_Calculations == false then
Kv * 0.3048 * ((den[1, :] * x[1, :] - P[1] / (R * T[1] * 1000)) * (P[1] / (R * T[1] * 1000))) ^ 0.5 * 1000* A_active = max(V);
d_weir = (A_active * 4 / 3.14) ^ 0.5;
else
A_active = Active_area;
d_weir = Weir_diameter;
end if;
for i in 1:N_Trays loop
der(M[i]) = 0;
der(T[i]) = 0;
end for;
equation
// port1.pressure = P[N_Feed]; "should be automatic"
for i in 1:N_Trays loop
if i == N_Feed then
F[i] = port1.moleflow;
else
F[i] = 0;
end if;
Tf[i] = port1.temperature;
z[i, 1] = port1.molefrac[3];
z[i, 2] = port1.molefrac[1];
end for;
//functions required
for i in 1:NOC loop
for j in 1:N_Trays loop
Psat[j, i] = Functions.Psat(comp[i].VP, T[j]);
hv[j, i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hl[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hf[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, Tf[j]);
den[j, i] = Functions.Density(comp[i].LiqDen, comp[i].Tc, T[j], P[j]);
end for;
hv_B[i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_B[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_C[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TC);
PsatC[i] = Functions.Psat(comp[i].VP, TC);
PsatB[i] = Functions.Psat(comp[i].VP, TB);
end for;
for i in 1:N_Trays loop
Ks[i] = (V[i] * R * T[i] / (A_active * P[i] )) * (P[i] / (R * T[i] * ((1000*sum(x[i, :] .* den[i, :])) - P[i] / (R * T[i]))))^0.5;
end for;
//tray mass balance
xr[:] = x[1, :];
yNT[:] = xr[:];
L[1] - VNT - B = 0;
for i in 1:N_Trays loop
M[i] = A_active * sum(x[i, :] .* den[i, :])*1000 * (exp(pi1 * Ks[i] ^ pi2) * h_weir + 44300 * 10 ^ (-3) * (L[i] / (sum(x[i, :] .* den[i, :]) * 1000 * d_weir * 1000)) ^ 0.704);
end for;
der(x[1, :] * M[1]) = VNT .* yNT[:] + L[2] .* x[2, :] - V[1] .* y[1, :] - L[1] .* x[1, :] + F[1] .* z[1, :];
for i in 2:N_Trays - 1 loop
der(x[i, :] * M[i]) = V[i - 1] .* y[i - 1, :] + L[i + 1] .* x[i + 1, :] - V[i] .* y[i, :] - L[i] .* x[i, :] + F[i] .* z[i, :];
end for;
der(x[N_Trays, :] * M[N_Trays]) = V[N_Trays - 1] .* y[N_Trays - 1, :] + L0 .* xc[:] - V[N_Trays] .* y[N_Trays, :] - L[N_Trays] .* x[N_Trays, :] + F[N_Trays] .* z[N_Trays, :];
V[N_Trays] - L0 - D = 0;
y[N_Trays, :] = xc[:];
//energy balance
VNT * sum(yNT[:] .* hv_B[:]) - V[1] * sum(y[1, :] .* hv[1, :]) + L[2] * sum(x[2, :] .* hl[2, :]) - L[1] * sum(x[1, :] .* hl[1, :]) + F[1] * sum(z[1, :] .* hf[1, :]) = der(x[1, :] * M[1] * hl[1,:]);
for i in 2:N_Trays - 1 loop
V[i - 1] * sum(y[i - 1, :] .* hv[i - 1, :]) - V[i] * sum(y[i, :] .* hv[i, :]) + L[i + 1] * sum(x[i + 1, :] .* hl[i + 1, :]) - L[i] * sum(x[i, :] .* hl[i, :]) + F[i] * sum(z[i, :] .* hf[i, :]) = der(x[i, :] * M[i] * hl[i,:]);
end for;
V[N_Trays - 1] * sum(y[N_Trays - 1, :] .* hv[N_Trays - 1, :]) - V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) + L0 * sum(xc[:] .* hl_C[:]) - L[N_Trays] * sum(x[N_Trays, :] .* hl[N_Trays, :]) + F[N_Trays] * sum(z[N_Trays, :] .* hf[N_Trays, :]) = der(x[N_Trays, :] * M[N_Trays] * hl[N_Trays,:]);
V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) - (L0 + D) * sum(xc[:] .* hl_C[:]) = QC;
L[1] * sum(x[1, :] .* hl[1, :]) - B * sum(xr[:] .* hl_B[:]) - VNT * sum(xr[:] .* hv_B[:]) = QB;
//pressure
for i in 1:N_Trays loop
P[i] =( P_condenser + (N_Trays - i + 1) * Pressure_drop)*101325;
end for;
//Equilibrium
for i in 1:N_Trays loop
Keq[i, :] = Psat[i, :] ./ P[i];
y_eq[i, :] = Keq[i, :] .* x[i, :];
{M_eff, M_eff} = (y[i, :] - y[i - 1, :]) ./ (y_eq[i, :] - y[i - 1, :]);
sum(x[i, :]) = 1;
sum(y_eq[i, :]) = 1;
end for;
sum(y[N_Trays, :] .* PsatC[:] / (P_condenser*101325)) = 1;
sum(x[1, :] .* (P[1] + (Pressure_drop*101325)) ./ PsatB[:]) = 1;
/* port2.moleflow = D;
port2.molefrac = {xc[2], 0, xc[1], 0};
port2.temperature = TC;
port2.pressure = P_condenser * 101325;
/* port3.moleflow = B;
port3.molefrac = {xr[2], 0, xr[1], 0};
port3.temperature = TB;
port3.pressure = (P[1] + Pressure_drop) * 101325; */
//Equations for Specification
if Integer(specification1) == 1 then
QC = specification1_value;
elseif Integer(specification1) == 2 then
D = specification1_value;
elseif Integer(specification1) == 3 then
xc[1] * D = specification1_value;
//yet to modify
elseif Integer(specification1) == 4 then
xc[1] = specification1_value;
//yet to modify
elseif Integer(specification1) == 5 then
L0 = specification1_value * D;
else
TC = specification1_value;
end if;
if Integer(specification2) == 1 then
QB = specification2_value;
elseif Integer(specification2) == 2 then
B = specification2_value;
elseif Integer(specification2) == 3 then
xr[1] * D = specification2_value;
//yet to modify
elseif Integer(specification2) == 4 then
xc[1] = specification2_value;
//yet to modify
elseif Integer(specification2) == 5 then
VNT = specification2_value * B;
else
TB = specification2_value;
end if;
annotation(Icon(graphics = {Rectangle(origin = {-2, -1}, fillColor = {0, 85, 127}, fillPattern = FillPattern.VerticalCylinder, extent = {{-94, 95}, {94, -95}})}), Documentation(info = "<HTML> <p> This is a generalized model for distilation column </p> </HTML>"));
end DistillationNew;
model DistillationNewTest
DistillationPackage.DistillationNew distillation1(M_eff = 0.99,Override_Sizing_Calculations = false, Pressure_drop = 0.01, h_weir = 0.1, specification1 = DistillationPackage.Distillation.spec1.RefluxRatio, specification1_value = 2, specification2 = DistillationPackage.Distillation.spec2.ProductMolarFlow, specification2_value = 41) annotation(Placement(visible = true, transformation(origin = {-3, -9}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
MaterialStream materialStream1(Flowrate = 80, Pressure = 1e5, Tdf(start = 370), Temperature = 360, molefraction = {0.45, 0, 0.55, 0}, step_value = 2, stepchange = true, unspecified = false) annotation(Placement(visible = true, transformation(origin = {-70, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(materialStream1.port2, distillation1.port1) annotation(Line(points = {{-62, -8}, {-20, -8}, {-20, -9}}));
end DistillationNewTest;
model DistillationNewTestEuler
DistillationPackage.DistillationNew distillation1(Override_Sizing_Calculations = false, Pressure_drop = 0.01, specification1 = DistillationPackage.Distillation.spec1.RefluxRatio, specification1_value = 2, specification2 = DistillationPackage.Distillation.spec2.ProductMolarFlow, specification2_value = 41) annotation(Placement(visible = true, transformation(origin = {-3, -9}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
MaterialStream materialStream1(Flowrate = 80, Pressure = 1e5, Tdf(start = 370), Temperature = 360, molefraction = {0.45, 0, 0.55, 0}, step_value = 2, stepchange = true, unspecified = false) annotation(Placement(visible = true, transformation(origin = {-70, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(materialStream1.port2, distillation1.port1) annotation(Line(points = {{-62, -8}, {-20, -8}, {-20, -9}}));
end DistillationNewTestEuler;
model DistillationNewRK
extends DistillationPackage.Distillationwithsizingtest;
end DistillationNewRK;
model Distillation1
parameter Chemsep_Database.Benzene comp1;
parameter Chemsep_Database.Toluene comp2;
parameter Chemsep_Database.General_Properties comp[2] = {comp1, comp2};
parameter Integer N_Trays = 20, NOC = 2, N_Feed = 10;
parameter Real M_eff[N_Trays, NOC] = fill(0.99, N_Trays, NOC);
parameter Real Pressure_drop = 2432, P_condenser = 101350, R = 8.314;
parameter Real A_active = 1, h_weir = 0.01, d_weir = 0.8, taul = 0.062, Tray_volume = 0.1;
parameter Real pi1 = -12.55, pi2 = 0.91;
Real y[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)), x[N_Trays, NOC](start = fill(0.5, N_Trays, NOC)), y_eq[N_Trays, NOC], Tf[N_Trays];
Real V[N_Trays](each start = 70), L[N_Trays](each start = 100);
Real T[N_Trays](start = linspace(381, 369, N_Trays)), TC(start = 368), TB(start = 377), L0(start = 50), VNT, D, B, xc[NOC], xr[NOC], QC, QB;
Real Keq[N_Trays, NOC], Psat[N_Trays, NOC], PsatC[NOC], PsatB[NOC];
Real yNT[NOC], M[N_Trays](each start = 1), den[N_Trays, NOC];
Real hv[N_Trays, NOC], hl[N_Trays, NOC], hf[N_Trays, NOC], hv_B[NOC], hl_B[NOC], hl_C[NOC];
Real P[N_Trays], Ks[N_Trays];
Real dx[N_Trays, NOC], dM[N_Trays], dhl[N_Trays, NOC];
Real F[N_Trays](each start = 0), z[N_Trays, NOC](start = fill(0.5, N_Trays, NOC));
port port1 annotation(Placement(visible = true, transformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-88, 2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
port port2 annotation(Placement(visible = true, transformation(origin = {92, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {92, 80}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
port port3 annotation(Placement(visible = true, transformation(origin = {94, -74}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {94, -74}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
initial equation
for i in 1:N_Trays loop
//M[i] = M0[i];
der(M[i]) = 0;
//der(x[i,1]) = 0;
//dM[i] = 0;
dhl[i, 1] = 0;
//dx[i,1] = 0;
end for;
equation
port1.pressure = P[N_Feed];
for i in 1:N_Trays loop
if i == N_Feed then
F[i] = port1.moleflow;
else
F[i] = 0;
end if;
Tf[i] = port1.temperature;
z[i, 1] = port1.molefrac[3];
z[i, 2] = port1.molefrac[1];
end for;
//functions required
for i in 1:NOC loop
for j in 1:N_Trays loop
Psat[j, i] = Functions.Psat(comp[i].VP, T[j]);
hv[j, i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hl[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, T[j]);
hf[j, i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, Tf[j]);
den[j, i] = Functions.Density(comp[i].LiqDen, comp[i].Tc, T[j], P[j]);
end for;
hv_B[i] = Functions.HVapId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_B[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TB);
hl_C[i] = Functions.HLiqId(comp[i].VapCp, comp[i].HOV, comp[i].Tc, TC);
PsatC[i] = Functions.Psat(comp[i].VP, TC);
PsatB[i] = Functions.Psat(comp[i].VP, TB);
end for;
for i in 1:N_Trays loop
Ks[i] = V[i] * R * T[i] / (A_active * P[i] * 10 ^ (-3)) * (P[i] * 10 ^ (-3) / (R * T[i] * (sum(x[i, :] .* den[i, :]) - P[i] * 10 ^ (-3) / (R * T[i]))));
end for;
//defining state variables!
for i in 1:N_Trays loop
dx[i, :] = der(x[i, :]);
dM[i] = der(M[i]);
dhl[i, :] = der(hl[i, :]);
end for;
//tray mass balance
xr[:] = x[1, :];
yNT[:] = xr[:];
L[1] - VNT - B = 0;
//when time>0 then
for i in 1:N_Trays loop
M[i] = A_active * sum(x[i, :] .* den[i, :]) * (exp(pi1 * Ks[i] ^ pi2) * h_weir + 44300 * 10 ^ (-3) * (L[i] / (sum(x[i, :] .* den[i, :]) * d_weir * 1000 * 3600)) ^ 0.704);
end for;
//end when;
M[1] * dx[1, :] + x[1, :] * dM[1] = VNT .* yNT[:] + L[2] .* x[2, :] - V[1] .* y[1, :] - L[1] .* x[1, :] + F[1] .* z[1, :];
//M0[1] = Tray_volume * sum(x[1,:].*den[1,:]);
//L[1] = L0 + (M[1]-M0[1])/taul;
//M[1] = A_active * sum(x[1,:].*den[1,:])*(exp(pi1*Ks[1]^pi2)*h_weir + 44300*(L[1]/(sum(x[1,:].*den[1,:]) * 0.5* d_weir))^0.704);
for i in 2:N_Trays - 1 loop
dM[i] * x[i, :] + dx[i, :] * M[i] = V[i - 1] .* y[i - 1, :] + L[i + 1] .* x[i + 1, :] - V[i] .* y[i, :] - L[i] .* x[i, :] + F[i] .* z[i, :];
//L[i] = L0 + (M[i]-M0[i])/taul;
//M0[i] = Tray_volume * sum(x[i,:].*den[i,:]);
end for;
M[N_Trays] * dx[N_Trays, :] + x[N_Trays, :] * dM[N_Trays] = V[N_Trays - 1] .* y[N_Trays - 1, :] + L0 .* xc[:] - V[N_Trays] .* y[N_Trays, :] - L[N_Trays] .* x[N_Trays, :] + F[N_Trays] .* z[N_Trays, :];
//M0[N_Trays] = Tray_volume * sum(x[N_Trays,:].*den[N_Trays,:]);
//L[N_Trays] = L0 + (M[N_Trays]-M0[N_Trays])/taul;
//M[N_Trays] = A_active * sum(x[N_Trays,:].*den[N_Trays,:])*(exp(pi1*Ks[N_Trays]^pi2)*h_weir + 44300*(L[N_Trays]/(sum(x[N_Trays,:].*den[N_Trays,:]) * 0.5* d_weir))^0.704);
V[N_Trays] - L0 - D = 0;
y[N_Trays, :] = xc[:];
//energy balance
VNT * sum(yNT[:] .* hv_B[:]) - V[1] * sum(y[1, :] .* hv[1, :]) + L[2] * sum(x[2, :] .* hl[2, :]) - L[1] * sum(x[1, :] .* hl[1, :]) + F[1] * sum(z[1, :] .* hf[1, :]) = M[1] * x[1, :] * dhl[1, :] + M[1] * dx[1, :] * hl[1, :] + dM[1] * x[1, :] * hl[1, :];
for i in 2:N_Trays - 1 loop
V[i - 1] * sum(y[i - 1, :] .* hv[i - 1, :]) - V[i] * sum(y[i, :] .* hv[i, :]) + L[i + 1] * sum(x[i + 1, :] .* hl[i + 1, :]) - L[i] * sum(x[i, :] .* hl[i, :]) + F[i] * sum(z[i, :] .* hf[i, :]) = M[i] * x[i, :] * dhl[i, :] + M[i] * dx[i, :] * hl[i, :] + dM[i] * x[i, :] * hl[i, :];
end for;
V[N_Trays - 1] * sum(y[N_Trays - 1, :] .* hv[N_Trays - 1, :]) - V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) + L0 * sum(xc[:] .* hl_C[:]) - L[N_Trays] * sum(x[N_Trays, :] .* hl[N_Trays, :]) + F[N_Trays] * sum(z[N_Trays, :] .* hf[N_Trays, :]) = dM[N_Trays] * x[N_Trays, :] * hl[N_Trays, :] + M[N_Trays] * dx[N_Trays, :] * hl[N_Trays, :] + M[N_Trays] * x[N_Trays, :] * dhl[N_Trays, :];
V[N_Trays] * sum(y[N_Trays, :] .* hv[N_Trays, :]) - (L0 + D) * sum(xc[:] .* hl_C[:]) = QC;
L[1] * sum(x[1, :] .* hl[1, :]) - B * sum(xr[:] .* hl_B[:]) - VNT * sum(xr[:] .* hv_B[:]) = QB;
//pressure
for i in 1:N_Trays loop
P[i] = P_condenser + (N_Trays - i + 1) * Pressure_drop;
end for;
//Equilibrium
for i in 1:N_Trays loop
Keq[i, :] = Psat[i, :] ./ P[i];
y_eq[i, :] = Keq[i, :] .* x[i, :];
M_eff[i, :] = (y[i, :] - y[i - 1, :]) ./ (y_eq[i, :] - y[i - 1, :]);
sum(x[i, :]) = 1;
sum(y_eq[i, :]) = 1;
end for;
sum(y[N_Trays, :] .* PsatC[:] / P_condenser) = 1;
//sum(xc[:]) =1
sum(x[1, :] .* (P[1] + Pressure_drop) ./ PsatB[:]) = 1;
//sum(yNT[:]) =1;
D = 0.5 * L0;
B = 61.1;