-
Notifications
You must be signed in to change notification settings - Fork 4
/
temexd_mod.c
3973 lines (3596 loc) · 194 KB
/
temexd_mod.c
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
/*=========================================================================
= =
= T E N N E S S S E E E A S T M A N P R O C E S S =
= C O N T R O L T E S T P R O B L E M =
= =
= Original Model by =
= James J. Downs and Ernest F. Vogel =
= =
= Revision by =
= Andreas Bathelt* and N. Lawrence Ricker** =
= =
= * Laboratory of Control Engineering and Mechatronics =
= Cologne University of Applied Science =
= Betzdorfer Strasse 2 =
= 50679 Cologne, Germany =
= e-mail: andreas.bathelt@fh-koeln.de =
= =
= ** Professor Emeritus =
= Department of Chemical Engineering =
= University of Washington =
= Seattle, WA 98195-1750, USA =
= e-mail: ricker@u.washington.edu =
===========================================================================
Description
This s-function contains the model of the Tennessee Eastman Process which
was originally published by Downs & Vogel in [1]. Later the FORTRAN
source of [1] was converted into a C-s-function and made available by
[2], in order to use it in conjunction with MATLAB(R)/Simulink(R). This
present version is the result of a revision of the original C source.
This revision was necessary, since the simulation engine of MATLAB(R)/
Simulink(R) and the orginal structure of the model (the way it was de-
vised to be used) didn't match anymore. A description of the problems
found out and the subsequent changes made is available in [3].
There are two models of the revised version. The difference between the
two models is the way the activation of the disturbances is handled. This
model treats the activation vector as an additional input (the other mo-
del uses a parameter for the purpose of passing the activation).
Since this is only the source code of the model, it is necessary to com-
pile the model before using it. Please refer to the installation instruc-
tions given in the following section.
Please Note:
Since this revision was made during the time of the PhD studies at the
Cologne University of Applied Science it is highly likely that A. Ba-
thelt can't answer your questions using the given e-mail-address
from 2016/2017 onwards. In this case please contact his supervisor
Mohieddine Jelali (mohieddine.jelali@fh-koeln.de) or use the e-mail-
address andreas.bathelt@t-online.de. If you encounter any problems or
have ideas for the improvement of the model, feel free to send a
message.
Installation Instructions
Informtion regarding the compilation using the command mex
If you are using a 64-Bit version of MATLAB, there is no default C com-
piler shipped with the release. A list of compatible comiliers is given
under "Supported and Compatible Compilers - Release R20XXa/b" (website
(R2014b): http://de.mathworks.com/support/compilers/R2014b/index.html).
The Microsoft Windows SDK is compatible and available at no charge.
Compilation
1. Copy the source AND THE HEADER-FILE "teprob_mod.h" into a directory of
your choice - there is no need for the directory to be the directory
of the final simulation model.
2. Set this directory to be the the current directory (folder) MATLAB(R)
is working with (the window "Current Folder" needs to show the direc-
tory consisting the model's files).
3. Change to the command line and type "mex temexd_mod.c". This command
starts the compiling of the model. After the compiling is (success-
fully) completed, there should be a file named "temexd_mod.mexw32" or
"temexd_mod.mex64" (depending on the system). However, the file identi-
tifier following the last dot should contain "mex", which stands for
MATLAB executable.
Simulation using Simulink
4. Copy the MEX-File into the directory in which the simulation will be
run and make it the default directory. NOTE: the source code is not
needed for simulations.
5. Use the "S-Function" block from the Simulink Library Browser to
include the plant model in your simulation. Place this block in
your Simulink model and connect the required input and output signals
(see more about these below).
6. Open the dialog "Function Block Parameters" of this block and type
"temexd_mod" into the field "S-function name". In the field "S-func-
tion parameters" specify the 3 parameters of this model (separated
by commas and in the usual MATLAB-style); the description of the
parameters is given below.
7. See [2] for some example simulations.
References
[1] J. J. Downs, E. F. Vogel, "A Plant-Wide Industrial Process Control
Problem", Computers & Chemical Engineering, Vol. 17, Nr. 3,
S. 245–255 (1993)
[2] N. L. Ricker, "Tennessee Eastman Challenge archive", 2005. [Online]
Available:http://depts.washington.edu/control/LARRY/TE/download.html
[3] A. Bathelt, N. L. Ricker, M. Jelali, "Revision of the Tennessee
Eastman Process Model", International Symposium on Advanced Control
of Chemical Processes (ADCHEM) 2015, Submitted
Units
When Downs & Vogel build the model, they chose to use the imperial unit
system. Thus all the internal values, that is states, constants, etc.,
are given in imperial units. In the following these units are given along
with the respective counterpart of the SI unit system. Furthermore other
units are given (for the sake of clarification).
ft³: Cubic foot; 1 ft³ = 0.028317 m³
lb-mol: Pound-mole; 1 lb-mol = 453.59237 mol
Torr: Pressure in millimeter of mercury; 1 Torr = 101325/760 Pa
760 Torr = 1 atm; 1 atm = 101325 Pa
gpm: US gallon per minute; 1 gpm = 0.2271 m³/h
MM BTU: Million (10^6) British Thermal Unit (heat needed to increase
the tempreature of one british Pound of water by 1 degree
Fahrenheit); 1 MM BTU = 1055.05685262 MJ
Pa gauge: Pressure relative to ambient (air) pressure (1 bar)
scmh: Standard cubic meters per hour; the amount of substance of
one standard cubic meter is independent of the substance un-
der consideration and always 44.615 mol (assumption of ideal
gas). The values of pressure, temperature and relativ humi-
dity of the assumed standard condition are
p_n = 101325 Pa (760 Torr, 1 atm)
T_n = 273.15 K (DIN* 1343) / 288.15 K (ISO 2533)
phi = 0%
* DIN - German Institute for Standardization (Deutsches In-
stitut für Normung e.V.)
Used within the model, the relation between standard cubic
foot (scf) and standard cubic meter (m³ i. N.) is
35.30834 scf = 1 m³ i. N.
NOTE: Actually, a standard cubic meter is not a unit of vol-
ume, but a unit of amount of substance, which occupies
a volume of one cubic meter given standard conditions.
Parameters (3)
The parameters are optional, i.e., each can be ommited, in which case
a default value is used. If any are supplied, the parameters must be
listed in the correct sequence. To omit a parameter while still
supplying one later in the sequence, replace it with "[]" (a MATLAB
empty matrix).
Number|Description
------|------------------------------------------------------------------
1 |Vector of 52 initial states; if empty, default values of Mode 1
|(see [1]) are used.
2 |Scalar for seed of Random generator; if empty, default value is
|used.
3 |Structure parameter; by means of this parameter, the features of
|the revised model can be activated. The base version is the one
|C-s-function of [2]. The value of this parameter is evaluated bi-
|nary. That is, every bit of this parameter (given in integer re-
|presentation) represents a switch for one feature. Setting one bit
|to changes the model in comparison to the original model. Thus, if
|the parameter is 0, the model is the model equals the original mo-
|del (except for the change, which allow for a faster computation;
|turned of by setting bit 15 to 1).
| Bit | Description
| -----|----------------------------------------------------------
| 0 |Activation of additional process measurments
| 1 |Activation of the monitoring output for the values which
| |are subject to process disturbances of the type "random"
| |(random variation); Output 2
| 2 |Activation of the monitoring output for the internal
| |values of the reaction anf process; Output 3
| 3 |Activation of the monitoring output for the concentrations
| |of the components of in the process units; Output 4
| 4 |Deactivation of the measurement noise
| 5 |Set random number generator to use two states, one for the
| |generation of the measurment noise and one for the gene-
| |ration of the process disturbances
| 6 |Activation of the recalculation of the process disturban-
| |ces based on the pre-determined time
| 7 |Activation of the scaling of the disturbances between 0
| |and 100% (0 and 1) using the disturbance activation flags
| 15 |Reset of the model to the original structure, including
| |the adaption of the program flow of the model to the pro-
| |gram flow of the simulation
States (50)
Number|Description |Unit
------|---------------------------------------------------------|--------
1 |Holdup of component A in vapor phase of reactor |lb-mol
2 |Holdup of component B in vapor phase of reactor |lb-mol
3 |Holdup of component C in vapor phase of reactor |lb-mol
4 |Holdup of component D in liquid phase of reactor |lb-mol
5 |Holdup of component E in liquid phase of reactor |lb-mol
6 |Holdup of component F in liquid phase of reactor |lb-mol
7 |Holdup of component G in liquid phase of reactor |lb-mol
8 |Holdup of component H in liquid phase of reactor |lb-mol
9 |Internal energy of reactor |MM BTU
10 |Holdup of component A in vapor phase of seperator |lb-mol
11 |Holdup of component B in vapor phase of seperator |lb-mol
12 |Holdup of component C in vapor phase of seperator |lb-mol
13 |Holdup of component D in liquid phase of seperator |lb-mol
14 |Holdup of component E in liquid phase of seperator |lb-mol
15 |Holdup of component F in liquid phase of seperator |lb-mol
16 |Holdup of component G in liquid phase of seperator |lb-mol
17 |Holdup of component H in liquid phase of seperator |lb-mol
18 |Internal energy of seperator |MM BTU
19 |Holdup of component A in liquid phase of stripper (sump) |lb-mol
20 |Holdup of component B in liquid phase of stripper (sump) |lb-mol
21 |Holdup of component C in liquid phase of stripper (sump) |lb-mol
22 |Holdup of component D in liquid phase of stripper (sump) |lb-mol
23 |Holdup of component E in liquid phase of stripper (sump) |lb-mol
24 |Holdup of component F in liquid phase of stripper (sump) |lb-mol
25 |Holdup of component G in liquid phase of stripper (sump) |lb-mol
26 |Holdup of component H in liquid phase of stripper (sump) |lb-mol
27 |Internal energy of stripper (sump) |MM BTU
28 |Holdup of component A in vapor phase of header (stream 6)|lb-mol
29 |Holdup of component B in vapor phase of header (stream 6)|lb-mol
30 |Holdup of component C in vapor phase of header (stream 6)|lb-mol
31 |Holdup of component D in vapor phase of header (stream 6)|lb-mol
32 |Holdup of component E in vapor phase of header (stream 6)|lb-mol
33 |Holdup of component F in vapor phase of header (stream 6)|lb-mol
34 |Holdup of component G in vapor phase of header (stream 6)|lb-mol
35 |Holdup of component H in vapor phase of header (stream 6)|lb-mol
36 |Internal energy of header (stream 6) |MM BTU
37 |Temperature cooling water outlet of reactor |°C
38 |Temperature cooling water outlet of separator |°C
39 |Valve position feed component D (stream 2) |%
40 |Valve position feed component E (stream 3) |%
41 |Valve position feed component A (stream 1) |%
42 |Valve position feed component A & C (stream 4) |%
43 |Valve position compressor re-cycle |%
44 |Valve position purge (stream 9) |%
45 |Valve position underflow separator (stream 10) |%
46 |Valve position underflow stripper (stream 11) |%
47 |Valve position stripper steam |%
48 |Valve position cooling water outlet of reactor |%
49 |Valve position cooling water outlet of separator |%
50 |Rotation of agitator of reactor |%
Inputs (12 manipulated variables + 28 disturbance flags)
Number|Description
------|------------------------------------------------------------------
1 |Valve position feed component D (stream 2)
2 |Valve position feed component E (stream 3)
3 |Valve position feed component A (stream 1)
4 |Valve position feed component A & C (stream 4)
5 |Valve position compressor re-cycle
6 |Valve position purge (stream 9)
7 |Valve position underflow separator (stream 10)
8 |Valve position underflow stripper (stream 11)
9 |Valve position stripper steam
10 |Valve position cooling water outlet of reactor
11 |Valve position cooling water outlet of separator
12 |Rotation of agitator of reactor
Number|Type |Disturbed Value
------|-----------|------------------------------------------------------
1 |Step |A/C-ratio of stream 4, B composition constant
2 |Step |B composition of stream 4, A/C-ratio constant
3 |Step |D feed (stream 2) temperature
4 |Step |Cooling water inlet temperature of reactor
5 |Step |Cooling water inlet temperature of separator
6 |Step |A feed loss (stream 1)
7 |Step |C header pressure loss (stream 4)
8 |Random |A/B/C composition of stream 4
9 |Random |D feed (stream 2) temperature
10 |Random |C feed (stream 4) temperature
11 |Random |Cooling water inlet temperature of reactor
12 |Random |Cooling water inlet temperature of separator
13 |Drift |Reaction kinetics
14 |Stiction |Cooling water outlet valve of reactor
15 |Stiction |Cooling water outlet valve of separator
16 |Random |(unknown); deviations of heat transfer within stripper
| |(heat exchanger)
17 |Random |(unknown); deviations of heat transfer within reactor
18 |Random |(unknown); deviations of heat transfer within conden-
| |ser
19 |Stiction |(unknown); re-cycle valve of compressor, underflow
| |separator (stream 10), underflow stripper (stream 11)
| |and steam valve stripper
20 |Random |(unknown)
-------------------------------------------------------------------------
a d d i t i o n a l p r o c e s s d i s t u r b a n c e s
-------------------------------------------------------------------------
21 |Random |A feed (stream 1) temperature
22 |Random |E feed (stream 3) temperature
23 |Random |A feed (stream 1) pressure ( = flow)
24 |Random |D feed (stream 2) pressure ( = flow)
25 |Random |E feed (stream 3) pressure ( = flow)
26 |Random |A & C feed (stream 4) pressure ( = flow)
27 |Random |Cooling water pressure ( = flow) of reactor
28 |Random |Cooling water pressure ( = flow) of condenser
Outputs
The number of active outputs depends on the value of the structure para-
meter of the model. Output 1 with outputs 1 through 41 is the default
output. The other outputs (values) are additional.
Output 1 - Measured Values
Number|Description |Unit
------|---------------------------------------------------|------------
1 |Feed flow component A (stream 1) |kscmh
2 |Feed flow component D (stream 2) |kg/h
3 |Feed flow component E (stream 3) |kg/h
4 |Feed flow components A & C (stream 4) |kscmh
5 |Recycle flow to reactor from separator (stream 8) |kscmh
6 |Reactor feed (stream 6) |kscmh
7 |Reactor pressure |kPa gauge
8 |Reactor level |%
9 |Reactor temperature |°C
10 |Purge flow (stream 9) |kscmh
11 |Separator temperature |°C
12 |Separator level |%
13 |Separator pressure |kPa gauge
14 |Sperator underflow (liquid phase) |m³/h
15 |Stripper level |%
16 |Stripper pressure |kPa gauge
17 |Stripper underflow (stream 11) |m³/h
18 |Stripper temperature |°C
19 |Stripper steam flow |kg/h
20 |Compressor work |kW
21 |Reactor cooling water outlet temperature |°C
22 |Condenser cooling water outlet temperature |°C
23 |Concentration of A in Reactor feed (stream 6) |mol %
24 |Concentration of B in Reactor feed (stream 6) |mol %
25 |Concentration of C in Reactor feed (stream 6) |mol %
26 |Concentration of D in Reactor feed (stream 6) |mol %
27 |Concentration of E in Reactor feed (stream 6) |mol %
28 |Concentration of F in Reactor feed (stream 6) |mol %
29 |Concentration of A in Purge (stream 9) |mol %
30 |Concentration of B in Purge (stream 9) |mol %
31 |Concentration of C in Purge (stream 9) |mol %
32 |Concentration of D in Purge (stream 9) |mol %
33 |Concentration of E in Purge (stream 9) |mol %
34 |Concentration of F in Purge (stream 9) |mol %
35 |Concentration of G in Purge (stream 9) |mol %
36 |Concentration of H in Purge (stream 9) |mol %
37 |Concentration of D in stripper underflow (stream |mol %
|11) |
38 |Concentration of E in stripper underflow (stream |mol %
|11) |
39 |Concentration of F in stripper underflow (stream |mol %
|11) |
40 |Concentration of G in stripper underflow (stream |mol %
|11) |
41 |Concentration of H in stripper underflow (stream |mol %
|11) |
-----------------------------------------------------------------------
a d d i t i o n a l o u t p u t v a l u e s
-----------------------------------------------------------------------
42 |Feed component A temperature (stream 1) |°C
43 |Feed component D temperature (stream 2) |°C
44 |Feed component E temperature (stream 3) |°C
45 |Feed component A & C temperature (stream 4) |°C
46 |Reactor cooling water inlet temperature |°C
47 |Reactor cooling water flow |m³/h
48 |Condenser cooling water inlet temperature |°C
49 |Condenser cooling water flow |m³/h
50 |Concentration of A in stream 1 |mol %
51 |Concentration of B in stream 1 |mol %
52 |Concentration of C in stream 1 |mol %
53 |Concentration of D in stream 1 |mol %
54 |Concentration of E in stream 1 |mol %
55 |Concentration of F in stream 1 |mol %
56 |Concentration of A in stream 2 |mol %
57 |Concentration of B in stream 2 |mol %
58 |Concentration of C in stream 2 |mol %
59 |Concentration of D in stream 2 |mol %
60 |Concentration of E in stream 2 |mol %
61 |Concentration of F in stream 2 |mol %
62 |Concentration of A in stream 3 |mol %
63 |Concentration of B in stream 3 |mol %
64 |Concentration of C in stream 3 |mol %
65 |Concentration of D in stream 3 |mol %
66 |Concentration of E in stream 3 |mol %
67 |Concentration of F in stream 3 |mol %
68 |Concentration of A in stream 4 |mol %
69 |Concentration of B in stream 4 |mol %
70 |Concentration of C in stream 4 |mol %
71 |Concentration of D in stream 4 |mol %
72 |Concentration of E in stream 4 |mol %
73 |Concentration of F in stream 4 |mol %
Output 2 - Monitoring of Random-Variation-Disturbances
The values given by this output are not subject to measurement noise.
Thus it is not a duplication of the afore listed measured values.
Number|Flag |Value |Unit
------|---------|-----------------------------------------|------------
1 |IDV(8) |Concentration of component A in stream 4 |mol %
2 |IDV(8) |Concentration of component B in stream 4 |mol %
3 |IDV(8) |Concentration of component C in stream 4 |mol %
4 |IDV(9) |Feed component D temperature (stream 2) |°C
5 |IDV(10) |Feed components A & C temperature (stream|°C
| |4) |
6 |IDV(11) |Reactor cooling water inlet tempreature |°C
7 |IDV(12) |Condenser cooling water inlet tempreature|°C
8 |IDV(13) |Deviations of reaction kinetics of first |1
| |reaction (A + C + D -> G) |
9 |IDV(13) |Deviations of reaction kinetics of second|1
| |reaction (A + C + E -> F) |
10 |IDV(16) |(unknown); deviations of heat transfer |1
| |of stripper |
11 |IDV(17) |(unknown); deviations of heat transfer |1
| |reactor |
12 |IDV(18) |(unknown); deviations of heat transfer |1
| |condenser |
13 |IDV(20) |(unknown) |
-----------------------------------------------------------------------
a d d i t i o n a l p r o c e s s d i s t u r b a n c e s
-----------------------------------------------------------------------
14 |IDV(21) |Feed component A temperature (stream 1) |°C
15 |IDV(22) |Feed component E temperature (stream 3) |°C
16 |IDV(23) |Feed component A pressure (stream 1); |kmol/h
| |deviation of base value of flow |
17 |IDV(24) |Feed component D pressure (stream 2); |kmol/h
| |deviation of base value of flow |
18 |IDV(25) |Feed component A pressure (stream 3); |kmol/h
| |deviation of base value of flow |
19 |IDV(26) |Feed components A & C pressure (stream |kmol/h
| |4); deviation of base value of flow |
20 |IDV(27) |Reactor cooling water supply pressure; |m³/h
| |deviation of base value of flow |
21 |IDV(28) |Condenser cooling water supply pressure; |m³/h
| |deviation of base value of flow |
Output 3 - Monitoring of Reaction and Analyzers
Number|Value |Unit
------|---------------------------------------------------|------------
1 |Consumption of component A (reator) (value < 0) |kmol/h
2 |Consumption of component C (reator) (value < 0) |kmol/h
3 |Consumption of component D (reator) (value < 0) |kmol/h
4 |Consumption of component E (reator) (value < 0) |kmol/h
5 |Creation of component F (reator) (value > 0) |kmol/h
6 |Creation of component G (reator) (value > 0) |kmol/h
7 |Creation of component H (reator) (value > 0) |kmol/h
8 |Partial pressure of component A (reactor) |kPa abs
9 |Partial pressure of component B (reactor) |kPa abs
10 |Partial pressure of component C (reactor) |kPa abs
11 |Partial pressure of component D (reactor) |kPa abs
12 |Partial pressure of component E (reactor) |kPa abs
13 |Partial pressure of component F (reactor) |kPa abs
14 |Partial pressure of component G (reactor) |kPa abs
15 |Partial pressure of component H (reactor) |kPa abs
16 |Delay-free concentration of A in reactor feed |mol %
|(stream 6) |
17 |Delay-free concentration of B in reactor feed |mol %
|(stream 6) |
18 |Delay-free concentration of C in reactor feed |mol %
|(stream 6) |
19 |Delay-free concentration of D in reactor feed |mol %
|(stream 6) |
20 |Delay-free concentration of E in reactor feed |mol %
|(stream 6) |
21 |Delay-free concentration of F in reactor feed |mol %
|(stream 6) |
22 |Delay-free concentration of A in purge (stream 9) |mol %
23 |Delay-free concentration of B in purge (stream 9) |mol %
24 |Delay-free concentration of C in purge (stream 9) |mol %
25 |Delay-free concentration of D in purge (stream 9) |mol %
26 |Delay-free concentration of E in purge (stream 9) |mol %
27 |Delay-free concentration of F in purge (stream 9) |mol %
28 |Delay-free concentration of G in purge (stream 9) |mol %
29 |Delay-free concentration of H in purge (stream 9) |mol %
30 |Delay-free concentration of H in product stream |mol %
|strom (stream 11) |
31 |Delay-free concentration of D in product stream |mol %
|(stream 11) |
32 |Delay-free concentration of E in product stream |mol %
|(stream 11) |
33 |Delay-free concentration of F in product stream |mol %
|(stream 11) |
34 |Delay-free concentration of G in product stream |mol %
|(stream 11) |
35 |Delay-free concentration of A in feed A (stream 1) |mol %
36 |Delay-free concentration of B in feed A (stream 1) |mol %
37 |Delay-free concentration of C in feed A (stream 1) |mol %
38 |Delay-free concentration of D in feed A (stream 1) |mol %
39 |Delay-free concentration of E in feed A (stream 1) |mol %
40 |Delay-free concentration of F in feed A (stream 1) |mol %
41 |Delay-free concentration of A in feed D (stream 2) |mol %
42 |Delay-free concentration of B in feed D (stream 2) |mol %
43 |Delay-free concentration of C in feed D (stream 2) |mol %
44 |Delay-free concentration of D in feed D (stream 2) |mol %
45 |Delay-free concentration of E in feed D (stream 2) |mol %
46 |Delay-free concentration of F in feed D (stream 2) |mol %
47 |Delay-free concentration of A in feed E (stream 3) |mol %
48 |Delay-free concentration of B in feed E (stream 3) |mol %
49 |Delay-free concentration of C in feed E (stream 3) |mol %
50 |Delay-free concentration of D in feed E (stream 3) |mol %
51 |Delay-free concentration of E in feed E (stream 3) |mol %
52 |Delay-free concentration of F in feed E (stream 3) |mol %
53 |Delay-free concentration of A in feed A & C (stream|mol %
|4) |
54 |Delay-free concentration of A in feed A & C (stream|mol %
|4) |
55 |Delay-free concentration of A in feed A & C (stream|mol %
|4) |
56 |Delay-free concentration of A in feed A & C (stream|mol %
|4) |
57 |Delay-free concentration of A in feed A & C (stream|mol %
|4) |
58 |Delay-free concentration of A in feed A & C (stream|mol %
|4) |
59 |Production costs, based on the measured (noise-cor-|ct/(kmol
|rupted) values relative to the amount of product | product)
60 |Calculation of 59 based on the internal (noise- |ct/(kmol
|free) values | product)
61 |Production costs, based on the measured (noise-cor-|$/h
|rupted) values relative to time |
62 |Calculation of 61 based on the internal (noise- |$/h
|free) values (see [1]) |
Output 4 - Concentration within the process units
Every group of eight values gives the concentrations of the components
A through H within different sections of the process.
Number |Section |Unit
-------|---------------------------------------------------|-----------
1 - 8 |Feed component D (stream 2) |mol %
9 - 16 |Feed component E (stream 3) |mol %
17 - 24|Feed component A (stream 1) |mol %
25 - 32|Feed components A & C (stream 4) |mol %
33 - 40|Stripper overhead (stream 5) |mol %
41 - 48|Reactor feed (stream 6) |mol %
49 - 56|Reactor effluent (stream 7) |mol %
57 - 64|Recycle to reactor from separator (stream 8) |mol %
65 - 72|Purge (stream 9) |mol %
73 - 80|Separator underflow (stream 10) |mol %
81 - 88|Stripper; Liquid entering sump |mol %
89 - 96|Stripper underflow (stream 11) |mol %
Version
1.3.3
Latest Change
12/18/2014
S-Function Change-Log
Version |Date |Description
--------|-----------|----------------------------------------------------
1.0.0 |12/31/1998 |Base version of the Tennessee Eastman Process model
| |for MATLAB by N. L. Ricker (ricker@u.washington.edu)
1.1.0 |10/29/2013 |Extensions of the paramter list
| | 1. Initial value for the random number generation
| | The parameter list was extended by another
| | (scalar) parameter, which inititializes the
| | state of the random number generator. This fa-
| | cilitates the simulation of the model with
| | diffrent disturbance characteristics (evolu-
| | tions).
| | 2. Deactivarion of measurement noise
| | The second new parameter (third overall) is
| | used to switch off the measurement noise. That
| | is the amplitudes of the measurment noise will
| | be set to 0, if the parmater has the value 1
| |Extension of the values returned by the model
| | In addition to the 41 return values described in
| | [1] (process measurments), the 13 values subject
| | to (random walk) process disturbances are retur-
| | ned. These values are mere monitoring values.
1.1.1 |11/12/2013 |Extension of the usage of the IDV flags
| | The values of the IDV flags (activation of process
| | disturbances) are now used to scale the amplitudes
| | of the disturbances between 0 and 1 (100%).
1.2.0 |03/20/2014 |Matching of the release level of "temexd_mod.c" and
| |"temex_mod.c"
| | The release level of "temexd_mod.c" and
| | "temex_mod.c" was matched in terms of the code and
| | annotations.
| |Allocation of (local) memory cell for the model data
| | The model data, which is made of the genuine pro-
| | cess data and the control data (e.g. state of the
| | random generator), had been one global memory
| | cell. Thus the operating of two (or more) proces-
| | ses within one simulation model was not possible,
| | since the process models mutally overwrote their
| | data. A correct simulation is than impossible.
| | Now, the model data was encapsulated within one
| | data structure, which is used to allocate memory
| | of appropriate size for the model data. That is,
| | at the beginning of the simulation each processes
| | model allocates memory for its model data and is
| | thus independend from the other process models.
| | The addressing of the memory is made using the
| | pointer to the memory and the Pwork vector of the
| | s-function.
1.3.0 |03/31/2014 |Independence of solver
| | By adding another state for the random number ge-
| | nerator and a slight change of the recalculation
| | of the (random walk) process disturbance poly-
| | nomials, the calculation and simulation of the
| | process disturbance is now independend from the
| | choice of the solver and simulation time incre-
| | ment. That is, the evolution of the process dis-
| | turbances is always the same, irrespective of the
| | solver. A complete description is given in [3].
| |Reduced program flow
| | Since 'tefunc' calculates the whole process model,
| | i.e. the state of the processes as well as the
| | outputs and derivatives of the simulation states,
| | and is called twice per simulation time step (cal-
| | (culation of the outputs in 'mdlOutputs' and cal-
| | culation of the derivaties in 'mdlDerivatives'),
| | unnecessary calculations are performed (the calcu-
| | lation of the derivatives in 'mdlOutputs' is not
| | needed and vice versa). Introducing a program flow
| | flag, which indicates the current position of the
| | simulation run, the not needed caluclation are
| | omited. See also [3]
| |Additional outputs
| | The outputs are extended by another set of moni-
| | toring outputs and by addiional process measur-
| | ments. Furthermore the outputs are structured in
| | order to group all the outputs logically. There is
| | now an output (vector) for the measured values,
| | for monitored process disturbances, for internal
| | process values and for the component concentra-
| | tions.
| | (The last output is created, but not yet "connec-
| | ted with the respective values.)
| |Model structure parameter
| | The third parameter of the parameter list has been
| | changed to a parameter, which determines the acti-
| | vation of the changes made to the original process
| | model and thus the structure of the model. It is
| | one parameter (integer value) whose binary struc-
| | ture determines the activation (each bit is as-
| | signed to one modification).
1.3.1 |10/20/2014 |The forth output group is now operating.
1.3.2 |11/19/2014 |Changes of the declaration of variables in 'mdl-
| |CheckParameters' (Bug-fix)
| | The array and one auxillary variable which were
| | declared as 'int_T' but used in connection with
| | the method 'mxGetNumberOfElements' which returns
| | values of type 'size_t' caused a compiler warning.
| | Depending of the compiler setup, this warning
| | could cause an abortion of the compilation.
| |Changes of the disturbance recalculation
| | In order to switch the process model back to the
| | original one (version 1.0), all the changes need
| | to be ignored. This also includes the recalcula-
| | tion of the 7 new (random walk) process disturban-
| | ces using the original recaulculation procedure.
| | These 7 disturbance are now skipped in this case
| | to keep the random number generator from additio-
| | nal runs which wouldn't occur in the original mo-
| | del.
| |Optional parameter list
| | The parameters are no longer a requiered element
| | for the simulation. If all or some are omited, the
| | respective value will be replace by a default
| | value.
1.3.3 |12/18/2014 |Revised Feed-through-property
| | The internal handling of the input (done by 'get-
| | Curr()') is changed according to the calculation
| | of the process in 'mdlOutputs' and 'mdlDeriva-
| | tives'. The inputs (manipulated variables and IDV)
| | are exclusively read in during the execution of
| | 'mdlDerivatives' and not anymore with the execu-
| | tion of 'mdlOutputs'. Thus the input can be set to
| | be an non-feed-through-input. This eases the use
| | of the model in conjunction with a controller. In
| | fact, this property was just a remnant of the ori-
| | ginal code, since the valves already possess first
| | order characteristics.
| |Changes of the span of the cooling water flow dis-
| |turbances
| | The maximal span of the deviations of the nominal
| | (100%) flow of the reactor and condenser cooling
| | water is changed from 5 (gpm) to 5% of the re-
| | spective nominal values.
| |Bug-fixes
| | - Inserting of missing break statements at the
| | switch-case-command of the call of 'teinit()'
| | for different parameter sets.
| | - Correction of the conditions of if-statements
| | masking the first bit of the structure parameter
| | (comparison with respect to equality to one and
| | great than one)
| | - Usage of wrong base index while calculating the
| | outputs of the input stream analyzers
*/
/**************************************************************************
* *
* S - F U N C T I O N D E S C R I P T I O N *
* *
**************************************************************************/
#define S_FUNCTION_NAME temexd_mod
#define S_FUNCTION_LEVEL 2
/**************************************************************************
* *
* I N C L U D E S *
* *
**************************************************************************/
#include "math.h"
#include "simstruc.h"
#include "teprob_mod.h"
/**************************************************************************
* *
* D E F I N I T I O N S *
* *
**************************************************************************/
#define IS_PARAM_DOUBLE(pVal) (mxIsNumeric(pVal) && !mxIsLogical(pVal) &&\
!mxIsEmpty(pVal) && !mxIsSparse(pVal) &&\
!mxIsComplex(pVal) && mxIsDouble(pVal))
/*-------------------------------------------------------------------------
- A c t i v a t i o n o f S - f u n c t i o n - m e t h o d s -
-------------------------------------------------------------------------*/
#define MDL_CHECK_PARAMETERS
#undef MDL_PROCESS_PARAMETERS
#undef MDL_SET_INPUT_PORT_FRAME_DATA
#undef MDL_SET_INPUT_PORT_WIDTH
#undef MDL_SET_OUTPUT_PORT_WIDTH
#undef MDL_SET_INPUT_PORT_DIMENSION_INFO
#undef MDL_SET_OUTPUT_PORT_DIMENSION_INFO
#undef MDL_SET_DEFAULT_PORT_DIMENSION_INFO
#undef MDL_SET_INPUT_PORT_SAMPLE_TIME
#undef MDL_SET_OUTPUT_PORT_SAMPLE_TIME
#undef MDL_SET_INPUT_PORT_DATA_TYPE
#undef MDL_SET_OUTPUT_PORT_DATA_TYPE
#undef MDL_SET_DEFAULT_PORT_DATA_TYPES
#undef MDL_SET_INPUT_PORT_COMPLEX_SIGNAL
#undef MDL_SET_OUTPUT_PORT_COMPLEX_SIGNAL
#undef MDL_SET_DEFAULT_PORT_COMPLEX_SIGNALS
#undef MDL_SET_WORK_WIDTHS
#define MDL_INITIALIZE_CONDITIONS
#define MDL_START
#undef MDL_SIM_STATE
#undef MDL_GET_TIME_OF_NEXT_VAR_HIT
#undef MDL_ZERO_CROSSINGS
#undef MDL_UPDATE
#define MDL_DERIVATIVES
#undef MDL_RTW
/**************************************************************************
* *
* D E F I N I T I O N S O F I N T E R N A L T Y P E S *
* *
***************************************************************************
---------------------------------------------------------------------------
- P r o c e s s V a l u e s -
-------------------------------------------------------------------------*/
struct ProcessValues {
doublereal xmeas[41], xmeasadd[32], xmeasdist[21], xmeasmonitor[62],
xmeascomp[96], xmv[12];
};
/*-------------------------------------------------------------------------
- D i s t V e c t o r -
-------------------------------------------------------------------------*/
struct DistVector{
doublereal idv[29];
};
/*-------------------------------------------------------------------------
- R a n d S t a t e -
-------------------------------------------------------------------------*/
struct RandState {
doublereal g;
doublereal measnoise;
doublereal procdist;
};
/*-------------------------------------------------------------------------
- C o m p o n e n t D a t a -
-------------------------------------------------------------------------*/
struct ComponentData{
doublereal avp[8], bvp[8], cvp[8], ah[8], bh[8], ch[8], ag[8], bg[8],
cg[8], av[8], ad[8], bd[8], cd[8], xmw[8];
};
/*-------------------------------------------------------------------------
- P r o c e s s -
-------------------------------------------------------------------------*/
struct Process{
doublereal uclr[8] , ucvr[8] , utlr , utvr ,
xlr[8] , xvr[8] , etr , esr ,
tcr , tkr , dlr , vlr ,
vvr , vtr , ptr , ppr[8] ,
crxr[8] , rr[4] , rh , fwr ,
twr , qur , hwr , uar ,
ucls[8] , ucvs[8] , utls , utvs ,
xls[8] , xvs[8] , ets , ess ,
tcs , tks , dls , vls ,
vvs , vts , pts , pps[8] ,
fws , tws , qus , hws ,
uclc[8] , utlc , xlc[8] , etc ,
esc , tcc , dlc , vlc ,
vtc , quc ,
ucvv[8] , utvv , xvv[8] , etv ,
esv , tcv , tkv , vtv ,
ptv , vcv[12] , vrng[12] , vtau[12] ,
ftm[13] , fcm[104], xst[104], xmws[13] ,
hst[13] , tst[13] , sfr[8] , cpflmx ,
cpprmx , cpdh , tcwr , tcws ,
htr[3] , agsp , xdel[41] , xdeladd[24] ,
xns[41] , xnsadd[34] , tgas , tprod ,
vst[12] , ivst[12];
};
/*-------------------------------------------------------------------------
- R a n d P r o c e s s -
-------------------------------------------------------------------------*/
struct RandProcess {
doublereal adist[20], bdist[20], cdist[20], ddist[20], tlast[20],
tnext[20], hspan[20], hzero[20], sspan[20], szero[20],
spspan[20];
doublereal idvwlk[20];
doublereal rdumm;
};
/*-------------------------------------------------------------------------
- s t M o d e l D a t a -
-------------------------------------------------------------------------*/
struct stModelData {
struct ProcessValues pv_;
struct DistVector dvec_;
struct RandState randsd_;
struct ComponentData const_;
struct Process teproc_;
struct RandProcess wlk_;
char msg[256];
doublereal code_sd;
doublereal tlastcomp;
integer MSFlag;
};
/**************************************************************************
* *
* D E F I N I T I O N S O F C O N S T A N T S *
* *
***************************************************************************
---------------------------------------------------------------------------
- S - F u n c t i o n - C o n s t a n t s -
-------------------------------------------------------------------------*/
const integer NX = 50;
const int NU = 12;
const int NIDV = 28;
const int NY = 41;
const int NYADD = 32;
const int NYDIST = 21;
const int NYMONITOR = 62;
const int NYCOMP = 96;
const int NPAR = 3;
/*-------------------------------------------------------------------------
- C o n s t a n t s o f P r o c e s s m o d e l -
-------------------------------------------------------------------------*/
const integer c__50 = 50;
const integer c__12 = 12;
const integer c__21 = 21;
const integer c__153 = 153;
const integer c__586 = 586;
const integer c__139 = 139;
const integer c__6 = 6;
const integer c__1 = 1;
const integer c__0 = 0;
const integer c__41 = 41;
const integer c__2 = 2;
const integer c__3 = 3;
const integer c__4 = 4;
const integer c__5 = 5;
const integer c__7 = 7;
const integer c__8 = 8;
const doublereal c_b73 = 1.1544;
const doublereal c_b74 = .3735;
const integer c__9 = 9;
const integer c__10 = 10;
const integer c__11 = 11;
const doublereal c_b123 = 4294967296.;
const integer c__13 = 13;
const integer c__14 = 14;
const integer c__15 = 15;
const integer c__16 = 16;
const integer c__17 = 17;
const integer c__18 = 18;
const integer c__19 = 19;
const integer c__20 = 20;
/**************************************************************************
* *
* S - F U N C T I O N - M E T H O D S *
* *
***************************************************************************
* Level 2 S-function methods
* --------------------------
* Notation: "=>" indicates method is required.
* [method] indicates method is optional.
*
* Note, many of the methods below are only available for use in level 2
* C-MEX S-functions.
*
* Model Initialization in Simulink
* --------------------------------
*=> mdlInitializeSizes - Initialize SimStruct sizes array
*
* [mdlSetInputPortFrameData] - Optional method. Check and set input and
* output port frame data attributes.
*
* NOTE: An S-function cannot use mdlSetInput(Output)PortWidth and
* mdlSetInput(Output)PortDimensionInfo at the same time. It can use
* either a width or dimension method, but not both.
*
* [mdlSetInputPortWidth] - Optional method. Check and set input and
* optionally other port widths.
* [mdlSetOutputPortWidth] - Optional method. Check and set output
* and optionally other port widths.
*
* [mdlSetInputPortDimensionInfo]
* - Optional method. Check and set input and
* optionally other port dimensions.
* [mdlSetOutputPortDimensionInfo]
* - Optional method. Check and set output
* and optionally other port dimensions.
* [mdlSetDefaultPortDimensionInfo]
* - Optional method. Set dimensions of all
* input and output ports that have unknown
* dimensions.
*
* [mdlSetInputPortSampleTime] - Optional method. Check and set input
* port sample time and optionally other
* port sample times.
* [mdlSetOutputPortSampleTime]- Optional method. Check and set output
* port sample time and optionally other
* port sample times.
*=> mdlInitializeSampleTimes - Initialize sample times and optionally
* function-call connections.
*
* [mdlSetInputPortDataType] - Optional method. Check and set input
* port data type. See SS_DOUBLE to
* SS_BOOEAN in simstruc_types.h for
* built-in data types.
* [mdlSetOutputPortDataType] - Optional method. Check and set output
* port data type. See SS_DOUBLE to
* SS_BOOLEAN in simstruc_types.h for
* built-in data types.
* [mdlSetDefaultPortDataTypes] - Optional method. Set data types of all
* dynamically typed input and output
* ports.
*
* [mdlInputPortComplexSignal] - Optional method. Check and set input
* port complexity attribute (COMPLEX_YES,
* COMPLEX_NO).
* [mdlOutputPortComplexSignal] - Optional method. Check and set output
* port complexity attribute (COMPLEX_YES,
* COMPLEX_NO).
* [mdlSetDefaultPortComplexSignals]
* - Optional method. Set complex signal
* flags of all input and output ports who
* have their complex signals set to
* COMPLEX_INHERITED (dynamic complexity).
*
* [mdlSetWorkWidths] - Optional method. Set the state, iwork,
* rwork, pwork, dwork, etc sizes.
*
* [mdlStart] - Optional method. Perform actions such
* as allocating memory and attaching to
* pwork elements.
*
* [mdlInitializeConditions] - Initialize model parameters (usually
* states). Will not be called if your
* S-function does not have an initialize
* conditions method.
*
* ['constant' mdlOutputs] - Execute blocks with constant sample
* times. These are only executed once
* here.
*
* [mdlSetSimState] - Optional method. Load the complete simu-
* lation state for this block, which is
* called when starting the simulation from
* an initial simulation state and this s-
* function has set its ssSetSimStateCom-
* pliance to USE_CUSTOM_SIM_STATE. See
* also mdlGetSimState
*
* Model simulation loop in Simulink
* ---------------------------------
* [mdlCheckParameters] - Optional method. Will be called at
* any time during the simulation loop when
* parameters change.
* SimulationLoop:
* [mdlProcessParameters] - Optional method. Called during
* simulation after parameters have been
* changed and verified to be okay by
* mdlCheckParameters. The processing is
* done at the "top" of the simulation
* loop when it is safe to process the
* changed parameters.
* [mdlGetTimeOfNextVarHit] - Optional method. If your S-function