Te
Te
Te
=
=
=
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 devised 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 model uses a parameter for the purpose of passing the activation).
Since this is only the source code of the model, it is necessary to compile the model before using it. Please refer to the installation instructions 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. Bathelt 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-mailaddress 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 compiler 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).
one standard cubic meter is independent of the substance under consideration and always 44.615 mol (assumption of ideal
gas). The values of pressure, temperature and relativ humidity 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 Institut fr 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 volume, 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
5
6
7
8
9
10
11
12
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 parameter 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
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
|Concentration
of
of
of
of
of
of
of
of
of
of
of
of
of
of
of
of
C
D
E
F
A
B
C
D
E
F
A
B
C
D
E
F
in
in
in
in
in
in
in
in
in
in
in
in
in
in
in
in
stream
stream
stream
stream
stream
stream
stream
stream
stream
stream
stream
stream
stream
stream
stream
stream
2
2
2
2
3
3
3
3
3
3
4
4
4
4
4
4
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
|mol
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
1.1.1
1.2.0
1.3.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|11/12/2013
|
|
|
|03/20/2014
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|03/31/2014
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|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%).
|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.
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.3.1 |10/20/2014
1.3.2 |11/19/2014
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.3.3 |12/18/2014
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
/**************************************************************************
*
*
*
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
#undef
#undef
#undef
#define
#define
#undef
#undef
#undef
#undef
#define
#undef
MDL_SET_INPUT_PORT_COMPLEX_SIGNAL
MDL_SET_OUTPUT_PORT_COMPLEX_SIGNAL
MDL_SET_DEFAULT_PORT_COMPLEX_SIGNALS
MDL_SET_WORK_WIDTHS
MDL_INITIALIZE_CONDITIONS
MDL_START
MDL_SIM_STATE
MDL_GET_TIME_OF_NEXT_VAR_HIT
MDL_ZERO_CROSSINGS
MDL_UPDATE
MDL_DERIVATIVES
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
xlr[8] ,
xvr[8] ,
etr
,
tcr
,
tkr
,
utvr
esr
,
dlr
,
,
vlr
,
vvr
vtr
,
crxr[8] ,
ptr
,
rr[4] ,
ppr[8] ,
rh
,
fwr
,
twr
ucls[8]
xls[8]
tcs
vvs
,
qur
,
hwr
,
uar
,
,
ucvs[8] ,
utls
,
utvs
,
,
xvs[8] ,
ets
,
ess
,
,
tks
,
dls
,
vls
,
,
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] ,
vst[12] ,
ivst[12];
tgas
tprod
};
/*------------------------------------------------------------------------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
*
has a variable step sample time, then
*
this method will be called.
*
[mdlInitializeConditions]- Optional method. Only called if your
*
S-function resides in an enabled
*
subsystem configured to reset states,
*
and the subsystem has just enabled.
*
=> mdlOutputs
- Major output call (usually updates
*
output signals).
*
[mdlUpdate]
- Update the discrete states, etc.
*
*
Integration (Minor time step)
*
[mdlDerivatives]
- Compute the derivatives.
*
Do
*
[mdlOutputs]
*
[mdlDerivatives]
*
EndDo - number of iterations depends on solver
*
Do
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
[mdlOutputs]
[mdlZeroCrossings]
EndDo - number of iterations depends on zero crossings signals
EndIntegration
EndSimulationLoop
[mdlGetSimState] - Optional method. Called to get the complete
simulation state for this block if the model is
configured to save its final simulation state and
this S-Function has set its ssSetSimStateCompliance to USE_CUSTOM_SIM_STATE. See also mdlSetSimState
=> mdlTerminate
mdlTerminate
*
[mdlZeroCrossings]
*
EndDo - number of iterations depends on zero crossings signals
* EndExecutionLoop
* mdlTerminate
- End of model housekeeping - free memory,
*
etc.
*/
/*====================================================================*
* Parameter handling methods. These methods are not supported by RTW *
*====================================================================*/
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
/*-------------- P r p r o z e s s o r a n w e i s u n g -----------------------------------------------------------------------------------------m d l C h e c k P a r a m e t e r s
-------------------------------------------------------------------------*/
static void mdlCheckParameters(SimStruct *S){
/*----------------------------- Variables -----------------------------*/
static char msg[256];
size_t Plen[3];
size_t nEls;
int_T i;
/*--------------------------- Function Body ---------------------------*/
Plen[0] = NX;
Plen[1] = 1;
Plen[2] = 1;
for (i=0; i < ssGetSFcnParamsCount(S); i++){
if (!mxIsEmpty(ssGetSFcnParam(S,i))){
if (!IS_PARAM_DOUBLE(ssGetSFcnParam(S,i))){
sprintf(msg,"Error in parameter %i: %s",i+1,
"Parameter must be a real, non-sparse vector.");
ssSetErrorStatus(S,msg);
return;
} //if (!IS_PARAM_DOUBLE(ssGetSFcnParam(S,i)){
nEls = mxGetNumberOfElements(ssGetSFcnParam(S,i));
if (nEls != Plen[i]){
sprintf(msg,"Error in parameter %i: Length = %i"
". Expecting length = %i", i+1, nEls, Plen[i]);
ssSetErrorStatus(S,msg);
return;
} //if (nEls != Plen[i]){
} //if (!mxIsEmpty(ssGetSFcnParam(S,i))){
} //for (i=0; i < ssGetSFcnParamsCount(S); i++){
}
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
#endif //#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
/*=====================================*
* Configuration and execution methods *
*=====================================*/
/*------------------------------------------------------------------------m d l I n i t i a l i z e S i z e s
-------------------------------------------------------------------------*/
static void mdlInitializeSizes(SimStruct *S){
/*----------------------------- Variables -----------------------------*/
integer MSFlag;
integer i__;
/*--------------------------- Function Body ---------------------------*/
if((ssGetSFcnParamsCount(S) < 3) || (mxIsEmpty(ssGetSFcnParam(S,2)))){
MSFlag = 0;
}else{
MSFlag = (integer)*mxGetPr(ssGetSFcnParam(S,2));
} //if((ssGetSFcnParamsCount(S) < 3) || (mxIsEmpty(ssGetSFcnParam(S,2))))
if((MSFlag & 0x8000) > 0){
MSFlag = (integer)0x8000;
} //if((*tcModelData).MSFlag & 0x8000) > 0){
if (NPAR >= ssGetSFcnParamsCount(S)){
ssSetNumSFcnParams(S, ssGetSFcnParamsCount(S));
mdlCheckParameters(S);
if (ssGetErrorStatus(S) != NULL){
return;
} //if (ssGetErrorStatus(S) != NULL){
}else{
ssSetNumSFcnParams(S, NPAR);
return;
/*Simulink will report a parameter mismatch error */
} //if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)){
ssSetNumContStates(S, NX);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 1)){
return;
} //if (!ssSetNumInputPorts(S, 1)){
ssSetInputPortWidth(S, 0, NU+NIDV);
ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1 +
+
+
return;
} //if (!ssSetNumOutputPorts(S,
ssSetOutputPortWidth(S, 0, NY +
//Beobachterausgnge Strungen
if((MSFlag & 0x2) > 0){
ssSetOutputPortWidth(S, 1, NYDIST);
} //if((MSFlag & 0x2) > 0){
//Beobachterausgnge Prozess (Reaktor)
if((MSFlag & 0x4) > 0){
ssSetOutputPortWidth(S, 1 + ((MSFlag & 0x2) >> 1), NYMONITOR);
} //if((MSFlag & 0x4) > 0){
//Beobachterausgnge Stoffkonzentrationen (Prozess)
/*-------------- P r p r o z e s s o r a n w e i s u n g -----------------------------------------------------------------------------------------m d l I n i t i a l i z e C o n d i t i o n s
-------------------------------------------------------------------------*/
static void mdlInitializeConditions(SimStruct *S){
/*----------------------------- Variables -----------------------------*/
real_T *x0;
real_T *pr;
integer nx;
real_T dxdt[50];
real_T rt;
struct stModelData *ModelData;
int_T i;
/*Retrieving and Typcast of Dataset Pointer*/
ModelData = (struct stModelData *)ssGetPWorkValue(S,0);
/*--------------------------- Function Body ---------------------------*/
x0 = ssGetContStates(S);
nx = NX;
rt = 0;
if (ssIsFirstInitCond(S)){
switch(ssGetSFcnParamsCount(S)){
case 3: teinit(ModelData, &nx, &rt, x0, dxdt,
mxGetPr(ssGetSFcnParam(S,1)),
mxGetPr(ssGetSFcnParam(S,2)));
break;
case 2: teinit(ModelData, &nx, &rt, x0, dxdt,
mxGetPr(ssGetSFcnParam(S,1)),NULL);
break;
default: teinit(ModelData, &nx, &rt, x0, dxdt, NULL, NULL);
break;
} //switch(ssGetSFcnParamsCount(S)){
} //if (ssIsFirstInitCond(S)){
if ((ssGetSFcnParamsCount(S) == 0) || (mxIsEmpty(ssGetSFcnParam(S,0)))){
x0[0] = (float)10.40491389;
x0[1] = (float)4.363996017;
x0[2] = (float)7.570059737;
x0[3] = (float).4230042431;
x0[4] = (float)24.15513437;
x0[5] = (float)2.942597645;
x0[6] = (float)154.3770655;
x0[7] = (float)159.186596;
x0[8] = (float)2.808522723;
x0[9] = (float)63.75581199;
x0[10] = (float)26.74026066;
x0[11] = (float)46.38532432;
x0[12] = (float).2464521543;
x0[13] = (float)15.20484404;
x0[14] = (float)1.852266172;
x0[15] = (float)52.44639459;
x0[16] = (float)41.20394008;
x0[17] = (float).569931776;
x0[18] = (float).4306056376;
x0[19] = .0079906200783;
x0[20] = (float).9056036089;
x0[21] = .016054258216;
x0[22] = (float).7509759687;
x0[23] = .088582855955;
x0[24] = (float)48.27726193;
x0[25] = (float)39.38459028;
x0[26] = (float).3755297257;
x0[27] = (float)107.7562698;
x0[28] = (float)29.77250546;
x0[29] = (float)88.32481135;
x0[30] = (float)23.03929507;
x0[31] = (float)62.85848794;
x0[32] = (float)5.546318688;
x0[33] = (float)11.92244772;
x0[34] = (float)5.555448243;
x0[35] = (float).9218489762;
x0[36] = (float)94.59927549;
x0[37] = (float)77.29698353;
x0[38] = (float)63.05263039;
x0[39] = (float)53.97970677;
x0[40] = (float)24.64355755;
x0[41] = (float)61.30192144;
x0[42] = (float)22.21;
x0[43] = (float)40.06374673;
x0[44] = (float)38.1003437;
x0[45] = (float)46.53415582;
x0[46] = (float)47.44573456;
x0[47] = (float)41.10581288;
x0[48] = (float)18.11349055;
x0[49] = (float)50.;
}else{
pr = mxGetPr(ssGetSFcnParam(S,0));
for (i=0; i<nx; i++){
x0[i] = pr[i];
} //for (i=0; i<nx; i++){
} //if (mxIsEmpty(ssGetSFcnParam(S,0))){
(*ModelData).dvec_.idv[28] = (float)0.;
(*ModelData).code_sd = (float)0.;
setidv(S);
}
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
#endif /* MDL_INITIALIZE_CONDITIONS */
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
/*------------------------------------------------------------------------m d l I n i t i a l i z e S a m p l e T i m e s
-------------------------------------------------------------------------*/
static void mdlInitializeSampleTimes(SimStruct *S){
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
/*------------------------------------------------------------------------m d l O u t p u t s
-------------------------------------------------------------------------*/
static void mdlOutputs(SimStruct *S, int_T tid){
/*----------------------------- Variables -----------------------------*/
real_T *y[4];
doublereal rx[50];
doublereal dx[50];
doublereal rt;
struct stModelData *ModelData;
int i;
/*Retrieving and Typcast of Dataset Pointer*/
ModelData = (struct stModelData *)ssGetPWorkValue(S,0);
/*--------------------------- Function Body ---------------------------*/
// Get current time, states, and inputs
rt = getcurr(rx, S, 1);
// Call TEFUNC to update everything
tefunc(ModelData, &NX, &rt, rx, dx, 1);
y[0] = ssGetOutputPortRealSignal(S,0);
y[1] = ssGetOutputPortRealSignal(S,(((*ModelData).MSFlag &
y[2] = ssGetOutputPortRealSignal(S,(((*ModelData).MSFlag &
(((*ModelData).MSFlag &
y[3] = ssGetOutputPortRealSignal(S,(((*ModelData).MSFlag &
(((*ModelData).MSFlag &
(((*ModelData).MSFlag &
for (i = 0; i
y[0][i]
} //for (i=0;
for (i = 0; i
y[0][NY
} //for (i=0;
0x2)
0x2)
0x4)
0x2)
0x4)
0x8)
>>
>>
>>
>>
>>
>>
1));
1) +
2));
1) +
2) +
3));
}
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
#endif /* MDL_UPDATE */
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
#if defined(MDL_DERIVATIVES)
/*-------------- P r p r o z e s s o r a n w e i s u n g -----------------------------------------------------------------------------------------m d l D e r i v a t i v e s
-------------------------------------------------------------------------*/
static void mdlDerivatives(SimStruct *S){
/*----------------------------- Variables -----------------------------*/
doublereal x[50];
doublereal *dx;
doublereal rt;
void* ModelData;
/*--------------------------- Function Body ---------------------------*/
// Call TEFUNC to update dx
rt = getcurr(x, S, 2);
dx = ssGetdX(S);
ModelData = ssGetPWorkValue(S,0);
tefunc(ModelData, &NX, &rt, x, dx, 2);
}
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
#endif /* MDL_DERIVATIVES */
/*-------------- P r p r o z e s s o r a n w e i s u n g --------------*/
/*------------------------------------------------------------------------m d l T e r m i n a t e
-------------------------------------------------------------------------*/
static void mdlTerminate(SimStruct *S){
/*Variables*/
struct stModelData *ModelData;
/*Retrieving and Typcast of Dataset Pointer*/
ModelData = (struct stModelData *)ssGetPWorkValue(S,0);
/*--------------------------- Function Body ---------------------------*/
if ((*ModelData).code_sd != (float)0. ){
strcat((*ModelData).msg, "\n in ");
strcat((*ModelData).msg, ssGetPath(S));
mexWarnMsgTxt((*ModelData).msg);
} //if (code_sd != (float)0. ){
free(ModelData);
}
/**************************************************************************
*
*
*
T R A N S F E R F U N C T I O N S
*
*
*
***************************************************************************
--------------------------------------------------------------------------g e t c u r r
-------------------------------------------------------------------------*/
static doublereal getcurr(doublereal x[], SimStruct *S, shortint Callflag){
/*----------------------------- Variables -----------------------------*/
doublereal rt;
real_T *xPtr;
InputRealPtrsType uPtrs;
struct stModelData *ModelData;
int i;
/*Retrieving and Typcast of Dataset Pointer*/
ModelData = (struct stModelData *)ssGetPWorkValue(S,0);
/*--------------------------- Function Body ---------------------------*/
rt = ssGetT(S);
xPtr = ssGetContStates(S);
if(Callflag == 2){
setidv(S);
uPtrs = ssGetInputPortRealSignalPtrs(S,0);
for (i=0; i<NU; i++){
(*ModelData).pv_.xmv[i] = *uPtrs[i];
} //for (i=0; i<NU; i++){
} //if(Callflag == 2){
for (i=0; i<NX; i++){
x[i] = xPtr[i];
} //for (i=0; i<NX; i++){
return rt;
}
/*------------------------------------------------------------------------s e t i d v
-------------------------------------------------------------------------*/
static void setidv(SimStruct *S){
/*----------------------------- Variables -----------------------------*/
InputRealPtrsType uPtrs;
struct stModelData *ModelData;
int i;
/*Retrieving and Typcast of Dataset Pointer*/
ModelData = (struct stModelData *)ssGetPWorkValue(S,0);
/*--------------------------- Function Body ---------------------------*/
uPtrs = ssGetInputPortRealSignalPtrs(S,0);
/*Assinging of Disturbance Activations (and Disturbance Scaling)*/
for (i=0; i<NIDV; i++){
if (((*ModelData).MSFlag & 0x80) > 1){
(*ModelData).dvec_.idv[i] = (float)*uPtrs[i + NU];
}else{
(*ModelData).dvec_.idv[i] = (float)(*uPtrs[i + NU] >= 0.5);
} //if (((*ModelData).MSFlag & 0x80) > 1){
=
=
=
=
=
=
=
=
(float)2.;
(float)25.4;
(float)28.;
(float)32.;
(float)46.;
(float)48.;
(float)62.;
(float)76.;
//in
//in
//in
//in
//in
//in
//in
//in
g/mol
g/mol
g/mol
g/mol
g/mol
g/mol
g/mol
g/mol
(*tcModelData).const_.avp[0]
(*tcModelData).const_.avp[1]
(*tcModelData).const_.avp[2]
(*tcModelData).const_.avp[3]
(*tcModelData).const_.avp[4]
(*tcModelData).const_.avp[5]
(*tcModelData).const_.avp[6]
(*tcModelData).const_.avp[7]
(*tcModelData).const_.bvp[0]
(*tcModelData).const_.bvp[1]
=
=
=
=
=
=
=
=
=
=
(float)0.;
(float)0.;
(float)0.;
(float)15.92;
(float)16.35;
(float)16.35;
(float)16.43;
(float)17.21;
(float)0.;
(float)0.;
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
ln(Torr)
ln(Torr)
ln(Torr)
ln(Torr)
ln(Torr)
ln(Torr)
ln(Torr)
ln(Torr)
ln(Torr)*C
ln(Torr)*C
/
/
/
/
/
/
/
/
kg/kmol
kg/kmol
kg/kmol
kg/kmol
kg/kmol
kg/kmol
kg/kmol
kg/kmol
(*tcModelData).const_.bvp[2]
(*tcModelData).const_.bvp[3]
(*tcModelData).const_.bvp[4]
(*tcModelData).const_.bvp[5]
(*tcModelData).const_.bvp[6]
(*tcModelData).const_.bvp[7]
(*tcModelData).const_.cvp[0]
(*tcModelData).const_.cvp[1]
(*tcModelData).const_.cvp[2]
(*tcModelData).const_.cvp[3]
(*tcModelData).const_.cvp[4]
(*tcModelData).const_.cvp[5]
(*tcModelData).const_.cvp[6]
(*tcModelData).const_.cvp[7]
=
=
=
=
=
=
=
=
=
=
=
=
=
=
(float)0.;
(float)-1444.;
(float)-2114.;
(float)-2114.;
(float)-2748.;
(float)-3318.;
(float)0.;
(float)0.;
(float)0.;
(float)259.;
(float)265.5;
(float)265.5;
(float)232.9;
(float)249.6;
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
ln(Torr)*C
ln(Torr)*C
ln(Torr)*C
ln(Torr)*C
ln(Torr)*C
ln(Torr)*C
C
C
C
C
C
C
C
C
(*tcModelData).const_.ad[0]
(*tcModelData).const_.ad[1]
(*tcModelData).const_.ad[2]
(*tcModelData).const_.ad[3]
(*tcModelData).const_.ad[4]
(*tcModelData).const_.ad[5]
(*tcModelData).const_.ad[6]
(*tcModelData).const_.ad[7]
(*tcModelData).const_.bd[0]
(*tcModelData).const_.bd[1]
(*tcModelData).const_.bd[2]
(*tcModelData).const_.bd[3]
(*tcModelData).const_.bd[4]
(*tcModelData).const_.bd[5]
(*tcModelData).const_.bd[6]
(*tcModelData).const_.bd[7]
(*tcModelData).const_.cd[0]
(*tcModelData).const_.cd[1]
(*tcModelData).const_.cd[2]
(*tcModelData).const_.cd[3]
(*tcModelData).const_.cd[4]
(*tcModelData).const_.cd[5]
(*tcModelData).const_.cd[6]
(*tcModelData).const_.cd[7]
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
(float)1.;
(float)1.;
(float)1.;
(float)23.3;
(float)33.9;
(float)32.8;
(float)49.9;
(float)50.5;
(float)0.;
(float)0.;
(float)0.;
(float)-.07;
(float)-.0957;
(float)-.0995;
(float)-.0191;
(float)-.0541;
(float)0.;
(float)0.;
(float)0.;
(float)-2e-4;
(float)-1.52e-4;
(float)-2.33e-4;
(float)-4.25e-4;
(float)-1.5e-4;
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
(*tcModelData).const_.ah[0]
(*tcModelData).const_.ah[1]
(*tcModelData).const_.ah[2]
(*tcModelData).const_.ah[3]
(*tcModelData).const_.ah[4]
(*tcModelData).const_.ah[5]
(*tcModelData).const_.ah[6]
(*tcModelData).const_.ah[7]
(*tcModelData).const_.bh[0]
(*tcModelData).const_.bh[1]
(*tcModelData).const_.bh[2]
(*tcModelData).const_.bh[3]
(*tcModelData).const_.bh[4]
(*tcModelData).const_.bh[5]
(*tcModelData).const_.bh[6]
(*tcModelData).const_.bh[7]
(*tcModelData).const_.ch[0]
(*tcModelData).const_.ch[1]
(*tcModelData).const_.ch[2]
(*tcModelData).const_.ch[3]
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
1e-6;
1e-6;
1e-6;
9.6e-7;
5.73e-7;
6.52e-7;
5.15e-7;
4.71e-7;
(float)0.;
(float)0.;
(float)0.;
8.7e-9;
2.41e-9;
2.18e-9;
5.65e-10;
8.7e-10;
(float)0.;
(float)0.;
(float)0.;
4.81e-11;
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
(*tcModelData).const_.ch[4]
(*tcModelData).const_.ch[5]
(*tcModelData).const_.ch[6]
(*tcModelData).const_.ch[7]
=
=
=
=
1.82e-11;
1.94e-11;
3.82e-12;
2.62e-12;
//in
//in
//in
//in
?
?
?
?
(*tcModelData).const_.av[0]
(*tcModelData).const_.av[1]
(*tcModelData).const_.av[2]
(*tcModelData).const_.av[3]
(*tcModelData).const_.av[4]
(*tcModelData).const_.av[5]
(*tcModelData).const_.av[6]
(*tcModelData).const_.av[7]
(*tcModelData).const_.ag[0]
(*tcModelData).const_.ag[1]
(*tcModelData).const_.ag[2]
(*tcModelData).const_.ag[3]
(*tcModelData).const_.ag[4]
(*tcModelData).const_.ag[5]
(*tcModelData).const_.ag[6]
(*tcModelData).const_.ag[7]
(*tcModelData).const_.bg[0]
(*tcModelData).const_.bg[1]
(*tcModelData).const_.bg[2]
(*tcModelData).const_.bg[3]
(*tcModelData).const_.bg[4]
(*tcModelData).const_.bg[5]
(*tcModelData).const_.bg[6]
(*tcModelData).const_.bg[7]
(*tcModelData).const_.cg[0]
(*tcModelData).const_.cg[1]
(*tcModelData).const_.cg[2]
(*tcModelData).const_.cg[3]
(*tcModelData).const_.cg[4]
(*tcModelData).const_.cg[5]
(*tcModelData).const_.cg[6]
(*tcModelData).const_.cg[7]
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
1e-6;
1e-6;
1e-6;
8.67e-5;
1.6e-4;
1.6e-4;
2.25e-4;
2.09e-4;
3.411e-6;
3.799e-7;
2.491e-7;
3.567e-7;
3.463e-7;
3.93e-7;
1.7e-7;
1.5e-7;
7.18e-10;
1.08e-9;
1.36e-11;
8.51e-10;
8.96e-10;
1.02e-9;
0.;
0.;
6e-13;
-3.98e-13;
-3.93e-14;
-3.12e-13;
-3.27e-13;
-3.12e-13;
0.;
0.;
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
lb-mol
lb-mol
lb-mol
lb-mol
lb-mol
lb-mol
lb-mol
lb-mol
?
lb-mol
lb-mol
lb-mol
lb-mol
lb-mol
lb-mol
lb-mol
lb-mol
?
?
?
?
yy[22] = .016054258216;
yy[23] = (float).7509759687;
yy[24] = .088582855955;
yy[25] = (float)48.27726193;
yy[26] = (float)39.38459028;
yy[27] = (float).3755297257;
yy[28] = (float)107.7562698;
yy[29] = (float)29.77250546;
yy[30] = (float)88.32481135;
yy[31] = (float)23.03929507;
yy[32] = (float)62.85848794;
yy[33] = (float)5.546318688;
yy[34] = (float)11.92244772;
yy[35] = (float)5.555448243;
yy[36] = (float).9218489762;
/*Cooling Water Outlet Temperatures*/
yy[37] = (float)94.59927549;
yy[38] = (float)77.29698353;
/*Valve Positions*/
yy[39] = (float)63.05263039;
yy[40] = (float)53.97970677;
yy[41] = (float)24.64355755;
yy[42] = (float)61.30192144;
yy[43] = (float)22.21;
yy[44] = (float)40.06374673;
yy[45] = (float)38.1003437;
yy[46] = (float)46.53415582;
yy[47] = (float)47.44573456;
yy[48] = (float)41.10581288;
yy[49] = (float)18.11349055;
yy[50] = (float)50.;
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
//in C
//in C
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
%
%
%
%
%
%
%
%
%
%
%
%
//in
//in
//in
//in
//in
//in
//in
//in
//in
lb-mol/h
lb-mol/h
lb-mol/h
lb-mol/h
lb-mol/h
lb-mol/h
?
gpm
gpm
/*Volumes of Vessels*/
(*tcModelData).teproc_.vtr
(*tcModelData).teproc_.vts
(*tcModelData).teproc_.vtc
(*tcModelData).teproc_.vtv
//in
//in
//in
//in
ft
ft
ft
?
=
=
=
=
(float)1300.;
(float)3500.;
(float)156.5;
(float)5e3;
(*tcModelData).teproc_.htr[0] = .06899381054;
(*tcModelData).teproc_.htr[1] = .05;
(*tcModelData).teproc_.hwr = (float)7060.;
(*tcModelData).teproc_.hws = (float)11138.;
(*tcModelData).teproc_.sfr[0] = (float).995;
(*tcModelData).teproc_.sfr[1] = (float).991;
(*tcModelData).teproc_.sfr[2] = (float).99;
(*tcModelData).teproc_.sfr[3] = (float).916;
(*tcModelData).teproc_.sfr[4] = (float).936;
(*tcModelData).teproc_.sfr[5] = (float).938;
(*tcModelData).teproc_.sfr[6] = .058;
(*tcModelData).teproc_.sfr[7] = .0301;
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
?
?
?
?
1
1
1
1
1
1
1
1
/*Stream 2*/
(*tcModelData).teproc_.xst[0]
(*tcModelData).teproc_.xst[1]
(*tcModelData).teproc_.xst[2]
(*tcModelData).teproc_.xst[3]
(*tcModelData).teproc_.xst[4]
(*tcModelData).teproc_.xst[5]
(*tcModelData).teproc_.xst[6]
(*tcModelData).teproc_.xst[7]
(*tcModelData).teproc_.tst[0]
//in
//in
//in
//in
//in
//in
//in
//in
//in
mol%
mol%
mol%
mol%
mol%
mol%
mol%
mol%
C
/*Stream 3*/
(*tcModelData).teproc_.xst[8] = (float)0.;
(*tcModelData).teproc_.xst[9] = (float)0.;
(*tcModelData).teproc_.xst[10] = (float)0.;
(*tcModelData).teproc_.xst[11] = (float)0.;
(*tcModelData).teproc_.xst[12] = (float).9999;
(*tcModelData).teproc_.xst[13] = (float)1e-4;
(*tcModelData).teproc_.xst[14] = (float)0.;
(*tcModelData).teproc_.xst[15] = (float)0.;
(*tcModelData).teproc_.tst[1] = (float)45.;
//in
//in
//in
//in
//in
//in
//in
//in
//in
mol%
mol%
mol%
mol%
mol%
mol%
mol%
mol%
C
/*Stream 1*/
(*tcModelData).teproc_.xst[16] = (float).9999;
(*tcModelData).teproc_.xst[17] = (float)1e-4;
(*tcModelData).teproc_.xst[18] = (float)0.;
(*tcModelData).teproc_.xst[19] = (float)0.;
(*tcModelData).teproc_.xst[20] = (float)0.;
(*tcModelData).teproc_.xst[21] = (float)0.;
(*tcModelData).teproc_.xst[22] = (float)0.;
(*tcModelData).teproc_.xst[23] = (float)0.;
(*tcModelData).teproc_.tst[2] = (float)45.;
//in
//in
//in
//in
//in
//in
//in
//in
//in
mol%
mol%
mol%
mol%
mol%
mol%
mol%
mol%
C
/*Stream 4*/
(*tcModelData).teproc_.xst[24] = (float).485;
(*tcModelData).teproc_.xst[25] = (float).005;
(*tcModelData).teproc_.xst[26] = (float).51;
(*tcModelData).teproc_.xst[27] = (float)0.;
(*tcModelData).teproc_.xst[28] = (float)0.;
(*tcModelData).teproc_.xst[29] = (float)0.;
(*tcModelData).teproc_.xst[30] = (float)0.;
(*tcModelData).teproc_.xst[31] = (float)0.;
(*tcModelData).teproc_.tst[3] = (float)45.;
//in
//in
//in
//in
//in
//in
//in
//in
//in
mol%
mol%
mol%
mol%
mol%
mol%
mol%
mol%
C
(*tcModelData).teproc_.cpflmx = (float)280275.;
(*tcModelData).teproc_.cpprmx = (float)1.3;
//in ?
//in ?
=
=
=
=
=
=
=
=
=
(float)0.;
(float)1e-4;
(float)0.;
(float).9999;
(float)0.;
(float)0.;
(float)0.;
(float)0.;
(float)45.;
seconds
seconds
seconds
seconds
seconds
seconds
seconds
seconds
seconds
seconds
seconds
seconds
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
kscmh
kg/h
kg/h
kscmh
kscmh
kscmh
kPa gauge
%
C
kscmh
C
%
kPa gauge
m/h
%
kPa gauge
m/h
C
kg/h
kW
C
(*tcModelData).teproc_.xns[21]
(*tcModelData).teproc_.xns[22]
(*tcModelData).teproc_.xns[23]
(*tcModelData).teproc_.xns[24]
(*tcModelData).teproc_.xns[25]
(*tcModelData).teproc_.xns[26]
(*tcModelData).teproc_.xns[27]
(*tcModelData).teproc_.xns[28]
(*tcModelData).teproc_.xns[29]
(*tcModelData).teproc_.xns[30]
(*tcModelData).teproc_.xns[31]
(*tcModelData).teproc_.xns[32]
(*tcModelData).teproc_.xns[33]
(*tcModelData).teproc_.xns[34]
(*tcModelData).teproc_.xns[35]
(*tcModelData).teproc_.xns[36]
(*tcModelData).teproc_.xns[37]
(*tcModelData).teproc_.xns[38]
(*tcModelData).teproc_.xns[39]
(*tcModelData).teproc_.xns[40]
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
.01;
.25;
.1;
.25;
.1;
.25;
.025;
.25;
.1;
.25;
.1;
.25;
.025;
.05;
.05;
.01;
.01;
.01;
.5;
.5;
(*tcModelData).teproc_.xnsadd[0] = .01;
(*tcModelData).teproc_.xnsadd[1] = .01;
(*tcModelData).teproc_.xnsadd[2] = .01;
(*tcModelData).teproc_.xnsadd[3] = .01;
(*tcModelData).teproc_.xnsadd[4] = .01;
(*tcModelData).teproc_.xnsadd[5] = .125;
(*tcModelData).teproc_.xnsadd[6] = .01;
(*tcModelData).teproc_.xnsadd[7] = .125;
(*tcModelData).teproc_.xnsadd[8] = .01;
(*tcModelData).teproc_.xnsadd[9] = .01;
(*tcModelData).teproc_.xnsadd[10] = .25;
(*tcModelData).teproc_.xnsadd[11] = .1;
(*tcModelData).teproc_.xnsadd[12] = .25;
(*tcModelData).teproc_.xnsadd[13] = .1;
(*tcModelData).teproc_.xnsadd[14] = .25;
(*tcModelData).teproc_.xnsadd[15] = .025;
(*tcModelData).teproc_.xnsadd[16] = .25;
(*tcModelData).teproc_.xnsadd[17] = .1;
(*tcModelData).teproc_.xnsadd[18] = .25;
(*tcModelData).teproc_.xnsadd[19] = .1;
(*tcModelData).teproc_.xnsadd[20] = .25;
(*tcModelData).teproc_.xnsadd[21] = .025;
(*tcModelData).teproc_.xnsadd[22] = .25;
(*tcModelData).teproc_.xnsadd[23] = .1;
(*tcModelData).teproc_.xnsadd[24] = .25;
(*tcModelData).teproc_.xnsadd[25] = .1;
(*tcModelData).teproc_.xnsadd[26] = .25;
(*tcModelData).teproc_.xnsadd[27] = .025;
(*tcModelData).teproc_.xnsadd[28] = .25;
(*tcModelData).teproc_.xnsadd[29] = .1;
(*tcModelData).teproc_.xnsadd[30] = .25;
(*tcModelData).teproc_.xnsadd[31] = .1;
(*tcModelData).teproc_.xnsadd[32] = .25;
(*tcModelData).teproc_.xnsadd[33] = .025;
} //if (((*tcModelData).MSFlag & 0x10) > 0){
/*Initilization of Disturbance Flags*/
for (i__ = 1; i__ <= 28; ++i__){
(*tcModelData).dvec_.idv[i__ - 1] = (float)0.;
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
C
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
mol
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
//in
C
C
C
C
C
m/h
C
m/h
C
C
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
mol %
//in 1
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
/* L500: */
} //for (i__ = 1; i__ <= 28; ++i__){
/*Data of Disturbance Processes*/
(*tcModelData).wlk_.hspan[0] = .2;
(*tcModelData).wlk_.hzero[0] = .5;
(*tcModelData).wlk_.sspan[0] = .03;
(*tcModelData).wlk_.szero[0] = .485;
(*tcModelData).wlk_.spspan[0] = 0.;
//in
//in
//in
//in
//in
h
h
mole-ratio
mole-ratio
mole-ratio/h
(*tcModelData).wlk_.hspan[1] = .7;
(*tcModelData).wlk_.hzero[1] = 1.;
(*tcModelData).wlk_.sspan[1] = .003;
(*tcModelData).wlk_.szero[1] = .005;
(*tcModelData).wlk_.spspan[1] = 0.;
//in
//in
//in
//in
//in
h
h
mole-ratio
mole-ratio
mole-ratio/h
(*tcModelData).wlk_.hspan[2] = .25;
(*tcModelData).wlk_.hzero[2] = .5;
(*tcModelData).wlk_.sspan[2] = 10.;
(*tcModelData).wlk_.szero[2] = 45.;
(*tcModelData).wlk_.spspan[2] = 0.;
//in
//in
//in
//in
//in
h
h
C
C
C/h
(*tcModelData).wlk_.hspan[3] = .7;
(*tcModelData).wlk_.hzero[3] = 1.;
(*tcModelData).wlk_.sspan[3] = 10.;
(*tcModelData).wlk_.szero[3] = 45.;
(*tcModelData).wlk_.spspan[3] = 0.;
//in
//in
//in
//in
//in
h
h
C
C
C/h
(*tcModelData).wlk_.hspan[4] = .15;
(*tcModelData).wlk_.hzero[4] = .25;
(*tcModelData).wlk_.sspan[4] = 10.;
(*tcModelData).wlk_.szero[4] = 35.;
(*tcModelData).wlk_.spspan[4] = 0.;
//in
//in
//in
//in
//in
h
h
C
C
C/h
(*tcModelData).wlk_.hspan[5] = .15;
(*tcModelData).wlk_.hzero[5] = .25;
(*tcModelData).wlk_.sspan[5] = 10.;
(*tcModelData).wlk_.szero[5] = 40.;
(*tcModelData).wlk_.spspan[5] = 0.;
//in
//in
//in
//in
//in
h
h
C
C
C/h
(*tcModelData).wlk_.hspan[6] = 1.;
(*tcModelData).wlk_.hzero[6] = 2.;
(*tcModelData).wlk_.sspan[6] = .25;
(*tcModelData).wlk_.szero[6] = 1.;
(*tcModelData).wlk_.spspan[6] = 0.;
//in
//in
//in
//in
//in
h
h
1
1
1/h
(*tcModelData).wlk_.hspan[7] = 1.;
(*tcModelData).wlk_.hzero[7] = 2.;
(*tcModelData).wlk_.sspan[7] = .25;
(*tcModelData).wlk_.szero[7] = 1.;
(*tcModelData).wlk_.spspan[7] = 0.;
//in
//in
//in
//in
//in
h
h
1
1
1/h
(*tcModelData).wlk_.hspan[8] = .4;
(*tcModelData).wlk_.hzero[8] = .5;
(*tcModelData).wlk_.sspan[8] = .25;
(*tcModelData).wlk_.szero[8] = 0.;
(*tcModelData).wlk_.spspan[8] = 0.;
//in
//in
//in
//in
//in
h
h
?
?
?/h
(*tcModelData).wlk_.hspan[9] = 1.5;
(*tcModelData).wlk_.hzero[9] = 2.;
//in h
//in h
(*tcModelData).wlk_.sspan[9] = 0.;
(*tcModelData).wlk_.szero[9] = 0.;
(*tcModelData).wlk_.spspan[9] = 0.;
//in ?
//in ?
//in ?/h
(*tcModelData).wlk_.hspan[10] = 2.;
(*tcModelData).wlk_.hzero[10] = 3.;
(*tcModelData).wlk_.sspan[10] = 0.;
(*tcModelData).wlk_.szero[10] = 0.;
(*tcModelData).wlk_.spspan[10] = 0.;
//in
//in
//in
//in
//in
h
h
?
?
?/h
(*tcModelData).wlk_.hspan[11] = 1.5;
(*tcModelData).wlk_.hzero[11] = 2.;
(*tcModelData).wlk_.sspan[11] = 0.;
(*tcModelData).wlk_.szero[11] = 0.;
(*tcModelData).wlk_.spspan[11] = 0.;
//in
//in
//in
//in
//in
h
h
?
?
?/h
(*tcModelData).wlk_.hspan[12] = .15;
(*tcModelData).wlk_.hzero[12] = .25;
(*tcModelData).wlk_.sspan[12] = 10.;
(*tcModelData).wlk_.szero[12] = 45.;
(*tcModelData).wlk_.spspan[12] = 0.;
//in
//in
//in
//in
//in
h
h
C
C
C/h
(*tcModelData).wlk_.hspan[13] = .25;
(*tcModelData).wlk_.hzero[13] = .5;
(*tcModelData).wlk_.sspan[13] = 10.;
(*tcModelData).wlk_.szero[13] = 45.;
(*tcModelData).wlk_.spspan[13] = 0.;
//in
//in
//in
//in
//in
h
h
C
C
C/h
(*tcModelData).wlk_.hspan[14] = .15;
(*tcModelData).wlk_.hzero[14] = .25;
(*tcModelData).wlk_.sspan[14] = 5.;
(*tcModelData).wlk_.szero[14] = 100.;
(*tcModelData).wlk_.spspan[14] = 0.;
//in
//in
//in
//in
//in
h
h
lb-mol/h
lb-mol/h
lb-mol/h
(*tcModelData).wlk_.hspan[15] = .25;
(*tcModelData).wlk_.hzero[15] = .5;
(*tcModelData).wlk_.sspan[15] = 20.;
(*tcModelData).wlk_.szero[15] = 400.;
(*tcModelData).wlk_.spspan[15] = 0.;
//in
//in
//in
//in
//in
h
h
lb-mol/h
lb-mol/h
lb-mol/h
(*tcModelData).wlk_.hspan[16] = .25;
(*tcModelData).wlk_.hzero[16] = .5;
(*tcModelData).wlk_.sspan[16] = 20.;
(*tcModelData).wlk_.szero[16] = 400.;
(*tcModelData).wlk_.spspan[16] = 0.;
//in
//in
//in
//in
//in
h
h
lb-mol/h
lb-mol/h
lb-mol/h
(*tcModelData).wlk_.hspan[17] = .7;
(*tcModelData).wlk_.hzero[17] = 1.;
(*tcModelData).wlk_.sspan[17] = 75.;
(*tcModelData).wlk_.szero[17] = 1500.;
(*tcModelData).wlk_.spspan[17] = 0.;
//in
//in
//in
//in
//in
h
h
lb-mol/h
lb-mol/h
lb-mol/h
(*tcModelData).wlk_.hspan[18] = .1;
(*tcModelData).wlk_.hzero[18] = .2;
(*tcModelData).wlk_.sspan[18] = 50.;
(*tcModelData).wlk_.szero[18] = (float)1e3;
(*tcModelData).wlk_.spspan[18] = 0.;
//in
//in
//in
//in
//in
h
h
gpm
gpm
gpm/h
(*tcModelData).wlk_.hspan[19] = .1;
(*tcModelData).wlk_.hzero[19] = .2;
//in h
//in h
(*tcModelData).wlk_.sspan[19] = 60.;
(*tcModelData).wlk_.szero[19] = 1200.;
(*tcModelData).wlk_.spspan[19] = 0.;
//in gpm
//in gpm
//in gpm/h
doublereal vpr;
doublereal uas;
doublereal prate;
integer aux;
integer i__;
integer j__;
#define isd ((doublereal *)&(*tcModelData).dvec_ + 28)
/*Typcast of Dataset Pointer*/
tcModelData = ModelData;
/*Parameter adjustments*/
--yp;
--yy;
/*--------------------------- Function Body ---------------------------*/
if((((*tcModelData).tlastcomp != *time) || (Callflag == 1)) &&
(((*tcModelData).MSFlag & 0x8000) == 0)){
/*Limiting of Disturbance Activations*/
for (i__ = 1; i__ <= 28; ++i__){
if ((*tcModelData).dvec_.idv[i__ - 1] < (float)0.){
(*tcModelData).dvec_.idv[i__ - 1] = (float)0.;
} //if ((*tcModelData).dvec_.idv[i__ - 1] < 0){
if ((*tcModelData).dvec_.idv[i__ - 1] > (float)1.){
(*tcModelData).dvec_.idv[i__ - 1] = (float)1.;
} //if ((*tcModelData).dvec_.idv[i__ - 1] > 1){
/* L500: */
} //for (i__ = 1; i__ <= 20; ++i__){
/*Assignment of Disturbance Activations*/
(*tcModelData).wlk_.idvwlk[0] = (*tcModelData).dvec_.idv[7];
(*tcModelData).wlk_.idvwlk[1] = (*tcModelData).dvec_.idv[7];
(*tcModelData).wlk_.idvwlk[2] = (*tcModelData).dvec_.idv[8];
(*tcModelData).wlk_.idvwlk[3] = (*tcModelData).dvec_.idv[9];
(*tcModelData).wlk_.idvwlk[4] = (*tcModelData).dvec_.idv[10];
(*tcModelData).wlk_.idvwlk[5] = (*tcModelData).dvec_.idv[11];
(*tcModelData).wlk_.idvwlk[6] = (*tcModelData).dvec_.idv[12];
(*tcModelData).wlk_.idvwlk[7] = (*tcModelData).dvec_.idv[12];
(*tcModelData).wlk_.idvwlk[8] = (*tcModelData).dvec_.idv[15];
(*tcModelData).wlk_.idvwlk[9] = (*tcModelData).dvec_.idv[16];
(*tcModelData).wlk_.idvwlk[10] = (*tcModelData).dvec_.idv[17];
(*tcModelData).wlk_.idvwlk[11] = (*tcModelData).dvec_.idv[19];
(*tcModelData).wlk_.idvwlk[12] = (*tcModelData).dvec_.idv[20];
(*tcModelData).wlk_.idvwlk[13] = (*tcModelData).dvec_.idv[21];
(*tcModelData).wlk_.idvwlk[14] = (*tcModelData).dvec_.idv[22];
(*tcModelData).wlk_.idvwlk[15] = (*tcModelData).dvec_.idv[23];
(*tcModelData).wlk_.idvwlk[16] = (*tcModelData).dvec_.idv[24];
(*tcModelData).wlk_.idvwlk[17] = (*tcModelData).dvec_.idv[25];
(*tcModelData).wlk_.idvwlk[18] = (*tcModelData).dvec_.idv[26];
(*tcModelData).wlk_.idvwlk[19] = (*tcModelData).dvec_.idv[27];
if (((*tcModelData).MSFlag & 0x40) > 0){
/*Recalculation of Disturbance Process Parameters - Determination of
Processes to be Updated (1 - 9/13 - 20)*/
distnum = 0;
for (i__ = 1; i__ <= 20; ++i__){
if (*time >= (*tcModelData).wlk_.tnext[i__ - 1]){
distindex[distnum] = i__ - 1;
distnum++;
} //if (*time >= (*tcModelData).wlk_.tnext[i__ - 1]){
distindex[distnum] = i__ - 1;
distnum++;
} //if (*time >= (*tcModelData).wlk_.tnext[i__ - 1]){
} //for (i__ = 1; i__ <= 9; ++i__){ */
/*Recalculation of Disturbance Process Parameters - Sorting (10 12)*/
for(i__ = 1; i__ < distnum; ++i__){
distindch = distindex[i__];
j__ = i__;
while((j__ > 0) &&
((*tcModelData).wlk_.tnext[j__ - 1] >
(*tcModelData).wlk_.tnext[distindch])){
distindex[j__] = distindex[j__ - 1];
j__--;
} //while((j__ > 0) && ...
distindex[j__] = distindch;
} //for(i__ = 1; i__ < distnum; ++i__){
/*Recalculation of Disturbance Process Parameters - Update (10 12)*/
for(i__ = 0; i__ < distnum; ++i__){
hwlk = (*tcModelData).wlk_.tnext[distindex[i__]] (*tcModelData).wlk_.tlast[distindex[i__]];
swlk = (*tcModelData).wlk_.adist[distindex[i__]] +
hwlk * ((*tcModelData).wlk_.bdist[distindex[i__]] +
hwlk * ((*tcModelData).wlk_.cdist[distindex[i__]] +
hwlk * (*tcModelData).wlk_.ddist[distindex[i__]]));
spwlk =
(*tcModelData).wlk_.bdist[distindex[i__]] +
hwlk * ((*tcModelData).wlk_.cdist[distindex[i__]] * 2. +
hwlk * 3. * (*tcModelData).wlk_.ddist[distindex[
i__]]);
(*tcModelData).wlk_.tlast[distindex[i__]] =
(*tcModelData).wlk_.tnext[distindex[i__]];
if (swlk > .1){
(*tcModelData).wlk_.adist[distindex[i__]] = swlk;
(*tcModelData).wlk_.bdist[distindex[i__]] = spwlk;
(*tcModelData).wlk_.cdist[distindex[i__]] =
-(swlk * 3. + spwlk * .2) / .01;
(*tcModelData).wlk_.ddist[distindex[i__]] =
(swlk * 2. + spwlk * .1) / .001;
(*tcModelData).wlk_.tnext[distindex[i__]] =
(*tcModelData).wlk_.tlast[distindex[i__]] + .1;
}else{
aux = -1;
hwlk = (*tcModelData).wlk_.hspan[distindex[i__]] *
tesub7_(ModelData, &aux) +
(*tcModelData).wlk_.hzero[distindex[i__]];
(*tcModelData).wlk_.adist[distindex[i__]] = swlk;
(*tcModelData).wlk_.bdist[distindex[i__]] = spwlk;
/* Computing 2nd power */
d__1 = hwlk;
(*tcModelData).wlk_.cdist[distindex[i__]] =
((*tcModelData).wlk_.idvwlk[distindex[i__]] 2*spwlk*d__1) / (d__1 * d__1);
(*tcModelData).wlk_.ddist[distindex[i__]] =
spwlk / (d__1 * d__1);
(*tcModelData).wlk_.tnext[distindex[i__]] =
(*tcModelData).wlk_.tlast[distindex[i__]] + hwlk;
} //if (swlk > .1){
} //for(i__ = 0; i__ < distnum; ++i__){
}else{
/* Original Code of J.J. Downs & E.F. Vogel and N.L. Ricker [2]*/
/*Recalculation of Disturbance Process Parameters (1 - 9/13 - 20)*/
if(((*tcModelData).MSFlag & 0x8000) > 0){
distende = 9;
}else{
distende = 20;
} //if(((*tcModelData).MSFlag & 0x8000) > 0){
for (i__ = 1; i__ <= distende; ++i__){
if (*time >= (*tcModelData).wlk_.tnext[i__ - 1]){
hwlk = (*tcModelData).wlk_.tnext[i__ - 1] (*tcModelData).wlk_.tlast[i__ - 1];
swlk = (*tcModelData).wlk_.adist[i__ - 1] +
hwlk * ((*tcModelData).wlk_.bdist[i__ - 1] +
hwlk * ((*tcModelData).wlk_.cdist[i__ - 1] +
hwlk * (*tcModelData).wlk_.ddist[i__ - 1]));
spwlk = (*tcModelData).wlk_.bdist[i__ - 1] +
hwlk * ((*tcModelData).wlk_.cdist[i__ - 1] * 2. +
hwlk * 3. * (*tcModelData).wlk_.ddist[i__ - 1]
);
(*tcModelData).wlk_.tlast[i__ - 1] =
(*tcModelData).wlk_.tnext[i__ - 1];
tesub5_(ModelData, &swlk, &spwlk,
&(*tcModelData).wlk_.adist[i__ - 1],
&(*tcModelData).wlk_.bdist[i__ - 1],
&(*tcModelData).wlk_.cdist[i__ - 1],
&(*tcModelData).wlk_.ddist[i__ - 1],
&(*tcModelData).wlk_.tlast[i__ - 1],
&(*tcModelData).wlk_.tnext[i__ - 1],
&(*tcModelData).wlk_.hspan[i__ - 1],
&(*tcModelData).wlk_.hzero[i__ - 1],
&(*tcModelData).wlk_.sspan[i__ - 1],
&(*tcModelData).wlk_.szero[i__ - 1],
&(*tcModelData).wlk_.spspan[i__ - 1],
&(*tcModelData).wlk_.idvwlk[i__ - 1]);
} //if (*time >= (*tcModelData).wlk_.tnext[i__ - 1]){
/*Step-over of 10 through 12*/
if(i__ == 9){
i__ = i__ + 3;
}
/* L900: */
} //for (i__ = 1; i__ <= 20; ++i__){ */
/*Recalculation of Disturbance Process Parameters (10 - 12)*/
for (i__ = 10; i__ <= 12; ++i__){
if (*time >= (*tcModelData).wlk_.tnext[i__ - 1]){
hwlk = (*tcModelData).wlk_.tnext[i__ - 1] (*tcModelData).wlk_.tlast[i__ - 1];
swlk = (*tcModelData).wlk_.adist[i__ - 1] +
hwlk * ((*tcModelData).wlk_.bdist[i__ - 1] +
hwlk * ((*tcModelData).wlk_.cdist[i__ - 1] +
hwlk * (*tcModelData).wlk_.ddist[i__ - 1]));
spwlk = (*tcModelData).wlk_.bdist[i__ - 1] +
hwlk * ((*tcModelData).wlk_.cdist[i__ - 1] * 2. +
hwlk * 3. * (*tcModelData).wlk_.ddist[i__ - 1]
);
(*tcModelData).wlk_.tlast[i__ - 1] =
(*tcModelData).wlk_.tnext[i__ - 1];
if (swlk > .1){
(*tcModelData).wlk_.adist[i__ - 1] = swlk;
(*tcModelData).wlk_.bdist[i__ - 1] = spwlk;
(*tcModelData).wlk_.cdist[i__ - 1] =
-(swlk * 3. + spwlk * .2) / .01;
(*tcModelData).wlk_.ddist[i__ - 1] =
(swlk * 2. + spwlk * .1) / .001;
(*tcModelData).wlk_.tnext[i__ - 1] =
(*tcModelData).wlk_.tlast[i__ - 1] + .1;
}else{
aux = -1;
hwlk = (*tcModelData).wlk_.hspan[i__ - 1] *
tesub7_(ModelData, &aux) +
(*tcModelData).wlk_.hzero[i__ - 1];
(*tcModelData).wlk_.adist[i__ - 1] = swlk;
(*tcModelData).wlk_.bdist[i__ - 1] = spwlk;
/* Computing 2nd power */
d__1 = hwlk;
(*tcModelData).wlk_.cdist[i__ - 1] =
((*tcModelData).wlk_.idvwlk[i__ - 1] 2*spwlk*d__1) / (d__1 * d__1);
(*tcModelData).wlk_.ddist[i__ - 1] = spwlk / (d__1 * d__1);
(*tcModelData).wlk_.tnext[i__ - 1] =
(*tcModelData).wlk_.tlast[i__ - 1] + hwlk;
} //if (swlk > .1){
} //if (*time >= (*tcModelData).wlk_.tnext[i__ - 1]){
/* L910: */
} //for (i__ = 10; i__ <= 12; ++i__){
} //if (((*tcModelData).MSFlag & 0x40) > 0){
/*Initilization of Disturbance Processes Parameters*/
if (*time == 0.){
for (i__ = 1; i__ <= 20; ++i__){
(*tcModelData).wlk_.adist[i__ - 1] =
(*tcModelData).wlk_.szero[i__ - 1];
(*tcModelData).wlk_.bdist[i__ - 1] = 0.;
(*tcModelData).wlk_.cdist[i__ - 1] = 0.;
(*tcModelData).wlk_.ddist[i__ - 1] = 0.;
(*tcModelData).wlk_.tlast[i__ - 1] = 0.;
(*tcModelData).wlk_.tnext[i__ - 1] = .1;
/* L950: */
} //for (i__ = 1; i__ <= 20; ++i__){
} //if (*time == 0.){
/*Determination of Disturbed Values*/
(*tcModelData).teproc_.xst[24] = tesub8_(ModelData, &c__1, time) -
(*tcModelData).teproc_.xst[24]*100;
(*tcModelData).teproc_.xst[25]*100;
(*tcModelData).teproc_.xst[26]*100;
(*tcModelData).teproc_.tst[0];
(*tcModelData).teproc_.tst[3];
(*tcModelData).teproc_.tcwr;
(*tcModelData).teproc_.tcws;
r1f;
r2f;
tesub8_(ModelData, &c__9, time);
tesub8_(ModelData, &c__10, time);
tesub8_(ModelData, &c__11, time);
tesub8_(ModelData, &c__12, time);
(*tcModelData).teproc_.tst[2];
(*tcModelData).teproc_.tst[1];
(*tcModelData).teproc_.vrng[2]*
(float).454;
(*tcModelData).teproc_.vrng[0]*
(float).454;
(*tcModelData).teproc_.vrng[1]*
(float).454;
(*tcModelData).teproc_.vrng[3]*
(float).454;
(*tcModelData).teproc_.vrng[9]*
(float)0.003785411784 * (float)60.;
(*tcModelData).teproc_.vrng[10]*
(float)0.003785411784 * (float)60.;
/*Calculation of Temperatures*/
tesub2_(ModelData, (*tcModelData).teproc_.xlr,
&(*tcModelData).teproc_.tcr, &(*tcModelData).teproc_.esr,
&c__0);
(*tcModelData).teproc_.tkr = (*tcModelData).teproc_.tcr +
(float)273.15;
tesub2_(ModelData, (*tcModelData).teproc_.xls,
&(*tcModelData).teproc_.tcs, &(*tcModelData).teproc_.ess,
&c__0);
(*tcModelData).teproc_.tks = (*tcModelData).teproc_.tcs +
(float)273.15;
tesub2_(ModelData, (*tcModelData).teproc_.xlc,
&(*tcModelData).teproc_.tcc, &(*tcModelData).teproc_.esc,
&c__0);
tesub2_(ModelData, (*tcModelData).teproc_.xvv,
&(*tcModelData).teproc_.tcv, &(*tcModelData).teproc_.esv,
&c__2);
(*tcModelData).teproc_.tkv = (*tcModelData).teproc_.tcv +
(float)273.15;
/*Calculation of Densities*/
tesub4_(ModelData, (*tcModelData).teproc_.xlr,
&(*tcModelData).teproc_.tcr, &(*tcModelData).teproc_.dlr);
tesub4_(ModelData, (*tcModelData).teproc_.xls,
&(*tcModelData).teproc_.tcs, &(*tcModelData).teproc_.dls);
tesub4_(ModelData, (*tcModelData).teproc_.xlc,
&(*tcModelData).teproc_.tcc, &(*tcModelData).teproc_.dlc);
/*Calculation of Volume of Liquid and Vapor
(*tcModelData).teproc_.vlr =
(*tcModelData).teproc_.utlr /
(*tcModelData).teproc_.vls =
(*tcModelData).teproc_.utls /
(*tcModelData).teproc_.vlc =
(*tcModelData).teproc_.utlc /
(*tcModelData).teproc_.vvr =
(*tcModelData).teproc_.vtr (*tcModelData).teproc_.vvs =
(*tcModelData).teproc_.vts -
Phase*/
(*tcModelData).teproc_.dlr;
(*tcModelData).teproc_.dls;
(*tcModelData).teproc_.dlc;
(*tcModelData).teproc_.vlr;
(*tcModelData).teproc_.vls;
/*Calculation of Pressure*/
(*tcModelData).teproc_.ptr = (float)0.;
(*tcModelData).teproc_.pts = (float)0.;
rg = (float)998.9;
for (i__ = 1; i__ <= 3; ++i__){
(*tcModelData).teproc_.ppr[i__ - 1] =
(*tcModelData).teproc_.ucvr[i__ - 1] * rg *
(*tcModelData).teproc_.tkr / (*tcModelData).teproc_.vvr;
(*tcModelData).teproc_.ptr += (*tcModelData).teproc_.ppr[i__ - 1];
(*tcModelData).teproc_.pps[i__ - 1] =
(*tcModelData).teproc_.ucvs[i__ - 1] * rg *
(*tcModelData).teproc_.tks / (*tcModelData).teproc_.vvs;
(*tcModelData).teproc_.pts += (*tcModelData).teproc_.pps[i__ - 1];
/* L1110: */
} //for (i__ = 1; i__ <= 3; ++i__){
.767488334;
if ((*tcModelData).teproc_.ppr[0] > (float)0. &&
(*tcModelData).teproc_.ppr[2] > (float)0.){
r1f = pow_dd((*tcModelData).teproc_.ppr, &c_b73);
r2f = pow_dd(&(*tcModelData).teproc_.ppr[2], &c_b74);
(*tcModelData).teproc_.rr[0] = (*tcModelData).teproc_.rr[0] *
r1f * r2f * (*tcModelData).teproc_.ppr[3];
(*tcModelData).teproc_.rr[1] = (*tcModelData).teproc_.rr[1] *
r1f * r2f * (*tcModelData).teproc_.ppr[4];
}else{
(*tcModelData).teproc_.rr[0] = (float)0.;
(*tcModelData).teproc_.rr[1] = (float)0.;
} //if ((*tcModelData).teproc_.ppr[0] > (float)0. && ...
(*tcModelData).teproc_.rr[2] = (*tcModelData).teproc_.rr[2] *
(*tcModelData).teproc_.ppr[0] * (*tcModelData).teproc_.ppr[4];
(*tcModelData).teproc_.rr[3] = (*tcModelData).teproc_.rr[3] *
(*tcModelData).teproc_.ppr[0] * (*tcModelData).teproc_.ppr[3];
for (i__ = 1; i__ <= 4; ++i__){
(*tcModelData).teproc_.rr[i__ - 1] *= (*tcModelData).teproc_.vvr;
/* L1200: */
} //for (i__ = 1; i__ <= 4; ++i__){
/*Consumption and Creation of Components in Reactor*/
(*tcModelData).teproc_.crxr[0] = -(*tcModelData).teproc_.rr[0] (*tcModelData).teproc_.rr[1] - (*tcModelData).teproc_.rr[2];
(*tcModelData).teproc_.crxr[2] = -(*tcModelData).teproc_.rr[0] (*tcModelData).teproc_.rr[1];
(*tcModelData).teproc_.crxr[3] = -(*tcModelData).teproc_.rr[0] (*tcModelData).teproc_.rr[3] * 1.5;
(*tcModelData).teproc_.crxr[4] = -(*tcModelData).teproc_.rr[1] (*tcModelData).teproc_.rr[2];
(*tcModelData).teproc_.crxr[5] = (*tcModelData).teproc_.rr[2] +
(*tcModelData).teproc_.rr[3];
(*tcModelData).teproc_.crxr[6] = (*tcModelData).teproc_.rr[0];
(*tcModelData).teproc_.crxr[7] = (*tcModelData).teproc_.rr[1];
(*tcModelData).teproc_.rh =
(*tcModelData).teproc_.rr[0] * (*tcModelData).teproc_.htr[0] +
(*tcModelData).teproc_.rr[1] * (*tcModelData).teproc_.htr[1];
(*tcModelData).teproc_.xmws[0] = (float)0.;
(*tcModelData).teproc_.xmws[1] = (float)0.;
(*tcModelData).teproc_.xmws[5] = (float)0.;
(*tcModelData).teproc_.xmws[7] = (float)0.;
(*tcModelData).teproc_.xmws[8] = (float)0.;
(*tcModelData).teproc_.xmws[9] = (float)0.;
for (i__ = 1; i__ <= 8; ++i__){
(*tcModelData).teproc_.xst[i__ + 39] =
(*tcModelData).teproc_.xvv[i__
(*tcModelData).teproc_.xst[i__ + 55] =
(*tcModelData).teproc_.xvr[i__
(*tcModelData).teproc_.xst[i__ + 63] =
(*tcModelData).teproc_.xvs[i__
(*tcModelData).teproc_.xst[i__ + 71] =
(*tcModelData).teproc_.xvs[i__
(*tcModelData).teproc_.xst[i__ + 79] =
(*tcModelData).teproc_.xls[i__
- 1];
- 1];
- 1];
- 1];
- 1];
(*tcModelData).teproc_.xst[i__ + 95] =
(*tcModelData).teproc_.xlc[i__ - 1];
(*tcModelData).teproc_.xmws[0] +=
(*tcModelData).teproc_.xst[i__ - 1] *
(*tcModelData).const_.xmw[i__ - 1];
(*tcModelData).teproc_.xmws[1] +=
(*tcModelData).teproc_.xst[i__ + 7] *
(*tcModelData).const_.xmw[i__ - 1];
(*tcModelData).teproc_.xmws[5] +=
(*tcModelData).teproc_.xst[i__ + 39] *
(*tcModelData).const_.xmw[i__ - 1];
(*tcModelData).teproc_.xmws[7] +=
(*tcModelData).teproc_.xst[i__ + 55] *
(*tcModelData).const_.xmw[i__ - 1];
(*tcModelData).teproc_.xmws[8] +=
(*tcModelData).teproc_.xst[i__ + 63] *
(*tcModelData).const_.xmw[i__ - 1];
(*tcModelData).teproc_.xmws[9] +=
(*tcModelData).teproc_.xst[i__ + 71] *
(*tcModelData).const_.xmw[i__ - 1];
/* L2010: */
} //for (i__ = 1; i__ <= 8; ++i__){
(*tcModelData).teproc_.tst[5] = (*tcModelData).teproc_.tcv;
(*tcModelData).teproc_.tst[7] = (*tcModelData).teproc_.tcr;
(*tcModelData).teproc_.tst[8] = (*tcModelData).teproc_.tcs;
(*tcModelData).teproc_.tst[9] = (*tcModelData).teproc_.tcs;
(*tcModelData).teproc_.tst[10] = (*tcModelData).teproc_.tcs;
(*tcModelData).teproc_.tst[12] = (*tcModelData).teproc_.tcc;
tesub1_(ModelData, (*tcModelData).teproc_.xst,
(*tcModelData).teproc_.tst, (*tcModelData).teproc_.hst, &c__1);
tesub1_(ModelData, &(*tcModelData).teproc_.xst[8],
&(*tcModelData).teproc_.tst[1], &(*tcModelData).teproc_.hst[1],
&c__1);
tesub1_(ModelData, &(*tcModelData).teproc_.xst[16],
&(*tcModelData).teproc_.tst[2], &(*tcModelData).teproc_.hst[2],
&c__1);
tesub1_(ModelData, &(*tcModelData).teproc_.xst[24],
&(*tcModelData).teproc_.tst[3], &(*tcModelData).teproc_.hst[3],
&c__1);
tesub1_(ModelData, &(*tcModelData).teproc_.xst[40],
&(*tcModelData).teproc_.tst[5], &(*tcModelData).teproc_.hst[5],
&c__1);
tesub1_(ModelData, &(*tcModelData).teproc_.xst[56],
&(*tcModelData).teproc_.tst[7], &(*tcModelData).teproc_.hst[7],
&c__1);
tesub1_(ModelData, &(*tcModelData).teproc_.xst[64],
&(*tcModelData).teproc_.tst[8], &(*tcModelData).teproc_.hst[8],
&c__1);
(*tcModelData).teproc_.hst[9] = (*tcModelData).teproc_.hst[8];
tesub1_(ModelData, &(*tcModelData).teproc_.xst[80],
&(*tcModelData).teproc_.tst[10], &(*tcModelData).teproc_.hst[10],
&c__0);
tesub1_(ModelData, &(*tcModelData).teproc_.xst[96],
&(*tcModelData).teproc_.tst[12], &(*tcModelData).teproc_.hst[12],
&c__0);
(*tcModelData).teproc_.ftm[0] = vpos[0] *
(*tcModelData).teproc_.vrng[0] / (float)100.;
(*tcModelData).teproc_.ftm[1] = vpos[1] *
(*tcModelData).teproc_.vrng[1] / (float)100.;
(*tcModelData).teproc_.ftm[2] = vpos[2] *
(1. - (*tcModelData).dvec_.idv[5]) *
(*tcModelData).teproc_.vrng[2] / (float)100.;
(*tcModelData).teproc_.ftm[3] = vpos[3] *
(1. - (*tcModelData).dvec_.idv[6] * .2) *
(*tcModelData).teproc_.vrng[3] / (float)100. +
1e-10;
(*tcModelData).teproc_.ftm[10] = vpos[6] *
(*tcModelData).teproc_.vrng[6] / (float)100.;
(*tcModelData).teproc_.ftm[12] = vpos[7] *
(*tcModelData).teproc_.vrng[7] / (float)100.;
uac = vpos[8] * (*tcModelData).teproc_.vrng[8] *
(tesub8_(ModelData, &c__9, time) + 1.) / (float)100.;
(*tcModelData).teproc_.fwr = vpos[9] *
(*tcModelData).teproc_.vrng[9] / (float)100.;
(*tcModelData).teproc_.fws = vpos[10] *
(*tcModelData).teproc_.vrng[10] / (float)100.;
(*tcModelData).teproc_.agsp = (vpos[11] + (float)150.) / (float)100.;
dlp = (*tcModelData).teproc_.ptv - (*tcModelData).teproc_.ptr;
if (dlp < (float)0.){
dlp = (float)0.;
} //if (dlp < (float)0.){
flms = sqrt(dlp) * 1937.6;
(*tcModelData).teproc_.ftm[5] = flms / (*tcModelData).teproc_.xmws[5];
dlp = (*tcModelData).teproc_.ptr - (*tcModelData).teproc_.pts;
if (dlp < (float)0.){
dlp = (float)0.;
} //if (dlp < (float)0.){
flms = sqrt(dlp) * 4574.21 *
(1. - tesub8_(ModelData, &c__12, time) * .25);
(*tcModelData).teproc_.ftm[7] = flms / (*tcModelData).teproc_.xmws[7];
dlp = (*tcModelData).teproc_.pts - (float)760.;
if (dlp < (float)0.){
dlp = (float)0.;
} //if (dlp < (float)0.){
flms = vpos[5] * .151169 * sqrt(dlp);
(*tcModelData).teproc_.ftm[9] = flms / (*tcModelData).teproc_.xmws[9];
pr = (*tcModelData).teproc_.ptv / (*tcModelData).teproc_.pts;
if (pr < (float)1.){
pr = (float)1.;
} //if (pr < (float)1.){
if (pr > (*tcModelData).teproc_.cpprmx){
pr = (*tcModelData).teproc_.cpprmx;
} //if (pr > (*tcModelData).teproc_.cpprmx){
flcoef = (*tcModelData).teproc_.cpflmx / 1.197;
/* Computing 3rd power */
d__1 = pr;
flms = (*tcModelData).teproc_.cpflmx +
flcoef * ((float)1. - d__1 * (d__1 * d__1));
(*tcModelData).teproc_.cpdh =
flms * ((*tcModelData).teproc_.tcs + 273.15) * 1.8e-6 * 1.9872 *
((*tcModelData).teproc_.ptv - (*tcModelData).teproc_.pts) /
((*tcModelData).teproc_.xmws[8] * (*tcModelData).teproc_.pts);
/* L6130: */
} //for (i__ = 1; i__ <= 8; ++i__){
/*Calculation of Heat Transfer in Reactor*/
if ((*tcModelData).teproc_.vlr / (float)7.8 > (float)50.){
uarlev = (float)1.;
}else if ((*tcModelData).teproc_.vlr / (float)7.8 < (float)10.){
uarlev = (float)0.;
}else{
uarlev = (*tcModelData).teproc_.vlr * (float).025 / (float)7.8 (float).25;
} //if ((*tcModelData).teproc_.vlr / (float)7.8 > (float)50.){
/* Computing 2nd power */
d__1 = (*tcModelData).teproc_.agsp;
(*tcModelData).teproc_.uar = uarlev *
(d__1 * d__1 * (float)-.5 +
(*tcModelData).teproc_.agsp * (float)2.75 - (float)2.5) * .85549;
(*tcModelData).teproc_.qur = (*tcModelData).teproc_.uar *
((*tcModelData).teproc_.twr - (*tcModelData).teproc_.tcr) *
(1. - tesub8_(ModelData, &c__10, time) * .35);
/*Calculation of Heat Transfer in Condenser (Separator)*/
/* Computing 4th power */
d__1 = (*tcModelData).teproc_.ftm[7] / (float)3528.73;
d__1 *= d__1;
uas = ((float)1. - (float)1. / (d__1 * d__1 + (float)1.)) *
(float).404655;
(*tcModelData).teproc_.qus = uas *
((*tcModelData).teproc_.tws - (*tcModelData).teproc_.tst[7]) *
(1. - tesub8_(ModelData, &c__11, time) * .25);
/*Calculation of Heat Transfer in Stripper*/
(*tcModelData).teproc_.quc = 0.;
if ((*tcModelData).teproc_.tcc < (float)100.){
(*tcModelData).teproc_.quc = uac *
((float)100. - (*tcModelData).teproc_.tcc);
} //if ((*tcModelData).teproc_.tcc < (float)100.){
(*tcModelData).tlastcomp = *time;
}else{
for (i__ = 1; i__ <= 12; ++i__){
vpos[i__ - 1] = yy[i__ + 38];
} //for (i__ = 1; i__ <= 12; ++i__){
} //if((((*tcModelData).tlastcomp < *time) || (Callflag == 1)) && ...
/*Setting of Measured Values*/
if((Callflag < 2) && (((*tcModelData).MSFlag & 0x8000) == 0)){
(*tcModelData).pv_.xmeas[0] = (*tcModelData).teproc_.ftm[2] *
(float).359 / (float)35.3145;
(*tcModelData).pv_.xmeas[1] = (*tcModelData).teproc_.ftm[0] *
(*tcModelData).teproc_.xmws[0] * (float).454;
(*tcModelData).pv_.xmeas[2] = (*tcModelData).teproc_.ftm[1] *
(*tcModelData).teproc_.xmws[1] * (float).454;
(*tcModelData).pv_.xmeas[3] = (*tcModelData).teproc_.ftm[3] *
(float).359 / (float)35.3145;
(*tcModelData).pv_.xmeas[4] = (*tcModelData).teproc_.ftm[8] *
(float).359 / (float)35.3145;
(*tcModelData).pv_.xmeas[5] = (*tcModelData).teproc_.ftm[5] *
(float).359 / (float)35.3145;
Outputs*/
(*tcModelData).teproc_.xst[48]
(*tcModelData).teproc_.xst[49]
(*tcModelData).teproc_.xst[50]
(*tcModelData).teproc_.xst[51]
(*tcModelData).teproc_.xst[52]
(*tcModelData).teproc_.xst[53]
(*tcModelData).teproc_.xst[72]
(*tcModelData).teproc_.xst[73]
(*tcModelData).teproc_.xst[74]
*
*
*
*
*
*
*
*
*
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
xcmp[31]
xcmp[32]
xcmp[33]
xcmp[34]
xcmp[35]
xcmp[36]
xcmp[37]
xcmp[38]
xcmp[39]
xcmp[40]
=
=
=
=
=
=
=
=
=
=
(*tcModelData).teproc_.xst[75] * (float)100.;
(*tcModelData).teproc_.xst[76] * (float)100.;
(*tcModelData).teproc_.xst[77] * (float)100.;
(*tcModelData).teproc_.xst[78] * (float)100.;
(*tcModelData).teproc_.xst[79] * (float)100.;
(*tcModelData).teproc_.xst[99] * (float)100.;
(*tcModelData).teproc_.xst[100] * (float)100.;
(*tcModelData).teproc_.xst[101] * (float)100.;
(*tcModelData).teproc_.xst[102] * (float)100.;
(*tcModelData).teproc_.xst[103] * (float)100.;
*
*
*
*
*
*
xcmpadd[6]
xcmpadd[7]
xcmpadd[8]
xcmpadd[9]
xcmpadd[10]
xcmpadd[11]
=
=
=
=
=
=
(*tcModelData).teproc_.xst[0]
(*tcModelData).teproc_.xst[1]
(*tcModelData).teproc_.xst[2]
(*tcModelData).teproc_.xst[3]
(*tcModelData).teproc_.xst[4]
(*tcModelData).teproc_.xst[5]
xcmpadd[12]
xcmpadd[13]
xcmpadd[14]
xcmpadd[15]
xcmpadd[16]
xcmpadd[17]
=
=
=
=
=
=
(*tcModelData).teproc_.xst[8] * (float)100.;
(*tcModelData).teproc_.xst[9] * (float)100.;
(*tcModelData).teproc_.xst[10] * (float)100.;
(*tcModelData).teproc_.xst[11] * (float)100.;
(*tcModelData).teproc_.xst[12] * (float)100.;
(*tcModelData).teproc_.xst[13] * (float)100.;
xcmpadd[18] = (*tcModelData).teproc_.xst[24]
xcmpadd[19] = (*tcModelData).teproc_.xst[25]
xcmpadd[20] = (*tcModelData).teproc_.xst[26]
xcmpadd[21] = (*tcModelData).teproc_.xst[27]
xcmpadd[22] = (*tcModelData).teproc_.xst[28]
xcmpadd[23] = (*tcModelData).teproc_.xst[29]
} //if(((*tcModelData).MSFlag & 0x1) == 1){
*
*
*
*
*
*
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
*
*
*
*
*
*
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
(float)100.;
if (*time == 0.){
for (i__ = 23; i__ <= 41; ++i__){
(*tcModelData).teproc_.xdel[i__ - 1] = xcmp[i__ - 1];
(*tcModelData).pv_.xmeas[i__ - 1] = xcmp[i__ - 1];
/* L7010: */
} //for (i__ = 23; i__ <= 41; ++i__){
if(((*tcModelData).MSFlag & 0x1) == 1){
for (i__ = 1; i__ <= 24; ++i__){
(*tcModelData).teproc_.xdeladd[i__ - 1] = xcmpadd[i__ - 1];
(*tcModelData).pv_.xmeasadd[i__ + 7] = xcmpadd[i__ - 1];
} //for (i__ = 23; i__ <= 41; ++i__){
} //if((*ModelData).MSFlag & 0x1) == 1){
(*tcModelData).teproc_.tgas = (float).1;
(*tcModelData).teproc_.tprod = (float).25;
} //if (*time == 0.){
if (*time >= (*tcModelData).teproc_.tgas){
(float)760. * (float)101.325;
(*tcModelData).pv_.xmeasmonitor[11] = (*tcModelData).teproc_.ppr[4] /
(float)760. * (float)101.325;
(*tcModelData).pv_.xmeasmonitor[12] = (*tcModelData).teproc_.ppr[5] /
(float)760. * (float)101.325;
(*tcModelData).pv_.xmeasmonitor[13] = (*tcModelData).teproc_.ppr[6] /
(float)760. * (float)101.325;
(*tcModelData).pv_.xmeasmonitor[14] = (*tcModelData).teproc_.ppr[7] /
(float)760. * (float)101.325;
(*tcModelData).pv_.xmeasmonitor[15] = (*tcModelData).teproc_.xst[48]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[16] = (*tcModelData).teproc_.xst[49]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[17] = (*tcModelData).teproc_.xst[50]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[18] = (*tcModelData).teproc_.xst[51]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[19] = (*tcModelData).teproc_.xst[52]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[20] = (*tcModelData).teproc_.xst[53]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[21] = (*tcModelData).teproc_.xst[72]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[22] = (*tcModelData).teproc_.xst[73]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[23] = (*tcModelData).teproc_.xst[74]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[24] = (*tcModelData).teproc_.xst[75]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[25] = (*tcModelData).teproc_.xst[76]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[26] = (*tcModelData).teproc_.xst[77]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[27] = (*tcModelData).teproc_.xst[78]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[28] = (*tcModelData).teproc_.xst[79]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[29] = (*tcModelData).teproc_.xst[99]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[30] =(*tcModelData).teproc_.xst[100]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[31] =(*tcModelData).teproc_.xst[101]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[32] =(*tcModelData).teproc_.xst[102]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[33] =(*tcModelData).teproc_.xst[103]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[34] = (*tcModelData).teproc_.xst[16]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[35] = (*tcModelData).teproc_.xst[17]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[36] = (*tcModelData).teproc_.xst[18]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[37] = (*tcModelData).teproc_.xst[19]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[38] = (*tcModelData).teproc_.xst[20]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[39] = (*tcModelData).teproc_.xst[21]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[40] = (*tcModelData).teproc_.xst[0] *
(float)100.;
(*tcModelData).pv_.xmeasmonitor[41] = (*tcModelData).teproc_.xst[1] *
(float)100.;
(*tcModelData).pv_.xmeasmonitor[42] = (*tcModelData).teproc_.xst[2] *
(float)100.;
(*tcModelData).pv_.xmeasmonitor[43] = (*tcModelData).teproc_.xst[3] *
(float)100.;
(*tcModelData).pv_.xmeasmonitor[44] = (*tcModelData).teproc_.xst[4] *
(float)100.;
(*tcModelData).pv_.xmeasmonitor[45] = (*tcModelData).teproc_.xst[5] *
(float)100.;
(*tcModelData).pv_.xmeasmonitor[46] = (*tcModelData).teproc_.xst[8] *
(float)100.;
(*tcModelData).pv_.xmeasmonitor[47] = (*tcModelData).teproc_.xst[9] *
(float)100.;
(*tcModelData).pv_.xmeasmonitor[48] = (*tcModelData).teproc_.xst[10]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[49] = (*tcModelData).teproc_.xst[11]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[50] = (*tcModelData).teproc_.xst[12]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[51] = (*tcModelData).teproc_.xst[13]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[52] = (*tcModelData).teproc_.xst[24]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[53] = (*tcModelData).teproc_.xst[25]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[54] = (*tcModelData).teproc_.xst[26]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[55] = (*tcModelData).teproc_.xst[27]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[56] = (*tcModelData).teproc_.xst[28]*
(float)100.;
(*tcModelData).pv_.xmeasmonitor[57] = (*tcModelData).teproc_.xst[29]*
(float)100.;
prate = (float)211.3 * yy[46] / (float)46.534 + (float)1.0e-6;
(*tcModelData).pv_.xmeasmonitor[58] =
(float)100 * ((float).0536 * (*tcModelData).pv_.xmeas[19] +
(float).0318 * (*tcModelData).pv_.xmeas[18] +
(*tcModelData).pv_.xmeas[9] * (float).44791 *
((float)2.209 * (*tcModelData).pv_.xmeas[28] +
(float)6.177 * (*tcModelData).pv_.xmeas[30] +
(float)22.06 * (*tcModelData).pv_.xmeas[31] +
(float)14.56 * (*tcModelData).pv_.xmeas[32] +
(float)17.89 * (*tcModelData).pv_.xmeas[33] +
(float)30.44 * (*tcModelData).pv_.xmeas[34] +
(float)22.94 * (*tcModelData).pv_.xmeas[35]) +
prate *
((float).2206 * (*tcModelData).pv_.xmeas[36] +
(float).1456 * (*tcModelData).pv_.xmeas[37] +
(float).1789 * (*tcModelData).pv_.xmeas[38])
) / prate;
(*tcModelData).pv_.xmeasmonitor[59] =
(float)100 * ((float).0536 * (*tcModelData).teproc_.cpdh * 293.07 +
(float).0318 * (*tcModelData).teproc_.quc * 1040. *
(float).454 +
(*tcModelData).teproc_.ftm[9] *
(float).359 / (float)35.3145 * (float).44791 *
((float)2.209 * xcmp[28] +
(float)6.177 * xcmp[30] +
(float)22.06 * xcmp[31] +
(float)14.56 * xcmp[32] +
(float)17.89 * xcmp[33] +
(float)30.44 * xcmp[34] +
(float)22.94 * xcmp[35]) +
prate *
((float).2206 * xcmp[36] +
(float).1456 * xcmp[37] +
(float).1789 * xcmp[38])
) / prate;
(*tcModelData).pv_.xmeasmonitor[60] =
((float).0536 * (*tcModelData).pv_.xmeas[19] +
(float).0318 * (*tcModelData).pv_.xmeas[18] +
(*tcModelData).pv_.xmeas[9] * (float).44791 *
((float)2.209 * (*tcModelData).pv_.xmeas[28] +
(float)6.177 * (*tcModelData).pv_.xmeas[30] +
(float)22.06 * (*tcModelData).pv_.xmeas[31] +
(float)14.56 * (*tcModelData).pv_.xmeas[32] +
(float)17.89 * (*tcModelData).pv_.xmeas[33] +
(float)30.44 * (*tcModelData).pv_.xmeas[34] +
(float)22.94 * (*tcModelData).pv_.xmeas[35]) +
prate *
((float).2206 * (*tcModelData).pv_.xmeas[36] +
(float).1456 * (*tcModelData).pv_.xmeas[37] +
(float).1789 * (*tcModelData).pv_.xmeas[38]));
(*tcModelData).pv_.xmeasmonitor[61] =
((float).0536 * (*tcModelData).teproc_.cpdh * 293.07 +
(float).0318 * (*tcModelData).teproc_.quc * 1040. * (float).454 +
(*tcModelData).teproc_.ftm[9] *
(float).359 / (float)35.3145 * (float).44791 *
((float)2.209 * xcmp[28] +
(float)6.177 * xcmp[30] +
(float)22.06 * xcmp[31] +
(float)14.56 * xcmp[32] +
(float)17.89 * xcmp[33] +
(float)30.44 * xcmp[34] +
(float)22.94 * xcmp[35]) +
prate *
((float).2206 * xcmp[36] +
(float).1456 * xcmp[37] +
(float).1789 * xcmp[38]));
} //if((*ModelData).MSFlag & 0x4) > 1){
/*Output of Component Concentrations*/
if(((*tcModelData).MSFlag & 0x8) > 1){
for (i__ = 1; i__ <= 8; ++i__){
(*tcModelData).pv_.xmeascomp[0 + i__ - 1] =
(*tcModelData).teproc_.xst[0
(*tcModelData).pv_.xmeascomp[8 + i__ - 1] =
(*tcModelData).teproc_.xst[8
(*tcModelData).pv_.xmeascomp[16 + i__ - 1] =
(*tcModelData).teproc_.xst[16
(*tcModelData).pv_.xmeascomp[24 + i__ - 1] =
(*tcModelData).teproc_.xst[24
(*tcModelData).pv_.xmeascomp[32 + i__ - 1] =
(*tcModelData).teproc_.xst[32
(*tcModelData).pv_.xmeascomp[40 + i__ - 1] =
(*tcModelData).teproc_.xst[40
(*tcModelData).pv_.xmeascomp[48 + i__ - 1] =
+ i__ - 1];
+ i__ - 1];
+ i__ - 1];
+ i__ - 1];
+ i__ - 1];
+ i__ - 1];
(*tcModelData).teproc_.xst[56
(*tcModelData).pv_.xmeascomp[56 + i__ - 1] =
(*tcModelData).teproc_.xst[64
(*tcModelData).pv_.xmeascomp[64 + i__ - 1] =
(*tcModelData).teproc_.xst[72
(*tcModelData).pv_.xmeascomp[72 + i__ - 1] =
(*tcModelData).teproc_.xst[80
(*tcModelData).pv_.xmeascomp[80 + i__ - 1] =
(*tcModelData).teproc_.xst[88
(*tcModelData).pv_.xmeascomp[88 + i__ - 1] =
(*tcModelData).teproc_.xst[96
} //for (i__ = 1; i__ <= 8; ++i__){
} //if(((*tcModelData).MSFlag & 0x8) > 1){
} //if((Callflag < 2) && (((*tcModelData).MSFlag & 0x8000) ==
/*Calculation of State Derivative*/
if(((Callflag == 2) ||(Callflag == 0)) &&
(((*tcModelData).MSFlag & 0x8000) == 0)){
for (i__ = 1; i__ <= 8; ++i__){
yp[i__]
= (*tcModelData).teproc_.fcm[i__ + 47]
(*tcModelData).teproc_.fcm[i__ + 55]
(*tcModelData).teproc_.crxr[i__ - 1];
yp[i__ + 9] = (*tcModelData).teproc_.fcm[i__ + 55] (*tcModelData).teproc_.fcm[i__ + 63] (*tcModelData).teproc_.fcm[i__ +
(*tcModelData).teproc_.fcm[i__ + 79];
yp[i__ + 18] = (*tcModelData).teproc_.fcm[i__ + 87] (*tcModelData).teproc_.fcm[i__ + 95];
yp[i__ + 27] = (*tcModelData).teproc_.fcm[i__ - 1]
(*tcModelData).teproc_.fcm[i__ + 7] +
(*tcModelData).teproc_.fcm[i__ + 15]
(*tcModelData).teproc_.fcm[i__ + 31] +
(*tcModelData).teproc_.fcm[i__ +
(*tcModelData).teproc_.fcm[i__ + 39];
/* L9010: */
} //for (i__ = 1; i__ <= 8; ++i__){
+ i__ - 1];
+ i__ - 1];
+ i__ - 1];
+ i__ - 1];
+ i__ - 1];
+ i__ - 1];
0)){
71] -
+
+
63] -
yp[36] =
(*tcModelData).teproc_.hst[0] * (*tcModelData).teproc_.ftm[0] +
(*tcModelData).teproc_.hst[1] * (*tcModelData).teproc_.ftm[1] +
(*tcModelData).teproc_.hst[2] * (*tcModelData).teproc_.ftm[2] +
(*tcModelData).teproc_.hst[4] * (*tcModelData).teproc_.ftm[4] +
(*tcModelData).teproc_.hst[8] * (*tcModelData).teproc_.ftm[8] (*tcModelData).teproc_.hst[5] * (*tcModelData).teproc_.ftm[5];
yp[37] = ((*tcModelData).teproc_.fwr * (float)500.53 *
((*tcModelData).teproc_.tcwr - (*tcModelData).teproc_.twr) (*tcModelData).teproc_.qur * 1e6 / (float)1.8) /
(*tcModelData).teproc_.hwr;
yp[38] = ((*tcModelData).teproc_.fws * (float)500.53 *
((*tcModelData).teproc_.tcws - (*tcModelData).teproc_.tws) (*tcModelData).teproc_.qus * 1e6 / (float)1.8) /
(*tcModelData).teproc_.hws;
(*tcModelData).teproc_.ivst[9] = (*tcModelData).dvec_.idv[13];
(*tcModelData).teproc_.ivst[10] = (*tcModelData).dvec_.idv[14];
(*tcModelData).teproc_.ivst[4] = (*tcModelData).dvec_.idv[18];
(*tcModelData).teproc_.ivst[6] = (*tcModelData).dvec_.idv[18];
(*tcModelData).teproc_.ivst[7] = (*tcModelData).dvec_.idv[18];
(*tcModelData).teproc_.ivst[8] = (*tcModelData).dvec_.idv[18];
for (i__ = 1; i__ <= 12; ++i__){
if ((*time == 0.) ||
(d__1 = (*tcModelData).teproc_.vcv[i__ - 1] (*tcModelData).pv_.xmv[i__ - 1],
abs(d__1)) > (*tcModelData).teproc_.vst[i__ - 1] *
(*tcModelData).teproc_.ivst[i__ - 1]){
(*tcModelData).teproc_.vcv[i__ - 1] =
(*tcModelData).pv_.xmv[i__ - 1];
} //if ((*time == 0.) || ...
/*Constraints of Manipulated Variable*/
if ((*tcModelData).teproc_.vcv[i__ - 1] < (float)0.){
(*tcModelData).teproc_.vcv[i__ - 1] = (float)0.;
} //if ((*tcModelData).teproc_.vcv[i__ - 1] < (float)0.){
if ((*tcModelData).teproc_.vcv[i__ - 1] > (float)100.){
(*tcModelData).teproc_.vcv[i__ - 1] = (float)100.;
} //if ((*tcModelData).teproc_.vcv[i__ - 1] > (float)100.){
yp[i__ + 38] =
((*tcModelData).teproc_.vcv[i__ - 1] - vpos[i__ - 1]) /
(*tcModelData).teproc_.vtau[i__ - 1];
/* L9020: */
} //for (i__ = 1; i__ <= 12; ++i__){
if (*time > (float)0. && *isd != (float)0.){
i__1 = *nn;
for (i__ = 1; i__ <= i__1; ++i__){
yp[i__] = (float)0.;
/* L9030: */
} //for (i__ = 1; i__ <= i__1; ++i__){
} //if (*time > (float)0. && *isd != 0){
} //if(((Callflag == 3) ||(Callflag == 0)) && ...
#undef isd
return 0;
} /* tefunc_ */
/*------------------------------------------------------------------------t e s u b 1 _
-------------------------------------------------------------------------*/
static int tesub1_(void *ModelData,
doublereal *z__, doublereal *t, doublereal *h__,
const integer *ity){
/*----------------------------- Variables -----------------------------*/
doublereal d__1;
struct stModelData *tcModelData;
integer i__;
doublereal r__, hi;
/*Typcast of Dataset Pointer*/
tcModelData = ModelData;
/*Parameter adjustments*/
--z__;
/*--------------------------- Function Body ---------------------------*/
if (*ity == 0){
*h__ = 0.;
for (i__ = 1; i__ <= 8; ++i__){
/* Computing 2nd power */
d__1 = *t;
/*Integration von Enthalpie-Gleichung (temperaturabhngigkeit)
in tesub3_*/
hi = *t * ((*tcModelData).const_.ah[i__ - 1] +
(*tcModelData).const_.bh[i__ - 1] * *t / 2. +
(*tcModelData).const_.ch[i__ - 1] * (d__1 * d__1) / 3.);
hi *= 1.8;
*h__ += z__[i__] * (*tcModelData).const_.xmw[i__ - 1] * hi;
/* L100: */
} //for (i__ = 1; i__ <= 8; ++i__){
}else{
*h__ = 0.;
for (i__ = 1; i__ <= 8; ++i__){
/* Computing 2nd power */
d__1 = *t;
hi = *t * ((*tcModelData).const_.ag[i__ - 1] +
(*tcModelData).const_.bg[i__ - 1] * *t / 2. +
(*tcModelData).const_.cg[i__ - 1] * (d__1 * d__1) / 3.)
;
hi *= 1.8;
hi += (*tcModelData).const_.av[i__ - 1];
*h__ += z__[i__] * (*tcModelData).const_.xmw[i__ - 1] * hi;
/* L200: */
} //for (i__ = 1; i__ <= 8; ++i__){
} //if (*ity == 0){
if (*ity == 2){
r__ = 3.57696e-6;
*h__ -= r__ * (*t + (float)273.15);
} //if (*ity == 2){
return 0;
} /* tesub1_ */
/*------------------------------------------------------------------------t e s u b 2 _
-------------------------------------------------------------------------*/
static int tesub2_(void *ModelData,
doublereal *z__, doublereal *t, doublereal *h__,
const integer *ity){
/*----------------------------- Variables -----------------------------*/
integer j;
doublereal htest;
doublereal dh;
doublereal dt, err, tin;
/*Parameter adjustments*/
--z__;
/*--------------------------- Function Body ---------------------------*/
tin = *t;
for (j = 1; j <= 100; ++j){
tesub1_(ModelData, &z__[1], t, &htest, ity);
err = htest - *h__;
tesub3_(ModelData, &z__[1], t, &dh, ity);
dt = -err / dh;
*t += dt;
/* L250: */
if (abs(dt) < 1e-12){
goto L300;
} //if (abs(dt) < 1e-12){
} //for (j = 1; j <= 100; ++j){
*t = tin;
/*------------------------ B R A N C H M A R K ------------------------*/
L300:
/*------------------------ B R A N C H M A R K ------------------------*/
return 0;
} /* tesub2_ */
/*------------------------------------------------------------------------t e s u b 3 _
-------------------------------------------------------------------------*/
static int tesub3_(void *ModelData,
doublereal *z__, doublereal *t, doublereal *dh,
const integer *ity){
/*----------------------------- Variables -----------------------------*/
doublereal d__1;
struct stModelData *tcModelData;
integer i__;
doublereal r__, dhi;
/*Typcast of Dataset Pointer*/
tcModelData = ModelData;
/*Parameter adjustments*/
--z__;
/*--------------------------- Function Body ---------------------------*/
if (*ity == 0){
*dh = 0.;
for (i__ = 1; i__ <= 8; ++i__){
/* Computing 2nd power */
d__1 = *t;
dhi = (*tcModelData).const_.ah[i__ - 1] +
(*tcModelData).const_.bh[i__ - 1] * *t +
(*tcModelData).const_.ch[i__ - 1]
dhi *= 1.8;
*dh += z__[i__] * (*tcModelData).const_.xmw[i__
/* L100: */
} //for (i__ = 1; i__ <= 8; ++i__){
}else{
*dh = 0.;
for (i__ = 1; i__ <= 8; ++i__){
/* Computing 2nd power */
d__1 = *t;
dhi = (*tcModelData).const_.ag[i__ - 1] +
(*tcModelData).const_.bg[i__ - 1] * *t +
(*tcModelData).const_.cg[i__ - 1]
dhi *= 1.8;
*dh += z__[i__] * (*tcModelData).const_.xmw[i__
/* L200: */
} //for (i__ = 1; i__ <= 8; ++i__){
} //if (*ity == 0){
* (d__1 * d__1);
- 1] * dhi;
* (d__1 * d__1);
- 1] * dhi;
if (*ity == 2){
r__ = 3.57696e-6;
*dh -= r__;
} //if (*ity == 2){
return 0;
} /* tesub3_ */
/*------------------------------------------------------------------------t e s u b 4 _
-------------------------------------------------------------------------*/
static int tesub4_(void *ModelData,
doublereal *x, doublereal *t, doublereal *r__){
/*----------------------------- Variables -----------------------------*/
struct stModelData *tcModelData;
integer i__;
doublereal v;
/*Typcast of Dataset Pointer*/
tcModelData = ModelData;
/*Parameter adjustments*/
--x;
/*--------------------------- Function Body ---------------------------*/
v = (float)0.;
for (i__ = 1; i__ <= 8; ++i__){
v += x[i__] * (*tcModelData).const_.xmw[i__ - 1] /
((*tcModelData).const_.ad[i__ - 1] +
((*tcModelData).const_.bd[i__ - 1] +
(*tcModelData).const_.cd[i__ - 1] * *t) * *t);
/* L10: */
} //for (i__ = 1; i__ <= 8; ++i__){
*r__ = (float)1. / v;
return 0;
} /* tesub4_ */
/*------------------------------------------------------------------------t e s u b 5 _
-------------------------------------------------------------------------*/
static int tesub5_(void *ModelData,
doublereal *s, doublereal *sp, doublereal *adist,
doublereal *bdist, doublereal *cdist, doublereal *ddist,
doublereal *tlast, doublereal *tnext, doublereal *hspan,
doublereal *hzero, doublereal *sspan, doublereal
*szero,
doublereal *spspan, doublereal *idvflag){
/*----------------------------- Variables -----------------------------*/
doublereal h__;
integer i__;
doublereal s1;
doublereal s1p;
doublereal d__1;
/*--------------------------- Function Body ---------------------------*/
i__
= -1;
h__
= *hspan * tesub7_(ModelData, &i__) + *hzero;
s1
= *sspan * tesub7_(ModelData, &i__) * *idvflag + *szero;
s1p
= *spspan * tesub7_(ModelData, &i__) * *idvflag;
/* Computing 0th power */
*adist = *s;
/* Computing 1rd power */
*bdist = *sp;
/* Computing 2nd power */
d__1 = h__;
*cdist = ((s1 - *s) * 3. - h__ * (s1p + *sp * 2.)) / (d__1 * d__1);
/* Computing 3rd power */
d__1 = h__;
*ddist = ((*s - s1) * 2. + h__ * (s1p + *sp)) / (d__1 * (d__1 * d__1));
*tnext = *tlast + h__;
return 0;
} /* tesub5_ */
/*------------------------------------------------------------------------t e s u b 6 _
-------------------------------------------------------------------------*/
static int tesub6_(void *ModelData, doublereal *std, doublereal *x){
/*----------------------------- Variables -----------------------------*/
integer i__;
/*--------------------------- Function Body ---------------------------*/
*x = 0.;
for (i__ = 1; i__ <= 12; ++i__){
*x += tesub7_(ModelData, &i__);
} //for (i__ = 1; i__ <= 12; ++i__){
*x = (*x - 6.) * *std;
return 0;
} /* tesub6_ */
/*------------------------------------------------------------------------t e s u b 7 _
-------------------------------------------------------------------------*/
static doublereal tesub7_(void *ModelData, integer *i__){
/*----------------------------- Variables -----------------------------*/
struct stModelData *tcModelData;
doublereal ret_val, *d__1, c_b78;
/*Typcast of Dataset Pointer*/
tcModelData = ModelData;
/*--------------------------- Function Body ---------------------------*/
c_b78 = 4294967296.;
/*Generation of Random Numbers for Measurment Noise*/
if (*i__ >= 0){
if(((*tcModelData).MSFlag & 0x20) > 0){
d__1 = &(*tcModelData).randsd_.measnoise;
}else{
d__1 = &(*tcModelData).randsd_.g;
}
*d__1 = *d__1 * 9228907.;
*d__1 = d_mod(d__1, &c_b78);
ret_val = *d__1 / 4294967296.;
} //if (*i__ >= 0){
/*Generation of Random Numbers for Process Disturbances*/
if (*i__ < 0){
if(((*tcModelData).MSFlag & 0x20) > 0){
d__1 = &(*tcModelData).randsd_.procdist;
}else{
d__1 = &(*tcModelData).randsd_.g;
}
*d__1 = *d__1 * 9228907.;
*d__1 = d_mod(d__1, &c_b78);
ret_val = *d__1 * 2.0 / 4294967296. - 1.;
} //if (*i__ < 0){
return ret_val;
} /* tesub7_ */
/*------------------------------------------------------------------------t e s u b 8 _
-------------------------------------------------------------------------*/
static doublereal tesub8_(void *ModelData,
const integer *i__, doublereal *t){
/*----------------------------- Variables -----------------------------*/
doublereal ret_val;
struct stModelData *tcModelData;
doublereal h__;
/*Typcast of Dataset Pointer*/
tcModelData = ModelData;
/ *y) >= 0)
floor(quotient);
-floor(-quotient);
quotient );
/*------------------------------------------------------------------------? ? ? ? ? ?
-
-------------------------------------------------------------------------*/
#ifdef KR_headers
double pow();
double pow_dd(ap, bp) doublereal *ap, *bp;
#else
#undef abs
double pow_dd(doublereal *ap, const doublereal *bp)
#endif
{
return(pow(*ap, *bp) );
} //??
/*=============================*
* Required S-function trailer *
*=============================*/
#ifdef MATLAB_MEX_FILE
#include "simulink.c"
#else
#include "cg_sfun.h"
#endif