% Initial conditions, Standard Model, Usoro, MIT, 1977
% "A drum boiler-turbine power plant under emergency state control"
% eqm 7feb'19
%-------------------------------------------------------------------
% set constant and system parameter values
knp5=0.5; kn0=0; kn1=1; kn2=2; kn3=3; kn4=4; kn5=5; kn6=6; km1=-1;
km5=-5; kn4p7=4.7; kc1gn=1; kmwr=4.428e8; kntr=377; ktclh=60;
ktcde=280; ktchh=60; hcnw=56.7; khcpd=1.4; khfpd=11; ketr=0.88;
kmwx=1.355e-6; kfsh=2.7e-3; kcv=0.459; kwhp=0.895; kwrh=1.784;
kmece=1.784e5; kmwwme=1.524e6; kswwm=0.11; kvsh=5000; kmshe=1.693e5;
kfrh=4.59e-5; khlpo=1025; kvrh=6000; kmrhe=1.078e5; kefl=1;
khfl=18200; ksgpe=0.28; ksar=0.252; ktar=1060; ksgr=0.27; 
ktecgo=1077.7; ksfl=0.49; ktfl=860; ksfng=0.31; k1xgg=1; 
k2xgg=-0.2865; kjtre=150*6.25e5; ktcfw=10; kuwwgm=186.19; kuwwmw=25876.4;
kj=778.17; kt0=537; k1tgr=929.7; k2tgr=2.1512; % kjtre=6.25e5;
%------------------------------------------------------------------
% drum parameters
kvdr=1958.7; kvdrw=1170.2; kvdrs=788.5; kdr1=49.271; kdr2=-2.137;
kdr3=0.03348; kdr4=1241.7; kdr5=-21.344; kdr6=0.21; kdr7=526.6;
kdr8=31.044; kdr9=-0.6209;
%------------------------------------------------------------------
% boiler master control parameters
kcl=1; kcu=5; kpssol=0; kpssou=3015.0; kc1md=20; kc2md=0.5; 
ktc1md=60; % kc2md=0.5;
%------------------------------------------------------------------
% air flow control parameters
kwarl=0; kwaru=1381.4; kc1ar=3; kc2arl=1.817; kc4ar=1; ktc1ar=60; 
ktc2ar=5;%ktc1ar=60
%------------------------------------------------------------------
% fuel flow control parameters
kwfll=0; kwflu=90; kc1fl=3; kc3fl=1; ktc1fl=60; ktc2fl=5;%ktc1fl=60
%------------------------------------------------------------------
% gas recirculation control parameters
knp087=0.08727; ktrhol=1159.7; ktrhou=1559.7; kwgrl=0; kwgru=500;
kc1gr=0.004; ktc1gr=20; kc2gr=0.8; kc3gr=1;
%------------------------------------------------------------------
% reheat temperature control parameters
kcryl=-2; kcryu=-1; kwryl=0; kwryu=50; kxggl=-0.5236; kxggu=0.5236;
k1trh=1192.5; k2trh=0.4126; k3trh=1259.7; k4trh=1459.7; kc1rh=5;
kc4rh=1; kc5rh=1; ktc1rh=60; ktc2rh=5; ktc3rh=5; kc1ry=-1;
%------------------------------------------------------------------
% superheat temperature control parameters
ktssol=1159.7; ktssou=1559.7; kcsyl=-5; kcsyu=-1; k1tss=1338; 
k2tss=0.1925; k3tss=1359.7; k4tss=1459.7; kwsyl=0; kwsyu=100;
kc1sy=10; kc4sy=-1; kc5sy=1; ktc1sy=60; ktc2sy=5;
%------------------------------------------------------------------
% turbine control parameters
kntrl=0; kntru=450; kavl=0; kavu=1; kmwtrl=0; kmwtru=531.36e6;
kcvreg=0.05; kc1tr=1; kc2tr=1; ktc1tr=10; ktc2tr=1; ktc3tr=1;
%------------------------------------------------------------------
ldc=5; jcount=0; jc=0; jcnt=400;
% Initial states 77.5%, ldc=3.875, #81/101
% x0=[628.28; 8.3034; 1145.4; 3.1415; 1459.4; 0.48468; 1523.3;...
%     377.0; 194.51; 252.15; 446.66; 3.7233; 3.7237; 3.7232;...
%     3.6709; 2.6319; 2.7344; 3.7361; 3.7252; 3.7019; 2.6234;...
%     2.6234; 2.7882; -0.15590; 3.7198; 3.7172; 0.39777];           
% Initial states 100%, ldc=5, #71, eqm 
x0=[ 6.3529e+02;9.3019e+00;1.1564e+03;3.1395e+00;1.4598e+03;6.5532e-01;...
    1.5190e+03;3.7699e+02;2.0254e+02;2.6246e+02;4.7228e+02;4.5086e+00;...
    4.5088e+00;4.5083e+00;2.5594e+00;2.7706e+00;3.9321e+00;4.5117e+00;...
    4.5105e+00;2.5594e+00;2.7723e+00;2.7723e+00;3.9330e+00;-6.4588e-03;...
    4.9931e+00;4.9922e+00;4.9594e-01];
% Initial states 50%, ldc=2.5, #91, eqm
% x0=[ 6.4019e+02;7.7414e+00;1.1375e+03;3.2070e+00;1.4470e+03;3.2361e-01;...
%     1.5033e+03;3.7701e+02;1.8637e+02;2.3957e+02;4.1777e+02;2.7942e+00;...
%     2.7942e+00;2.7939e+00;3.8740e+00;2.7388e+00;4.9266e+00;2.7946e+00;...
%     2.7945e+00;3.8740e+00;2.7436e+00;2.7436e+00;4.8905e+00;-8.2693e-02;...
%     2.4177e+00;2.4145e+00;2.4307e-01];
xx=x0';xx2=[]; x00=x0; tprint=0;
% equivalence
% x0=[heco, rdrs, twwm, rsso, hsso, rrho, hrho,...
%     ntr, hlho, hdew, hhho, c3md, c5ar, c5fl,...
%     c2gr, c5rh, c5sy, card, cfld, cgrd, cwryd,...
%     cxggd, csyd, c6tr, c9tr, c12tr, delta];
heco=x0(1); rdrs=x0(2); twwm=x0(3); rsso=x0(4); hsso=x0(5);
rrho=x0(6); hrho=x0(7); ntr=x0(8); hlho=x0(9); hdew=x0(10);
hhho=x0(11); c3md=x0(12); c5ar=x0(13); c5fl=x0(14); c2gr=x0(15);
c5rh=x0(16); c5sy=x0(17); card=x0(18); cfld=x0(19); cgrd=x0(20);
cwryd=x0(21); cxggd=x0(22); csyd=x0(23); c6tr=x0(24); c9tr=x0(25);
c12tr=x0(26); delta=x0(27);
% --  System to be Controlled (MATLAB)  --
mat_model = 'stdpte';       % Name of MATLAB model
%model_out = 'stdout';         % Output equation (function of the states)
% ------    General Initializations  -------
Ts = 0.1;                   % Sampling period (in seconds)
samples  = 7001;              % Number of samples to be simulated