0% found this document useful (0 votes)
29 views3 pages

Two CSTR GMC PI FunctionFile

Uploaded by

kavigopaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Two CSTR GMC PI FunctionFile

Uploaded by

kavigopaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

%==========FUNCTION FILE=================================================

%Solves for Volume, Temperaure and the integral of the error for each. This
%file calculates the apparently continuous response and MV values for the
%tank under PI control. The MV is not sent to the main file and is
%therefore recalculated in that file.
%This file is used with ODE45 in the main file where it can obtain the PV
%and integral of the error values.
%========================================================================
function xdot = Two_CSTR_GMC_PI_FunctionFile(t,x)
%x(1)=h
%x(2)=V
%x(3)=T
%x(4)=C
%x(5)=IeV Integral of Volume error
%x(6)=IeT Integral of Temperature error
%x(7)=h2
%x(8)=V2
%x(9)=T2
%x(10)=C2
%x(11)=IeV Integral of Volume error
%x(12)=IeT Integral of Temperature error

%===========IMPORT GLOBAL VARIABLES=================================


global Fos Fins mcs Tins Cins Tcins SPVs SPTs %Steadystate values
global kcV kcT tauiV tauiT tauionT tauionV MV1min MV1max MV2min MV2max %Controller
paramaters
global K1V K2V K1T K2T
global dFo2 dTin dCin dTcin dSPV dSPT % dFo dmc %Step changes
global A Ua DH E_R K0 Cpc pCp

global Fos2 Tcins2 mcs2 SPVs2 SPTs2 %Steadystate values


global kcV2 kcT2 tauiV2 tauiT2 tauionT2 tauionV2 MV3min MV3max MV4min MV4max
%Controller paramaters
global K1V2 K2V2 K1T2 K2T2
global dTcin2 dSPV2 dSPT2 % dFo dmc %Step changes
global A2 Ua2 DH2 E_R2 K02 Cpc2 pCp2

global FinOLs FoOLs mcOLs mc2OLs dFinOL dFoOL dmcOL dmc2OL


global ratio
global Frstep steptime steptime2 steptime3 dSPV_2 dSPT_2 dSPV2_2 dSPT2_2
dFo2_2%Timing
%============SYSTEM CHANGES=========================================
if t<=steptime
Fo2=Fos2;
Tin=Tins;
Cin=Cins;
Tcin=Tcins;
SPV=SPVs;
SPT= SPTs;

Tcin2=Tcins2;
SPV2=SPVs2;
SPT2= SPTs2;

elseif t>steptime
Fo2=Fos2+dFo2;
Tin=Tins+dTin;
Cin=Cins+dCin;
Tcin=Tcins+dTcin;
SPV=SPVs+dSPV; %Setpoint change
SPT=SPTs+dSPT; %Setpoint change

Tcin2=Tcins2+dTcin2;
SPV2=SPVs2+dSPV2; %Setpoint change
SPT2=SPTs2+dSPT2; %Setpoint change

end
if t<=Frstep
Fr=0;
else
Fr=Fo2*ratio;
end
%NOTE:Implements any changes to the system

%=========ERROR VALUES=============================================
eV=SPV-x(2); %Calculate error in height
eT=SPT-x(3); %Calculate error in temp

eV2=SPV2-x(8); %Calculate error in height


eT2=SPT2-x(9); %Calculate error in temp

%=========CONTROLLER(PI and GMC)===========================================


MV1=Fins+kcV*(eV+x(5)*tauionV/tauiV); %Calculate MV1=Fin
MV3=Fos+kcV2*(eV2+x(11)*tauionV2/tauiV2); % Tank2 Volume PI Controller
% Tank1 Temperature controller (GMC)
MV2=Ua/( ((Cpc*Ua*(x(3)-Tcin))/(-pCp*( (x(2)*(K1T*eT + K2T*x(6))) +DH*(K0*exp(-
(E_R)/x(3)))*x(4)*x(2) -MV1*Tin -(Fr*x(9)) +MV3*x(3) + x(3)*(MV1+Fr-MV3)))) - Cpc)
; %Calculate MV2
% Tank2 Temperature controller (GMC)
%MV4=Ua2/( ((Cpc2*Ua2*(x(9)-Tcin2))/(-pCp2*( (x(8)*(K1T2*eT2 + K2T2*x(12)))
+DH*(K0*exp(-(E_R2)/x(9)))*x(10)*x(8) -MV3*x(9) +Fo2*x(9) +(Fr*x(9)) + x(9)*(MV3-
Fo2-Fr)))) - Cpc2) ; %Calculate MV4
MV4= - (x(9)*Ua2 + Ua2*pCp2*(Fo2*(x(9) - x(3)) + x(8)*(K1T2*eT2 + x(12)*K2T2*eT2) +
x(10)*DH*K0*x(8)*exp((-6000/x(9)))))/(Cpc*(Tcin2 + pCp2*(Fo2*(x(9) - x(3)) +
x(8)*(K1T2*eT2 + x(12)*K2T2*eT2) + x(10)*DH*K0*x(8)*exp((-6000/x(9))))));

%=========CONTROLLER OUTPUT LIMITS=================================


%TANK 1
if MV1<=MV1min %Considers MV1 minimum limit
Fin=MV1min;
elseif MV1>=MV1max %Considers MV1 maximum limit
Fin=MV1max;
else
Fin=MV1;
end
if MV2<=MV2min %Considers MV1 minimum limit
mc=MV2min;
elseif MV2>=MV2max %Considers MV2 maximum limit
mc=MV2max;
else
mc=MV2;
end
%TANK 2
if MV3<=MV3min %Considers MV1 minimum limit
Fo=MV3min;
elseif MV3>=MV3max %Considers MV1 maximum limit
Fo=MV3max;
else
Fo=MV3;
end
if MV4<=MV4min %Considers MV1 minimum limit
mc2=MV4min;
elseif MV4>=MV4max %Considers MV2 maximum limit
mc2=MV4max;
else
mc2=MV4;
end

%=========SYSTEM OF ODEs===========================================
%TANK 1
Tc=( ((Ua*x(3)) + (mc*Cpc*Tcin))/(Ua + mc*Cpc) );
rate=-(K0*exp(-(E_R)/x(3)) )*x(4)*x(2);
cool=mc*Cpc*(Tc-Tcin);

xdot(1)=(1/A)*(Fin + Fr - Fo ); %dh/dt
xdot(2)=(Fin + Fr - Fo); % dV/dt
xdot(3)=(1/x(2))*( (DH*rate) + (Fin*Tin) + (Fr*x(9)) - (Fo*x(3)) - (cool/pCp) -
(x(3)*xdot(2)) ); %dT/dt
xdot(4)=(1/x(2))*( rate + (Fin*Cin) + (Fr*x(10)) - (Fo*x(4)) - (x(4)*xdot(2)));
%dC/dt
xdot(5)=eV; %dIeV/dt
xdot(6)=eT; %dIeT/dt

%TANK 2
Tc2=( ((Ua2*x(9)) + (mc2*Cpc2*Tcin2))/(Ua2 + mc2*Cpc2) );
rate2=-(K02*exp(-(E_R2)/x(9)) )*x(10)*x(8);
cool2=mc2*Cpc2*(Tc2-Tcin2);

xdot(7)=(1/A2)*(Fo - (Fo2+Fr) ); %dh2/dt


xdot(8)=(Fo - (Fo2+Fr)); % dV2/dt
xdot(9)=(1/x(8))*( (DH2*rate2) + (Fo*x(3)) - ((Fo2+Fr)*x(9)) - (cool2/pCp2) -
(x(9)*xdot(8)) ); %dT2/dt
xdot(10)=(1/x(8))*( rate2 + (Fo*x(4)) - ((Fo2+Fr)*x(10)) - (x(10)*xdot(8)) );
%dC2/dt
xdot(11)=eV2; %dIeV2/dt
xdot(12)=eT2; %dIeT2/dt
xdot=[xdot(1) xdot(2) xdot(3) xdot(4) xdot(5) xdot(6) xdot(7) xdot(8) xdot(9)
xdot(10) xdot(11) xdot(12)]'; %put the system of ODE into an array

You might also like