%% Author: Ida Andersskog

clear
close all
clc;
warning off

%% Run parameters

runtime = 1000;
relTol = 1e-8;
run Parameters.m

%% Run simulink

sim('ClosedSteamCycle.slx')

%% Plot settings

set(findobj(gcf,'type','line'),'LineWidth',1);
set(findobj(gcf,'type','axes'),'FontSize',12);
set(findobj(gcf,'type','legend'),'FontSize',12);
set(findall(gcf,'Type','text'),'FontSize',14,'Interpreter','latex');
set(gcf,'color','white')

%% Plotting

width = 2;
length = 4;

figure(1)
subplot(length,width,1)
plot(time,M1/1000,time,Mturbine/1.003100000000000e+02,time,Mmix/2.645020e+01)
xlabel('Time [s]')
ylabel('Liquid holdup [kg]')
legend('M_1','M_{turbine}','M_{mix}')

subplot(length,width,2)
plot(time,P1/9.929867204853673e+06, time, P2/9800100,time,P3/9291900)
xlabel('Time [s]')
ylabel('Pressure [Pa]')
legend('P_1','P_2','P_3')

subplot(length,width,3)
plot(time,T1/5.840833000000000e+02,time,T2hot/8.767845000000000e+02,time,T2/8.021171000000001e+02)%,time,T3mid,time,TG3)
xlabel('Time [s]')
ylabel('Temperature [K]')
legend('T_1','T_{2hot}','T_2')%,'T{3mid}','T_{G3}')

subplot(length,width,4)
plot(time,m1/5.9750,time,m2/5.9750,'.')
xlabel('Time [s]')
ylabel('massflow [kg/s]')
legend('m_1','m_2')

subplot(length,width,5)
plot(time, Ws/-9726000)
xlabel('Time [s]')
ylabel('Power $W_s$ [MW]')

subplot(length,width,6)
plot(time,uT/0.891100000000000,time,mbypass/0.264900000000000)
xlabel('Time [s]')
legend('Valve opening','m_{bypass}')

subplot(length,width,7)
plot(time, T4x/3.183851488646865e+02, time,T4/318.15)%,time,T0,'.')
xlabel('Time [s]')
ylabel('Temperature [K]')
legend('T_{4x}','T_4')%,'T_0')

subplot(length,width,8)
plot(time, m3/6.233810380357867,'-',time,mturbine/6.233810380357867,'.',time,mG/7)
xlabel('Time [s]')
ylabel('massflow [kg/s]')
legend('m_3','m_{turbine}','m_G')


% %% Plotting holdups
% figure(1)
% 
% subplot(3,2,1)
% plot(time,M1/1000)
% xlabel('Time [s]')
% ylabel('M_1 [kg]')
% 
% subplot(3,2,2)
% plot(time,m1/5.975000000000000,time,m2/5.975000000000000)
% xlabel('Time [s]')
% ylabel('Mass flows [kg/s]')
% legend('m_1','m_2')
% 
% subplot(3,2,3)
% plot(time,Mmix/253)
% xlabel('Time [s]')
% ylabel('M_{mix} [kg]')
% 
% subplot(3,2,4)
% plot(time,(m2+mbypass)/ 6.239900000000000,time,m3/ 6.239900000000000)
% xlabel('Time [s]')
% ylabel('Mass flows [kg/s]')
% legend('m_2 + m_{bypass}','m_3')
% 
% subplot(3,2,5)
% plot(time,Mturbine/1000)
% xlabel('Time [s]')
% ylabel('M_{turbine} [kg]')
% 
% subplot(3,2,6)
% plot(time,m3/ 6.239900000000000,time,mturbine/ 6.239900000000000)
% xlabel('Time [s]')
% ylabel('Mass flows [kg/s]')
% legend('m_3','m_{turbine}')



