Improve reactor controls, reactions, and maintenance UI

This commit is contained in:
Codex Agent
2025-11-22 18:04:36 +01:00
parent d37620ccc1
commit 863060ee78
15 changed files with 447 additions and 14 deletions

54
tests/test_atomic.py Normal file
View File

@@ -0,0 +1,54 @@
from reactor_sim.atomic import AtomicPhysics, make_atom
def test_alpha_decay_reduces_mass_and_charge():
physics = AtomicPhysics(seed=1)
parent = make_atom(92, 143)
event = physics.alpha_decay(parent)
daughter, alpha = event.products
assert daughter.protons == 90
assert daughter.neutrons == 141
assert alpha.protons == 2 and alpha.neutrons == 2
assert "alpha" in event.emitted_particles
assert event.energy_mev > 0
def test_beta_minus_conserves_mass_number():
physics = AtomicPhysics(seed=2)
parent = make_atom(26, 30)
event = physics.beta_minus_decay(parent)
(daughter,) = event.products
assert daughter.mass_number == parent.mass_number
assert daughter.protons == parent.protons + 1
assert "beta-" in event.emitted_particles
def test_beta_plus_and_electron_capture_lower_proton_count():
physics = AtomicPhysics(seed=3)
parent = make_atom(15, 16)
beta_plus = physics.beta_plus_decay(parent)
capture = physics.electron_capture(parent)
assert beta_plus.products[0].protons == parent.protons - 1
assert capture.products[0].protons == parent.protons - 1
assert "beta+" in beta_plus.emitted_particles
assert "gamma" in capture.emitted_particles
def test_gamma_emission_keeps_nuclide_same():
physics = AtomicPhysics(seed=4)
parent = make_atom(8, 8)
event = physics.gamma_emission(parent, energy_mev=0.3)
(product,) = event.products
assert product == parent
assert "gamma" in event.emitted_particles
assert event.energy_mev == 0.3
def test_spontaneous_fission_creates_two_fragments():
physics = AtomicPhysics(seed=5)
parent = make_atom(92, 143)
event = physics.spontaneous_fission(parent)
assert len(event.products) == 2
total_mass = sum(atom.mass_number for atom in event.products)
assert total_mass <= parent.mass_number
assert event.energy_mev > 0

40
tests/test_fuel.py Normal file
View File

@@ -0,0 +1,40 @@
from reactor_sim.atomic import AtomicPhysics
from reactor_sim.fuel import FuelAssembly
from reactor_sim.state import CoreState
def _core_state(
temp: float = 600.0,
flux: float = 1e6,
burnup: float = 0.05,
power: float = 100.0,
) -> CoreState:
return CoreState(
fuel_temperature=temp,
neutron_flux=flux,
reactivity_margin=0.0,
power_output_mw=power,
burnup=burnup,
)
def test_decay_reaction_power_positive_and_capped():
physics = AtomicPhysics(seed=7)
fuel = FuelAssembly(enrichment=0.045, mass_kg=80_000.0, atomic_physics=physics)
state = _core_state()
power = fuel.decay_reaction_power(state)
assert power > 0
# Should stay under 10% of current power_output_mw.
assert power <= state.power_output_mw * 0.1 + 1e-6
def test_decay_reaction_power_scales_with_burnup_and_flux():
physics = AtomicPhysics(seed=9)
fuel = FuelAssembly(enrichment=0.045, mass_kg=80_000.0, atomic_physics=physics)
low = _core_state(burnup=0.01, flux=1e5, power=50.0)
high = _core_state(burnup=0.5, flux=5e6, power=200.0)
low_power = fuel.decay_reaction_power(low)
high_power = fuel.decay_reaction_power(high)
assert high_power > low_power
# Still capped to a reasonable fraction of the prevailing power.
assert high_power <= high.power_output_mw * 0.1 + 1e-6