Skip to content

Commit

Permalink
stdcm: towed rolling stock parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Egor Berezovskiy <egor@berezify.fr>
  • Loading branch information
Wadjetz committed Oct 22, 2024
1 parent f79e009 commit 07b8f13
Show file tree
Hide file tree
Showing 21 changed files with 527 additions and 29 deletions.
6 changes: 6 additions & 0 deletions editoast/editoast_schemas/src/rolling_stock/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ pub struct Gamma {
#[derivative(Hash(hash_with = "editoast_common::hash_float::<3,_>"))]
value: f64,
}

impl Gamma {
pub fn new(gamma_type: String, value: f64) -> Self {
Self { gamma_type, value }
}
}
22 changes: 18 additions & 4 deletions editoast/editoast_schemas/src/rolling_stock/rolling_resistance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,25 @@ editoast_common::schemas! {
#[allow(non_snake_case)]
pub struct RollingResistance {
#[serde(rename = "type")]
rolling_resistance_type: String,
pub rolling_resistance_type: String,
/// kN
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
A: f64,
pub A: f64,
/// kN/(km/h)
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
B: f64,
pub B: f64,
/// kN/(km/h)²
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
C: f64,
pub C: f64,
}

impl RollingResistance {
pub fn new(rolling_resistance_type: String, a: f64, b: f64, c: f64) -> Self {
Self {
rolling_resistance_type,
A: a,
B: b,
C: c,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ pub struct TowedRollingStock {
pub name: String,
pub railjson_version: String,

/// In kg
pub mass: f64,
/// In m
pub length: f64,
pub comfort_acceleration: f64,
pub startup_acceleration: f64,
Expand Down
56 changes: 56 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,10 @@ paths:
format: double
description: Total mass of the consist in kg
nullable: true
towed_rolling_stock_id:
type: integer
format: int64
nullable: true
work_schedule_group_id:
type: integer
format: int64
Expand Down Expand Up @@ -4212,10 +4216,12 @@ components:
- $ref: '#/components/schemas/EditoastRollingStockErrorKeyNotFound'
- $ref: '#/components/schemas/EditoastRollingStockErrorLiveryMultipartError'
- $ref: '#/components/schemas/EditoastRollingStockErrorNameAlreadyUsed'
- $ref: '#/components/schemas/EditoastSTDCMErrorConsistEntryInvalid'
- $ref: '#/components/schemas/EditoastSTDCMErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastSTDCMErrorInvalidPathItems'
- $ref: '#/components/schemas/EditoastSTDCMErrorRollingStockNotFound'
- $ref: '#/components/schemas/EditoastSTDCMErrorTimetableNotFound'
- $ref: '#/components/schemas/EditoastSTDCMErrorTowedRollingStockNotFound'
- $ref: '#/components/schemas/EditoastScenarioErrorInfraNotFound'
- $ref: '#/components/schemas/EditoastScenarioErrorNotFound'
- $ref: '#/components/schemas/EditoastScenarioErrorTimetableNotFound'
Expand Down Expand Up @@ -5111,6 +5117,25 @@ components:
type: string
enum:
- editoast:rollingstocks:NameAlreadyUsed
EditoastSTDCMErrorConsistEntryInvalid:
type: object
required:
- type
- status
- message
properties:
context:
type: object
message:
type: string
status:
type: integer
enum:
- 400
type:
type: string
enum:
- editoast:stdcm_v2:ConsistEntryInvalid
EditoastSTDCMErrorInfraNotFound:
type: object
required:
Expand Down Expand Up @@ -5207,6 +5232,30 @@ components:
type: string
enum:
- editoast:stdcm_v2:TimetableNotFound
EditoastSTDCMErrorTowedRollingStockNotFound:
type: object
required:
- type
- status
- message
properties:
context:
type: object
required:
- towed_rolling_stock_id
properties:
towed_rolling_stock_id:
type: integer
message:
type: string
status:
type: integer
enum:
- 400
type:
type: string
enum:
- editoast:stdcm_v2:TowedRollingStockNotFound
EditoastScenarioErrorInfraNotFound:
type: object
required:
Expand Down Expand Up @@ -8171,12 +8220,15 @@ components:
A:
type: number
format: double
description: kN
B:
type: number
format: double
description: kN/(km/h)
C:
type: number
format: double
description: kN/(km/h)²
type:
type: string
additionalProperties: false
Expand Down Expand Up @@ -8732,6 +8784,10 @@ components:
format: double
description: Total mass of the consist in kg
nullable: true
towed_rolling_stock_id:
type: integer
format: int64
nullable: true
work_schedule_group_id:
type: integer
format: int64
Expand Down
116 changes: 109 additions & 7 deletions editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use editoast_schemas::rolling_stock::EffortCurves;
use editoast_schemas::rolling_stock::Gamma;
use editoast_schemas::rolling_stock::RollingResistance;
use editoast_schemas::rolling_stock::RollingStock;
use editoast_schemas::rolling_stock::TowedRollingStock;
use editoast_schemas::train_schedule::Comfort;
use editoast_schemas::train_schedule::Distribution;
use editoast_schemas::train_schedule::MarginValue;
Expand Down Expand Up @@ -68,40 +69,63 @@ pub struct PhysicsRollingStock {

#[derive(Debug, Default)]
pub struct SimulationParameters {
/// In kg
pub total_mass: Option<f64>,
pub total_length: Option<f64>,
pub max_speed: Option<f64>,
}

impl PhysicsRollingStock {
pub fn new(traction_engine: RollingStock, params: SimulationParameters) -> Self {
pub fn new(
traction_engine: RollingStock,
towed_rolling_stock: Option<TowedRollingStock>,
params: SimulationParameters,
) -> Self {
let traction_engine_length = traction_engine.length * 1000.0;

let towed_rolling_stock_length = towed_rolling_stock
.as_ref()
.map(|trs| trs.length)
.unwrap_or(0.0);
let length = params
.total_length
.map(|tl| tl * 1000.0)
.unwrap_or(traction_engine_length)
.unwrap_or_else(|| traction_engine_length + towed_rolling_stock_length)
.round() as u64;

let traction_engine_mass = traction_engine.mass;
let mass = params.total_mass.unwrap_or(traction_engine_mass).round() as u64;
let towed_rolling_stock_mass = towed_rolling_stock.as_ref().map(|trs| trs.mass);
let mass = params
.total_mass
.unwrap_or_else(|| traction_engine_mass + towed_rolling_stock_mass.unwrap_or(0.0))
.round() as u64;

let max_speed = f64::min(
traction_engine.max_speed,
params.max_speed.unwrap_or(traction_engine.max_speed),
);

let comfort_acceleration =
compute_comfort_acceleration(&traction_engine, &towed_rolling_stock);
let startup_acceleration =
compute_startup_acceleration(&traction_engine, &towed_rolling_stock);
let inertia_coefficient =
compute_inertia_coefficient(&traction_engine, &towed_rolling_stock, params.total_mass);
let rolling_resistance =
compute_rolling_resistance(&traction_engine, &towed_rolling_stock, params.total_mass);

Self {
effort_curves: traction_engine.effort_curves,
base_power_class: traction_engine.base_power_class,
length,
mass,
max_speed,
startup_time: (traction_engine.startup_time * 1000.0).round() as u64,
startup_acceleration: traction_engine.startup_acceleration,
comfort_acceleration: traction_engine.comfort_acceleration,
startup_acceleration,
comfort_acceleration,
gamma: traction_engine.gamma,
inertia_coefficient: traction_engine.inertia_coefficient,
rolling_resistance: traction_engine.rolling_resistance,
inertia_coefficient,
rolling_resistance,
power_restrictions: traction_engine.power_restrictions.into_iter().collect(),
electrical_power_startup_time: traction_engine
.electrical_power_startup_time
Expand All @@ -113,6 +137,84 @@ impl PhysicsRollingStock {
}
}

fn compute_rolling_resistance(
traction_engine: &RollingStock,
towed_rolling_stock: &Option<TowedRollingStock>,
total_mass: Option<f64>,
) -> RollingResistance {
if let (Some(towed_rolling_stock), Some(total_mass)) = (towed_rolling_stock, total_mass) {
let traction_engine_rr = &traction_engine.rolling_resistance;
let towed_rs_rr = &towed_rolling_stock.rolling_resistance;
let traction_engine_mass = traction_engine.mass; // kg

let mass_carriage = total_mass - traction_engine_mass; // kg

let rav_a_te = traction_engine_rr.A * 1000.0; // N
let rav_b_te = traction_engine_rr.B * 1000.0 * 3.6; // N/(m/s)
let rav_c_te = traction_engine_rr.C * 1000.0 * 3.6 * 3.6; // N/(m/s)²

let rav_a_towed = towed_rs_rr.A * 1e-2 * mass_carriage; // N
let rav_b_towed = towed_rs_rr.B * 1e-2 * mass_carriage * 3.6; // N/(m/s)
let rav_c_towed = towed_rs_rr.C * 1e-2 * mass_carriage * 3.6 * 3.6; // N/(m/s)²

let rav_a = rav_a_te + rav_a_towed;
let rav_b = rav_b_te + rav_b_towed;
let rav_c = rav_c_te + rav_c_towed;

RollingResistance::new(
traction_engine_rr.rolling_resistance_type.clone(),
rav_a,
rav_b,
rav_c,
)
} else {
traction_engine.rolling_resistance.clone()
}
}

fn compute_inertia_coefficient(
traction_engine: &RollingStock,
towed_rolling_stock: &Option<TowedRollingStock>,
total_mass: Option<f64>,
) -> f64 {
if let (Some(towed_rolling_stock), Some(total_mass)) = (towed_rolling_stock, total_mass) {
let mass_carriage = total_mass - traction_engine.mass;
let traction_engine_inertia = traction_engine.mass * traction_engine.inertia_coefficient;
let towed_inertia = mass_carriage * towed_rolling_stock.inertia_coefficient;
(traction_engine_inertia + towed_inertia) / total_mass
} else {
traction_engine.inertia_coefficient
}
}

fn compute_startup_acceleration(
traction_engine: &RollingStock,
towed_rolling_stock: &Option<TowedRollingStock>,
) -> f64 {
if let Some(towed_rolling_stock) = towed_rolling_stock {
f64::max(
traction_engine.startup_acceleration,
towed_rolling_stock.startup_acceleration,
)
} else {
traction_engine.startup_acceleration
}
}

fn compute_comfort_acceleration(
traction_engine: &RollingStock,
towed_rolling_stock: &Option<TowedRollingStock>,
) -> f64 {
if let Some(towed_rolling_stock) = towed_rolling_stock {
f64::min(
traction_engine.comfort_acceleration,
towed_rolling_stock.comfort_acceleration,
)
} else {
traction_engine.comfort_acceleration
}
}

#[derive(Debug, Clone, Hash, PartialEq, Serialize, Deserialize, ToSchema)]
pub struct ZoneUpdate {
pub zone: String,
Expand Down
2 changes: 2 additions & 0 deletions editoast/src/models/towed_rolling_stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub struct TowedRollingStockModel {
pub railjson_version: String,
pub locked: bool,

/// In kg
pub mass: f64,
/// In m
pub length: f64,
pub comfort_acceleration: f64,
pub startup_acceleration: f64,
Expand Down
Loading

0 comments on commit 07b8f13

Please sign in to comment.