Simulation¶
simulation
¶
Time-domain tramway simulations with and without onboard battery storage.
This module contains the main simulation routines used to evaluate a battery design. The simulation is performed sample by sample over a train trajectory.
Two configurations are supported:
- baseline operation without battery;
- hybrid operation with onboard battery storage and rule-based energy management.
simulate_without_battery(time_s, position_m, network=None, train=None)
¶
Simulate the tramway supply system without onboard battery storage.
In this baseline configuration, positive train power is fully supplied by the DC line. Negative train power, corresponding to regenerative braking, is not sent back to the grid and is therefore ignored from the line-power point of view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_s
|
ndarray
|
Simulation time samples, in seconds. |
required |
position_m
|
ndarray
|
Train position at each time sample, in meters. |
required |
network
|
ElectricalNetwork | None
|
Electrical network configuration.
If |
None
|
train
|
TrainConfig | None
|
Train configuration. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SimulationResult |
SimulationResult
|
Time-domain simulation outputs, including train power, |
SimulationResult
|
line power, train voltage and voltage drop. |
Notes
This function provides the reference case used to evaluate the benefit of adding onboard battery storage.
Source code in src\tramway_optimization\simulation.py
apply_battery_rule(train_power_w, battery_energy_j, battery, dt_s)
¶
Apply the rule-based battery controller for one time step.
The controller follows a simple energy-management strategy:
- during braking, regenerative power is stored in the battery when free capacity is available;
- when traction demand is below the threshold, the line supplies all power;
- when traction demand is above the threshold, the battery supplies the excess power if enough energy is available;
- energy that cannot be recovered during braking is dissipated in the rheostat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_power_w
|
float
|
Electrical power requested by the train, in watts. Positive values represent traction demand, while negative values represent braking. |
required |
battery_energy_j
|
float
|
Battery energy available at the beginning of the time step, in joules. |
required |
battery
|
BatteryConfig
|
Battery configuration containing capacity, threshold and efficiency. |
required |
dt_s
|
float
|
Time-step duration, in seconds. |
required |
Returns:
| Type | Description |
|---|---|
float
|
tuple[float, float, float, float]: Line power in watts, battery power in |
float
|
watts, rheostat power in watts, and updated battery energy in joules. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
Battery power follows the project sign convention:
- positive battery power means discharge into the train;
- negative battery power means charging during regenerative braking.
Battery efficiency is applied differently during charge and discharge: during charge, only a fraction of recovered braking energy is stored; during discharge, more stored energy is consumed than the power delivered to the train because of losses.
Source code in src\tramway_optimization\simulation.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
simulate_with_battery(time_s, position_m, battery, network=None, train=None)
¶
Simulate the tramway supply system with onboard battery storage.
This simulation evaluates the complete hybrid system over the train trip. At each time step, train power demand is computed, the battery rule is applied, and the resulting line power is used to compute train voltage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_s
|
ndarray
|
Simulation time samples, in seconds. |
required |
position_m
|
ndarray
|
Train position at each time sample, in meters. |
required |
battery
|
BatteryConfig
|
Battery configuration and control parameters. |
required |
network
|
ElectricalNetwork | None
|
Electrical network configuration.
If |
None
|
train
|
TrainConfig | None
|
Train configuration. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SimulationResult |
SimulationResult
|
Time-domain simulation outputs, including line power, |
SimulationResult
|
battery power, rheostat power, battery energy, train voltage and voltage |
|
SimulationResult
|
drop. |
Notes
The battery state is propagated sequentially, so the result depends on the full history of traction and braking events. This is why each battery design must be evaluated through a complete time-domain simulation during optimization.