diff --git a/fastsim-core/src/simdrivelabel/mod.rs b/fastsim-core/src/simdrivelabel/mod.rs index e25f062f7..662dd9cd1 100644 --- a/fastsim-core/src/simdrivelabel/mod.rs +++ b/fastsim-core/src/simdrivelabel/mod.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; // crate local use crate::drive_cycle::{Cycle, CYC_ACCEL}; use crate::imports::*; -use crate::simdrive::SimDrive; +use crate::simdrive::{params::SimParams, SimDrive}; use crate::vehicle::{PowertrainType, Vehicle}; /// Return first index of `arr` greater than `cut` @@ -54,8 +54,15 @@ pub fn get_0_to_60_time_from_accel_data(accel_data: &AccelData) -> anyhow::Resul } /// Run the acceleration test and return the time/speed trace. -pub fn run_accel(veh: &Vehicle) -> anyhow::Result { - let mut sd_accel = SimDrive::new(veh.clone(), CYC_ACCEL.clone(), None); +pub fn run_accel( + veh: &Vehicle, + sim_params: &HashMap<&'static str, SimParams>, +) -> anyhow::Result { + let mut sd_accel = SimDrive::new( + veh.clone(), + CYC_ACCEL.clone(), + sim_params.get("accel").cloned(), + ); sd_accel.sim_params.trace_miss_opts = TraceMissOptions::Allow; sd_accel.walk_once().map_err(|e| { anyhow!( @@ -1005,7 +1012,8 @@ pub fn run_label_simulations( // max_epa_adj: Option, fuel_props: Option, phev_utilization_params: Option, -) -> anyhow::Result<(SimulationDataForLabel, HashMap<&str, SimDrive>)> { + sim_params: &HashMap<&'static str, SimParams>, +) -> anyhow::Result<(SimulationDataForLabel, HashMap<&'static str, SimDrive>)> { // let max_epa_adj = max_epa_adj.unwrap_or(0.3); let phev_utilization_params = &phev_utilization_params.unwrap_or_default(); let fuel_props = fuel_props.unwrap_or_default(); @@ -1030,9 +1038,20 @@ pub fn run_label_simulations( // run simdrive for non-phev powertrains sd.insert( "udds", - SimDrive::new(veh.clone(), cyc["udds"].clone(), None), + SimDrive::new( + veh.clone(), + cyc["udds"].clone(), + sim_params.get("udds").cloned(), + ), + ); + sd.insert( + "hwy", + SimDrive::new( + veh.clone(), + cyc["hwy"].clone(), + sim_params.get("hwy").cloned(), + ), ); - sd.insert("hwy", SimDrive::new(veh.clone(), cyc["hwy"].clone(), None)); for (k, val) in sd.iter_mut() { val.walk().map_err(|e| { @@ -1311,19 +1330,23 @@ pub fn get_label_fe( full_detail: bool, fuel_props: Option, phev_utilization_params: Option, + sim_params: Option>, verbose: bool, -) -> anyhow::Result<(LabelFe, Option>)> { +) -> anyhow::Result<(LabelFe, Option>)> { let max_epa_adj = max_epa_adj.unwrap_or(0.3); let phev_utilization_params = &phev_utilization_params.unwrap_or_default(); let fuel_props = fuel_props.unwrap_or_default(); let veh_copy = veh.clone(); + let sim_params = sim_params.unwrap_or_default(); + let (sim_data, sd) = run_label_simulations( veh, Some(fuel_props.clone()), Some(phev_utilization_params.clone()), + &sim_params, )?; - let accel_data = run_accel(&veh_copy)?; + let accel_data = run_accel(&veh_copy, &sim_params)?; let mut label_fe = calculate_label_fuel_economy( &fuel_props, phev_utilization_params, @@ -1351,7 +1374,7 @@ pub fn get_label_fe( #[cfg_attr( feature = "pyo3", pyo3(signature = ( - veh, max_epa_adj=None, full_detail=None, fuel_props=None, phev_utilization_params=None, verbose=None)) + veh, max_epa_adj=None, full_detail=None, fuel_props=None, phev_utilization_params=None, sim_params=None, verbose=None)) )] /// pyo3 version of [get_label_fe] pub fn get_label_fe_py( @@ -1360,6 +1383,7 @@ pub fn get_label_fe_py( full_detail: Option, fuel_props: Option, phev_utilization_params: Option, + sim_params: Option>, verbose: Option, ) -> anyhow::Result { let (label_fe, _) = get_label_fe( @@ -1368,6 +1392,21 @@ pub fn get_label_fe_py( full_detail.unwrap_or_default(), fuel_props, phev_utilization_params, + sim_params + .map(|m| { + m.into_iter() + .map(|(k, v)| -> anyhow::Result<(&'static str, SimParams)> { + let key = match k.as_str() { + "udds" => "udds", + "hwy" => "hwy", + "accel" => "accel", + other => bail!("Unknown sim_params key: {other:?}"), + }; + Ok((key, v)) + }) + .collect() + }) + .transpose()?, verbose.unwrap_or_default(), )?; Ok(label_fe) @@ -2027,7 +2066,7 @@ mod tests { let mut veh = Vehicle::try_from(f2veh.clone()).unwrap(); // Get FASTSim-3 label FE results - let (label_fe_f3, _) = get_label_fe(&mut veh, None, false, None, None, false) + let (label_fe_f3, _) = get_label_fe(&mut veh, None, false, None, None, None, false) .with_context(|| format_dbg!()) .unwrap(); @@ -2062,7 +2101,7 @@ mod tests { let mut veh = Vehicle::try_from(f2veh.clone()).unwrap(); // Get FASTSim-3 label FE results - let (label_fe_f3, _) = get_label_fe(&mut veh, None, false, None, None, false) + let (label_fe_f3, _) = get_label_fe(&mut veh, None, false, None, None, None, false) .with_context(|| format_dbg!()) .unwrap(); @@ -2096,7 +2135,7 @@ mod tests { let mut veh = Vehicle::try_from(f2veh.clone()).unwrap(); // Get FASTSim-3 label FE results - let (label_fe_f3, _) = get_label_fe(&mut veh, None, false, None, None, false) + let (label_fe_f3, _) = get_label_fe(&mut veh, None, false, None, None, None, false) .with_context(|| format_dbg!()) .unwrap(); @@ -2153,7 +2192,7 @@ mod tests { ); // Get FASTSim-3 label FE results (if PHEV functionality is implemented) - let label_fe_f3 = get_label_fe(&mut veh, None, false, None, None, false) + let label_fe_f3 = get_label_fe(&mut veh, None, false, None, None, None, false) .unwrap() .0;