Improve reactor controls, reactions, and maintenance UI
This commit is contained in:
@@ -16,11 +16,21 @@ class CoreState:
|
||||
reactivity_margin: float # delta rho
|
||||
power_output_mw: float # MW thermal
|
||||
burnup: float # fraction of fuel consumed
|
||||
fission_product_inventory: dict[str, float] = field(default_factory=dict)
|
||||
emitted_particles: dict[str, float] = field(default_factory=dict)
|
||||
|
||||
def update_burnup(self, dt: float) -> None:
|
||||
produced_energy_mwh = self.power_output_mw * (dt / 3600.0)
|
||||
self.burnup = clamp(self.burnup + produced_energy_mwh * 1e-5, 0.0, 0.99)
|
||||
|
||||
def add_products(self, products: dict[str, float]) -> None:
|
||||
for element, amount in products.items():
|
||||
self.fission_product_inventory[element] = self.fission_product_inventory.get(element, 0.0) + amount
|
||||
|
||||
def add_emitted_particles(self, particles: dict[str, float]) -> None:
|
||||
for name, amount in particles.items():
|
||||
self.emitted_particles[name] = self.emitted_particles.get(name, 0.0) + amount
|
||||
|
||||
|
||||
@dataclass
|
||||
class CoolantLoopState:
|
||||
@@ -61,6 +71,8 @@ class PlantState:
|
||||
"primary_outlet_temp": self.primary_loop.temperature_out,
|
||||
"secondary_pressure": self.secondary_loop.pressure,
|
||||
"turbine_electric": self.total_electrical_output(),
|
||||
"products": self.core.fission_product_inventory,
|
||||
"particles": self.core.emitted_particles,
|
||||
}
|
||||
|
||||
def total_electrical_output(self) -> float:
|
||||
@@ -71,6 +83,9 @@ class PlantState:
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> "PlantState":
|
||||
core_blob = dict(data["core"])
|
||||
inventory = core_blob.pop("fission_product_inventory", {})
|
||||
particles = core_blob.pop("emitted_particles", {})
|
||||
turbines_blob = data.get("turbines")
|
||||
if turbines_blob is None:
|
||||
# Compatibility with previous single-turbine snapshots.
|
||||
@@ -78,7 +93,7 @@ class PlantState:
|
||||
turbines_blob = [old_turbine] if old_turbine else []
|
||||
turbines = [TurbineState(**t) for t in turbines_blob]
|
||||
return cls(
|
||||
core=CoreState(**data["core"]),
|
||||
core=CoreState(**core_blob, fission_product_inventory=inventory, emitted_particles=particles),
|
||||
primary_loop=CoolantLoopState(**data["primary_loop"]),
|
||||
secondary_loop=CoolantLoopState(**data["secondary_loop"]),
|
||||
turbines=turbines,
|
||||
|
||||
Reference in New Issue
Block a user