Skip to content

Commit

Permalink
fixed rust get functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruchon, Matthew authored and Bruchon, Matthew committed Jul 17, 2024
1 parent 62f9c01 commit 1cd6292
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
20 changes: 15 additions & 5 deletions rust/altrios-core/src/train/speed_limit_train_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ impl From<&Vec<LinkIdxTime>> for TimedLinkPath {
Ok(self.get_save_interval())
}
#[pyo3(name = "get_kilometers")]
pub fn get_kilometers_py(&self, annualize: bool) -> f64 {
self.get_kilometers(annualize)
}
#[pyo3(name = "get_megagram_kilometers")]
pub fn get_megagram_kilometers_py(&self, annualize: bool) -> f64 {
self.get_megagram_kilometers(annualize)
}
#[pyo3(name = "get_kilometers")]
pub fn get_kilometers_py(&self, annualize: bool) -> f64 {
self.get_kilometers(annualize)
#[pyo3(name = "get_car_kilometers")]
pub fn get_car_kilometers_py(&self, annualize: bool) -> f64 {
self.get_car_kilometers(annualize)
}
#[pyo3(name = "get_res_kilometers")]
Expand Down Expand Up @@ -206,14 +211,19 @@ impl SpeedLimitTrainSim {
}
}

pub fn get_kilometers(&self, annualize: bool) -> f64 {
self.state.total_dist.get::<si::kilometer>() * self.get_scaling_factor(annualize)
}

pub fn get_megagram_kilometers(&self, annualize: bool) -> f64 {
self.state.mass_freight.get::<si::megagram>()
* self.state.total_dist.get::<si::kilometer>()
* self.get_scaling_factor(annualize)
}

pub fn get_kilometers(&self, annualize: bool) -> f64 {
self.state.total_dist.get::<si::kilometer>() * self.get_scaling_factor(annualize)
pub fn get_car_kilometers(&self, annualize: bool) -> f64 {
let n_cars = self.state.cars_total as f64;
self.state.total_dist.get::<si::kilometer>() * n_cars * self.get_scaling_factor(annualize)
}

pub fn get_res_kilometers(&mut self, annualize: bool) -> f64 {
Expand Down
25 changes: 19 additions & 6 deletions rust/altrios-core/src/train/train_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ impl TrainSimBuilder {
+ veh.braking_ratio_loaded * self.train_config.cars_loaded as f64)
/ cars_total;

let state = TrainState::new(
let mut state = TrainState::new(
length,
mass_static,
mass_adj,
mass_freight,
self.init_train_state,
);
state.cars_total = self.train_config.cars_total();

let path_tpc = PathTpc::new(train_params);

Expand Down Expand Up @@ -984,14 +985,19 @@ pub fn run_speed_limit_train_sims(
self.get_net_energy_res(annualize).get::<si::joule>()
}
#[pyo3(name = "get_kilometers")]
pub fn get_kilometers_py(&self, annualize: bool) -> f64 {
self.get_kilometers(annualize)
}
#[pyo3(name = "get_megagram_kilometers")]
pub fn get_megagram_kilometers_py(&self, annualize: bool) -> f64 {
self.get_megagram_kilometers(annualize)
}
#[pyo3(name = "get_kilometers")]
pub fn get_kilometers_py(&self, annualize: bool) -> f64 {
self.get_kilometers(annualize)
#[pyo3(name = "get_car_kilometers")]
pub fn get_car_kilometers_py(&self, annualize: bool) -> f64 {
self.get_car_kilometers(annualize)
}
#[pyo3(name = "get_res_kilometers")]
Expand Down Expand Up @@ -1027,15 +1033,22 @@ impl SpeedLimitTrainSimVec {
.sum()
}

pub fn get_kilometers(&self, annualize: bool) -> f64 {
self.0.iter().map(|sim| sim.get_kilometers(annualize)).sum()
}

pub fn get_megagram_kilometers(&self, annualize: bool) -> f64 {
self.0
.iter()
.map(|sim| sim.get_megagram_kilometers(annualize))
.sum()
}

pub fn get_kilometers(&self, annualize: bool) -> f64 {
self.0.iter().map(|sim| sim.get_kilometers(annualize)).sum()
pub fn get_car_kilometers(&self, annualize: bool) -> f64 {
self.0
.iter()
.map(|sim| sim.get_car_kilometers(annualize))
.sum()
}

pub fn get_res_kilometers(&mut self, annualize: bool) -> f64 {
Expand Down
4 changes: 4 additions & 0 deletions rust/altrios-core/src/train/train_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pub struct TrainState {
pub res_grade: si::Force,
pub res_curve: si::Force,

/// Number of cars included on the train
pub cars_total: u32,

/// Grade at front of train
pub grade_front: si::Ratio,
/// Grade at back of train of train if strap method is used
Expand Down Expand Up @@ -142,6 +145,7 @@ impl Default for TrainState {
mass_static: Default::default(),
mass_adj: Default::default(),
mass_freight: Default::default(),
cars_total: Default::default(),
elev_front: Default::default(),
energy_whl_out: Default::default(),
grade_front: Default::default(),
Expand Down

0 comments on commit 1cd6292

Please sign in to comment.