Skip to content

Commit

Permalink
editoast: qualify units
Browse files Browse the repository at this point in the history
Signed-off-by: Tristram Gräbener <[email protected]>
  • Loading branch information
Tristramg committed Jan 16, 2025
1 parent 1d0f95f commit 833fe27
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 242 deletions.
20 changes: 11 additions & 9 deletions editoast/editoast_common/src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
//! ```
/// Re-export the Quantities that are used in OSRD
pub use uom::si::f64::{Acceleration, Length, Mass, Ratio, Time, Velocity};

pub type SolidFriction = uom::si::f64::Force;
pub type SolidFrictionPerWeight = uom::si::f64::Acceleration;
pub type ViscosityFriction = uom::si::f64::MassRate;
pub type ViscosityFrictionPerWeight = uom::si::f64::Frequency;
pub type AerodynamicDrag = uom::si::f64::LinearMassDensity;
pub type AerodynamicDragPerWeight = uom::si::f64::LinearNumberDensity;
pub type Deceleration = uom::si::f64::Acceleration;
pub mod quantities {
pub use uom::si::f64::{Acceleration, Length, Mass, Ratio, Time, Velocity};
pub type SolidFriction = uom::si::f64::Force;
pub type SolidFrictionPerWeight = uom::si::f64::Acceleration;
pub type ViscosityFriction = uom::si::f64::MassRate;
pub type ViscosityFrictionPerWeight = uom::si::f64::Frequency;
pub type AerodynamicDrag = uom::si::f64::LinearMassDensity;
pub type AerodynamicDragPerWeight = uom::si::f64::LinearNumberDensity;
pub type Deceleration = uom::si::f64::Acceleration;
}

macro_rules! quantity_to_path {
(Length, $unit:ident) => {
Expand Down Expand Up @@ -199,6 +200,7 @@ macro_rules! define_unit {
}

// Any new value here must also be added in editoast_derive/src/annotate_units.rs
use quantities::*;
define_unit!(meter, Length);
define_unit!(millimeter, Length);
define_unit!(meter_per_second, Velocity);
Expand Down
25 changes: 14 additions & 11 deletions editoast/editoast_schemas/src/rolling_stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ pub use rolling_stock_livery::RollingStockLiveryMetadata;
mod towed_rolling_stock;
pub use towed_rolling_stock::TowedRollingStock;

use editoast_common::units::*;
use editoast_common::units;
use editoast_common::units::quantities::{
Acceleration, Deceleration, Length, Mass, Ratio, Time, Velocity,
};
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
Expand All @@ -61,24 +64,24 @@ pub struct RollingStock {
pub locked: bool,
pub effort_curves: EffortCurves,
pub base_power_class: Option<String>,
#[serde(with = "meter")]
#[serde(with = "units::meter")]
pub length: Length,
#[serde(with = "meter_per_second")]
#[serde(with = "units::meter_per_second")]
pub max_speed: Velocity,
#[serde(with = "second")]
#[serde(with = "units::second")]
pub startup_time: Time,
#[serde(with = "meter_per_second_squared")]
#[serde(with = "units::meter_per_second_squared")]
pub startup_acceleration: Acceleration,
#[serde(with = "meter_per_second_squared")]
#[serde(with = "units::meter_per_second_squared")]
pub comfort_acceleration: Acceleration,
// The constant gamma braking coefficient used when NOT circulating
// under ETCS/ERTMS signaling system
#[serde(with = "meter_per_second_squared")]
#[serde(with = "units::meter_per_second_squared")]
pub const_gamma: Deceleration,
pub etcs_brake_params: Option<EtcsBrakeParams>,
#[serde(with = "basis_point")]
#[serde(with = "units::basis_point")]
pub inertia_coefficient: Ratio,
#[serde(with = "kilogram")]
#[serde(with = "units::kilogram")]
pub mass: Mass,
pub rolling_resistance: RollingResistance,
pub loading_gauge: LoadingGaugeType,
Expand All @@ -89,11 +92,11 @@ pub struct RollingStock {
pub energy_sources: Vec<EnergySource>,
/// The time the train takes before actually using electrical power (in seconds).
/// Is null if the train is not electric.
#[serde(default, with = "second::option")]
#[serde(default, with = "units::second::option")]
pub electrical_power_startup_time: Option<Time>,
/// The time it takes to raise this train's pantograph in seconds.
/// Is null if the train is not electric.
#[serde(default, with = "second::option")]
#[serde(default, with = "units::second::option")]
pub raise_pantograph_time: Option<Time>,
pub supported_signaling_systems: RollingStockSupportedSignalingSystems,
pub railjson_version: String,
Expand Down
30 changes: 17 additions & 13 deletions editoast/editoast_schemas/src/rolling_stock/rolling_resistance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use derivative::Derivative;
use editoast_common::units::*;
use editoast_common::units;
use editoast_common::units::quantities::{
AerodynamicDrag, AerodynamicDragPerWeight, SolidFriction, SolidFrictionPerWeight,
ViscosityFriction, ViscosityFrictionPerWeight,
};
use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;
Expand All @@ -18,16 +22,16 @@ pub struct RollingResistance {
#[serde(rename = "type")]
pub rolling_resistance_type: String,
/// Solid friction
#[derivative(Hash(hash_with = "newton::hash"))]
#[serde(with = "newton")]
#[derivative(Hash(hash_with = "units::newton::hash"))]
#[serde(with = "units::newton")]
pub A: SolidFriction,
/// Viscosity friction in N·(m/s)⁻¹; N = kg⋅m⋅s⁻²
#[derivative(Hash(hash_with = "kilogram_per_second::hash"))]
#[serde(with = "kilogram_per_second")]
#[derivative(Hash(hash_with = "units::kilogram_per_second::hash"))]
#[serde(with = "units::kilogram_per_second")]
pub B: ViscosityFriction,
/// Aerodynamic drag in N·(m/s)⁻²; N = kg⋅m⋅s⁻²
#[derivative(Hash(hash_with = "kilogram_per_meter::hash"))]
#[serde(with = "kilogram_per_meter")]
#[derivative(Hash(hash_with = "units::kilogram_per_meter::hash"))]
#[serde(with = "units::kilogram_per_meter")]
pub C: AerodynamicDrag,
}

Expand All @@ -40,15 +44,15 @@ pub struct RollingResistancePerWeight {
#[serde(rename = "type")]
pub rolling_resistance_type: String,
/// Solid friction in N·kg⁻¹; N = kg⋅m⋅s⁻²
#[derivative(Hash(hash_with = "meter_per_second_squared::hash"))]
#[serde(with = "meter_per_second_squared")]
#[derivative(Hash(hash_with = "units::meter_per_second_squared::hash"))]
#[serde(with = "units::meter_per_second_squared")]
pub A: SolidFrictionPerWeight,
/// Viscosity friction in (N·kg⁻¹)·(m/s)⁻¹; N = kg⋅m⋅s⁻²
#[derivative(Hash(hash_with = "hertz::hash"))]
#[serde(with = "hertz")]
#[derivative(Hash(hash_with = "units::hertz::hash"))]
#[serde(with = "units::hertz")]
pub B: ViscosityFrictionPerWeight,
/// Aerodynamic drag per kg in (N·kg⁻¹)·(m/s)⁻²; N = kg⋅m⋅s⁻²
#[derivative(Hash(hash_with = "per_meter::hash"))]
#[serde(with = "per_meter")]
#[derivative(Hash(hash_with = "units::per_meter::hash"))]
#[serde(with = "units::per_meter")]
pub C: AerodynamicDragPerWeight,
}
19 changes: 11 additions & 8 deletions editoast/editoast_schemas/src/rolling_stock/towed_rolling_stock.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
use super::RollingResistancePerWeight;
use editoast_common::units::*;
use editoast_common::units;
use editoast_common::units::quantities::{
Acceleration, Deceleration, Length, Mass, Ratio, Velocity,
};

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct TowedRollingStock {
pub name: String,
pub label: String,
pub railjson_version: String,
#[serde(with = "kilogram")]
#[serde(with = "units::kilogram")]
pub mass: Mass,
#[serde(with = "meter")]
#[serde(with = "units::meter")]
pub length: Length,
#[serde(with = "meter_per_second_squared")]
#[serde(with = "units::meter_per_second_squared")]
pub comfort_acceleration: Acceleration,
#[serde(with = "meter_per_second_squared")]
#[serde(with = "units::meter_per_second_squared")]
pub startup_acceleration: Acceleration,
#[serde(with = "basis_point")]
#[serde(with = "units::basis_point")]
pub inertia_coefficient: Ratio,
pub rolling_resistance: RollingResistancePerWeight,
/// The constant gamma braking coefficient used when NOT circulating
/// under ETCS/ERTMS signaling system
#[serde(with = "meter_per_second_squared")]
#[serde(with = "units::meter_per_second_squared")]
pub const_gamma: Deceleration,
#[serde(default, with = "meter_per_second::option")]
#[serde(default, with = "units::meter_per_second::option")]
pub max_speed: Option<Velocity>,
}
Loading

0 comments on commit 833fe27

Please sign in to comment.