function out = valve(x, aux)
u = aux.u;
d = aux.d;
sc = aux.sc;
x = x.*sc.x;
z = x(1);
n = x(2);
hout = x(3);
hin = u(1);
rho = u(2);
Pl = u(3);
Ph = u(4);
out = [hin-hout;
       n-valve_flow(d.Cv, z, rho, Ph-Pl, d.MW)]./sc.res;
       
