-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptimizeFlowsheet.gms
1503 lines (1113 loc) · 39.3 KB
/
OptimizeFlowsheet.gms
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
* TOP OF FILE
* This is the "main" file for simple LPC synthesis and optimization. Include files are
* extensively used.
*
* Note: This file is based on ASU27_DualReboiler
*
* The optimization problem is solved in six stages/sections.
*
* 0. Either load stream data from a file or initial with constant stream properties
*
* 1. Simple thermodynamic flowsheet optimziation
* In the first stage a simplified flowsheet model featuring correlation based
* thermodynamic equations is optimized and heat integrated. This determines
* reasonable temperatures, pressures, flows, etc for all of the ASU streams. )
*
* 2. Cubic CEOS model initialization
* In the second stage stream properties are fixed, and the CEOS model
* are initialized. This is done by solving three optimization problems.
* During this stage the shadow streams used for bubble/dew point calculations
* are "activated".
*
* 3. CEOS flowsheet model optimization with Edmister cascades
* In the third stage the ASU with CEOS thermo is optimized and heat
* integrated. The group method Edmister-based cascade approximation is used
* in this model, which results in the number of theoretical trays being a
* continous optimization variable. The optimization parameter is originally
* solved with a large smoothing epsilon and loose group method bounds.
* Epsilon is decrease and the bounds are tightened in subsequent solves. In
* the final solves the number of stages in the cascades is rounded and fixed.
*
* 4. CEOS flowsheet model optimization with tray-by-tray cascades
* To facilitate model validation, the Edmister cascade model is replaced with
* a tray-by-tray (MESH) model in the fourth stage. For these final solved the number
* of trays remains fixed. Conversion from the group method to cascade model
* is automated with dynamic sets in GAMS. Initialization is also automated
* with loops.
*
* 5. The constant heat capacity assumption is checked by decomposing heat exchangers
* into multiple subunits
*
* 6. CEOS flowsheet model is re-optimized with MESH cascade model and refined heat exchange units
$setglobal GlobalIterlim "10000";
* global options
$eolcom //
option optcr = 1E-10; ;
*option solprint = ON ;
*option reslim = 600;
option reslim = 3600;
option iterlim = %GlobalIterlim%;
$onmacro
$onempty
$onexpand
$set matout "'gamsstat.gdx', Sec1Stat, Sec2Stat, Sec3Stat, Sec4Stat, Sec5Stat, Sec6Stat ";
// end of global options
***** Stage Mode Settings *****
* These parameters control the "operational mode" for each stage.
Parameter
ProblemSimpleFlowsheetOpt Initialization mode /1/
* Mode 0 - skip. don't solve
* Mode 1 - solve
ProblemInitCEOS Initialization mode /1/
* Mode 0 - don't solve
* Mode 1 - solve
* Mode 2 - don't solve and load previous solution
ProblemCEOSFlowsheetOpt Initialization mode /1/
* Mode 0 - don't solve
* Mode 1 - solve
* Mode 2 - don't solve and load previous solution
ProblemTrayByTray Solve mode /0/
* Mode 0 - don't solve
* Mode 1 - solve
* Mode 2 - don't solve and load previous solution
ProblemHeatChecker Solve mode /0/
* Mode 0 - don't solve
* Mode 1 - solve
* Mode 2 - don't solve and load previous solution
ProblemTrayByTrayDecomp Solve mode /0/
* Mode 0 - don't solve
* Mode 1 - solve
ThermoSwitch Toggle between thermo methods /1/
* Mode 1 - simple thermo (vapor pressure correlations)
* Mode 2 - CEOS thermo
* Should start as 1... don't change here
SectionSwitch Toggle between sections for problem specific init. /0/;
* Should start at 0... don't change here
***** Specify Master Include File *****
$include ../ASUSpecFiles/MasterIncludes.gms
*$include ../NewSpecFiles/MasterIncludes.gms
$include ../ThrottleValveExampleSpecFiles/MasterIncludes.gms
***********************************************************************
***** Do not change anything below this line for normal operation *****
***********************************************************************
**************************************
***** Setup Solve Status Storage *****
**************************************
Set stat /modelstat,solvestat,timer/;
Parameters
Sec1Stat(stat)
Sec2Stat(stat)
Sec3Stat(stat)
Sec4Stat(stat)
Sec5Stat(stat)
Sec6Stat(stat);
***********************************
***** External Initialization *****
***********************************
Parameters
NumStageInit Number of initial stages in cascades
PhiLBCEOS Lower bound for phi in cascade model for CEOS problems
UBASFact Upper bound on absorption or stripping factor
LBASFact Lower bound on absorption or stripping factor
Tmin Min temperature (K) for the flowsheet
Prune Manually remove equipment before FlowsheetOpt_Simple?
alpha Small number used for heat integration phase changes
saveAlpha
HRATSimple HRAT for FlowsheetOpt_Simple
HRATCEOS HRAT for FlowsheetOpt_CEOS and TrayByTray
HRATPlusBD Plus value for HRAT before decomposition of heat exchange units
FirstSolverSimple
FirstSolverCEOS
FirstSolverTray
HeatIntegModel
FirstDerivEpsilon
Inter1Epsilon
CascInterLB
PlusStages
FixEffForInit
SelectCEOSModel
ExternalInit ExternalInitialization flag /0/
LinuxOS Running on Unix or Linux? /0/
LoadInitPoint Load initial flows-temps-pressures from file
ProbSpecParam1
ProbSpecParam2
ProbSpecParam3
SimpleCscInitProb
CEOSCscInitProb /0/
PruneConfig
DualReboilerASU /0/
;
$if %system.filesys% == UNIX $set LinuxOS 1
display LinuxOS;
$gdxin initData
$load NumStageInit
$load PhiLBCEOS
$load UBASFact
$load LBASFact
$load Tmin
$load Prune
$load alpha
$load HRATSimple
*$load O2RecLowDelta
*$load O2RecLowCEOS
$load HRATPlusBD
$load HRATCEOS
$load FirstSolverSimple
$load FirstSolverCEOS
$load FirstSolverTray
$load HeatIntegModel
$load FirstDerivEpsilon
$load Inter1Epsilon
$load CascInterLB
$load PlusStages
$load FixEffForInit
$load SelectCEOSModel
$load PruneConfig
*$load o2pureSpec
$load SimpleCscInitProb
$load LoadInitPoint
$load ProbSpecParam1
$load ProbSpecParam2
$load ProbSpecParam3
$gdxin
$include ../%ExternalInitDefaultFile%
************************************
***** Include flowsheet models *****
************************************
* Generic parameters, some of which are used in the models
$include ../%GenericParamsFile%
* Flowsheet Topology
$include ../%FlowsheetTopologyFile%
$include ../ProcsFiles/FlowsheetTopologyProcessing.gms
* Define smoothed max operator
$macro smmax(x) ( 0.5*sqrt(Power(x,2) + epsiSmax) + 0.5*(x) )
* Load thermodynamic data and constants
$include ../%ThermoDataFile%
* Stream model
$include ../ModelFiles/StreamModel.gms
* Equipment models independent of thermo
$include ../ModelFiles/ThrmEModel.gms
$include ../ModelFiles/FlashModel.gms
$include ../ModelFiles/HeatExchangerModel.gms
$include ../ModelFiles/ReboilerModel.gms
$include ../ModelFiles/ValveModel.gms
$include ../ModelFiles/MixerModel.gms
* Thermo models
$include ../ModelFiles/CommonThermoModel.gms
$include ../ModelFiles/SimpleThermoModel.gms
$include ../ModelFiles/CEOSThermoModel.gms
$include ../ModelFiles/CEOSDewBubModel2.gms
* Equipment models dependent on thermo
$include ../ModelFiles/CondenserModel.gms
$include ../ModelFiles/CascadeModel.gms
$include ../ModelFiles/EntropyBalModel.gms
$include ../ModelFiles/SplitterModel.gms
* Heat integration model
$include ../ModelFiles/HeatIntegrationModelCommon.gms
$include ../ModelFiles/HeatIntegrationModelUpdated.gms
*$include ../ModelFiles/HeatIntegrationModelRevised.gms
* Advanced distillation models
$include ../ModelFiles/TrayByTrayModel.gms
$include ../ModelFiles/MESHwBypassModel3.gms
*--------------------------------*
* Dummy variables
*--------------------------------*
Variables
Z ;
$include ../%ProbSecSpecDeclFile%
$include ../ModelFiles/ObjFncsGeneric.gms
$include ../%ProbObjFncsFile%
*0000000000000000000000000000000000*
************************************
********** BEGIN SECTION 0 *********
************************************
*0000000000000000000000000000000000*
SectionSwitch = 0;
Parameters
loopExp /1/
loopCount /1/;
*--------------------------------*
* Load initial point from file
*--------------------------------*
F.l(Str) = 0;
Tscaled.l(Str) = 0;
P.l(Str) = 0;
*$ontext
$ontext
$gdxin %SolForInit%
$loadr F
$loadr Fc
$loadr Xc
$loadr P
$loadr Tscaled
$gdxin
$offtext
execute_load %SolForInit% F,Fc,Xc,P,Tscaled;
F.m(Str) = 0;
Fc.m(Str,Comp) = 0;
Xc.m(Str,Comp) = 0;
Tscaled.m(Str) = 0;
F.lo(Str) = -Inf;
F.up(Str) = Inf;
Fc.lo(Str,Comp) = -Inf;
Fc.up(Str,Comp) = Inf;
P.lo(Str) = -Inf;
P.up(Str) = Inf;
Tscaled.lo(Str) = -Inf;
Tscaled.up(Str) = Inf;
Tscaled.l(Str)$(Tscaled.l(Str) eq 0) = FeedT/Tref;
P.l(Str)$(P.l(Str) eq 0) = FeedP;
*F.l(Str) = max(F.l(Str), 1E-6);
T.l(Str) = Tscaled.l(Str)*Tref;
Xc.l(Str,Comp)$(SUM(Comp2, Xc.l(Str,Comp2)) < 0.1) = 1/card(Comp);
*$offtext
$ontext
F.l(Str) = 0;
Tscaled.l(Str) = 0;
P.l(Str) = 0;
$offtext
Parameters FeedTTmp /100/;
* Initialize new streams (not in the initPoint file)
loop(Str$(F.l(Str) eq 0 AND Tscaled.l(Str) eq 0 AND P.l(Str) eq 0),
Fc.l(Str,Comp) = FeedFlow(Comp);
F.l(Str) = SUM(Comp, Fc.l(Str,Comp));
Xc.l(Str,Comp) = Fc.l(Str,Comp)/Max(F.l(Str),epsi);
Tscaled.l(Str) = FeedTTmp/Tref;
P.l(Str) = FeedP;
);
$include ../%ProbSecSpecInitFile%
EpsilonZ = FirstDerivEpsilon;
EpsilonA = Inter1Epsilon;
Inter1.lo(Str) = 10**EpsilonA;
$include ../ModelFiles/SetupPostProcessing.gms
$include ../InitFiles/Bounds.gms
$include ../%ProbSpecificBounds%
*------------------------**
* Initialize Flows
*------------------------**
***** Option 1: Load From File *****
* In this option temperatures, pressures, compositions and flowrates
* are loaded from a file. This is analogous to starting from a known solution,
* such as results obtained from a commerical flowsheet simulator.
* Do nothing. This was already done above.
***** Option 2: Load a general guess ****
* Using this option the flowsheet is initialized to contain non-zero flows with
* some guess temperatures and pressures. In the current state, option 1 tends to
* be more effective. Refinement of the guesses in option 2 should improve
* performance.
Parameter FeedXc(Comp);
FeedXc(Comp) = FeedFlow(Comp)/SUM(Comp2, FeedFlow(Comp2));
Display FeedXc;
Equation EqInitObj;
EqInitObj..
Z =e= Sum(Str, (F(Str) - 1)*(F(Str) - 1)
+ 10*SUM(Comp, (Xc(Str,Comp) - FeedXc(Comp))*(Xc(Str,Comp) - FeedXc(Comp))));
Model MassBalEqns /EqTotMolStr, EqSplitFrac, EqTotCompMolBalEd1, EqCompMolBalGnrlE,
EqMolBalSptr, EqMolFracSptr, PurityRecoveryEquations/;
Model MassBal /MassBalEqns, EqInitObj,EqSumFrac/;
if(ProblemSimpleFlowsheetOpt eq 1,
* MassBal.savepoint = 1;
if(ExternalInit eq 1,
option NLP = CONOPT;
else
option NLP = GAMSCHK;
);
* EITHER: 1. Solve mass balance problem to initialize most streams with non-zero flows
* OR: 2. Don't overwrite initial point (F, Fc, Tscaled, P) loaded from file
if(LoadInitPoint eq 0,
Fc.l(Str,Comp) = FeedFlow(Comp);
F.l(Str) = SUM(Comp, Fc.l(Str,Comp));
Xc.l(Str,Comp) = Fc.l(Str,Comp)/Max(F.l(Str),epsi);
F.up(ExtraClmnFeeds) = 0;
Solve MassBal using NLP minimizing Z;
T.l(Str) = FeedTTmp;
P.l(Str) = FeedP;
T.l(FeedStr) = 300;
);
);
$include ../%ProbSpecPruneFile%
F.fx(ManualRemove) = 0;
Fc.fx(ManualRemove,Comp) = 0;
F.l(Str)$(NOT ManualRemove(Str)) = max(F.l(Str), 1E-3);
$include ../ProcsFiles/ManualRemoveEquipment.gms
if(DebugMode > 0,
display ManualRemove;
);
* Idea for initializing equipment that are "cut out" from the loaded point
* Written May 15th, 2014
$ontext
loop(GnrlE$(NOT InactiveGnrlE(GnrlE)),
if( SUM(Str$(NOT InactiveStr(Str) AND InGnrlE(GnrlE,Str)), F.l(Str)) < epsi*epsi,
loop(Str$(NOT InactiveStr(Str) AND InGnrlE(GnrlE,Str)),
F.l(Str) = 0.01;
Xc.l(Str,Comp) = FeedFlow(Comp)/SUM(Comp2, FeedFlow(Comp2));
Fc.l(Str,Comp) = F.l(Str)*Xc.l(Str,Comp);
);
);
);
$offtext
scalar timer;
*1111111111111111111111111111111111*
************************************
********** BEGIN SECTION 1 *********
************************************
*1111111111111111111111111111111111*
SectionSwitch = 1;
timer = timeElapsed;
$include ../%ProbSecSpecInitFile%
*********************************************
***** General Initialization and Bounds *****
*********************************************
***** General Specs *****
Tscaled.lo(Str) = T.lo(Str)/Tref;
Tscaled.up(Str) = T.up(Str)/Tref;
Tscaled.l(Str) = T.l(Str)/Tref;
* Only execute these scripts if P, Tscaled, F, etc not loaded from a file
if(LoadInitPoint eq 0,
* Initialize zones - depreciated
* $include ../IncludeFiles/InitZones.gms
* Set heat exchanger temperatures and pressures - requires debugging
* $include ../IncludeFiles/InitHtEx.gms
);
***** Initialize Thermo *****
$include ../InitFiles/InitSmpThermo.gms
***** Initialize Flash *****
Qin.fx(Flsh) = 0;
Qout.fx(Flsh) = 0;
PFlsh.l(Flsh) = SUM(Str$OutLGnrlE(Flsh,Str), P.l(Str));
TFlsh.l(Flsh) = SUM(Str$OutLGnrlE(Flsh,Str), Tscaled.l(Str));
***** Initialize Valves *****
Qin.fx(Valve) = 0;
Qout.fx(Valve) = 0;
$include ../InitFiles/Init_Smp_Valve.gms
***** Initialize Partial Reboilers *****
Qout.fx(PReb) = 0;
PPReb.l(PReb) = SUM(Str$OutLGnrlE(PReb,Str), P.l(Str));
***** Initialize Total Condenser *****
PTCond.l(TCond) = SUM(Str$OutTCond(TCond,Str), P.l(Str));
PTCond.up(TCond) = Pmax;
***** Initialize Splitters *****
$include ../InitFiles/InitSplitter.gms
***** Initialize Q in GnrlE *****
$include ../InitFiles/InitGnrlE.gms
***** Initialize Cascade *****
VNEd1.l(Ed1) = SUM(Str $InVEd1(Ed1,Str), F.l(Str));
L1Ed1.l(Ed1) = SUM(Str $InLEd1(Ed1,Str), F.l(Str)) ;
* Stages per cascade
StgEd1.l(Ed1) = NumStageInit ;
$include ../InitFiles/Init_Cascade.gms
***** Initialize Objective *****
Model FlowsheetOpt /EqStreams,EqCascade,EqThrmE,EqFlsh, EqPReb,EqValve,EqTCond,EqSpltr,EqObj/;
Model FlowsheetOpt_Simple /FlowsheetOpt, SimpleThermo, EqSpltrSimpleThermo/;
*Model FlowsheetOpt_Simple6_R /FlowsheetOpt_Simple, EqCsdSimple, EqHtEx, HeatIntegRevised, obj9/;
Model FlowsheetOpt_Simple6_U /FlowsheetOpt_Simple - EqTscaled, EqCsdSimple, EqHtEx, HeatIntegUpdated, ObjSec1/;
**************************************************
***** Special Cascade Initialization Problem *****
**************************************************
$include ../ModelFiles/InitializationEquations.gms
count = 0;
if(ProblemSimpleFlowsheetOpt eq 1 AND SimpleCscInitProb eq 1 AND SUM(Ed1$(NOT InactiveCsc(Ed1)), 1) > 0,
Fc.l(CscStr,Comp) = F.l(CscStr)*Xc.l(CscStr,Comp);
* Setup InitEqns for InitMassBal and InitCscNew
InitStr1(Str) = no;
InitStr1(CscStr) = yes;
InitStr2(Str) = no;
InitStr2(Str)$(NOT CscStr(Str)) = yes;
$include ../InitFiles/InitInitEqns.gms
option NLP = GAMSCHK;
solve InitMassBal using NLP minimizing FcPen;
$include ../InitFiles/InitSmpThermo.gms
InitCscNewObj.iterlim = 1500;
solve InitCscNewObj using NLP minimizing Z;
if(ProblemInitCEOS eq 0,
option NLP = CONVERTD;
InitCscNewObj.optfile = 1;
solve InitCscNewObj using NLP minimizing Z;
);
);
ComplPen = 10;
***** Initialize Heat Integration *****
if(HeatIntegModel eq 1,
$include ../InitFiles/Init_HtInteg_Updated.gms
else
*$include ../InitFiles/Init_HtInteg_Revised.gms
);
sL.fx(LiqStr) = 0;
sV.fx(VapStr) = 0;
if(ProblemSimpleFlowsheetOpt eq 1,
***** Initialize Slacks *****
liqPen.l = sum(ThrmE, sum(Str$OutLGnrlE(ThrmE,Str), sL.l(Str)*F.l(Str)));
vapPen.l = sum(ThrmE, sum(Str$OutVGnrlE(ThrmE,Str), sV.l(Str)*F.l(Str)));
ComplPen = 10;
epsiSmax = 1E-4;
$include ../InitFiles/Bounds.gms
$include ../%ProbSpecificBounds%
$include ../InitFiles/ThrmEBubDew.gms
$include ../%ProbObjSpecInitFile%
ComplPen = 1;
if(FirstSolverSimple eq 1,
option NLP = GAMSCHK;
elseif FirstSolverSimple eq 2,
option NLP = CONOPT;
* FlowsheetOpt_Simple6_R.optfile = 1;
FlowsheetOpt_Simple6_U.optfile = 1;
elseif FirstSolverSimple eq 3,
option NLP = IPOPTH;
elseif FirstSolverSimple eq 4,
option NLP = MINOS;
elseif FirstSolverSimple eq 5,
option NLP = SNOPT;
else
option NLP = CONOPT;
);
* FlowsheetOpt_Simple6_R.savepoint=1;
* FlowsheetOpt_Simple6_U.savepoint=1;
* FlowsheetOpt_Simple6_U.iterlim = 30000;
epsiSmax = 1E-3;
* Tscaled.l(Str) = T.l(Str)/Tref;
* Tscaled.lo(Str) = T.lo(Str)/Tref;
* Tscaled.up(Str) = T.up(Str)/Tref;
* FlowsheetOpt_Simple6_U.reslim = 3*60;
for(loopCount = 1 to 1 by 1,
for(loopExp = -1 to 0 by 1,
ComplPen = Power(10, loopExp+1+StartCPPower);
CascInterA.lo(Ed1,Comp) = Power(10, CascInterLB - 1 - loopExp);
CascInterS.lo(Ed1,Comp) = Power(10, CascInterLB - 1 - loopExp);
epsiSmax = Power(10, -5 - loopExp);
* Initialize Heat Integration
if(HeatIntegModel eq 1,
$include ../InitFiles/Init_HtInteg_Updated.gms
else
*$include ../InitFiles/Init_HtInteg_Revised.gms
);
if(HeatIntegModel eq 1,
solve FlowsheetOpt_Simple6_U using NLP minimizing Z9;
else
* solve FlowsheetOpt_Simple6_R using NLP minimizing Z9;
);
T.l(Str) = Tscaled.l(Str)*Tref;
display T.l, ComplPen, epsiSmax;
ChckCmpl(0);
*$include ../ProcsFiles/RemoveUnusedEquipment.gms
if(ExternalInit eq 1,
option NLP = CONOPT;
else
option NLP = GAMSCHK;
);
* FlowsheetOpt_Simple6_R.optfile = 0;
FlowsheetOpt_Simple6_U.optfile = 0;
);
);
if(HeatIntegModel eq 1,
Sec1Stat('modelstat') = FlowsheetOpt_Simple6_U.modelstat;
Sec1Stat('solvestat') = FlowsheetOpt_Simple6_U.solvestat;
else
* SimpleStat('modelstat') = FlowsheetOpt_Simple6_R.modelstat;
* SimpleStat('solvestat') = FlowsheetOpt_Simple6_R.solvestat;
);
if(ProblemInitCEOS eq 0,
option NLP = convertd;
* FlowsheetOpt_Simple6_R.optfile = 1;
FlowsheetOpt_Simple6_U.optfile = 1;
* FlowsheetOpt_Simple6_R.savepoint = 0;
FlowsheetOpt_Simple6_U.savepoint = 0;
if(HeatIntegModel eq 1,
solve FlowsheetOpt_Simple6_U using NLP minimizing Z9;
else
* solve FlowsheetOpt_Simple6_R using NLP minimizing Z9;
);
);
);
if( ProblemSimpleFlowsheetOpt eq 2,
F.l(Str) = 0;
Fc.l(Str,Comp) = 0;
execute_loadpoint 'Sec1_SimpleFlowsheetResults.gdx';
epsiSmax = 1E-6;
);
*$include ../ProcsFiles/AddUnusedEquipment.gms
F.fx(ManualRemove) = 0;
* The following line dramatically impacts the solution
F.l(Str)$(NOT ManualRemove(Str)) = max(F.l(Str), 10E-5);
* Tried this with initPoint4. No change when uncommented
* $include ../ProcsFiles/RemoveUnusedEquipment.gms
if(ProblemSimpleFlowsheetOpt eq 1,
execute_unload 'Sec1_SimpleFlowsheetResults.gdx';
);
Sec1Stat('timer') = timeElapsed - timer;
timer = timeElapsed;
*2222222222222222222222222222222222*
************************************
********** BEGIN SECTION 2 *********
************************************
*2222222222222222222222222222222222*
SectionSwitch = 2;
$include ../%ProbSecSpecInitFile%
* Switch from Simple Thermo to CEOS Thermo Model
ThermoSwitch = 2;
***** Initialize shadow stream compositions *****
Parameters
dPvapdT(Str,Comp)
dTs(Str)
Pbtemp(Str)
Pdtemp(Str);
Scalar iter;
Set
PrmShd(Str) Shadow stream that is the same phase as actual process stream it's paired with / /;
* Define parameters for analytical ZEOS initialization
$include ../ProcsFiles/SetupInitZEOS.gms
if(ProblemInitCEOS eq 1,
* Ensure shadow streams are properly setup
$include ../ProcsFiles/ProcessShadowStreams.gms
$include ../InitFiles/InitializeShadowStreams.gms
* Initialize ZEOS using analytical solutions
$batinclude ../InitFiles/Init_CEOS_Basic4.gms "(fEOSStr(Str) AND ((RealStr(Str) AND NOT InactiveStr(Str)) OR ActShdStr(Str)))"
* Set Xc, T and P targets for objective function
InitStr1(Str) = no;
InitStr1(Str)$(fEOSStr(Str) AND ((RealStr(Str) AND NOT InactiveStr(Str)) OR ActShdStr(Str))) = yes;
InitStr2(Str) = no;
$include ../InitFiles/InitInitEqns.gms
MinSlacks(Str) = no;
MinSlacks(Str)$(RealStr(Str) AND fEOSStr(Str) AND NOT InactiveStr(Str) AND F.l(Str) > 0) = yes;
MinSlacks(Str)$(fEOSStr(Str) AND ActShdStr(Str)) = yes;
display MinSlacks, Ttarget;
Z.l = SUM(MinSlacks, sV.l(MinSlacks) + sL.l(MinSlacks)) + 100*TPen.l + 10*XcPen.l + 10*PPen.l;
***** Store initialization *****
InitCEOS5.iterlim = 0;
*InitCEOS5.savepoint = 1;
option NLP = GAMSCHK;
Solve InitCEOS5 using NLP minimizing Z;
***** Try with CONOPT *****
* Initialize basic CEOS equations (everything required for calculating ZEOS)
InitCEOS5.iterlim = %GlobalIterlim%;
InitCEOS5.savepoint = 0;
option NLP = GAMSCHK;
if(ProblemInitCEOS eq 1,
Solve InitCEOS5 using NLP minimizing Z;
else
InitCEOS5.modelstat = -1;
);
***** Use IPOPT if CONOPT fails *****
if(ProblemInitCEOS eq 1 AND InitCEOS5.modelstat > %ModelStat.Infeasible% - 1 AND InitCEOS5.modelstat < %ModelStat.Intermediate Infeasible% + 1,
execute_loadpoint 'InitCEOS5_p';
option NLP = IPOPTH;
Solve InitCEOS5 using NLP minimizing Z;
);
InitStr1(Str) = no;
InitStr1(Str)$(fEOSStr(Str) AND (RealStr(Str) AND NOT InactiveStr(Str))) = yes;
$include ../InitFiles/InitInitEqns.gms
* Initialize departure functions
$include ../InitFiles/Init_CEOS_Adv.gms
* Solve with departure functions and phase stability, dew/bubble point constraints
option NLP = GAMSCHK;
*option iterlim = 0;
*Solve InitCEOS6 using NLP minimizing Z;
option iterlim = %GlobalIterlim%;
Solve InitCEOS6 using NLP minimizing Z;
if(Z.l > 10,
option NLP = KNITRO;
Solve InitCEOS6 using NLP minimizing Z;
);
Sec2Stat('modelstat') = InitCEOS6.modelstat;
Sec2Stat('solvestat') = InitCEOS6.solvestat;
if(ProblemCEOSFlowsheetOpt eq 0,
option NLP = CONVERTD;
InitCEOS6.optfile = 1;
Solve InitCEOS6 using NLP minimizing Z;
);
);
*if(ProblemInitCEOS eq 2,
* execute_loadpoint 'InitCEOS6_p.gdx';
*);
if(ProblemInitCEOS eq 1,
Z9.l = Z.l;
execute_unload 'Sec2_InitCEOSResults.gdx';
elseif ProblemInitCEOS eq 2,
execute_load 'Sec2_InitCEOSResults.gdx';
);
Sec2Stat('timer') = timeElapsed - timer;
timer = timeElapsed;
*3333333333333333333333333333333333*
************************************
********** BEGIN SECTION 3 *********
************************************
*3333333333333333333333333333333333*
SectionSwitch = 3;
* Adjust zone approach temperatures
HRAT(HIZone) = HRATCEOS + HRATPlusBD;
* This line is neccissary with the JT specific valve model, but has no effect
* with the H(T,P) simple thermo correlation
CalcGnrlE(Valve) = yes;
Model FlowsheetOpt_CEOS_Base /FlowsheetOpt - EqTscaled, CubicEOSEqns, EqCsdCEOS, BubbleDewEqns, PhaseStabilityEqns, EqHtEx, EqSpltrCEOSThermo/;
*Model FlowsheetOpt_CEOS9b2_R /FlowsheetOpt_CEOS_Base, HeatIntegRevised, obj9, /;
Model FlowsheetOpt_CEOS9b2_U /FlowsheetOpt_CEOS_Base, HeatIntegUpdated, ObjSec3/;
Equation EqInitSimpleThermoObj;
*********************************
*** Initialization and Bounds ***
*********************************
***** General *****
*PmaxC('HPC') = 10;
*PmaxC('LPC') = 5;
$include ../InitFiles/Bounds.gms
$include ../%ProbSpecificBounds%
$include ../%ProbSecSpecInitFile%
Tscaled.lo(Str) = T.lo(Str)/Tref;
Tscaled.up(Str) = T.up(Str)/Tref;
F.fx(ManualRemove) = 0;
* Init HIG
$include ../InitFiles/Init_CEOS_Adv.gms
***** Cascade *****
$include ../InitFiles/Init_Cascade.gms
***** Special Cascade Initialization Problem *****
* Setup InitEqns for InitCscCEOS
InitStr1(Str) = no;
InitStr1(CscStr) = yes;
InitStr2(Str) = no;
InitStr2(Str)$(NOT CscStr(Str)) = yes;
$include ../InitFiles/InitInitEqns.gms
epsiSmax = 1E-3;
if(CEOSCscInitProb eq 1,
loopExp = -2;
if(PhiLBCEOS eq 0,
PhiAEd1.lo(Ed1,Comp) = 0;
PhiSEd1.lo(Ed1,Comp) = 0;
else
PhiAEd1.lo(Ed1,Comp) = Power(10, PhiLBCEOS - loopExp);
PhiSEd1.lo(Ed1,Comp) = Power(10, PhiLBCEOS - loopExp);
DummyAe.lo(Ed1,Comp) = Power(10, PhiLBCEOS - loopExp);
DummySe.lo(Ed1,Comp) = Power(10, PhiLBCEOS - loopExp);
);
CascInterA.lo(Ed1,Comp) = Power(10, CascInterLB - loopExp);
CascInterS.lo(Ed1,Comp) = Power(10, CascInterLB - loopExp);
EpsilonZ = Power(10, FirstDerivEpsilon - loopExp);
Inter1.lo(Str) = Power(10, Inter1Epsilon - loopExp);
if(ProblemCEOSFlowsheetOpt > 0 AND ProblemCEOSFlowsheetOpt < 3,
option NLP = GAMSCHK;
* option NLP = IPOPTH;
* InitCscCEOS.reslim = 45;
InitCscCEOS.iterlim = 1500;
solve InitCscCEOS using NLP minimizing Z;
);
StgEd1.lo(Ed1) = LBStgEd1 ;
StgEd1.up(Ed1) = UBStgEd1 ;
);
$include ../InitFiles/InitGnrlE.gms
if(HeatIntegModel eq 1,
$include ../InitFiles/Init_HtInteg_Updated.gms
else
*$include ../IncludeFiles/Init_HtInteg_Revised.gms
);
$include ../%InitProbObjFncsFile%
$include ../InitFiles/Bounds.gms
$include ../%ProbSpecificBounds%
if(ProblemCEOSFlowsheetOpt eq 1,
ComplPen = 1;
$ontext
CmprPwr.l(FeedStr) = F.l(FeedStr)*Ncmpr*gamma/(gamma - 1)*Rsi*300*
( P.l(FeedStr)**((gamma - 1)/(gamma*Ncmpr)) - 1)
/(Fc.l('S15','O2') + Fc.l('S17','O2'))/(1000*115.2);
$offtext
PhiAEd1.lo(Ed1,Comp) = Power(10,PhiLBCEOS);
PhiSEd1.lo(Ed1,Comp) = Power(10,PhiLBCEOS);
$include ../InitFiles/ThrmEBubDew.gms
if(Prune eq 1,
$include ../ProcsFiles/RemoveUnusedEquipment.gms
);
* FlowsheetOpt_CEOS9b2_R.savepoint = 1;
* FlowsheetOpt_CEOS9b2_U.savepoint = 1;
if(FirstSolverCEOS eq 1,
if(ExternalInit eq 1,
option NLP = CONOPT;
FlowsheetOpt_CEOS9b2_U.optfile = 0;
else
option NLP = GAMSCHK;
);
elseif FirstSolverCEOS eq 2,
option NLP = CONOPT;
FlowsheetOpt_CEOS9b2_U.optfile = 1;
* FlowsheetOpt_CEOS9b2_R.optfile = 1;
else
option NLP = IPOPTH;
);
epsiSmax = 1E-3;
* Tscaled.l(Str) = T.l(Str)/Tref;
* Tscaled.lo(Str) = T.lo(Str)/Tref;
* Tscaled.up(Str) = T.up(Str)/Tref;
*option iterlim = 0;
for(loopCount = 1 to 1 by 1,
* for(loopExp = -1 to 1 by 1,
for(loopExp = -1 to -1 by 1,
ComplPen = Power(10, loopExp+1+StartCPPower);
if(PhiLBCEOS eq 0,
PhiAEd1.lo(Ed1,Comp) = 0;
PhiSEd1.lo(Ed1,Comp) = 0;
else
PhiAEd1.lo(Ed1,Comp) = Power(10, PhiLBCEOS - loopExp);