% File to load parameters and simulate the HEN connected to batch
% reactors
% Johannes Jaeschke 2012


%% Load parameters for the batch-hen system
clear;close all;clc
display('Loading Parameters...')
cp = 4e3;                       % kJ/Km3
rho = 800;                      % kg/m3
UA0 = 100;                      %  kw/K
Ar1 = 1*2;                      % crossectional area tank1
Ar2 = 0.6666667*2;              % crossectional area tank2
h_add = 0.2;                    % additional head
levelR1 = 1;                    % inital level in reactor 1
levelR2 = 0.75;                 % initial level in reactor 2
i=1:10;                         % number of reactors
BT=250-10*abs(8-i);             % Batch temperature
qh0=0.01;                       % hot stream reference flow rate for heat exchangers
k1 = 4.88e-4;                   % Valve constant for reactors 1-2
k2 = 3.177e-4;                  % Valve constant for reactors 3-10
g = 9.8;                        % gravity constant
Ttarget = 200;                  % Target temperature, to which the hot stream should be heated
deltaTempty = 240-15*abs(i-3);  % time between starting of the reactors for reactors i = 1.10
SimulationPeriod = 24*60 ;      % one day

openloop=false; % optimize
%openloop=true  % don't optimize

%% Simulate model 
simOut = sim('TankTest')
%% Plot results
run('plotgraphs')