Add generator power model and meltdown handling
This commit is contained in:
@@ -42,7 +42,9 @@ def test_health_monitor_flags_core_failure():
|
||||
reactor = Reactor.default()
|
||||
state = reactor.initial_state()
|
||||
state.core.fuel_temperature = constants.MAX_CORE_TEMPERATURE
|
||||
failures = reactor.health_monitor.evaluate(state, True, True, [True, True, True], dt=200.0)
|
||||
failures = reactor.health_monitor.evaluate(
|
||||
state, [True, True], [True, True], [True, True, True], state.generators, dt=200.0
|
||||
)
|
||||
assert "core" in failures
|
||||
reactor._handle_failure("core")
|
||||
assert reactor.shutdown is True
|
||||
@@ -50,10 +52,10 @@ def test_health_monitor_flags_core_failure():
|
||||
|
||||
def test_maintenance_recovers_component_health():
|
||||
monitor = HealthMonitor()
|
||||
pump = monitor.component("secondary_pump")
|
||||
pump = monitor.component("secondary_pump_1")
|
||||
pump.integrity = 0.3
|
||||
pump.fail()
|
||||
restored = monitor.maintain("secondary_pump", amount=0.5)
|
||||
restored = monitor.maintain("secondary_pump_1", amount=0.5)
|
||||
assert restored is True
|
||||
assert pump.integrity == pytest.approx(0.8)
|
||||
assert pump.failed is False
|
||||
@@ -88,19 +90,20 @@ def test_cold_shutdown_stays_subcritical():
|
||||
|
||||
def test_toggle_maintenance_progresses_until_restored():
|
||||
reactor = Reactor.default()
|
||||
reactor.primary_pump_units = [False, False]
|
||||
reactor.primary_pump_active = False
|
||||
pump = reactor.health_monitor.component("primary_pump")
|
||||
pump = reactor.health_monitor.component("primary_pump_1")
|
||||
pump.integrity = 0.2
|
||||
|
||||
def provider(t: float, _state):
|
||||
if t == 0:
|
||||
return ReactorCommand.maintain("primary_pump")
|
||||
return ReactorCommand.maintain("primary_pump_1")
|
||||
return None
|
||||
|
||||
sim = ReactorSimulation(reactor, timestep=1.0, duration=50.0, command_provider=provider)
|
||||
sim.log()
|
||||
assert pump.integrity >= 0.99
|
||||
assert "primary_pump" not in reactor.maintenance_active
|
||||
assert "primary_pump_1" not in reactor.maintenance_active
|
||||
|
||||
|
||||
def test_primary_pump_unit_toggle_updates_active_flag():
|
||||
@@ -134,16 +137,21 @@ def test_secondary_pump_unit_toggle_can_restart_pump():
|
||||
def test_primary_pumps_spool_up_over_seconds():
|
||||
reactor = Reactor.default()
|
||||
state = reactor.initial_state()
|
||||
reactor.secondary_pump_units = [False, False]
|
||||
# Enable both pumps and command full flow; spool should take multiple steps.
|
||||
target_flow = reactor.primary_pump.flow_rate(1.0) * len(reactor.primary_pump_units)
|
||||
reactor.step(state, dt=1.0, command=ReactorCommand(primary_pump_on=True, coolant_demand=1.0))
|
||||
reactor.step(
|
||||
state,
|
||||
dt=1.0,
|
||||
command=ReactorCommand(primary_pumps={1: True, 2: True}, generator_units={1: True}, coolant_demand=1.0),
|
||||
)
|
||||
first_flow = state.primary_loop.mass_flow_rate
|
||||
assert 0.0 < first_flow < target_flow
|
||||
|
||||
for _ in range(10):
|
||||
reactor.step(state, dt=1.0, command=ReactorCommand(coolant_demand=1.0))
|
||||
|
||||
assert state.primary_loop.mass_flow_rate == pytest.approx(target_flow, rel=0.1)
|
||||
assert state.primary_loop.mass_flow_rate == pytest.approx(target_flow, rel=0.15)
|
||||
|
||||
|
||||
def test_full_rod_withdrawal_reaches_gigawatt_power():
|
||||
@@ -178,3 +186,37 @@ def test_partially_inserted_rods_hold_near_three_gw():
|
||||
|
||||
assert 2_000.0 < state.core.power_output_mw < 4_000.0
|
||||
assert 500.0 < state.core.fuel_temperature < 800.0
|
||||
|
||||
|
||||
def test_generator_spools_and_powers_pumps():
|
||||
reactor = Reactor.default()
|
||||
state = reactor.initial_state()
|
||||
reactor.shutdown = False
|
||||
reactor.control.manual_control = True
|
||||
reactor.control.rod_fraction = 0.95 # keep power low; focus on aux power
|
||||
reactor.turbine_unit_active = [False, False, False]
|
||||
reactor.secondary_pump_units = [False, False]
|
||||
|
||||
for step in range(12):
|
||||
cmd = ReactorCommand(generator_units={1: True}, primary_pumps={1: True}) if step == 0 else None
|
||||
reactor.step(state, dt=1.0, command=cmd)
|
||||
|
||||
assert state.generators and state.generators[0].running is True
|
||||
assert state.generators[0].power_output_mw > 0.0
|
||||
assert state.primary_loop.mass_flow_rate > 0.0
|
||||
|
||||
|
||||
def test_meltdown_triggers_shutdown():
|
||||
reactor = Reactor.default()
|
||||
state = reactor.initial_state()
|
||||
reactor.shutdown = False
|
||||
reactor.control.manual_control = True
|
||||
reactor.control.rod_fraction = 0.0
|
||||
reactor.primary_pump_active = True
|
||||
reactor.secondary_pump_active = True
|
||||
state.core.fuel_temperature = constants.CORE_MELTDOWN_TEMPERATURE + 50.0
|
||||
|
||||
reactor.step(state, dt=1.0)
|
||||
|
||||
assert reactor.shutdown is True
|
||||
assert reactor.meltdown is True
|
||||
|
||||
Reference in New Issue
Block a user