Skip to content

Commit 81beeb0

Browse files
committed
editoast: fix all units about rolling resistance
The database is populated with SI units, which means Newton, kg, meter and seconds. Another important piece of information is: - Units of rolling resistance for traction engines (also named rolling stocks) are in N, N/(m/s) and N/(m/s)² - Units of rolling resistance for towed rolling stocks are in (N/kg), (N/kg)/(m/s) and (N/kg)/(m/s)². Therefore, we need 2 different `struct` for storing those, hence the introduction of `RollingResistancePerWeight`. Signed-off-by: Jean SIMARD <woshilapin@tuziwo.info>
1 parent 0e1ea9b commit 81beeb0

File tree

7 files changed

+52
-31
lines changed

7 files changed

+52
-31
lines changed

editoast/editoast_schemas/src/rolling_stock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub use effort_curves::ModeEffortCurves;
1010

1111
mod rolling_resistance;
1212
pub use rolling_resistance::RollingResistance;
13+
pub use rolling_resistance::RollingResistancePerWeight;
1314

1415
mod energy_source;
1516
pub use energy_source::EnergySource;

editoast/editoast_schemas/src/rolling_stock/rolling_resistance.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use utoipa::ToSchema;
55

66
editoast_common::schemas! {
77
RollingResistance,
8+
RollingResistancePerWeight,
89
}
910

1011
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, ToSchema, Derivative)]
@@ -14,13 +15,31 @@ editoast_common::schemas! {
1415
pub struct RollingResistance {
1516
#[serde(rename = "type")]
1617
pub rolling_resistance_type: String,
17-
/// Solid friction in kN
18+
/// Solid friction in N
1819
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
1920
pub A: f64,
20-
/// Viscosity friction in kN/(km/h)
21+
/// Viscosity friction in N/(m/s)
2122
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
2223
pub B: f64,
23-
/// Aerodynamic drag in kN/(km/h)²
24+
/// Aerodynamic drag in N/(m/s)²
25+
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
26+
pub C: f64,
27+
}
28+
29+
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, ToSchema, Derivative)]
30+
#[derivative(Hash)]
31+
#[serde(deny_unknown_fields)]
32+
#[allow(non_snake_case)]
33+
pub struct RollingResistancePerWeight {
34+
#[serde(rename = "type")]
35+
pub rolling_resistance_type: String,
36+
/// Solid friction in N/kg
37+
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
38+
pub A: f64,
39+
/// Viscosity friction in (N/kg)/(m/s)
40+
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
41+
pub B: f64,
42+
/// Aerodynamic drag in (N/kg)/(m/s)²
2443
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
2544
pub C: f64,
2645
}

editoast/editoast_schemas/src/rolling_stock/towed_rolling_stock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::Gamma;
2-
use super::RollingResistance;
2+
use super::RollingResistancePerWeight;
33

44
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
55
pub struct TowedRollingStock {
@@ -15,6 +15,6 @@ pub struct TowedRollingStock {
1515
/// In m/s²
1616
pub startup_acceleration: f64,
1717
pub inertia_coefficient: f64,
18-
pub rolling_resistance: RollingResistance,
18+
pub rolling_resistance: RollingResistancePerWeight,
1919
pub gamma: Gamma,
2020
}

editoast/src/core/simulation.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ pub struct PhysicsConsist {
6161
/// Mapping of power restriction code to power class
6262
#[serde(default)]
6363
pub power_restrictions: BTreeMap<String, String>,
64-
/// The time the train takes before actually using electrical power (in miliseconds).
64+
/// The time the train takes before actually using electrical power (in milliseconds).
6565
/// Is null if the train is not electric or the value not specified.
6666
pub electrical_power_startup_time: Option<u64>,
67-
/// The time it takes to raise this train's pantograph in miliseconds.
67+
/// The time it takes to raise this train's pantograph in milliseconds.
6868
/// Is null if the train is not electric or the value not specified.
6969
pub raise_pantograph_time: Option<u64>,
7070
}
@@ -180,18 +180,18 @@ impl PhysicsConsistParameters {
180180

181181
let towed_mass = total_mass - traction_engine_mass; // kg
182182

183-
let traction_engine_solid_friction_a = traction_engine_rr.A * 1000.0; // convert from kN to N
184-
let traction_engine_viscosity_friction_b = traction_engine_rr.B * 1000.0 * 3.6; // convert from kN/(km/h) to N/(m/s)
185-
let traction_engine_aerodynamic_drag_c = traction_engine_rr.C * 1000.0 * 3.6 * 3.6; // convert from kN/(km/h)² to N/(m/s)²
183+
let traction_engine_solid_friction_a = traction_engine_rr.A; // N
184+
let traction_engine_viscosity_friction_b = traction_engine_rr.B; // N/(m/s)
185+
let traction_engine_aerodynamic_drag_c = traction_engine_rr.C; // N/(m/s)²
186186

187-
let towed_solid_friction_a = towed_rs_rr.A * 1e-2 * towed_mass; // convert from daN/t to N
188-
let towed_viscosity_friction_b = towed_rs_rr.B * 1e-2 * towed_mass * 3.6; // convert from (daN/t)/(km/h) to N/(m/s)
189-
let towed_aerodynamic_drag_c = towed_rs_rr.C * 1e-2 * towed_mass * 3.6 * 3.6; // convert from (daN/t)/(km/h)² to N/(m/s)²
187+
let towed_solid_friction_a = towed_rs_rr.A * towed_mass; // N
188+
let towed_viscosity_friction_b = towed_rs_rr.B * towed_mass; // N/(m/s)
189+
let towed_aerodynamic_drag_c = towed_rs_rr.C * towed_mass; // N/(m/s)²
190190

191-
let solid_friction_a = traction_engine_solid_friction_a + towed_solid_friction_a;
191+
let solid_friction_a = traction_engine_solid_friction_a + towed_solid_friction_a; // N
192192
let viscosity_friction_b =
193-
traction_engine_viscosity_friction_b + towed_viscosity_friction_b;
194-
let aerodynamic_drag_c = traction_engine_aerodynamic_drag_c + towed_aerodynamic_drag_c;
193+
traction_engine_viscosity_friction_b + towed_viscosity_friction_b; // N/(m/s)
194+
let aerodynamic_drag_c = traction_engine_aerodynamic_drag_c + towed_aerodynamic_drag_c; // N/(m/s)²
195195

196196
RollingResistance {
197197
rolling_resistance_type: traction_engine_rr.rolling_resistance_type.clone(),
@@ -592,9 +592,9 @@ mod tests {
592592
physics_consist.compute_rolling_resistance(),
593593
RollingResistance {
594594
rolling_resistance_type: "davis".to_string(),
595-
A: 1350.0,
596-
B: 48.6,
597-
C: 7.387200000000001
595+
A: 35001.0,
596+
B: 350.01,
597+
C: 7.0005,
598598
}
599599
);
600600

editoast/src/models/fixtures.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use editoast_schemas::rolling_stock::EffortCurves;
1515
use editoast_schemas::rolling_stock::Gamma;
1616
use editoast_schemas::rolling_stock::LoadingGaugeType;
1717
use editoast_schemas::rolling_stock::RollingResistance;
18+
use editoast_schemas::rolling_stock::RollingResistancePerWeight;
1819
use editoast_schemas::rolling_stock::RollingStock;
1920
use editoast_schemas::rolling_stock::RollingStockSupportedSignalingSystems;
2021
use editoast_schemas::rolling_stock::TowedRollingStock;
@@ -230,11 +231,11 @@ pub fn create_towed_rolling_stock() -> TowedRollingStock {
230231
comfort_acceleration: 0.2, // In m/s²
231232
startup_acceleration: 0.06,
232233
inertia_coefficient: 1.05,
233-
rolling_resistance: RollingResistance {
234+
rolling_resistance: RollingResistancePerWeight {
234235
rolling_resistance_type: "davis".to_string(),
235-
A: 1.0, // In kN
236-
B: 0.01, // In kN/(km/h)
237-
C: 0.0002, // In kN/(km/h
236+
A: 1.0, // In N
237+
B: 0.01, // In N/(m/s)
238+
C: 0.0002, // In N/(m/s
238239
},
239240
gamma: Gamma {
240241
gamma_type: "CONST".to_string(),
@@ -268,9 +269,9 @@ pub fn create_simple_rolling_stock() -> RollingStock {
268269
railjson_version: "12".to_string(),
269270
rolling_resistance: RollingResistance {
270271
rolling_resistance_type: "davis".to_string(),
271-
A: 1.0, // In kN
272-
B: 0.01, // In kN/(km/h)
273-
C: 0.0005, // In kN/(km/h
272+
A: 1.0, // In N
273+
B: 0.01, // In N/(m/s)
274+
C: 0.0005, // In N/(m/s
274275
},
275276
length: 140.0, // m
276277
mass: 15000.0, // kg

editoast/src/models/towed_rolling_stock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use editoast_derive::Model;
22
use editoast_schemas::rolling_stock::Gamma;
3-
use editoast_schemas::rolling_stock::RollingResistance;
3+
use editoast_schemas::rolling_stock::RollingResistancePerWeight;
44
use editoast_schemas::rolling_stock::TowedRollingStock;
55
use serde::Deserialize;
66
use serde::Serialize;
@@ -29,7 +29,7 @@ pub struct TowedRollingStockModel {
2929
pub startup_acceleration: f64,
3030
pub inertia_coefficient: f64,
3131
#[model(json)]
32-
pub rolling_resistance: RollingResistance,
32+
pub rolling_resistance: RollingResistancePerWeight,
3333
#[model(json)]
3434
pub gamma: Gamma,
3535

editoast/src/views/rolling_stock/towed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use editoast_authz::BuiltinRole;
1818
use editoast_derive::EditoastError;
1919
use editoast_models::DbConnectionPoolV2;
2020
use editoast_schemas::rolling_stock::Gamma;
21-
use editoast_schemas::rolling_stock::RollingResistance;
21+
use editoast_schemas::rolling_stock::RollingResistancePerWeight;
2222
use editoast_schemas::rolling_stock::ROLLING_STOCK_RAILJSON_VERSION;
2323
use serde::Deserialize;
2424
use serde::Serialize;
@@ -59,7 +59,7 @@ struct TowedRollingStock {
5959
comfort_acceleration: f64,
6060
startup_acceleration: f64,
6161
inertia_coefficient: f64,
62-
rolling_resistance: RollingResistance,
62+
rolling_resistance: RollingResistancePerWeight,
6363
gamma: Gamma,
6464
}
6565

@@ -104,7 +104,7 @@ pub struct TowedRollingStockForm {
104104
pub comfort_acceleration: f64,
105105
pub startup_acceleration: f64,
106106
pub inertia_coefficient: f64,
107-
pub rolling_resistance: RollingResistance,
107+
pub rolling_resistance: RollingResistancePerWeight,
108108
pub gamma: Gamma,
109109
}
110110

0 commit comments

Comments
 (0)