
%% Reservoir model, calculate flow from reservoir


%% -----------RESERVOIR---------------------%
  % Boundary conditions 
P(1,i)=p_top_pipeline_bara(i);
P(end,i)=p_reservoir;
% Pressure distribution calc
    for j=2:size(xl,2)-1
        P(j,i+1)=P(j,i) + (dt/(k*h^2))*(P(j+1,i)-2*P(j,i)+P(j-1,i)) + (dt/(k*2*j*h^2))*(P(j+1,i)-P(j-1,i));
    end
% Flow calc
Q(i)=(c/h)*(P(1,i) - P(2,i)); % [m/s]
%% -----------------------------------------%
% inflow to the pipeline
%GOR=0.01166; 
%param = -6.834491399931654e+011*8.4000e-004*2.6*2.1235;%*0.9465;%*1.0043;
param =-9.3322e+008*2*0.8415*0.8212*0.8929*1.2761*2.4158*1.0894*0.9621;
w_tot_in(i) = param*Q(i)*A_pipeline*rho_oil; % [kg/s]


%% -----------------------------------------%