% ACCUM.M %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Accumulator model

function [sys,dm] = accum(t,x,u,flag)

if (flag == 1)
holdup = x(3);

q_in = u(1);
x_in = u(2:3);
q_out = u(4);
    % Derivatives
    
    dm = q_in - q_out;
    dx = q_in * (x_in - x(1:2))/holdup;
    sys = dx;
elseif (flag == 3)
    % Measurements
    sys = x;
end