% RUN FILE FOR DYNAMIC SIMULATION OF THE 6:1 HEN

% Topology to be investigated:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%            1     2     3     4     5     6           %
%        ----0-----0-----0-----0-----0-----0----       %
%   ----|                                       |----  %
%        -------------------0-------------------       %
%                           7                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;
close all;
clc;

[T0,Th1,Th2,Th3,Th4,Th5,Th6,Th7...
            m0,m1,m2,mh1,mh2,mh3,mh4,mh5,mh6,mh7...
            rho_0,hc,Cp0...
            Vwall,rho_wall,Cp_wall...
            P1,P2,P3,P4,P5,P6,P7] = Data
 

        
sim('dynamic_61')


% % TUNING OF CONTROLLER
% % 10% STEP CHANGE INLET MASS FLOW COLD STREAM
% % TUNING PLOT
% t0 = 800;
% tend = 2400;
% 
% cv1_0 = -43;
% cv1_end = 7;
% cv1_step = 10;
% 
% m1_0 = 40;
% m1_end = 48;
% m1_step = 2;
% 
% k = figure;
% [AX,H1,H2] = plotyy(t,cv1,t,m1);
% set(get(AX(1),'Ylabel'),'String','Controlled variable, JT [^{\circ}C]','fontsize',12)
% set(get(AX(2),'Ylabel'),'String','Mass flow m_1 to upper path [kg/sec]','fontsize',12)
% axis(AX(1),[t0 tend cv1_0 cv1_end]);
% axis(AX(2),[t0 tend m1_0 m1_end]);
% set(AX(1),'YLim',[cv1_0 cv1_end])
% set(AX(1),'YTick',cv1_0:cv1_step:cv1_end)
% set(AX(2),'YLim',[m1_0 m1_end])
% set(AX(2),'YTick',m1_0:m1_step:m1_end)
% xlabel('Time [sec]','fontsize',12)
% set(H1,'linewidth',2)
% set(H2,'linewidth',2)
% grid on
% print(k,'-depsc','tune_61.eps');


% PLOTTING THE RESULTS

t0 = 800;
tend = 5000;

cv1_0 = -1.5;
cv1_end = 1.5;
cv1_step = 0.5;

u_0 = 0.82;
u_end = 0.8601;

% CONTROLLED VARIABLE PROFILES
h = figure;
plot(t,cv1,'LineWidth',2)
xlabel('Time [sec]','fontsize',12)
ylabel('Controlled variable, JT [^{\circ}C]','fontsize',12)
axis([t0 tend cv1_0 cv1_end])
grid on
% print(h,'-depsc','CV_61.eps');

% SPLIT
j = figure;
plot(t,u1,'LineWidth',2)
xlabel('Time [sec]','fontsize',12)
ylabel('Split u (Upper path)','fontsize',12)
axis([t0 tend u_0 u_end])
grid on
% print(j,'-depsc','Split_61.eps');

% TEMPERATURE PROFILES
k = figure;
plot(t,T1,t,T2,t,T3,t,T4,t,T5,t,T6,t,T7,t,Tend,'LineWidth',2)
legend('T_{1,1}','T_{2,1}','T_{3,1}','T_{4,1}','T_{5,1}',...
    'T_{6,1}','T_{1,2}','T_{end}')
xlabel('Time [sec]','fontsize',12)
ylabel('Temperature [^{\circ}C]','fontsize',12)
axis([t0 tend 130 175])
% print(k,'-depsc','T_61.eps');




