function u = calculationBlock(x,v,d,p)
ME = x(1);    %[mol] mass of organic (extract) layer (acid, solvent, water)
MR = x(2);   %[mol] mass water (raffinate) layer (assumed to be pure water)
xAE = x(3);      % [-] mole fractions of acid in organic layer  (extract E)
xWE = x(4);     % [-] mole fractions of water in organic layer  (extract E)

S = d(1);                                    % [mol/s] organic solvent feed
xAF = d(2);                        % [-] mole frocation of acid in feed (F)

K = p(1);                  % [-] water acid equilibrium constant in extract
Kc1 = p(2);               % [1/s] proportional gain for holdup p-controller
Kc2 = p(3);     % [1/s] proportional gain for raffinate holdup p-controller

E0 = p(4);                  % [mol/s] steady state bias for extrate outflow
R0 = p(5);                % [mol/s] steady state bias for raffinate outflow

MEs = p(6);                              % [mol] extrate inventory setpoint
MRs = p(7);                            % [mol] raffinate inventory setpoint

structure = p(8);

CVtransform = p(9);

deltaE = Kc1*((MEs-ME)+(MRs-MR));
deltaR = Kc2*(MRs-MR);

E = E0 + deltaE;
R = R0 + deltaR;


switch structure
    case 1
        u =v*E/xAF;
    case 2
        u = (1+K)*v*E + R;
    case 3
        u = (1+K)*v/(1-(1+K)*v)*S + R;
    case 4
        u = (ME*v + xAE*E)/xAF;
    case 5
        u = (1+K)*(ME*v + xAE*E) + R;
    case 6
        u = ((1+K)*ME*v+R*(1-(1+K)*xAE)+(1+K)*xAE*S)/(1-(1+K)*xAE); %vFL3#
    case 7
        u = ME*v/xAF;
    case 8
        u = ME*v*(1+K)+R;
    case 9
        u = ((E/ME)-(E0/MEs))*ME*xAE/xAF+v*ME/xAF;
        if CVtransform == 1
            u =v*E/xAF*MEs/E0;
        end
    case 10
        u = (1+K)*ME*(((E/ME)-(E0/MEs))*xAE + v)+R;
        if CVtransform == 1
            u = (1+K)*v*(MEs/E0)/(1-(1+K)*v*(MEs/E0))*S + R;
        end
    case 11
        u = ((1+K)*ME*(v-E0/MEs*xAE)+R*(1-(1+K)*xAE)+(1+K)*xAE*S)/(1-(1+K)*xAE);
    otherwise
        u = 100;
end
end