clc; clear; close all;

% Variables

P_co = 250;                 % Heat exchanger effect in buffer tank [W]
P_dk = 400;                 % Heat source effect in varmetank [W]

m_b = 2;                    % Mass of water in buffer tank [kg]
m_v = 3;                    % Mass of water in heat tank [kg]

c = 4192;                   % Specific heat capacity of water [J/(kg K)]

pump = 480;                 % Pump effect [L/hr]
q_m = pump/3600;            % Mass flow from pump [kg/s]

t_v = 22;                   % Temperature in heat tank [°C]
t_vw = 15;                  % Desired temperature in heat tank [°C]
t_v_lim = 0.5;              % +/- limit of heat tank temperature [°C]
t_b = 22;                   % Temperature in buffer tank [°C]
t_bw = 5;                   % Desired temperature in buffer tank [°C]
t_b_lim = 3;                % +/- limit of buffer tank temperature [°C]

loops = 15;                 % Cycles
loop_tid = 600;             % Cycle time
simtime = loops*loop_tid;   % Total simulation time

sim('sl_tanke',simtime);

figure
plot(tau/60,tv,'b-',tau/60,tb,'r-'), grid;
xlabel('Time, \tau [min]'); ylabel('Temperature, t [°C]');
legend('Heat tank','Buffer tank','location','northeast');
set(gca,'XTick',[0:5:simtime/60]);

% figure
% plot(tau/60,dypkoger,'b-');