%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%               Pump module                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Returns flowrate from a given pressure differential. %
% 
% originaly given characteristics curve(pressure-flow)
% P_pump=[13.2 12.1 10.8 9.2 7.2];
% V_dot=[1000 1300 1650 1774 1876];
% extended to handle lower flow rates
% P_pump=[14.3 14 13.2 12.1 10.8 9.2 7.2 4 0];
% V_dot=[0 500 1000 1300 1650 1774 1876 1980 2000];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [q_out] = pump(u)
global rho;
dp=u/10^5;
P_pump=[14.3 14 13.2 12.1 10.8 9.2 7.2 4 0];
V_dot=[0 500 1000 1300 1650 1774 1876 1980 2000];
polyn = polyfit(P_pump,V_dot,5);
n=length(polyn);
flow=polyn(1,1)*dp^(n-1)+polyn(1,2)*dp^(n-2)+...
    polyn(1,3)*dp^(n-3)+polyn(1,4)*dp^(n-4)+...
    polyn(1,5)*dp^(n-5)+polyn(1,6);
q_out=flow;
end