% Script to plot the saved data from a dynamic simulation of a H2P cycle
% 25.09.2019.

%clc;clear;close all
%% Set default options for plotting. You can change it to your preferences
set(0,'DefaultTextFontName','Times','DefaultTextFontSize',18,...
'DefaultAxesFontName','Times','DefaultAxesFontSize',18,...
'DefaultLineLineWidth',2,'DefaultLineMarkerSize',7.75)

%% Load data
%filename = 'OLSteadyState' ;    % the name of the files where the data is saved
%filename  = 'OLStepFeedwater'
%filename  = 'OLStepBypass';
%filename  = 'OLStepAttemperator';
%load(filename); % load variables to workspace

%% Extract variables

TE   = v(:,1);                                % [K], economizer temperature
TD   = v(:,2);                                       % [K] drum temperature
TSh  = v(:,3);                                % [K] superheater temperature
MD   = v(:,4);                                      % [kg] drum mass holdup
MSh  = v(:,5);           % [kg] superheatr holdup to calculate the pressure
w    = v(:,6);       % [Hz] frequency (grid). assume turbine speed is equal
TGE  = v(:,7);               % [K] flue gas at economizer outlet. algebraic
TGD  = v(:,8);                                % [K] flue gas at drum outlet
TGSh = v(:,9);                                   % [K] flue gas at Shoutlet
TA   = v(:,10);                              % [K] attemperator temperature
pT   = v(:,11);                           % [bar] pressure at turbine inlet
Pm   = v(:,12);                                     % [kJ] mehcanical power

%% Plot temperatures: on steam and gas sides

figure('Name','Temperatures Steam and Gas sides')
subplot(241)
plot(t,TE)
xlabel('Time,[s]')
ylabel('TE')

subplot(242)
plot(t,TD)
xlabel('Time,[s]')
ylabel('TD')

subplot(243)
plot(t,TSh)
xlabel('Time,[s]')
ylabel('TSh')

subplot(244)
plot(t,TA)
xlabel('Time,[s]')
ylabel('TA')

subplot(245)
plot(t,TGE)
xlabel('Time,[s]')
ylabel('TGE')

subplot(246)
plot(t,TGD)
xlabel('Time,[s]')
ylabel('TGD')

subplot(247)
plot(t,TGSh)
xlabel('Time,[s]')
ylabel('TGSh')

%% Plot drum and superheater holdups
figure('Name','Holdups')
subplot(121)
plot(t,MD)
xlabel('Time,[s]')
ylabel('Drum holdup')

subplot(122)
plot(t,MSh)
xlabel('Time,[s]')
ylabel('TSh')

%% Plot frequency, power and pressure before turbine
figure('Name','Turbine&Generator')
subplot(311)
plot(t,w)
xlabel('Time,[s]')
ylabel('Frequency, [Hz]')

subplot(312)
plot(t,Pm)
xlabel('Time,[s]')
ylabel('Power [kW]')

subplot(313)
plot(t,pT)
xlabel('Time,[s]')
ylabel('Pressure turbine inlet [bar]')