%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   slug_3D_linearize.m
%
%   Script for linearizing the simplified slug model made as 
%   an aid in tuning the model. 
%   If parameters of the bifurbation point is used, the model should have a
%   pair of poles at the imaginary axis.
%   Use the parameter data.n set in the gen_data.m file to move the poles
%
%   Dependencies: initialize.m, gen_data.m, slug_3D_lin.m, Linearize.m
%
%   Written by :    Espen Storkaas (espen.storkaas@chemeng.ntnu.no)
%   Date:           08.10.02
%   
%   For questions, comments or documentation, contact author
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
global data 
%% Inputs for initialization
uL=2.39; %vannmengde inn l/min
uG=1.58; %luftmengde inn l/min
P_feed=1.325;
z=0.19;
uLs=uL/1000/60/pi/(0.0195/2)^2;
P1_stasj=1.133;
h1_stasj=0.019/2*0.6;
P2_stasj=1.036;
P0=1.013; %Bar
temp=293;


Ml=28.84/1000; %Molarmasse luft [kg/mol]
uLs=uL/1000/60/pi/(0.0195/2)^2; %Water rate (m/S)  %må endres
R=0.08205783*1.013; %l bar K^-1 mol^-1
rho_in= P1_stasj*Ml/R/temp;   %[kg/l]
mG_in= rho_in*uG/60; %(6.1717e-5)*1.5; % [kg/s] Endres 


%% Nominal Initialization
[x0,y_stasj,data]=initialize(z,mG_in,P1_stasj,h1_stasj,P2_stasj,P0,P_feed,uLs);
if ~isreal(y_stasj);
    disp('something is wrong')
end
d=[mG_in;P_feed;P0];


%% Linearizing
[A,B,C,D,E,F,ys]=linearize(@slug_3D_lin,[],x0(1:3),[],z,d);
%Computing poles
disp('Poles')
disp(eig(A)')