using "types"; Model BallWithSafetyValve ATTRIBUTES Info = "A fixed volume ball with a safety valve for the pressure."; PARAMETERS ValveMode as Switcher(Valid = ["closed", "opened"], Default = "closed"); R as Real(Unit="J/(K*mol)", Default=8.314472); V as volume; T as temperature; Pout as pressure; k as Real(Default=1e-3); VARIABLES flow_in as flow_mol; flow_out as flow_mol; P as pressure; n as mol; EQUATIONS "Ideal gas relation" P*V = n*R*T; "Mass balance" diff(n) = flow_in - flow_out; switch ValveMode case "closed": flow_out = 0 * "mol/h"; when P > 2*"atm" switchto "opened"; case "opened": flow_out = k*sqrt(P - Pout); when P < Pout * 1.1 switchto "closed"; end end FlowSheet BallWithSafetyValveTest DEVICES ball as BallWithSafetyValve; SET ball.V = 1 * "l"; ball.T = 300 * "K"; ball.Pout = 1 * "atm"; ball.ValveMode = "opened"; SPECIFY ball.flow_in = 50 * "mol/h"; INITIAL ball.P = 1.2 * "atm"; OPTIONS TimeStep = 0.05; TimeEnd = 10; end