function y=compressor(p1,p2,u)
%Model and coefficients taken from 
% https://brage.bibsys.no/xmlui/bitstream/handle/11250/260722/566388_FULLTEXT01.pdf?sequence=1&isAllowed=y
% On Modeling of a Ship Propulsion System for Control Purposes
% Andreas Torp Karlsen

% Extraction of parameters
%p1 is the compressor map from equations
a0=p1(1);
a1=p1(2);
a2=p1(3);
a3=p1(4);
b0=p1(5);
b1=p1(6);
b2=p1(7);
c0=p1(8);
c1=p1(9);
c2=p1(10);

%p2 are ambient conditions, or physical conditions
rho_a=      p2(1);  %kg/m^3  
kappa_a=    p2(2);  %ratio of specific heats
cp_a=       p2(3);  %J/(kg K)
R_a=        p2(4); %J/(kg K)
T_amb=      p2(5);  %K
d_c=        p2(6);  %m (compressor diameter)

%Manipulated variables
P_ratio=    u(2);   %Pressure ratio
N_c=        u(1);   %rpm;  range:9500-15300
%U_c =      u(1);   %tip speed

U_c=pi*d_c*N_c/60;  %tip speeed (m/s)

%Eq. 3.5 (Mach number)
M=U_c/sqrt(kappa_a*R_a*T_amb);

%Eq. 3.3 (dimensionless pressure head, psi)
Psi= cp_a*T_amb*(P_ratio^((kappa_a-1)/kappa_a)-1)/(0.5*U_c^2);

%Eq. 3.13 
a=a3*M^3+a2*M^2+a1*M+a0;

%Eq. 3.16
b=b2*M^2+b1*M+b0;

%Eq. 3.18
c=c2*M^2+c1*M+c0;

%Equation 3.20 (dimentionless/normalized flow rate)
Phi=a*(1-exp(Psi^c-b));     % Use this one, substracting b. (typo in thesis)

%Eq. 3.4 (Actual volumetric flow) 
Qc=Phi*(pi/4)*d_c^2*U_c;  % m^3/s
mc=Qc*rho_a;              % kg/s

y=[Qc,mc];
end 