% Running simulations of the OLGA system

%Simulating closed loop system one sampling period (Ts)
   t_current1 = OLGAGetTime;
   
   [t, y, p, errmsg] = OLGASimStep(t_current1+Ts);%,U);
   
   
p_downhole(:,i) = [y(1).Data y(4).Data y(7).Data y(10).Data]; 
flow(:,i) = [y(2).Data y(5).Data y(8).Data y(11).Data];
GOR(:,i) = [y(3).Data y(6).Data y(9).Data y(12).Data];



% p_well(i,:) = p(1).Data;
% holdup_well(i,:) = p(2).Data;

%% Send pressure to reservoir.m
%% Get Flowrate kg/s in


%% Set new input values
% 
% SourceGasFraction = 0.1;
% SourceMassFlowrate = 16;
% SourcePres=220E5;  % Pa
% SourceTemp=144;     %C
% SourceWaterFrac=0;
% %
% InpData = [SourceGasFraction SourceMassFlowrate SourcePres SourceTemp SourceWaterFrac];
% [errmsg] = OLGASetInputData( InpData );




   %y_closedloop(i,:) = yh;
   %t_closedloop(i,:) = th; 
   %d_closedloop = [d_closedloop;dh];
   %p_closedloop = [p_closedloop;ph];

%    PT_Wellhead(i) = y(2).Data;
%    GG_Wellhead(i) = y(2).Data;
%    GLT_Wellhead(i) = y(3).Data;
%    GT_Wellhead(i) = y(4).Data;
%    TM_Wellhead(i) = y(5).Data;
%    
%    PT_UP_CC(i) = y(6).Data;
%    QG_UP_CC(i) = y(7).Data;
%    QLT_UP_CC(i) = y(8).Data;
%    QT_UP_CC(i) = y(9).Data;
%    TM_UP_CC(i) = y(10).Data;
%    
%    GGSOUR_Gas_inj(i) = y(11).Data;
%    PT_DOWN_CC(i) = y(12).Data;
%    PT_DOWN_MC(i) = y(13).Data;   