Skip to content

Commit

Permalink
remove unnecessary type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarow committed Feb 28, 2024
1 parent 9cca67f commit 5bb62a8
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 216 deletions.
12 changes: 6 additions & 6 deletions rust/fastsim-cli/src/bin/fastsim-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ pub fn main() -> anyhow::Result<()> {

// TODO: put in logic here for loading vehicle for adopt-hd
// with same file format as regular adopt and same outputs retured
let is_adopt: bool = fastsim_api.adopt.is_some() && fastsim_api.adopt.unwrap();
let mut fc_pwr_out_perc: Option<Vec<f64>> = None;
let mut hd_h2_diesel_ice_h2share: Option<Vec<f64>> = None;
let is_adopt = fastsim_api.adopt.is_some() && fastsim_api.adopt.unwrap();
let mut fc_pwr_out_perc = None;
let mut hd_h2_diesel_ice_h2share = None;
let veh = if let Some(veh_string) = fastsim_api.veh {
if is_adopt || is_adopt_hd {
let (veh_string, pwr_out_perc, h2share) = json_rewrite(veh_string)?;
Expand Down Expand Up @@ -401,8 +401,8 @@ impl SerdeAPI for ParsedValue {}
fn json_rewrite(x: String) -> anyhow::Result<(String, Option<Vec<f64>>, Option<Vec<f64>>)> {
let adoptstring = x;

let mut fc_pwr_out_perc: Option<Vec<f64>> = None;
let mut hd_h2_diesel_ice_h2share: Option<Vec<f64>> = None;
let mut fc_pwr_out_perc = None;
let mut hd_h2_diesel_ice_h2share = None;

let mut parsed_data: Value = serde_json::from_str(&adoptstring)?;

Expand Down Expand Up @@ -440,7 +440,7 @@ fn json_rewrite(x: String) -> anyhow::Result<(String, Option<Vec<f64>>, Option<V
parsed_data["forceAuxOnFC"] = json!(force_aux_on_fc_value != 0)
}

let mut is_rear_wheel_drive: bool = false;
let mut is_rear_wheel_drive = false;
let fwd1rwd2awd3_raw = &parsed_data["fwd1rwd2awd3"];
if fwd1rwd2awd3_raw.is_i64() {
let fwd1rwd2awd3_value = fwd1rwd2awd3_raw.as_i64().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion rust/fastsim-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
// path when building using build_and_test.sh
let build_path = "../../python/fastsim/resources".to_string();

let prepath: String = match PathBuf::from(&publish_path).exists() {
let prepath = match PathBuf::from(&publish_path).exists() {
true => publish_path,
false => build_path,
};
Expand Down
4 changes: 2 additions & 2 deletions rust/fastsim-core/fastsim-proc-macros/src/add_pyo3_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn add_pyo3_api(attr: TokenStream, item: TokenStream) -> TokenStream {
let mut ast = syn::parse_macro_input!(item as syn::ItemStruct);
// println!("{}", ast.ident.to_string());
let ident = &ast.ident;
let _is_state_or_history: bool =
let _is_state_or_history =
ident.to_string().contains("State") || ident.to_string().contains("HistoryVec");

let mut impl_block = TokenStream2::default();
Expand Down Expand Up @@ -344,7 +344,7 @@ pub fn add_pyo3_api(attr: TokenStream, item: TokenStream) -> TokenStream {
final_output.extend::<TokenStream2>(quote! {
#[cfg_attr(feature="pyo3", pyclass(module = "fastsimrust", subclass))]
});
let mut output: TokenStream2 = ast.to_token_stream();
let mut output = ast.to_token_stream();
output.extend(impl_block);
// if ast.ident.to_string() == "RustSimDrive" {
// println!("{}", output.to_string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn approx_eq_derive(input: TokenStream) -> TokenStream {
generated.append_all(quote! {
impl ApproxEq for #name {
fn approx_eq(&self, other: &#name, tol: f64) -> bool {
let mut approx_eq_vals: Vec<bool> = Vec::new();
let mut approx_eq_vals = Vec::new();
#(approx_eq_vals.push(self.#field_names.approx_eq(&other.#field_names, tol));)*
approx_eq_vals.iter().all(|&x| x)
}
Expand Down
4 changes: 2 additions & 2 deletions rust/fastsim-core/fastsim-proc-macros/src/doc_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn doc_field(_attr: TokenStream, item: TokenStream) -> TokenStream {

let new_fields = if let syn::Fields::Named(FieldsNamed { named, .. }) = &mut item_struct.fields
{
let mut new_doc_fields: Vec<TokenStream2> = Vec::new();
let mut new_doc_fields = Vec::new();
for field in named.iter_mut() {
let mut skip_doc = false;
remove_handled_attrs(field, &mut skip_doc);
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn doc_field(_attr: TokenStream, item: TokenStream) -> TokenStream {
let struct_vis = item_struct.vis;
let struct_attrs = item_struct.attrs;

let output: TokenStream2 = quote! {
let output = quote! {
#(#struct_attrs)*
#struct_vis struct #struct_ident {
#new_fields
Expand Down
42 changes: 21 additions & 21 deletions rust/fastsim-core/src/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn accel_for_constant_jerk(n: usize, a0: f64, k: f64, dt: f64) -> f64 {

/// Apply `accel_for_constant_jerk` to full
pub fn accel_array_for_constant_jerk(nmax: usize, a0: f64, k: f64, dt: f64) -> Array1<f64> {
let mut accels: Vec<f64> = Vec::new();
let mut accels = Vec::new();
for n in 0..nmax {
accels.push(accel_for_constant_jerk(n, a0, k, dt));
}
Expand All @@ -120,7 +120,7 @@ pub fn accel_array_for_constant_jerk(nmax: usize, a0: f64, k: f64, dt: f64) -> A

/// Calculate the average speed per each step in m/s
pub fn average_step_speeds(cyc: &RustCycle) -> Array1<f64> {
let mut result: Vec<f64> = Vec::with_capacity(cyc.len());
let mut result = Vec::with_capacity(cyc.len());
result.push(0.0);
for i in 1..cyc.len() {
result.push(0.5 * (cyc.mps[i] + cyc.mps[i - 1]));
Expand All @@ -141,7 +141,7 @@ pub fn trapz_step_distances(cyc: &RustCycle) -> Array1<f64> {
}

pub fn trapz_step_distances_primitive(time_s: &Array1<f64>, mps: &Array1<f64>) -> Array1<f64> {
let mut delta_dists_m: Vec<f64> = Vec::with_capacity(time_s.len());
let mut delta_dists_m = Vec::with_capacity(time_s.len());
delta_dists_m.push(0.0);
for i in 1..time_s.len() {
delta_dists_m.push((time_s[i] - time_s[i - 1]) * 0.5 * (mps[i] + mps[i - 1]));
Expand All @@ -153,7 +153,7 @@ pub fn trapz_step_distances_primitive(time_s: &Array1<f64>, mps: &Array1<f64>) -
/// (i.e., distance traveled up to sample point i-1)
/// Distance is in meters.
pub fn trapz_step_start_distance(cyc: &RustCycle, i: usize) -> f64 {
let mut dist_m: f64 = 0.0;
let mut dist_m = 0.0;
for i in 1..i {
dist_m += (cyc.time_s[i] - cyc.time_s[i - 1]) * 0.5 * (cyc.mps[i] + cyc.mps[i - 1]);
}
Expand Down Expand Up @@ -199,7 +199,7 @@ pub fn time_spent_moving(cyc: &RustCycle, stopped_speed_m_per_s: Option<f64>) ->
/// that name to all microtrips
pub fn to_microtrips(cycle: &RustCycle, stop_speed_m_per_s: Option<f64>) -> Vec<RustCycle> {
let stop_speed_m_per_s = stop_speed_m_per_s.unwrap_or(1e-6);
let mut microtrips: Vec<RustCycle> = Vec::new();
let mut microtrips = Vec::new();
let ts = cycle.time_s.to_vec();
let vs = cycle.mps.to_vec();
let gs = cycle.grade.to_vec();
Expand Down Expand Up @@ -278,7 +278,7 @@ pub fn create_dist_and_target_speeds_by_microtrip(
} else {
blend_factor
};
let mut dist_and_tgt_speeds: Vec<(f64, f64)> = Vec::new();
let mut dist_and_tgt_speeds = Vec::new();
// Split cycle into microtrips
let microtrips = to_microtrips(cyc, None);
let mut dist_at_start_of_microtrip_m = 0.0;
Expand Down Expand Up @@ -421,9 +421,9 @@ impl RustCycleCache {
ndarrcumsum(&xs)
};
let stops = Array::from_iter(cyc.mps.iter().map(|v| v <= &tol));
let mut interp_ds: Vec<f64> = Vec::with_capacity(num_items);
let mut interp_is: Vec<f64> = Vec::with_capacity(num_items);
let mut interp_hs: Vec<f64> = Vec::with_capacity(num_items);
let mut interp_ds = Vec::with_capacity(num_items);
let mut interp_is = Vec::with_capacity(num_items);
let mut interp_hs = Vec::with_capacity(num_items);
for idx in 0..num_items {
let d = trapz_distances_m[idx];
if interp_ds.is_empty() || d > *interp_ds.last().unwrap() {
Expand Down Expand Up @@ -968,7 +968,7 @@ impl RustCycle {
distance_m: f64,
cache: Option<&RustCycleCache>,
) -> f64 {
let tol: f64 = 1e-6;
let tol = 1e-6;
match cache {
Some(rcc) => {
for (&dist, &v) in rcc.trapz_distances_m.iter().zip(self.mps.iter()) {
Expand Down Expand Up @@ -1071,8 +1071,8 @@ impl RustCycle {
// time-to-stop (s)
let tts_s = -v0 / brake_accel_m_per_s2;
// number of steps to take
let n: usize = (tts_s / dt).round() as usize;
let n: usize = if n < 2 { 2 } else { n }; // need at least 2 steps
let n = (tts_s / dt).round() as usize;
let n = if n < 2 { 2 } else { n }; // need at least 2 steps
let (jerk_m_per_s3, accel_m_per_s2) =
calc_constant_jerk_trajectory(n, 0.0, v0, dts_m, 0.0, dt)?;
Ok((
Expand Down Expand Up @@ -1154,16 +1154,16 @@ pub fn detect_passing(
}
let zero_speed_tol_m_per_s = 1e-6;
let dist_tol_m = dist_tol_m.unwrap_or(0.1);
let mut v0: f64 = cyc.mps[i - 1];
let d0: f64 = trapz_step_start_distance(cyc, i);
let mut v0_lv: f64 = cyc0.mps[i - 1];
let d0_lv: f64 = trapz_step_start_distance(cyc0, i);
let mut v0 = cyc.mps[i - 1];
let d0 = trapz_step_start_distance(cyc, i);
let mut v0_lv = cyc0.mps[i - 1];
let d0_lv = trapz_step_start_distance(cyc0, i);
let mut d = d0;
let mut d_lv = d0_lv;
let mut rendezvous_idx: Option<usize> = None;
let mut rendezvous_num_steps: usize = 0;
let mut rendezvous_distance_m: f64 = 0.0;
let mut rendezvous_speed_m_per_s: f64 = 0.0;
let mut rendezvous_idx = None;
let mut rendezvous_num_steps = 0;
let mut rendezvous_distance_m = 0.0;
let mut rendezvous_speed_m_per_s = 0.0;
for di in 0..(cyc.mps.len() - i) {
let idx = i + di;
let v = cyc.mps[idx];
Expand Down Expand Up @@ -1237,7 +1237,7 @@ mod tests {
#[test]
fn test_loading_a_cycle_from_the_filesystem() {
let cyc_file_path = resources_path().join("cycles/udds.csv");
let expected_udds_length: usize = 1370;
let expected_udds_length = 1370;
let cyc = RustCycle::from_csv_file(cyc_file_path).unwrap();
let num_entries = cyc.len();
assert_eq!(cyc.name, String::from("udds"));
Expand Down
1 change: 0 additions & 1 deletion rust/fastsim-core/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ pub(crate) use std::path::PathBuf;

pub(crate) use crate::traits::*;
pub(crate) use crate::utils::*;
pub(crate) use crate::vehicle_utils::*;
20 changes: 10 additions & 10 deletions rust/fastsim-core/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ impl SerdeAPI for RustPhysicalProperties {}

impl Default for RustPhysicalProperties {
fn default() -> Self {
let air_density_kg_per_m3: f64 = 1.2;
let a_grav_mps2: f64 = 9.81;
let kwh_per_gge: f64 = 33.7;
let air_density_kg_per_m3 = 1.2;
let a_grav_mps2 = 9.81;
let kwh_per_gge = 33.7;
#[allow(non_snake_case)]
let fuel_rho_kg__L: f64 = 0.75;
let fuel_afr_stoich: f64 = 14.7;
let fuel_rho_kg__L = 0.75;
let fuel_afr_stoich = 14.7;
Self {
air_density_kg_per_m3,
a_grav_mps2,
Expand Down Expand Up @@ -161,7 +161,7 @@ impl SerdeAPI for AdjCoef {}

impl Default for RustLongParams {
fn default() -> Self {
let long_params_str: &str = include_str!("../resources/longparams.json");
let long_params_str = include_str!("../resources/longparams.json");
let long_params = Self::from_json(long_params_str).unwrap();
long_params
}
Expand All @@ -173,22 +173,22 @@ mod params_test {

#[test]
fn test_get_long_params() {
let long_params: RustLongParams = RustLongParams::default();
let long_params = RustLongParams::default();

let adj_coef_2008: AdjCoef = AdjCoef {
let adj_coef_2008 = AdjCoef {
city_intercept: 0.003259,
city_slope: 1.1805,
hwy_intercept: 0.001376,
hwy_slope: 1.3466,
};
let adj_coef_2017: AdjCoef = AdjCoef {
let adj_coef_2017 = AdjCoef {
city_intercept: 0.004091,
city_slope: 1.1601,
hwy_intercept: 0.003191,
hwy_slope: 1.2945,
};

let mut adj_coef_map: HashMap<String, AdjCoef> = HashMap::new();
let mut adj_coef_map = HashMap::new();
adj_coef_map.insert(String::from("2008"), adj_coef_2008);
adj_coef_map.insert(String::from("2017"), adj_coef_2017);

Expand Down
36 changes: 18 additions & 18 deletions rust/fastsim-core/src/simdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ impl Default for RustSimDriveParams {
// if true, missed trace correction is active, default = false
let missed_trace_correction = false;
// maximum time dilation factor to "catch up" with trace -- e.g. 1.0 means 100% increase in step size
let max_time_dilation: f64 = 1.0;
let max_time_dilation = 1.0;
// minimum time dilation margin to let trace "catch up" -- e.g. -0.5 means 50% reduction in step size
let min_time_dilation: f64 = -0.5;
let time_dilation_tol: f64 = 5e-4; // convergence criteria for time dilation
let max_trace_miss_iters: u32 = 5; // number of iterations to achieve time dilation correction
let trace_miss_speed_mps_tol: f64 = 1.0; // # threshold of error in speed [m/s] that triggers warning
let trace_miss_time_tol: f64 = 1e-3; // threshold for printing warning when time dilation is active
let trace_miss_dist_tol: f64 = 1e-3; // threshold of fractional eror in distance that triggers warning
let sim_count_max: usize = 30; // max allowable number of HEV SOC iterations
let newton_gain: f64 = 0.9; // newton solver gain
let newton_max_iter: u32 = 100; // newton solver max iterations
let newton_xtol: f64 = 1e-9; // newton solver tolerance
let energy_audit_error_tol: f64 = 0.002; // tolerance for energy audit error warning, i.e. 0.1%
let min_time_dilation = -0.5;
let time_dilation_tol = 5e-4; // convergence criteria for time dilation
let max_trace_miss_iters = 5; // number of iterations to achieve time dilation correction
let trace_miss_speed_mps_tol = 1.0; // # threshold of error in speed [m/s] that triggers warning
let trace_miss_time_tol = 1e-3; // threshold for printing warning when time dilation is active
let trace_miss_dist_tol = 1e-3; // threshold of fractional eror in distance that triggers warning
let sim_count_max = 30; // max allowable number of HEV SOC iterations
let newton_gain = 0.9; // newton solver gain
let newton_max_iter = 100; // newton solver max iterations
let newton_xtol = 1e-9; // newton solver tolerance
let energy_audit_error_tol = 0.002; // tolerance for energy audit error warning, i.e. 0.1%
// Coasting
let coast_allow = false;
let coast_allow_passing = false;
Expand All @@ -99,7 +99,7 @@ impl Default for RustSimDriveParams {
let idm_decel_m_per_s2 = 1.5;
let idm_v_desired_in_m_per_s_by_distance_m = None;
// EPA fuel economy adjustment parameters
let max_epa_adj: f64 = 0.3; // maximum EPA adjustment factor
let max_epa_adj = 0.3; // maximum EPA adjustment factor
Self {
favor_grade_accuracy,
missed_trace_correction,
Expand Down Expand Up @@ -207,9 +207,9 @@ impl Default for RustSimDriveParams {
blend_factor: Option<f64>,
min_target_speed_m_per_s: Option<f64>,
) -> anyhow::Result<()> {
let by_microtrip: bool = by_microtrip.unwrap_or(false);
let extend_fraction: f64 = extend_fraction.unwrap_or(0.1);
let blend_factor: f64 = blend_factor.unwrap_or(0.0);
let by_microtrip = by_microtrip.unwrap_or(false);
let extend_fraction = extend_fraction.unwrap_or(0.1);
let blend_factor = blend_factor.unwrap_or(0.0);
let min_target_speed_m_per_s = min_target_speed_m_per_s.unwrap_or(8.0);
self.activate_eco_cruise_rust(
by_microtrip, extend_fraction, blend_factor, min_target_speed_m_per_s)
Expand Down Expand Up @@ -571,10 +571,10 @@ impl SerdeAPI for RustSimDrive {

// // SIM DRIVE
// let mut sd = RustSimDrive::__new__(cyc, veh);
// let init_soc: f64 = 0.5;
// let init_soc = 0.5;
// sd.walk(init_soc);

// let expected_final_i: usize = cycle_length;
// let expected_final_i = cycle_length;
// assert_eq!(sd.i, expected_final_i);
// }
// }
Loading

0 comments on commit 5bb62a8

Please sign in to comment.