43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from reactor_sim import constants
|
|
from reactor_sim.reactor import Reactor
|
|
from reactor_sim.simulation import ReactorSimulation
|
|
|
|
|
|
def test_reactor_initial_state_is_cold():
|
|
reactor = Reactor.default()
|
|
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
|
|
|
|
|
|
def test_state_save_and_load_roundtrip(tmp_path: Path):
|
|
reactor = Reactor.default()
|
|
sim = ReactorSimulation(reactor, timestep=5.0, duration=15.0)
|
|
sim.log()
|
|
save_path = tmp_path / "plant_state.json"
|
|
assert sim.last_state is not None
|
|
reactor.save_state(str(save_path), sim.last_state)
|
|
assert save_path.exists()
|
|
restored_reactor = Reactor.default()
|
|
restored_state = restored_reactor.load_state(str(save_path))
|
|
assert restored_state.core.fuel_temperature == pytest.approx(
|
|
sim.last_state.core.fuel_temperature
|
|
)
|
|
assert restored_reactor.control.rod_fraction == reactor.control.rod_fraction
|
|
|
|
|
|
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)
|
|
assert "core" in failures
|
|
reactor._handle_failure("core")
|
|
assert reactor.shutdown is True
|