Improve reactor controls, reactions, and maintenance UI
This commit is contained in:
@@ -27,6 +27,29 @@ def _default_state_path() -> Path:
|
||||
return Path(custom) if custom else Path("artifacts/last_state.json")
|
||||
|
||||
|
||||
def _poison_log_path() -> Path:
|
||||
custom = os.getenv("FISSION_POISON_LOG")
|
||||
return Path(custom) if custom else Path("artifacts/poisons.json")
|
||||
|
||||
|
||||
def _write_poison_log(path: Path, state: PlantState | None, snapshots: list[dict[str, float]] | None = None) -> None:
|
||||
if state is None and snapshots:
|
||||
latest = snapshots[-1]
|
||||
inventory = latest.get("products", {})
|
||||
particles = latest.get("particles", {})
|
||||
time_elapsed = latest.get("time_elapsed", 0.0)
|
||||
elif state is not None:
|
||||
inventory = state.core.fission_product_inventory
|
||||
particles = state.core.emitted_particles
|
||||
time_elapsed = state.time_elapsed
|
||||
else:
|
||||
return
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
payload = {"time_elapsed": time_elapsed, "products": inventory, "particles": particles}
|
||||
path.write_text(json.dumps(payload, indent=2))
|
||||
LOGGER.info("Wrote poison snapshot to %s", path)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReactorSimulation:
|
||||
reactor: Reactor
|
||||
@@ -113,6 +136,7 @@ def main() -> None:
|
||||
snapshots = sim.log()
|
||||
LOGGER.info("Captured %d snapshots", len(snapshots))
|
||||
print(json.dumps(snapshots[-5:], indent=2))
|
||||
_write_poison_log(_poison_log_path(), sim.last_state, snapshots)
|
||||
except KeyboardInterrupt:
|
||||
sim.stop()
|
||||
LOGGER.warning("Simulation interrupted by user")
|
||||
|
||||
Reference in New Issue
Block a user