Add enthalpy-based secondary boil-off and turbine mapping

This commit is contained in:
Codex Agent
2025-11-25 17:47:37 +01:00
parent 4162ecf712
commit 0f54540526
7 changed files with 113 additions and 38 deletions

View File

@@ -4,6 +4,8 @@ from __future__ import annotations
from dataclasses import dataclass, field, asdict
from . import constants
from .generator import GeneratorState
@@ -51,6 +53,7 @@ class CoolantLoopState:
steam_quality: float # fraction of vapor
inventory_kg: float = 0.0 # bulk mass of coolant
level: float = 1.0 # fraction full relative to nominal volume
energy_j: float = 0.0 # stored thermal/latent energy for the loop
def average_temperature(self) -> float:
return 0.5 * (self.temperature_in + self.temperature_out)
@@ -135,8 +138,8 @@ class PlantState:
delta_t = data.get("primary_to_secondary_delta_t", 0.0)
return cls(
core=CoreState(**core_blob, fission_product_inventory=inventory, emitted_particles=particles),
primary_loop=CoolantLoopState(**data["primary_loop"]),
secondary_loop=CoolantLoopState(**data["secondary_loop"]),
primary_loop=CoolantLoopState(**_with_energy(data["primary_loop"])),
secondary_loop=CoolantLoopState(**_with_energy(data["secondary_loop"])),
turbines=turbines,
primary_pumps=[PumpState(**p) for p in prim_pumps_blob],
secondary_pumps=[PumpState(**p) for p in sec_pumps_blob],
@@ -146,3 +149,14 @@ class PlantState:
primary_to_secondary_delta_t=delta_t,
time_elapsed=data.get("time_elapsed", 0.0),
)
def _with_energy(loop_blob: dict) -> dict:
"""Backwards compatibility: derive energy if missing."""
if "energy_j" in loop_blob:
return loop_blob
energy = 0.5 * (loop_blob.get("temperature_in", 295.0) + loop_blob.get("temperature_out", 295.0))
energy *= loop_blob.get("inventory_kg", 0.0) * constants.COOLANT_HEAT_CAPACITY
out = dict(loop_blob)
out["energy_j"] = energy
return out