You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Simulation does not stop on under-/overvoltage #11
Hi @milanofthe, I'm unsure what the correct pattern is in PathSim to auto-terminate simulations on specific events. Concretely, I need to stop when the voltage crosses the lower or upper cutoff voltage of the cell, as results become nonsensical outside (in real systems, the battery management system needs to ensure the thresholds are never crossed). I can use ZeroCrossingDown to define the event, but I'm not sure where to put them, as the block doesn't know about the simulation.
In the Python script you can do something like this, it sets a flag internally and exits the timestepping loop at next iteration. By the time its called Sim is already in the namespace:
#events to detectdeffunc_evt_1(t):
i, o, s=VL()
returns[0] -4deffunc_evt_2(t):
i, o, s=VL()
returns[1] -4E1=ZeroCrossingUp(
func_evt=func_evt_1,
tolerance=1e-4
)
E2=ZeroCrossingUp(
func_evt=func_evt_2,
func_act=lambda_: Sim.stop(), # <--- this one tolerance=1e-4
)
E3=ZeroCrossingDown(
func_evt=func_evt_1,
tolerance=1e-4
)
E4=ZeroCrossingDown(
func_evt=func_evt_2,
tolerance=1e-4
)
#initialize simulation with the blocks, connections, timestep and logging enabledSim=Simulation(
blocks,
connections,
[E1, E2, E3, E4],
dt=dt,
log=True,
Solver=RKBS32,
tolerance_lte_rel=1e-4,
tolerance_lte_abs=1e-6
)
A distinct Stop event might be nice to have though.
What do you think? Then certain events could just throw StopSimulation and it would bubble up to the calling simulation, without need for a reference to it.
Activity
DavidMStraub commentedon May 11, 2026
Hi @milanofthe, I'm unsure what the correct pattern is in PathSim to auto-terminate simulations on specific events. Concretely, I need to stop when the voltage crosses the lower or upper cutoff voltage of the cell, as results become nonsensical outside (in real systems, the battery management system needs to ensure the thresholds are never crossed). I can use
ZeroCrossingDownto define the event, but I'm not sure where to put them, as the block doesn't know about the simulation.milanofthe commentedon May 11, 2026
In the Python script you can do something like this, it sets a flag internally and exits the timestepping loop at next iteration. By the time its called
Simis already in the namespace:A distinct
Stopevent might be nice to have though.DavidMStraub commentedon May 11, 2026
Somehow I think it would be nice if models/blocks could gracefully tell the running simulation to stop.
What about the following modification to PathSim:
What do you think? Then certain events could just throw
StopSimulationand it would bubble up to the calling simulation, without need for a reference to it.milanofthe commentedon May 11, 2026
Yes that would work. I have played with the idea of introducing more custom exceptions anyway. This would be another argument for it.
DavidMStraub commentedon May 11, 2026
I could draft a PR.
DavidMStraub commentedon May 20, 2026
Fixed in #14.