From 2b33fe06558dee92f9fd96f089904726630b189c Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Sun, 19 Jan 2025 19:56:50 -0700 Subject: [PATCH] propagated `SetCumulatiive` trait/macro --- fastsim-core/src/vehicle/cabin.rs | 5 ++--- .../src/vehicle/powertrain/fuel_converter.rs | 13 +++++++++++++ .../powertrain/reversible_energy_storage.rs | 15 +++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/fastsim-core/src/vehicle/cabin.rs b/fastsim-core/src/vehicle/cabin.rs index 6c47da43..708d197d 100644 --- a/fastsim-core/src/vehicle/cabin.rs +++ b/fastsim-core/src/vehicle/cabin.rs @@ -78,14 +78,13 @@ pub struct LumpedCabin { pub history: LumpedCabinStateHistoryVec, // TODO: add `save_interval` and associated method } - -impl SerdeAPI for LumpedCabin {} -impl Init for LumpedCabin {} impl SetCumulative for LumpedCabin { fn set_cumulative(&mut self, dt: si::Time) { self.state.set_cumulative(dt); } } +impl SerdeAPI for LumpedCabin {} +impl Init for LumpedCabin {} impl LumpedCabin { /// Solve temperatures, HVAC powers, and cumulative energies of cabin and HVAC system diff --git a/fastsim-core/src/vehicle/powertrain/fuel_converter.rs b/fastsim-core/src/vehicle/powertrain/fuel_converter.rs index 31ba3793..4653f689 100755 --- a/fastsim-core/src/vehicle/powertrain/fuel_converter.rs +++ b/fastsim-core/src/vehicle/powertrain/fuel_converter.rs @@ -434,6 +434,14 @@ impl Init for FuelConverterThermalOption { } } impl SerdeAPI for FuelConverterThermalOption {} +impl SetCumulative for FuelConverterThermalOption { + fn set_cumulative(&mut self, dt: si::Time) { + match self { + Self::FuelConverterThermal(fct) => fct.set_cumulative(dt), + Self::None => {} + } + } +} impl FuelConverterThermalOption { /// Solve change in temperature and other thermal effects /// # Arguments @@ -669,6 +677,11 @@ impl FuelConverterThermal { } } impl SerdeAPI for FuelConverterThermal {} +impl SetCumulative for FuelConverterThermal { + fn set_cumulative(&mut self, dt: si::Time) { + self.state.set_cumulative(dt); + } +} impl Init for FuelConverterThermal { fn init(&mut self) -> anyhow::Result<()> { self.tstat_te_sto = self diff --git a/fastsim-core/src/vehicle/powertrain/reversible_energy_storage.rs b/fastsim-core/src/vehicle/powertrain/reversible_energy_storage.rs index 8ff7050b..61db835c 100644 --- a/fastsim-core/src/vehicle/powertrain/reversible_energy_storage.rs +++ b/fastsim-core/src/vehicle/powertrain/reversible_energy_storage.rs @@ -711,7 +711,6 @@ impl Default for ReversibleEnergyStorageState { } } } - impl Init for ReversibleEnergyStorageState {} impl SerdeAPI for ReversibleEnergyStorageState {} @@ -723,6 +722,14 @@ pub enum RESThermalOption { #[default] None, } +impl SetCumulative for RESThermalOption { + fn set_cumulative(&mut self, dt: si::Time) { + match self { + Self::RESLumpedThermal(rlt) => rlt.set_cumulative(dt), + Self::None => {} + } + } +} impl SaveState for RESThermalOption { fn save_state(&mut self) { match self { @@ -814,7 +821,11 @@ pub struct RESLumpedThermal { pub history: RESLumpedThermalStateHistoryVec, // TODO: add `save_interval` and associated methods } - +impl SetCumulative for RESLumpedThermal { + fn set_cumulative(&mut self, dt: si::Time) { + self.state.set_cumulative(dt); + } +} impl SerdeAPI for RESLumpedThermal {} impl Init for RESLumpedThermal {} impl RESLumpedThermal {