-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChemical.mo
More file actions
1828 lines (1768 loc) · 121 KB
/
Chemical.mo
File metadata and controls
1828 lines (1768 loc) · 121 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 Chemical
block System
parameter Integer set_n(start = 1) "Number of Compnents in Stream/System";
constant Real pi = 3.14159265359;
parameter Boolean use_fps = false "Give true if fps system is used";
Real g = if use_fps then 32.174 else 9.81 "Acceleration due to gravity";
parameter Boolean use_EnergyBal = false "Give true if Energy Balance calculations are to performed" annotation(Dialog(tab = "Energy Balance", group = "Assumptions"));
parameter Boolean OpenSys = false "Give true if it is an open system and mass flows across the system boundary" annotation(Dialog(tab = "Energy Balance", group = "Assumptions"));
parameter Boolean use_T = false "Give true if Temperature is used in calculations" annotation(Dialog(tab = "Energy Balance", group = "Assumptions"));
parameter Boolean known_en = false "Give true if heat capacity of any component is known" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Boolean[set_n] known_Cv = {false} "Give true if heat capacity at constant volume is known" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n, 4] Cv_coeff_gas = zeros(set_n, 4) "Enter coefficients of gas phase heat capacity of components at constant volume of the form A+B*T+C*T^2+D*T^3 as {A,B,C,D}" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n, 4] Cv_coeff_liq = zeros(set_n, 4) "Enter coefficients of liquid phase heat capacity of components at constant volume of the form A+B*T+C*T^2+D*T^3 as {A,B,C,D}" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n] Cv_coeff_aq = {0} "Enter coefficients of aqueous phase heat capacity of components at constant volume, for water give zero" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Boolean[set_n] known_Cp = {false} "Give true if heat capacity at constant pressure is known" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n, 4] Cp_coeff_gas = zeros(set_n, 4) "Enter coefficients of gas phase heat capacity of components at constant pressure of the form A+B*T+C*T^2+D*T^3 as {A,B,C,D}" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n, 4] Cp_coeff_liq = zeros(set_n, 4) "Enter coefficients of liquid phase heat capacity of components at constant pressure of the form A+B*T+C*T^2+D*T^3 as {A,B,C,D}" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n] Cp_coeff_aq = {0} "Enter coefficients of aqueous phase heat capacity of components at constant pressure, for water give zero" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n, 4] delHvap = zeros(set_n, 4) "Enter coefficients for heat of vaporization of components of the form C1*(1-Tr)^(C2+C3*Tr+C4*Tr^2)" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n, 3] A = zeros(set_n, 3) "Enter Antoine Coefficients [log(p*) = A-B/(T(degC)+C)] as {{A1,B1,C1},{A2,B2,C2}}" annotation(Dialog(tab = "PPDB", group = "T Dependent"));
parameter Real[set_n] MW "Enter Molecular weight of all the components" annotation(Dialog(tab = "PPDB", group = "Constant"));
parameter Real[set_n, 1] pc "Enter Critical Pressure of all the components" annotation(Dialog(tab = "PPDB", group = "Constant"));
parameter Real[set_n, 1] Tc "Enter Critical Temperature of all the components" annotation(Dialog(tab = "PPDB", group = "Constant"));
parameter Real[set_n, 1] w "Enter Acentric Factor of all the components" annotation(Dialog(tab = "PPDB", group = "Constant"));
parameter Real[set_n, set_n] kij "Enter Binary Interaction Parameters for all the component pairs, (3,4)th element is interaction between 3rd and 4th compound" annotation(Dialog(tab = "PPDB", group = "Constant"));
annotation(defaultComponentName = "system", defaultComponentPrefixes = "inner", Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(lineColor = {0, 0, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(lineColor = {0, 0, 255}, extent = {{-150, 150}, {150, 110}}, textString = "%name"), Line(points = {{-86, -30}, {82, -30}}), Line(points = {{-82, -68}, {-52, -30}}), Line(points = {{-48, -68}, {-18, -30}}), Line(points = {{-14, -68}, {16, -30}}), Line(points = {{22, -68}, {52, -30}}), Line(points = {{74, 84}, {74, 14}}), Polygon(fillPattern = FillPattern.Solid, points = {{60, 14}, {88, 14}, {74, -18}, {60, 14}}), Text(extent = {{16, 20}, {60, -18}}, textString = "n"), Text(extent = {{-90, 82}, {74, 50}}, textString = "defaults"), Line(points = {{-82, 14}, {-42, -20}, {2, 30}}, thickness = 0.5), Ellipse(fillColor = {255, 0, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, extent = {{-10, 40}, {12, 18}}, endAngle = 360)}));
end System;
model Interfaces
extends Modelica.Icons.InterfacesPackage;
connector FluidPort "Interface for quasi one-dimensional fluid flow in a piping network (incompressible or compressible, one or more phases, one or more substances)"
parameter Integer n(start = 1);
parameter Boolean EnergyBal(start = false);
parameter Boolean OpenSys(start = false);
parameter Boolean use_T(start = false);
output Real[n] n_flow;
output Real Ek if EnergyBal "Kinetic Energy of Stream";
output Real Ep if EnergyBal "Potential Energy of Stream";
output Real[n] U if EnergyBal "Specific Internal Energy of Stream";
output Real[n] H if EnergyBal and OpenSys "Enthalpy of Stream";
output Real P(start = 101325) if EnergyBal and OpenSys "Pressure Head of Stream";
output Real T(start = 298) if use_T;
end FluidPort;
connector Columnport "Fluid connector with filled, large icon to be used for vectors of FluidPorts (vector dimensions must be added after dragging)"
extends FluidPort;
annotation(defaultComponentName = "ports_a", Icon(coordinateSystem(extent = {{-30, -200}, {30, 200}}, preserveAspectRatio = false, initialScale = 0.2, grid = {2, 2}), graphics = {Rectangle(lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, pattern = LinePattern.None, extent = {{50, -200}, {-50, 200}}), Ellipse(origin = {0, 20}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid, extent = {{-30, 180}, {30, 120}}, endAngle = 360), Ellipse(origin = {0, -20}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid, extent = {{-30, -120}, {30, -180}}, endAngle = 360)}), Diagram(coordinateSystem(extent = {{-50, -200}, {50, 200}}, preserveAspectRatio = false, initialScale = 0.2, grid = {2, 2}), graphics = {Text(origin = {0, 72}, extent = {{-75, 130}, {75, 100}}, textString = "%name"), Rectangle(lineColor = {0, 127, 255}, pattern = LinePattern.None, extent = {{25, -100}, {-25, 100}}), Ellipse(origin = {0, 78}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid, extent = {{-25, 90}, {25, 40}}, endAngle = 360), Ellipse(origin = {0, -92}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid, extent = {{-25, -40}, {25, -90}}, endAngle = 360)}));
end Columnport;
partial connector HeatPort "Thermal port for 1-dim. heat transfer"
flow Real Q_flow "Heat flow rate (positive if flowing from outside into the component)";
end HeatPort;
connector HeatPort_In "Thermal port for 1-dim. heat transfer (filled rectangular icon)"
extends HeatPort;
annotation(defaultComponentName = "QIn", Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {191, 0, 0}, fillColor = {191, 0, 0}, fillPattern = FillPattern.Solid)}), Diagram(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Rectangle(extent = {{-50, 50}, {50, -50}}, lineColor = {191, 0, 0}, fillColor = {191, 0, 0}, fillPattern = FillPattern.Solid), Text(extent = {{-120, 120}, {100, 60}}, lineColor = {191, 0, 0}, textString = "%name")}));
end HeatPort_In;
connector HeatPort_Out "Thermal port for 1-dim. heat transfer (unfilled rectangular icon)"
extends HeatPort;
annotation(defaultComponentName = "QOut", Diagram(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Rectangle(extent = {{-50, 50}, {50, -50}}, lineColor = {191, 0, 0}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Text(extent = {{-100, 120}, {120, 60}}, lineColor = {191, 0, 0}, textString = "%name")}), Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {191, 0, 0}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid)}));
end HeatPort_Out;
connector Mports_In
extends FluidPort;
annotation(defaultComponentName = "MportsIn", Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-50, -200}, {50, 200}}, initialScale = 0.2), graphics = {Text(extent = {{-75, 130}, {75, 100}}, textString = "%name"), Rectangle(extent = {{-25, 100}, {25, -100}}, lineColor = {0, 0, 0}), Ellipse(extent = {{-25, 90}, {25, 40}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-25, 25}, {25, -25}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-25, -40}, {25, -90}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-15, -50}, {15, -80}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-15, 15}, {15, -15}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-15, 50}, {15, 80}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid)}), Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-50, -200}, {50, 200}}, initialScale = 0.2), graphics = {Rectangle(extent = {{-50, 200}, {50, -200}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-50, 180}, {50, 80}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-50, 50}, {50, -50}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-50, -80}, {50, -180}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-30, 30}, {30, -30}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-30, 100}, {30, 160}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-30, -100}, {30, -160}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid)}));
end Mports_In;
connector port_Out "Generic fluid connector"
extends FluidPort;
annotation(defaultComponentName = "portOut", Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Ellipse(extent = {{-40, 40}, {40, -40}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Text(extent = {{-150, 110}, {150, 50}}, textString = "%name")}), Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Ellipse(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 127, 255}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid)}));
end port_Out;
connector Mports_Out "Fluid connector with filled, large icon to be used for vectors of FluidPorts (vector dimensions must be added after dragging)"
extends FluidPort;
annotation(defaultComponentName = "MportsOut", Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-50, -200}, {50, 200}}, initialScale = 0.2), graphics = {Text(extent = {{-75, 130}, {75, 100}}, textString = "%name"), Rectangle(extent = {{25, -100}, {-25, 100}}, lineColor = {0, 127, 255}), Ellipse(extent = {{-25, 90}, {25, 40}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-25, 25}, {25, -25}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-25, -40}, {25, -90}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid)}), Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-50, -200}, {50, 200}}, initialScale = 0.2), graphics = {Rectangle(extent = {{50, -200}, {-50, 200}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-50, 180}, {50, 80}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-50, 50}, {50, -50}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-50, -80}, {50, -180}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid)}));
end Mports_Out;
connector port_In
extends FluidPort;
annotation(defaultComponentName = "portIn", Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Ellipse(extent = {{-40, 40}, {40, -40}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-30, 30}, {30, -30}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid), Text(extent = {{-150, 110}, {150, 50}}, textString = "%name")}), Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Ellipse(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 127, 255}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {0, 127, 255}, fillPattern = FillPattern.Solid), Ellipse(extent = {{-80, 80}, {80, -80}}, lineColor = {0, 127, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid)}));
end port_In;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end Interfaces;
package Specify
import Chemical.Utilities;
extends Modelica.Icons.SourcesPackage;
block point
extends Baseclass;
parameter Boolean known_u = false "Give true if you know the Velocity of Stream" annotation(Dialog(tab = "Energy Transfer", group = "Mechanical Energy"));
parameter Real u = 0 "Enter Velocity of stream, if known" annotation(Dialog(tab = "Energy Transfer", group = "Mechanical Energy"));
parameter Real z = 0 "Enter vertical postion of stream/state from reference level" annotation(Dialog(tab = "Energy Transfer", group = "Mechanical Energy"));
parameter Boolean known_P = true "Give true if Pressure of stream is known" annotation(Dialog(tab = "State"));
parameter Boolean known_T = true "Give true if Temperature of stream is known" annotation(Dialog(tab = "State"));
parameter Real P = 101325 "Enter Pressure of stream/state, if known, else 1" annotation(Dialog(tab = "State"));
parameter Real V = 0 "Enter Specific Volume of stream/state, if known, else 0" annotation(Dialog(tab = "State"));
parameter Real T = 25 "Enter Temperature in appropriate dimension" annotation(Dialog(tab = "State"));
parameter Real Tref = 0 "Enter Reference Temperature in appropriate dimension" annotation(Dialog(tab = "State"));
parameter Boolean Gas = true "Give true if the stream is in gas phase, false if it is in liquid phase" annotation(Dialog(tab = "State"));
parameter Boolean Aqueous = false "Give true if the stream is in Aqueous phase" annotation(Dialog(tab = "State"));
parameter Boolean[system.set_n] known_U "Give true if specific Internal Energy of stream is known" annotation(Dialog(tab = "Energy Transfer", group = "Internal Energy"));
parameter Real[system.set_n] U "Enter specific internal energy of stream/state, if known, else 0" annotation(Dialog(tab = "Energy Transfer", group = "Internal Energy"));
parameter Boolean[system.set_n] known_H "Give true if specific Enthalpy of component(s) is/are known for eg.{true,false}" annotation(Dialog(tab = "Energy Transfer", group = "Enthalpy"));
parameter Real[system.set_n] H "Enter specific enthalpy of stream/state, if known, else 0" annotation(Dialog(tab = "Energy Transfer", group = "Enthalpy"));
parameter Real[system.set_n, 1] lambda = zeros(system.set_n, 1) "Enter enthalpy change(s) for component(s) due to phase change from reference state(s), else zero for eg. {{lambda1, lambda2, 0}}" annotation(Dialog(tab = "Energy Transfer", group = "Enthalpy"));
Real v if system.use_EnergyBal;
Real[system.set_n, 4] U1 if system.use_EnergyBal;
Real[system.set_n, 4] H1 if system.use_EnergyBal and system.OpenSys;
Real[system.set_n, 4] Cv if system.use_EnergyBal;
Real[system.set_n, 4] Cp if system.use_EnergyBal and system.OpenSys;
equation
if system.use_EnergyBal then
if known_n then
if known_VF then
sum(port.n_flow) = n_flow * rho;
else
sum(port.n_flow) = n_flow;
end if;
end if;
if known_u then
v = u;
end if;
port.Ek = 0.5 * sum(port.n_flow) * v ^ 2;
port.Ep = sum(port.n_flow) * system.g * z;
for i in 1:system.set_n loop
if known_U[i] then
port.U[i] = U[i];
Cv[i, :] = {0, 0, 0, 0};
U1[i, :] = {0, 0, 0, 0};
if system.known_en then
U1[i, :] = {0, 0, 0, 0};
end if;
elseif system.known_Cv[i] then
if Gas then
Cv[i, :] = system.Cv_coeff_gas[i, :];
elseif Aqueous then
Cv[i, :] = {system.Cv_coeff_aq[i], 0, 0, 0};
else
Cv[i, :] = system.Cv_coeff_liq[i, :];
end if;
U1[i, 1] = Cv[i, 1] * (port.T - Tref);
for j in 2:4 loop
U1[i, j] = U1[i, j - 1] + Cv[i, j] / j * (port.T ^ j - Tref ^ j);
end for;
port.U[i] = U1[i, 4];
else
U1[i, :] = {0, 0, 0, 0};
Cv[i, :] = {0, 0, 0, 0};
end if;
end for;
if system.use_T then
if known_T then
port.T = T;
end if;
end if;
if known_P then
port.P = P;
end if;
if system.OpenSys then
for i in 1:system.set_n loop
if known_H[i] then
port.H[i] = H[i] + lambda[i, 1];
H1[i, :] = {0, 0, 0, 0};
Cp[i, :] = {0, 0, 0, 0};
elseif system.known_Cp[i] then
if Gas then
Cp[i, :] = system.Cp_coeff_gas[i, :];
elseif Aqueous then
Cp[i, :] = {system.Cp_coeff_aq[i], 0, 0, 0};
else
Cp[i, :] = system.Cp_coeff_liq[i, :];
end if;
H1[i, 1] = Cp[i, 1] * (port.T - Tref);
for j in 2:4 loop
H1[i, j] = H1[i, j - 1] + Cp[i, j] / j * (port.T ^ j - Tref ^ j);
end for;
port.H[i] = H1[i, 4] + lambda[i, 1];
else
H1[i, :] = {0, 0, 0, 0};
Cp[i, :] = {0, 0, 0, 0};
end if;
end for;
for i in 1:system.set_n loop
port.H[i] = port.U[i] + port.P * V;
end for;
end if;
end if;
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Text(origin = {0, 85}, extent = {{-100, 150}, {100, 20}}, textString = "%name"), Rectangle(origin = {0, 0}, extent = {{-50, 50}, {50, -50}})}));
end point;
block Dry_Basis
extends point;
Real[system.set_n - 1] X_dry "Mole fraction on Dry basis";
Real H2O_drystack "Mole ratio of H2O to dry stack gas";
equation
for i in 1:system.set_n - 1 loop
X_dry[i] = port.n_flow[i] / sum(port.n_flow[1:system.set_n - 1]);
end for;
H2O_drystack = port.n_flow[system.set_n] / sum(port.n_flow[1:system.set_n - 1]);
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(origin = {0, 0.23}, fillColor = {195, 192, 177}, fillPattern = FillPattern.Solid, extent = {{-50.12, 49.88}, {50.12, -50.35}})}));
end Dry_Basis;
block gas_ideal
extends point;
parameter Real R "Enter Gas Constant in appropriate dimensions" annotation(Dialog(tab = "State", group = "Constants"));
equation
Port.P * V = sum(port.n_flow) * R * (port.T + 273);
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Text(origin = {0, 85}, extent = {{-100, 150}, {100, 20}}, textString = "%name"), Rectangle(origin = {7.72665, -18.0332}, fillColor = {88, 219, 221}, fillPattern = FillPattern.Solid, extent = {{-57.848, 68.1456}, {42.3913, -32.08}})}));
end gas_ideal;
block gas_virial
extends point;
parameter Real R "Enter Gas Constants in appropriate dimensions" annotation(Dialog(tab = "State", group = "Constants"));
parameter Real Tc "Enter Critical Temperature in appropriate dimension" annotation(Dialog(tab = "State"));
parameter Real Pc "Enter Critical Pressure in appropriate dimension" annotation(Dialog(tab = "State"));
parameter Real PAf "Enter appropriate Pitzer Accentric Factor" annotation(Dialog(tab = "State"));
Real Tr, Pr "Reduced Temperature and Pressure";
Real B0, B1, B "Virial Coefficient";
Real V1 "Molar Volume";
equation
Tr = T / Tc;
Pr = Pressure / Pc;
B0 = 0.083 - 0.422 / Tr ^ 1.6;
B1 = 0.139 - 0.172 / Tr ^ 4.2;
B = R * Tc / Pc * (B0 + PAf * B1);
V1 = V / sum(port.n_flow);
Port.P = R * T / V1 * (1 + B / V1);
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Text(origin = {0, 85}, extent = {{-100, 150}, {100, 20}}, textString = "%name"), Rectangle(origin = {7.72335, -18.03}, fillColor = {104, 170, 249}, fillPattern = FillPattern.Solid, extent = {{-57.85, 68.15000000000001}, {42.3913, -32.08}})}));
end gas_virial;
block gas_Raoults
//import Chemical.Utilities;
extends gas_ideal;
parameter Real[3] A "Enter Antoine Coefficients [log(p*) = A-B/(T(degC)+C)] as {A,B,C}" annotation(Dialog(tab = "State", group = "Constants"));
Real Tdp(start = 0) "Dew point temperature of the gas";
Real superheat(start = 0) "Degree of Superheat of the gas";
Real pstar "Vapour Pressure of Pure component at T";
Real[system.set_n] p "Partial Pressure of Component";
parameter Boolean single_condensable "Give true if only one condensable species is present" annotation(Dialog(tab = "State"));
equation
for i in 1:system.set_n loop
p[i] = port.n_flow[i] / sum(port.n_flow) * Port.P;
end for;
pstar = Utilities.Antoine_equ(A, T - 273);
if single_condensable and not known_X[1] then
port.n_flow[1] / sum(port.n_flow) = pstar / Port.P;
end if;
p[1] = Utilities.Antoine_equ(A, Tdp);
superheat = T - 273 - Tdp;
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(origin = {-0.23, 0.23}, fillColor = {127, 191, 145}, fillPattern = FillPattern.Solid, extent = {{-49.88, 49.88}, {50.35, -50.35}})}));
end gas_Raoults;
block HumidAir
extends gas_ideal;
parameter Real[3] A "Enter Antoine Coefficients [log(p*) = A-B/(T(degC)+C)] as {A,B,C}" annotation(Dialog(tab = "State", group = "Constants"));
Real Tdp "Dew point of the gas";
Real superheat "Degree of Superheat of the gas";
Real pstar "Vapour Pressure of Pure component at T";
parameter Real Hr "Percent Relative Humidity" annotation(Dialog(tab = "State"));
Real[system.set_n] p "Partial Pressure of Component";
equation
for i in 1:system.set_n loop
p[i] = port.n_flow[i] / sum(port.n_flow) * Port.P;
end for;
p[1] = Hr / 100 * pstar / 760 * 1.01325;
pstar = Antoine_equ(A, T - 273);
p[1] / 1.01325 * 760 = Antoine_equ(A, Tdp);
superheat = T - 273 - Tdp;
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(origin = {0.23, -0.228384}, fillColor = {152, 189, 209}, fillPattern = FillPattern.Solid, extent = {{-50.35, 50.35}, {49.88, -49.88}})}));
end HumidAir;
block gas_Henrys
extends gas_ideal;
parameter Real[3] A "Enter Antoine Coefficients [log(p*) = A-B/(T(degC)+C)] as {A,B,C}" annotation(Dialog(tab = "State", group = "Constants"));
Real Tdp "Dew point of the gas";
Real superheat "Degree of Superheat of the gas";
Real pstar "Vapour Pressure of Pure component at T";
Real[system.set_n] p "Partial Pressure of Component";
parameter Boolean single_condensable "Give true if only one condensable species is present" annotation(Dialog(tab = "State"));
equation
for i in 1:system.set_n loop
p[i] = port.n_flow[i] / sum(port.n_flow) * Port.P;
end for;
log10(pstar) = A[1] - A[2] / (T - 273 + A[3]);
if single_condensable and not known_X[1] then
port.n_flow[1] / sum(port.n_flow) = pstar / Port.P;
end if;
log10(p[1]) = A[1] - A[2] / (Tdp + A[3]);
superheat = T - 273 - Tdp;
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(origin = {-0.236768, 0}, fillColor = {194, 149, 166}, fillPattern = FillPattern.Solid, extent = {{-49.88, 50.12}, {50.3484, -50.12}})}));
end gas_Henrys;
model Interm
outer Chemical.System system;
parameter Boolean known_n(start = false) "Give true if you know the total flow rate" annotation(Dialog(tab = "Mass Transfer"));
parameter Boolean[system.set_n] known_X "Give true if you know the mass/mole fraction of a component, and false otherwise e.g. {true,false}" annotation(Dialog(tab = "Mass Transfer"));
parameter Boolean[system.set_n] known_comp "Give true if you know the mass/molar flow rate of a component, and false otherwise e.g. {true,false}" annotation(Dialog(tab = "Mass Transfer"));
parameter Real n_flow(start = 1) "Give the total mass/molar flow rate" annotation(Dialog(tab = "Mass Transfer"));
parameter Real[system.set_n] X "Give the mass/mole fraction of the components e.g. {0.1,0.9}" annotation(Dialog(tab = "Mass Transfer"));
parameter Real[system.set_n] comp_flow "Give the mass/molar flow rate of the components e.g. {0.1,0.9}" annotation(Dialog(tab = "Mass Transfer"));
Chemical.Interfaces.port In(n = system.set_n) if not system.use_EnergyBal annotation(Placement(visible = true, transformation(origin = {-140, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-45, -45}, {45, 45}}, rotation = 0)));
Chemical.Interfaces.port Out(n = system.set_n) if not system.use_EnergyBal annotation(Placement(visible = true, transformation(origin = {120, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, -3.55271e-015}, extent = {{-45, -45}, {45, 45}}, rotation = 0)));
equation
if known_n then
sum(Out.n_flow) = n_flow;
end if;
for i in 1:system.set_n loop
if known_X[i] then
Out.n_flow[i] / sum(Out.n_flow) = X[i];
elseif known_comp[i] then
Out.n_flow[i] = comp_flow[i];
end if;
end for;
Out.n_flow = In.n_flow;
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(fillColor = {81, 133, 254}, fillPattern = FillPattern.HorizontalCylinder, extent = {{-100, 45}, {100, -45}}), Text(origin = {29.0398, -13.5831}, lineColor = {255, 255, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-88.76000000000001, 22.72}, {28.8068, 3.97789}}, textString = "Intermediate")}));
end Interm;
block pipe
extends point;
parameter Real ID "Enter Internal Diameter of Pipe (in m/ft), if present, else 1" annotation(Dialog(group = "Dimension"));
Real Area;
Real V_flow;
equation
Area = system.pi * (ID / 2) ^ 2;
V_flow = v * Area;
if not known_u then
V_flow = sum(port.n_flow) / rho;
end if;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end pipe;
block Baseclass
parameter Boolean known_n = false "Give true if you know the total flow rate" annotation(Dialog(tab = "Mass Transfer"));
parameter Boolean[system.set_n] known_X "Give true if you know the mass/mole fraction of a component, and false otherwise e.g. {true,false}" annotation(Dialog(tab = "Mass Transfer"));
parameter Boolean[system.set_n] known_comp "Give true if you know the mass/molar flow rate of a component, and false otherwise e.g. {true,false}" annotation(Dialog(tab = "Mass Transfer"));
parameter Real n_flow(start = 1) "Give the total mass/molar flow rate" annotation(Dialog(tab = "Mass Transfer"));
parameter Real[system.set_n] X "Give the mass/mole fraction of the components e.g. {0.1,0.9}" annotation(Dialog(tab = "Mass Transfer"));
parameter Real[system.set_n] comp_flow "Give the mass/molar flow rate of the components e.g. {0.1,0.9}" annotation(Dialog(tab = "Mass Transfer"));
parameter Boolean known_VF = false "Give true if n_flow is expressed as Volumetric flow rate of stream" annotation(Dialog(tab = "Mass Transfer"));
parameter Real rho = 1 "Enter density of fluid, if known, else 1" annotation(Dialog(tab = "Mass Transfer"));
outer Chemical.System system;
Chemical.Interfaces.port_Out port(n = system.set_n, EnergyBal = system.use_EnergyBal, OpenSys = system.OpenSys, use_T = system.use_T) annotation(Placement(visible = true, transformation(origin = {40, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {0, 0}, extent = {{-35, -35}, {35, 35}}, rotation = 0)));
equation
if known_n and not system.use_EnergyBal then
sum(port.n_flow) = n_flow;
end if;
for i in 1:system.set_n loop
if known_X[i] then
port.n_flow[i] / sum(port.n_flow) = X[i];
elseif known_comp[i] then
port.n_flow[i] = comp_flow[i];
end if;
end for;
end Baseclass;
block Soln
extends Baseclass;
parameter Boolean known_u = false "Give true if you know the Velocity of Stream" annotation(Dialog(tab = "Energy Transfer", group = "Mechanical Energy"));
parameter Real u = 0 "Enter Velocity of stream, if known" annotation(Dialog(tab = "Energy Transfer", group = "Mechanical Energy"));
parameter Real z = 0 "Enter vertical postion of stream/state from reference level" annotation(Dialog(tab = "Energy Transfer", group = "Mechanical Energy"));
parameter Boolean known_P = true "Give true if Pressure of stream is known" annotation(Dialog(tab = "State"));
parameter Boolean known_T = true "Give true if Temperature of stream is known" annotation(Dialog(tab = "State"));
parameter Real P = 101325 "Enter Pressure of stream/state, if known, else 1" annotation(Dialog(tab = "State"));
parameter Real V = 0 "Enter Specific Volume of stream/state, if known, else 0" annotation(Dialog(tab = "State"));
parameter Real T = 25 "Enter Temperature in appropriate dimension" annotation(Dialog(tab = "State"));
parameter Real Tref = 25 "Enter Reference Temperature in appropriate dimension" annotation(Dialog(tab = "State"));
parameter Boolean[system.set_n] known_U "Give true if specific Internal Energy of stream is known" annotation(Dialog(tab = "Energy Transfer", group = "Internal Energy"));
parameter Real[system.set_n] U "Enter specific internal energy of stream/state, if known, else 0" annotation(Dialog(tab = "Energy Transfer", group = "Internal Energy"));
parameter Boolean[system.set_n] known_H "Give true if specific Enthalpy of component(s) is/are known for eg.{true,false}" annotation(Dialog(tab = "Energy Transfer", group = "Enthalpy"));
parameter Real[system.set_n] H "Enter specific enthalpy of stream/state, if known, else 0" annotation(Dialog(tab = "Energy Transfer", group = "Enthalpy"));
parameter Boolean[system.set_n] PhaseChange "Give true if there is phase change after an operation" annotation(Dialog(tab = "Energy Transfer", group = "Enthalpy"));
parameter Real[system.set_n] delH "Enter specific enthalpy of solution of components" annotation(Dialog(tab = "Energy Transfer", group = "Enthalpy"));
Real v if system.use_EnergyBal;
Real Pressure if system.use_EnergyBal;
Real[system.set_n, 4] U1 if system.use_EnergyBal and system.known_en;
Real[system.set_n, 4] H1 if system.use_EnergyBal and system.OpenSys and system.known_en;
Real[system.set_n] HSol if system.use_EnergyBal and system.OpenSys;
equation
if system.use_EnergyBal then
if known_n then
if known_VF then
sum(port.n_flow) = n_flow * rho;
else
sum(port.n_flow) = n_flow;
end if;
end if;
if known_u then
v = u;
end if;
port.Ek = 0.5 * sum(port.n_flow) * v ^ 2;
port.Ep = sum(port.n_flow) * system.g * z;
for i in 1:system.set_n loop
if known_U[i] then
port.U[i] = U[i];
U1[i, :] = {0, 0, 0, 0};
elseif known_Cv[i] then
U1[i, 1] = Cv_aq[i, 1] * (port.T - Tref);
for j in 2:4 loop
U1[i, j] = U1[i, j - 1] + Cv_aq[i, j] / j * (port.T ^ j - Tref ^ j);
end for;
port.U[i] = U1[i, 4];
else
U1[i, :] = {0, 0, 0, 0};
end if;
end for;
if system.use_T then
if known_T then
port.T = T;
end if;
end if;
if known_P then
Pressure = P;
end if;
if system.OpenSys then
for i in 1:system.set_n loop
if known_H[i] then
port.H[i] = H[i];
H1[i, :] = {0, 0, 0, 0};
elseif known_Cp[i] then
H1[i, 1] = Cp_aq[i, 1] * (port.T - Tref);
for j in 2:4 loop
H1[i, j] = H1[i, j - 1] + Cp_aq[i, j] / j * (port.T ^ j - Tref ^ j);
end for;
if known_HSol[i] then
HSol[i] = delHSol[i];
end if;
port.H[i] = H1[i, 4] + delHSol[i];
else
H1[i, :] = {0, 0, 0, 0};
end if;
end for;
for i in 1:system.set_n loop
port.H[i] = port.U[i] + Pressure * V;
end for;
port.P = Pressure;
end if;
end if;
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Text(origin = {0, 85}, extent = {{-100, 150}, {100, 20}}, textString = "%name"), Rectangle(origin = {0, 0}, extent = {{-50, 50}, {50, -50}})}));
end Soln;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end Specify;
package Material_Bal
package EOS
//Equations of State
extends Modelica.Icons.VariantsPackage;
model Virial
parameter Boolean[4] known_state "Give true if the state property is known in the oreder {P,V,n,T} for eg. {true,true,false,true}";
parameter Real Pressure "Enter Pressure in appropriate dimension";
parameter Real Volume "Enter Volume in appropriate dimension";
parameter Real Moles "Enter no. of moles in appropriate dimension";
parameter Real Temperature "Enter Temperature in appropriate dimension";
parameter Real R "Enter Gas Constants in appropriate dimensions";
parameter Real Tc "Enter Critical Temperature in appropriate dimension";
parameter Real Pc "Enter Critical Pressure in appropriate dimension";
parameter Real PAf "Enter appropriate Pitzer Accentric Factor";
Real P, V, n, T;
Real Tr, Pr "Reduced Temperature and Pressure";
Real B0, B1, B "Virial Coefficient";
Real V1 "Molar Volume";
equation
if known_state[1] then
P = Pressure;
end if;
if known_state[2] then
V = Volume;
end if;
if known_state[3] then
n = Moles;
end if;
if known_state[4] then
T = Temperature;
end if;
Tr = T / Tc;
Pr = P / Pc;
B0 = 0.083 - 0.422 / Tr ^ 1.6;
B1 = 0.139 - 0.172 / Tr ^ 4.2;
B = R * Tc / Pc * (B0 + PAf * B1);
V1 = V / n;
P = R * T / V1 * (1 + B / V1);
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(fillColor = {132, 179, 222}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-4, 13}, extent = {{-61.83, 27.87}, {75.4131, -47.5421}}, textString = "Virial Equation \n of State")}));
end Virial;
model Ideal
parameter Boolean[4] known_state "Give true if the state property is known in the oreder {P,V,n,T} for eg. {true,true,false,true}";
parameter Real Pressure "Enter Pressure in appropriate dimension";
parameter Real Volume "Enter Volume in appropriate dimension";
parameter Real Moles "Enter no. of moles in appropriate dimension";
parameter Real Temperature "Enter Temperature in appropriate dimension";
parameter Real R "Enter Gas Constants in appropriate dimensions";
Real P, V, n, T;
equation
if known_state[1] then
P = Pressure;
end if;
if known_state[2] then
V = Volume;
end if;
if known_state[3] then
n = Moles;
end if;
if known_state[4] then
T = Temperature;
end if;
P * V = n * R * T;
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(fillColor = {136, 232, 229}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-4, 13}, extent = {{-61.83, 27.87}, {75.41, -47.54}}, textString = "Ideal Equation
of State")}));
end Ideal;
model SRK
parameter Boolean[4] known_state "Give true if the state property is known in the oreder {P,V,n,T} for eg. {true,true,false,true}";
parameter Real Pressure "Enter Pressure in appropriate dimension";
parameter Real Volume "Enter Volume in appropriate dimension";
parameter Real Moles "Enter no. of moles in appropriate dimension";
parameter Real Temperature "Enter Temperature in appropriate dimension";
parameter Real R "Enter Gas Constants in appropriate dimensions";
parameter Real Tc "Enter Critical Temperature in appropriate dimension";
parameter Real Pc "Enter Critical Pressure in appropriate dimension";
parameter Real PAf "Enter appropriate Pitzer Accentric Factor";
Real P, V, n, T;
Real Tr "Reduced Temperature ";
Real a, b, m, alpha;
Real V1 "Molar Volume";
equation
if known_state[1] then
P = Pressure;
end if;
if known_state[2] then
V = Volume;
end if;
if known_state[3] then
n = Moles;
end if;
if known_state[4] then
T = Temperature;
end if;
Tr = T / Tc;
a = 0.42747 * (R * Tc) ^ 2 / Pc;
b = 0.08663999999999999 * R * Tc / Pc;
m = 0.48508 + 1.55171 * PAf - 0.1561 * PAf ^ 2;
alpha = (1 + m * (1 - sqrt(Tr))) ^ 2;
V1 = V / n;
P = R * T / (V1 - b) - alpha * a / (V1 * (V1 + b));
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(fillColor = {137, 235, 178}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-4, 13}, extent = {{-61.83, 27.87}, {75.41, -47.54}}, textString = "SRK Equation
of State")}));
end SRK;
model CF
parameter Boolean[4] known_state "Give true if the state property is known in the oreder {P,V,n,T} for eg. {true,true,false,true}";
parameter Real Pressure "Enter Pressure in appropriate dimension";
parameter Real Volume "Enter Volume in appropriate dimension";
parameter Real Moles "Enter no. of moles in appropriate dimension";
parameter Real Temperature "Enter Temperature in appropriate dimension";
parameter Real R "Enter Gas Constants in appropriate dimensions";
parameter Real z "Enter Compressibility Factor";
Real P, V, n, T;
Real V1 "Molar Volume";
equation
if known_state[1] then
P = Pressure;
end if;
if known_state[2] then
V = Volume;
end if;
if known_state[3] then
n = Moles;
end if;
if known_state[4] then
T = Temperature;
end if;
V1 = V / n;
z = P * V1 / (R * T);
annotation(Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(fillColor = {100, 243, 148}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-14, 28}, extent = {{-61.83, 27.87}, {95.55, -76.11}}, textString = "Compressibility Factor \n Equation of State")}));
end CF;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end EOS;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end Material_Bal;
package Utilities
extends Modelica.Icons.UtilitiesPackage;
function Limiting_Reagent
extends Modelica.Icons.Function;
input Integer n;
input Real[n] o;
input Real[n] c;
output Integer LR;
protected
Real[n] flag1;
Real[n] flag2;
Integer i;
Integer nR;
algorithm
for i in 1:n loop
if c[i] < 0 then
nR := i;
else
break;
end if;
end for;
LR := 1;
for i in 1:nR - 1 loop
flag1[i] := o[i + 1] / o[1];
flag2[i] := c[i + 1] / c[1];
if flag1[i] < flag2[i] then
LR := i + 1;
end if;
end for;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end Limiting_Reagent;
function Antoine_equ
extends Modelica.Icons.Function;
input Real[3] A;
input Real T;
output Real pstar;
algorithm
pstar := 10 ^ (A[1] - A[2] / (T + A[3]));
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end Antoine_equ;
function VLE
//T = [n x y P T_guess dT]
extends Modelica.Icons.Function;
input Integer n;
input Real[n] x;
input Real[n] y;
input Real P;
input Real T_guess;
input Real dT;
input Real[n, 3] A;
output Real T;
output Real[n] Ps;
protected
Integer flag1 = -1;
Integer flag2 = -1;
algorithm
while 1 > 0 loop
for i in 1:n loop
Ps[i] := Antoine_equ(A[i, :], T_guess);
y[i] := x[i] * Ps[i] / P;
end for;
if abs(sum(y) - 1) <= 0.0001 then
T := T_guess;
break;
end if;
if sum(y) < 1 then
if flag1 > 0 then
dT := dT / 2;
end if;
T_guess := T_guess + dT;
flag2 := 1;
elseif sum(y) > 1 then
if flag2 > 0 then
dT := dT / 2;
end if;
T_guess := T_guess - dT;
flag1 := 1;
end if;
end while;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end VLE;
function PR_EOS
extends Modelica.Icons.Function;
// Peng-Robinson EOS computation
// Inputs:
// z = number of moles of all species (n x 1 column vector) [mol]
// p = pressure [Pa]
// T = temperature [K]
// pc = critical pressure of all components (n x 1 column vector)[Pa]
// Tc = critical temperature of all components (n x 1 column vector)[K]
// w = acentric factor of all components (n x 1 column vector)
// k = binary parameters (n x n symmetric matrix)
// cp = ideal gas heat capacity coefficients (n x m symmetric matrix) [J/mol-K]
// DHf = standard enthalpy of formation for ideal gas (298.15 K and 1 atm) (n x 1 column vector) [J/mol]
// ph = phase (L or V)
// Outputs:
// V = molar volume [m3/mol]
// Z = compressibility factor
// phi = fugacity coefficient
// H = enthalpy [J/mol]
//phi = PR_EOS(n,z,p,T,pc,Tc,w,k,ph)
input Integer n;
input Real[n, 1] z;
input Real p;
input Real T;
input Real[n, 1] pc;
input Real[n, 1] Tc;
input Real[n, 1] w;
input Real[n, n] k;
//input Real[n,5] cpig;
//input Real[n,1] DHf;
input String ph;
//output Real V;
//output Real Z;
output Real[n, 1] phi;
//output Real H;
protected
Real V;
Real Z;
//Real H;
Real R;
constant Real e = 1 - sqrt(2);
constant Real s = 1 + sqrt(2);
//Tr,Hr;
Real[n, 1] m;
Real[n, 1] alfa;
Real ai[n, 1];
Real bi[n, 1];
Real Q[n, n];
Real a[1, 1];
Real b[1, 1];
Real[n, n] dQdT;
Real[1, 1] dadT;
Real c[4];
Real r[3, 2];
Real[n, 1] abar;
Real[n, 1] bbar;
//Real Hig[n];
Real[n, 1] J;
Real[n, n] J1;
Real[n, 1] J2;
Real[n, 1] J3;
Real[n, 1] J4;
Real[n, 4] J6;
Real[3] r1;
Real[1, n] J7;
Real[1, n] J8;
Real[n, 1] J9;
algorithm
R := 8.314;
// m3 Pa/(mol K) = J/mol-K
//Tr:=298.15;
// K
m := 0.37464 * ones(n, 1) + 1.54226 * w - 0.26992 * w .^ 2;
alfa := (ones(n, 1) + m .* (ones(n, 1) - (T ./ Tc) .^ 0.5)) .^ 2;
J := Tc .^ 2;
ai := 0.45724 * R ^ 2 * J ./ pc .* alfa;
bi := 0.07779999999999999 .* R .* Tc ./ pc;
Q := (ai * transpose(ai)) .^ 0.5 .* (ones(n, n) - k);
a := transpose(z) * Q * z;
b := transpose(z) * bi;
J1 := (pc * transpose(pc)) .^ 0.5;
J2 := alfa .^ 0.5;
J3 := Tc .^ 0.5;
J4 := m ./ J3;
J6 := Tc * transpose(Tc);
dQdT := 0.45724 * R ^ 2 * (k - ones(n, n)) .* J6 ./ J1 .* 1 / (2 * T ^ 0.5) .* (J4 * transpose(J2) + J2 * transpose(J4));
dadT := transpose(z) * (Q - T * dQdT) * z;
// Coefficients of the EoS model equation
c[1] := 1;
c[2] := b[1, 1] - R * T / p;
c[3] := (-3 * b[1, 1] ^ 2) - 2 * R * T / p * b[1, 1] + a[1, 1] / p;
c[4] := b[1, 1] ^ 3 + R * T / p * b[1, 1] ^ 2 - a[1, 1] * b[1, 1] / p;
// Roots
r := Modelica.Math.Vectors.Utilities.roots(c);
//r := {{0.0052, 0}, {0.0007, 0}, {0.00013715, 0}};
for i in 1:3 loop
r1[i] := r[i, 1];
end for;
if ph == "L" then
V := min(r1);
else
V := max(r1);
end if;
Z := p * V / (R * T);
J7 := transpose(z) * Q;
J8 := a[1, 1] .* ones(1, n);
J9 := 2 .* J7 - J8;
abar := transpose(J9);
bbar := bi;
for i in 1:n loop
phi[i, 1] := exp((Z - 1) * bbar[i, 1] / b[1, 1] - log((V - b[1, 1]) * Z / V) + a[1, 1] / (b[1, 1] * R * T) / (e - s) * log((V + s * b[1, 1]) / (V + e * b[1, 1])) * (1 + abar[i, 1] / a[1, 1] - bbar[i, 1] / b[1, 1]));
end for;
//Hig[i]:=z[i,1] * (DHf[i,1] + cpig[i,1] * (T - Tr) + cpig[i,2] .* cpig[i,3] .* (1 / tanh(cpig[i,3] / T) - 1 / tanh(cpig[i,3] / Tr)) + cpig[i,4] .* cpig[i,5] .* (1 / tanh(cpig[i,5] / T) - 1 / tanh(cpig[i,5] / Tr)));
//HR:=R * T * (Z - 1) - dadT[1,1] / (2 * (s - 1) * b[1,1]) * log((V + s * b[1,1]) / (V + e * b[1,1]));
//H:=sum(Hig) + HR;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end PR_EOS;
function PTFlash
extends Modelica.Icons.Function;
//(T,K) = [n x y P T_guess dT pc Tc w k]
input Integer n;
input Real[n, 1] x;
input Real[n, 1] y;
input Real P;
input Real T_guess;
input Real dT;
input Real[n, 1] pc;
input Real[n, 1] Tc;
input Real[n, 1] w;
input Real[n, n] k;
input String ph;
output Real T;
output Real[n, 1] K;
protected
Real dT1;
Real T_guess1;
Real[n, 1] phiL;
Real[n, 1] phiV;
Integer flag1 = -1;
Integer flag2 = -1;
algorithm
T_guess1 := T_guess;
dT1 := dT;
while 1 > 0 loop
phiL := PR_EOS(n, x, P, T_guess1, pc, Tc, w, k, "L");
phiV := PR_EOS(n, y, P, T_guess1, pc, Tc, w, k, "V");
K := phiL ./ phiV;
y := K .* x;
if abs(sum(y) - 1) <= 0.0001 then
T := T_guess1;
break;
end if;
if sum(y) < 1 then
if flag1 > 0 then
dT1 := dT1 / 2;
end if;
T_guess1 := T_guess1 + dT1;
flag2 := 1;
elseif sum(y) > 1 then
if flag2 > 0 then
dT1 := dT1 / 2;
end if;
T_guess1 := T_guess1 - dT1;
flag1 := 1;
end if;
end while;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end PTFlash;
function VLE_PR
extends Modelica.Icons.Function;
//(T,K) = [n z P T_guess dT pc Tc w k]
input Integer n;
input Real[n, 1] z;
input Real P;
input Real T_guess;
input Real dT;
input Real[n, 1] pc;
input Real[n, 1] Tc;
input Real[n, 1] w;
input Real[n, n] k;
output Real T;
output Real[n, 1] K;
protected
Real dT1;
Real T_guess1;
Real[n, 1] x;
Real[n, 1] y;
Real[n, 1] phiL;
Real[n, 1] phiV;
Integer flag1 = -1;
Integer flag2 = -1;
algorithm
T_guess1 := T_guess;
dT1 := dT;
while 1 > 0 loop
x := z - y;
phiL := PR_EOS(n, x, P, T_guess1, pc, Tc, w, k, "L");
phiV := PR_EOS(n, y, P, T_guess1, pc, Tc, w, k, "V");
K := phiL ./ phiV;
y := K .* x;
if abs(sum(y) - 1) <= 0.0001 then
T := T_guess1;
break;
end if;
if sum(y) < 1 then
if flag1 > 0 then
dT1 := dT1 / 2;
end if;
T_guess1 := T_guess1 + dT1;
flag2 := 1;
elseif sum(y) > 1 then
if flag2 > 0 then
dT1 := dT1 / 2;
end if;
T_guess1 := T_guess1 - dT1;
flag1 := 1;
end if;
end while;
end VLE_PR;
annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2, 2})));
end Utilities;
model GenericModel
// parameter Integer nin "Number of inputs" annotation(Dialog(group = "Number of Ports"));
// parameter Integer nout "Number of outputs" annotation(Dialog(group = "Number of Ports"));
Real[nin, system.set_n] l(start = ones(nin, system.set_n)) "for calculation only. Please ignore";
Real[nout, system.set_n] m(start = ones(nout, system.set_n)) "for calculation only. Please ignore";
Real[system.set_n] o "for calculation only. Please ignore";
Real[system.set_n] p "for calculation only. Please ignore";
Real[nin] q "for calculation only. Please ignore";
Real[nout] r "for calculation only. Please ignore";
Real delEk if system.use_EnergyBal "Change in Kinetic Energy";
Real delEp if system.use_EnergyBal "Change in Potential Energy";
Real delU if system.use_EnergyBal "Change in Internal Energy of system";
Real delH if system.use_EnergyBal and system.OpenSys and not Bernoulli "Change in Enthalpy of system";
Real delVHead if system.use_EnergyBal and Bernoulli "Velocity Head";
Real delSHead if system.use_EnergyBal and Bernoulli "Static Head";
Real delPHead if system.use_EnergyBal and system.OpenSys "Change in Pressure Head of system";
Real[nin] Ekin if system.use_EnergyBal;
Real[nin] Epin if system.use_EnergyBal;
Real[nin] Uin if system.use_EnergyBal;
Real[nin] PHeadin if system.use_EnergyBal and system.OpenSys;
Real[nout] Ekout if system.use_EnergyBal;
Real[nout] Epout if system.use_EnergyBal;
Real[nout] Uout if system.use_EnergyBal;
Real[nout] PHeadout if system.use_EnergyBal and system.OpenSys;
Real[nin, system.set_n] H1 if system.use_EnergyBal and system.OpenSys and not Bernoulli "for calculation only. Please ignore";
Real[nout, system.set_n] H2 if system.use_EnergyBal and system.OpenSys and not Bernoulli "for calculation only. Please ignore";
Real[nin, system.set_n] U1 if system.use_EnergyBal "for calculation only. Please ignore";
Real[nout, system.set_n] U2 if system.use_EnergyBal "for calculation only. Please ignore";
Real[nin] Hin if system.use_EnergyBal and system.OpenSys and not Bernoulli;
Real[nout] Hout if system.use_EnergyBal and system.OpenSys and not Bernoulli;
// Real[system.set_n] Hp if system.use_EnergyBal and system.OpenSys and PhaseChange;
outer Chemical.System system;
equation
for i in 1:nin loop
for j in 1:system.set_n loop
l[i, j] = In[i].n_flow[j];
end for;
q[i] = sum(l[i, :]);
end for;
for i in 1:nout loop
for j in 1:system.set_n loop
m[i, j] = Out[i].n_flow[j];
end for;
r[i] = sum(m[i, :]);
end for;
for k in 1:system.set_n loop
o[k] = sum(l[:, k]);
p[k] = sum(m[:, k]);
end for;
if system.use_EnergyBal then
for i in 1:nin loop
Ekin[i] = In[i].Ek;
Epin[i] = In[i].Ep;
end for;
for i in 1:nout loop
Ekout[i] = Out[i].Ek;
Epout[i] = Out[i].Ep;
end for;
for i in 1:nin loop
for j in 1:system.set_n loop
U1[i, j] = In[i].n_flow[j] * In[i].U[j];
end for;
Uin[i] = sum(U1[i, :]);
end for;
for i in 1:nout loop
for j in 1:system.set_n loop
U2[i, j] = Out[i].n_flow[j] * Out[i].U[j];
end for;
Uout[i] = sum(U2[i, :]);
end for;
delEk = sum(Ekout) - sum(Ekin);
delEp = sum(Epout) - sum(Epin);
delU = sum(Uout) - sum(Uin);
if system.OpenSys then
for i in 1:nin loop
PHeadin[i] = In[i].P;
end for;
for i in 1:nout loop
PHeadout[i] = Out[i].P;
end for;
delPHead = sum(PHeadout) - sum(PHeadin);
if Bernoulli then
delVHead = sum(Ekout ./ r) - sum(Ekin ./ q);
delSHead = sum(Epout ./ r) - sum(Epin ./ q);
else
for i in 1:nin loop
for j in 1:system.set_n loop
H1[i, j] = In[i].n_flow[j] * In[i].H[j];
end for;
Hin[i] = sum(H1[i, :]);
end for;
for i in 1:nout loop
for j in 1:system.set_n loop
//if PhaseChange then
//if known_delHp[j] then
//Hp[j] = delHp[j];
//end if;
// H2[i,j] = Out[i].n_flow[j] * (Out[i].H[j] + Hp[j]);
//else
H2[i, j] = Out[i].n_flow[j] * Out[i].H[j];
//end if;
end for;
Hout[i] = sum(H2[i, :]);
end for;
delH = sum(Hout) - sum(Hin);
end if;
end if;
end if;