% init.m

% Initialiserer modell A

load globale_verdier_b  % gir b
b.Cv_pc = [ones(b.n,1)*2e-2 ones(b.n,1)*4e-1];
b.Cv_ventil=1.2e-3;
b.Cv_ngventil=0.08;

b.UA_pc(1) = 8e4;
b.UA_pc(2) = 1.8e4;

tau=0.1;
G=tf(1,[tau 1]);       % Transferfunksjon
G2x2=ss(append(G,G));

for i=1:6
    D1(1+(i-1)*b.n:i*b.n) = b.D1(i)*ones(1,b.n);
    D2(1+(i-1)*b.n:i*b.n) = b.D2(i)*ones(1,b.n);
end
b.D1=D1'; b.D2=D2';     % Radvektorer (120x1)

global b

% Innganger
% -----------------------------------------------------------------------
co2tank = [273+8, b.p_co2tank, 10]';    %T,p,V
ngtank  = [273+8, b.p_ngtank, 10]';

% Regulatorparameter
% --------------------------------------------------------------------
z = 0.5;                % Ventilåpning

% Startverdier for PC
% -----------------------------------------------------------------------
load startverdier       % gir s_ut

m=18;
p0l = s_ut(2:m:end,end);
p0v = s_ut(3:m:end,end);
w0ng= s_ut(4:m:end,end);
H0ng= s_ut(5:m:end,end);
p0ng= s_ut(6:m:end,end);
w0l = s_ut(7:m:end,end);
w0v = s_ut(8:m:end,end);

T0l = s_ut(11:m:end,end);
V0l = s_ut(12:m:end,end);
N0l = s_ut(13:m:end,end);
T0v = s_ut(14:m:end,end);
V0v = b.V_pc(1)-V0l;
N0v = s_ut(15:m:end,end);
T0ng = s_ut(16:m:end,end);
V0ng = s_ut(17:m:end,end);
N0ng = s_ut(18:m:end,end);
T0vegg = s_ut(19:m:end,end);

y0 = [T0l; V0l; N0l; T0v; N0v; T0ng; V0ng; N0ng; T0vegg];
save initial y0
