Improve persistence and reactor dynamics
This commit is contained in:
26
tests/test_neutronics.py
Normal file
26
tests/test_neutronics.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from reactor_sim.neutronics import NeutronDynamics
|
||||
from reactor_sim.state import CoreState
|
||||
|
||||
|
||||
def _core_state(
|
||||
temperature: float = 950.0,
|
||||
flux: float = 2e7,
|
||||
burnup: float = 0.01,
|
||||
power: float = 500.0,
|
||||
) -> CoreState:
|
||||
return CoreState(
|
||||
fuel_temperature=temperature,
|
||||
neutron_flux=flux,
|
||||
reactivity_margin=0.0,
|
||||
power_output_mw=power,
|
||||
burnup=burnup,
|
||||
)
|
||||
|
||||
|
||||
def test_reactivity_increases_with_rod_withdrawal():
|
||||
dynamics = NeutronDynamics()
|
||||
state = _core_state()
|
||||
rho_full_out = dynamics.reactivity(state, control_fraction=0.0)
|
||||
rho_half = dynamics.reactivity(state, control_fraction=0.5)
|
||||
assert rho_full_out > 0.0
|
||||
assert rho_full_out > rho_half
|
||||
@@ -4,6 +4,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from reactor_sim import constants
|
||||
from reactor_sim.failures import HealthMonitor
|
||||
from reactor_sim.reactor import Reactor
|
||||
from reactor_sim.simulation import ReactorSimulation
|
||||
|
||||
@@ -13,7 +14,7 @@ def test_reactor_initial_state_is_cold():
|
||||
state = reactor.initial_state()
|
||||
assert state.core.fuel_temperature == constants.ENVIRONMENT_TEMPERATURE
|
||||
assert state.primary_loop.mass_flow_rate == 0.0
|
||||
assert state.turbine.electrical_output_mw == 0.0
|
||||
assert state.total_electrical_output() == 0.0
|
||||
|
||||
|
||||
def test_state_save_and_load_roundtrip(tmp_path: Path):
|
||||
@@ -36,7 +37,18 @@ 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, dt=200.0)
|
||||
failures = reactor.health_monitor.evaluate(state, True, True, [True, True, True], dt=200.0)
|
||||
assert "core" in failures
|
||||
reactor._handle_failure("core")
|
||||
assert reactor.shutdown is True
|
||||
|
||||
|
||||
def test_maintenance_recovers_component_health():
|
||||
monitor = HealthMonitor()
|
||||
pump = monitor.component("secondary_pump")
|
||||
pump.integrity = 0.3
|
||||
pump.fail()
|
||||
restored = monitor.maintain("secondary_pump", amount=0.5)
|
||||
assert restored is True
|
||||
assert pump.integrity == pytest.approx(0.8)
|
||||
assert pump.failed is False
|
||||
|
||||
Reference in New Issue
Block a user