Skip to content

Commit

Permalink
editoast: consist compute gamma
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <[email protected]>
  • Loading branch information
Wadjetz committed Dec 5, 2024
1 parent 7a0728b commit ba0d378
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ impl PhysicsConsistParameters {
self.traction_engine.rolling_resistance.clone()
}
}

pub fn compute_const_gamma(&self) -> f64 {
self.towed_rolling_stock
.as_ref()
.map(|towed| f64::min(towed.const_gamma, self.traction_engine.const_gamma))
.unwrap_or_else(|| self.traction_engine.const_gamma)
}
}

impl From<PhysicsConsistParameters> for PhysicsConsist {
Expand All @@ -223,6 +230,7 @@ impl From<PhysicsConsistParameters> for PhysicsConsist {
let inertia_coefficient = params.compute_inertia_coefficient();
let mass = params.compute_mass();
let rolling_resistance = params.compute_rolling_resistance();
let const_gamma = params.compute_const_gamma();

let traction_engine = params.traction_engine;

Expand All @@ -235,7 +243,7 @@ impl From<PhysicsConsistParameters> for PhysicsConsist {
startup_time: (traction_engine.startup_time * 1000.0).round() as u64,
startup_acceleration,
comfort_acceleration,
const_gamma: traction_engine.const_gamma,
const_gamma,
inertia_coefficient,
rolling_resistance,
power_restrictions: traction_engine.power_restrictions.into_iter().collect(),
Expand Down Expand Up @@ -637,4 +645,19 @@ mod tests {
physics_consist.traction_engine.rolling_resistance,
);
}

#[test]
fn physics_consist_compute_gamma() {
// Towed const gamma 0.5
let mut physics_consist = create_physics_consist();
physics_consist.traction_engine.const_gamma = 0.4;

assert_eq!(physics_consist.compute_const_gamma(), 0.4);

physics_consist.traction_engine.const_gamma = 0.6;
assert_eq!(physics_consist.compute_const_gamma(), 0.5);

physics_consist.towed_rolling_stock = None;
assert_eq!(physics_consist.compute_const_gamma(), 0.6);
}
}
2 changes: 1 addition & 1 deletion editoast/src/models/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub fn create_towed_rolling_stock() -> TowedRollingStock {
B: 0.01, // In N/(m/s)
C: 0.0002, // In N/(m/s)²
},
const_gamma: 1.0,
const_gamma: 0.5,
max_speed: Some(35.0),
railjson_version: "3.4".to_string(),
}
Expand Down

0 comments on commit ba0d378

Please sign in to comment.