29 state = tank.initial_state(
30 pressure=from_psig(400.0),
32 liquid_temperature=293.15,
33 gas_temperature=293.15,
45def _refuse(sim: TankSim, times: int, monkeypatch: pytest.MonkeyPatch) -> list[int]:
46 """Make the tank refuse the first ``times`` candidates a step proposes.
48 Only candidates: the rates evaluation prices the state the sim is at,
49 which the equation of state has already accepted.
51 real = sim.tank.pressure
54 def pressure(state: TankState) -> Any:
55 if state
is not sim.state
and refused[0] < times:
57 raise ValueError(
"refused for the test")
60 monkeypatch.setattr(sim.tank,
"pressure", pressure)
64@pytest.mark.parametrize("times", [0, 1, 3])
66 times: int, monkeypatch: pytest.MonkeyPatch
69 refused =
_refuse(sim, times, monkeypatch)
71 dt, liquid_out, net_gas = 0.05, 2.0, 0.01
73 sim._one_step(dt, liquid_out, net_gas, sim.tank.gas_enthalpy(before))
75 assert refused[0] == times
76 assert before.liquid_mass - sim.state.liquid_mass == pytest.approx(
77 liquid_out * dt, rel=1e-12
79 assert sim.state.ullage.mass - before.ullage.mass == pytest.approx(
80 net_gas * dt, rel=1e-9
85 """The common case is unchanged bit for bit: one Euler step of ``dt``."""
88 dt, liquid_out, net_gas = 0.05, 2.0, 0.01
89 h = sim.tank.gas_enthalpy(before)
90 rates = sim.tank.rates(
91 before, mdot_liquid_out=liquid_out, mdot_gas_in=net_gas, enthalpy_gas_in=h
93 expected = sim.tank.step(before, rates, dt)
95 sim._one_step(dt, liquid_out, net_gas, h)
97 assert sim.state.liquid_mass == expected.liquid_mass
98 assert sim.state.ullage == expected.ullage