function u = CalcBlock(x,v,d,p)
% model for level and concentration 
V = x(1);                                       % [m3] Hold up CSTR reactor
ca = x(2);                         % [kmol/m3] Concentration of component A

caf = d(1);                % [kmol/m3] Concentration of component A in feed
k = d(2);                            % [m3/kmol/min] Reaction rate constant  

A22 = p(1);
switch p(2)
    case 0  %base case
        u = v;
%         u(1) = v(2); 
%         u(2) = v(1);
    case 1
        T = [1,-1;(caf-ca)/V,0];
        b = [0;-ca*(k*ca+A22)];
        Tinv = [0,V/(caf-ca);-1,V/(caf-ca)];
        u = Tinv*(v-b);
    otherwise
        u = v;
end
end
