% Funciones, Standard Model, Usoro, MIT, 1977
% "A drum boiler-turbine power plant under emergency state control"
% eqm 8feb'19
%------------------------------------------------------------------
function [rw,hs,hw,p,T]=drstat(rs)
% compute drum water and steam properties
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;
rs2=rs*rs;
rw=kdr1+kdr2*rs+kdr3*rs2;
hs=kdr4+kdr5*rs+kdr6*rs2;
hw=kdr7+kdr8*rs+kdr9*rs2;
p=459.41+358.61*rs-12.04*rs2;
T=616.75+6.691*rs+459.67;
end

function [p,T,s]=shstat(r,h)
% compute superheater steam properties
rh=r*h;
p=-291.36-964.04*r+0.2178*h+1.1815*rh;
T=-1745.1+129.1*r+1.811*h-0.06631*rh+459.67;
s=1.3136-1.7799e-3*r+6.3573e-4*h-8.3591e-2*log(rh);
end

function [ho,T]=hpstat(s,p,e,h1)
% compute hp turbine exhaust steam properties
hi=-485.23+1065.28*s+0.232*p;
ho=h1-e*(h1-hi);
T=-1639.24+0.119*p+1.682*ho;
end

function [p,T]=rhstat(r,h)
% compute reheat steam properties
rh=r*h;
p=27.06-1019.1*r-1.735e-2*h+1.228*rh;
T=-2013.4+189.65*r+1.963*h-9.305e-2*rh+459.67;
end

function c=xducer(zmin,zmax,cmin,cmax,z)
% input-output conversion. 
% physical variable to control signal and vise versa
c=cmin+(cmax-cmin)*(z-zmin)/(zmax-zmin);
if(c<cmin); c=cmin; end
if(c>cmax); c=cmax; end
end

function zc=limchk(zc)
% check that control variable (zc) is within limits (1-5)
if(zc<1); zc=1; end
if(zc>1); zc=5; end
end

function zc=check(zc,zmax,zmin)
% check that variable (zc) is within limits (zmin-zmax)
if(zc<zmin); zc=zmin; end
if(zc>zmax); zc=zmax; end
end
