
% % Assesessment of BOG Energy requirements

% This file calculates the energy required to be removed from the BOG gas
% in the system. This energy requirement Q_BOG, is the required duty for
% QHA_07 in the main code.

m=605; %Gas mass flow [Kg/h] (Neskaa, 2010)
z=[0.11 0.89 0 0 0]; %Gas Mole compositions 
M_N= 28; %Nitrogen (N2) molecular mass [Kg/Kmol]
M_C1=16; %Methane (CH4) molecular mass [Kg/Kmol]
n= 605/(z(1)*M_N+z(2)*M_C1)*(1/3600); %BOG Molar Flow [Kmol/s]

Tin = -32 + 273.15; %Inlet temperature [K]
Tout = -154 +273.15; %Outlet temperature [K]
P = 18.2e5;% Pressure [Pa] (Assumed constant through the exchanger)

[Zin,phiin,Hin,Vin]= srks(z,Tin,P,2); %Inlet SRK Calculations. Initial phase vapor only.
[Zout,phiout,Hout,Vout]= srks(z,Tout,P,1); %Outlet SRK Calculations. Outlet liquid only. 

Q_BOG= n*(Hout-Hin); %Heat flow from the gas [Kj/s]

QHA_07= 7.3768e+03; %Heat flow [Kj/s] for refrigerant mole flow = 1 Kmol/s;

%This solves a simplified version of the main model to calculate the required flow
global Q 
Q=Q_BOG;
w0=0.013;
lb=0;
ub=Inf;
N_ref=fmincon('1',w0,[],[],[],[],lb,ub,@nfunc)

% Save information to file
filename='BOGresults.mat';
save(filename,'N_ref','Q_BOG')