Skip to content

Commit

Permalink
editoast: stdcm towed rolling stock parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Wadjetz committed Oct 18, 2024
1 parent 40063de commit b2901ec
Show file tree
Hide file tree
Showing 20 changed files with 466 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 }
}
}
19 changes: 15 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,22 @@ editoast_common::schemas! {
#[allow(non_snake_case)]
pub struct RollingResistance {
#[serde(rename = "type")]
rolling_resistance_type: String,
pub rolling_resistance_type: String,
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
A: f64,
pub A: f64,
#[derivative(Hash(hash_with = "editoast_common::hash_float::<5,_>"))]
B: f64,
pub B: f64,
#[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
33 changes: 33 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 @@ -4216,6 +4220,7 @@ components:
- $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 @@ -5207,6 +5212,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 @@ -8728,6 +8757,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
88 changes: 81 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 @@ -74,34 +75,79 @@ pub struct SimulationParameters {
}

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); // TODO check the unit
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 = f64::min(
traction_engine.comfort_acceleration,
towed_rolling_stock
.as_ref()
.map(|trs| trs.comfort_acceleration)
.unwrap_or(traction_engine.comfort_acceleration),
);

let startup_acceleration = f64::max(
traction_engine.startup_acceleration,
towed_rolling_stock
.as_ref()
.map(|trs| trs.startup_acceleration)
.unwrap_or(traction_engine.startup_acceleration),
);

let inertia_coefficient = if let (Some(towed_rolling_stock), Some(total_mass)) =
(&towed_rolling_stock, params.total_mass)
{
compute_inertia_coefficient(&traction_engine, towed_rolling_stock, total_mass)
} else {
traction_engine.inertia_coefficient
};

let rolling_resistance = if let (Some(towed_rolling_stock), Some(total_mass)) =
(&towed_rolling_stock, params.total_mass)
{
compute_rolling_resistance(&traction_engine, towed_rolling_stock, total_mass)
} else {
traction_engine.rolling_resistance
};

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 +159,34 @@ impl PhysicsRollingStock {
}
}

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

let a = traction_engine_rr.A * traction_engine_mass
+ towed_rs_rr.A * (total_mass - traction_engine_mass);
let b = traction_engine_rr.B * traction_engine_mass
+ towed_rs_rr.B * (total_mass - traction_engine_mass);
let c = traction_engine_rr.C * traction_engine_mass
+ towed_rs_rr.C * (total_mass - traction_engine_mass);

RollingResistance::new(traction_engine_rr.rolling_resistance_type.clone(), a, b, c)
}

fn compute_inertia_coefficient(
traction_engine: &RollingStock,
towed_rolling_stock: &TowedRollingStock,
total_mass: f64,
) -> f64 {
(total_mass * traction_engine.inertia_coefficient)
+ ((total_mass - towed_rolling_stock.mass) * towed_rolling_stock.inertia_coefficient)
}

#[derive(Debug, Clone, Hash, PartialEq, Serialize, Deserialize, ToSchema)]
pub struct ZoneUpdate {
pub zone: String,
Expand Down
5 changes: 5 additions & 0 deletions editoast/src/models/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use editoast_schemas::infra::DirectionalTrackRange;
use editoast_schemas::infra::InfraObject;
use editoast_schemas::infra::RailJson;
use editoast_schemas::primitives::OSRDObject;
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::TrainScheduleBase;
use postgis_diesel::types::LineString;
use serde_json::Value;
Expand All @@ -31,6 +34,8 @@ use crate::models::Scenario;
use crate::models::Study;
use crate::models::Tags;

use super::towed_rolling_stock::TowedRollingStockModel;

pub fn project_changeset(name: &str) -> Changeset<Project> {
Project::changeset()
.name(name.to_owned())
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 b2901ec

Please sign in to comment.