% COMPUTE_VAPOUR.M %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Compute vapour flows for a section using heat loss and vapour bypassing

function V = compute_vapour(secnr,V_in,x)

global coldata termodata

temp = x;

V_heatloss = termodata.U * pi * coldata.diameter * ...
    coldata.sech(secnr) * (temp - termodata.T0) ...
    ./ (coldata.Nt(secnr) * termodata.deltaH);

V = [
    zeros(coldata.Nt(secnr),1)
    V_in
    ];
for k = coldata.Nt(secnr):-1:1
    V(k,1) = (1 - termodata.alpha) * V(k + 1,1) + ...
        termodata.alpha * V(k + 2,1) + ...
        V_heatloss(k,1);
end

V = V(1:coldata.Nt(secnr));