Improve persistence and reactor dynamics
This commit is contained in:
@@ -49,7 +49,7 @@ class PlantState:
|
||||
core: CoreState
|
||||
primary_loop: CoolantLoopState
|
||||
secondary_loop: CoolantLoopState
|
||||
turbine: TurbineState
|
||||
turbines: list[TurbineState]
|
||||
time_elapsed: float = field(default=0.0)
|
||||
|
||||
def snapshot(self) -> dict[str, float]:
|
||||
@@ -60,18 +60,27 @@ class PlantState:
|
||||
"neutron_flux": self.core.neutron_flux,
|
||||
"primary_outlet_temp": self.primary_loop.temperature_out,
|
||||
"secondary_pressure": self.secondary_loop.pressure,
|
||||
"turbine_electric": self.turbine.electrical_output_mw,
|
||||
"turbine_electric": self.total_electrical_output(),
|
||||
}
|
||||
|
||||
def total_electrical_output(self) -> float:
|
||||
return sum(t.electrical_output_mw for t in self.turbines)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return asdict(self)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> "PlantState":
|
||||
turbines_blob = data.get("turbines")
|
||||
if turbines_blob is None:
|
||||
# Compatibility with previous single-turbine snapshots.
|
||||
old_turbine = data.get("turbine")
|
||||
turbines_blob = [old_turbine] if old_turbine else []
|
||||
turbines = [TurbineState(**t) for t in turbines_blob]
|
||||
return cls(
|
||||
core=CoreState(**data["core"]),
|
||||
primary_loop=CoolantLoopState(**data["primary_loop"]),
|
||||
secondary_loop=CoolantLoopState(**data["secondary_loop"]),
|
||||
turbine=TurbineState(**data["turbine"]),
|
||||
turbines=turbines,
|
||||
time_elapsed=data.get("time_elapsed", 0.0),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user