From 067789254d5b33eb342445f601b344a4b8a75c1e Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 3 Dec 2024 12:54:46 -0700 Subject: [PATCH] code cleanup --- rust/fastsim-core/src/thermal.rs | 25 +++++++++--------------- rust/fastsim-core/src/vehicle_thermal.rs | 4 ++-- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/rust/fastsim-core/src/thermal.rs b/rust/fastsim-core/src/thermal.rs index 59943523..3b3460b5 100644 --- a/rust/fastsim-core/src/thermal.rs +++ b/rust/fastsim-core/src/thermal.rs @@ -234,10 +234,7 @@ impl SimDriveHot { }, None => ( None, // 1st return element - match init_state { - Some(state) => state, // 2nd return element - None => ThermalState::default(), - }, + init_state.unwrap_or_default(), ), }; @@ -416,8 +413,7 @@ impl SimDriveHot { // limited between 0 and 1, but should really not get near 1 self.state.fc_qdot_per_net_heat = (self.vehthrm.fc_coeff_from_comb * (self.state.fc_te_adiabatic_deg_c - self.state.fc_te_deg_c)) - .min(1.0) - .max(0.0); + .clamp(0.0, 1.0); // heat generation self.state.fc_qdot_kw = self.state.fc_qdot_per_net_heat @@ -481,8 +477,7 @@ impl SimDriveHot { if let CabinHvacModelTypes::Internal(hvac_model) = &mut self.vehthrm.cabin_hvac_model { // flat plate model for isothermal, mixed-flow from Incropera and deWitt, Fundamentals of Heat and Mass // Transfer, 7th Edition - let cab_te_film_ext_deg_c = - 0.5 * (self.state.cab_te_deg_c + self.state.amb_te_deg_c); + let cab_te_film_ext_deg_c = 0.5 * (self.state.cab_te_deg_c + self.state.amb_te_deg_c); let re_l = self.air.get_rho(cab_te_film_ext_deg_c, None) * self.sd.mps_ach[i - 1] * self.vehthrm.cab_l_length @@ -498,20 +493,18 @@ impl SimDriveHot { (0.037 * re_l.powf(0.8) - a) * self.air.get_pr(cab_te_film_ext_deg_c) }; - if self.sd.mph_ach[i - 1] > 2.0 { - self.state.cab_qdot_to_amb_kw = 1e-3 - * (self.vehthrm.cab_l_length * self.vehthrm.cab_l_width) + self.state.cab_qdot_to_amb_kw = if self.sd.mph_ach[i - 1] > 2.0 { + 1e-3 * (self.vehthrm.cab_l_length * self.vehthrm.cab_l_width) / (1.0 / (nu_l_bar * self.air.get_k(cab_te_film_ext_deg_c) / self.vehthrm.cab_l_length) + self.vehthrm.cab_r_to_amb) - * (self.state.cab_te_deg_c - self.state.amb_te_deg_c); + * (self.state.cab_te_deg_c - self.state.amb_te_deg_c) } else { - self.state.cab_qdot_to_amb_kw = 1e-3 - * (self.vehthrm.cab_l_length * self.vehthrm.cab_l_width) + 1e-3 * (self.vehthrm.cab_l_length * self.vehthrm.cab_l_width) / (1.0 / self.vehthrm.cab_htc_to_amb_stop + self.vehthrm.cab_r_to_amb) - * (self.state.cab_te_deg_c - self.state.amb_te_deg_c); - } + * (self.state.cab_te_deg_c - self.state.amb_te_deg_c) + }; let te_delta_vs_set_deg_c = self.state.cab_te_deg_c - hvac_model.te_set_deg_c; let te_delta_vs_amb_deg_c = self.state.cab_te_deg_c - self.state.amb_te_deg_c; diff --git a/rust/fastsim-core/src/vehicle_thermal.rs b/rust/fastsim-core/src/vehicle_thermal.rs index bc40adac..3cfca08c 100644 --- a/rust/fastsim-core/src/vehicle_thermal.rs +++ b/rust/fastsim-core/src/vehicle_thermal.rs @@ -120,7 +120,7 @@ pub struct HVACModel { /// coefficient between 0 and 1 to calculate HVAC efficiency by multiplying by /// coefficient of performance (COP) pub frac_of_ideal_cop: f64, - /// whether heat comes from fuel converter + /// whether heat comes from [FuelConverter] pub use_fc_waste_heat: bool, /// max cooling aux load pub pwr_max_aux_load_for_cooling_kw: f64, @@ -481,7 +481,7 @@ impl VehicleThermal { /// parameter for engine surface area \[m**2\] for heat transfer calcs pub fn fc_area_ext(&self) -> f64 { - PI * self.fc_l.powf(2.0 / 4.0) + PI * self.fc_l.powf(2.0) / 4.0 } /// parameter for catalyst surface area \[m**2\] for heat transfer calcs