Physics¶
physics
¶
Physical equations used by the tramway simulation.
This module implements the simplified physical models used to estimate:
- train kinematics: speed and acceleration;
- electrical power demand;
- equivalent electrical network seen by the train;
- resulting train voltage.
The models are intentionally simplified to remain computationally efficient and suitable for repeated evaluation within optimization loops.
compute_kinematics(time_s, position_m)
¶
Compute train speed and acceleration from position samples.
The derivatives are approximated using NumPy's gradient function, which applies central differences in the interior and first-order differences at the boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_s
|
ndarray
|
Time samples, in seconds. |
required |
position_m
|
ndarray
|
Train position samples, in meters. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
tuple[np.ndarray, np.ndarray]: Speed in meters per second and acceleration |
ndarray
|
in meters per second squared. |
Notes
This numerical differentiation is sufficient for estimating power demand, but it may introduce noise if the position signal is not smooth.
Source code in src\tramway_optimization\physics.py
compute_train_electrical_power(time_s, position_m, train)
¶
Estimate the train electrical power demand over time.
The computation follows three steps: compute speed and acceleration from the position profile, estimate traction force from inertia, slope and resistive forces, then convert mechanical power to electrical power.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_s
|
ndarray
|
Time samples, in seconds. |
required |
position_m
|
ndarray
|
Train position samples, in meters. |
required |
train
|
TrainConfig
|
Train configuration containing mass, efficiency and resistance coefficients. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Electrical power demand in watts. |
Notes
Positive values correspond to traction demand. Negative values correspond to regenerative braking power. A constant auxiliary power is added to account for onboard systems.
The resistive force follows a Davis-like model:
F = A + Bv + Cv²
Source code in src\tramway_optimization\physics.py
equivalent_resistance(position_m, line_length_m, network)
¶
Compute the equivalent electrical resistance seen by the train.
The tramway is supplied by two substations located at both ends of the line. Each substation is connected to the train through the overhead line and rails. The two branches are combined into a Thevenin equivalent resistance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position_m
|
ndarray | float
|
Train position along the line, in meters. |
required |
line_length_m
|
float
|
Total length of the line, in meters. |
required |
network
|
ElectricalNetwork
|
Electrical network parameters. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Equivalent resistance in ohms. |
Notes
The equivalent resistance is computed as:
R_eq = (R_left * R_right) / (R_left + R_right)
The resistance varies with train position because the lengths of the left and right supply branches change over time.
Source code in src\tramway_optimization\physics.py
train_voltage_from_line_power(line_power_w, position_m, line_length_m, network, fallback_voltage_v=500.0)
¶
Compute train voltage from line power using a Thevenin model.
The electrical network is modeled as a voltage source with an equivalent series resistance. This leads to a quadratic equation in train voltage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_power_w
|
ndarray | float
|
Power drawn from the line, in watts. |
required |
position_m
|
ndarray | float
|
Train position along the line, in meters. |
required |
line_length_m
|
float
|
Total length of the line, in meters. |
required |
network
|
ElectricalNetwork
|
Electrical network parameters. |
required |
fallback_voltage_v
|
float
|
Voltage returned when the quadratic equation has no real solution. |
500.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Train voltage in volts. |
Notes
The voltage is obtained from:
V_train² - V_sst * V_train + R_eq * P = 0
Only the physically meaningful high-voltage root is used. If the
discriminant is negative, the requested power exceeds what the network
can supply at that position, and fallback_voltage_v is returned to
avoid numerical failure.