Skip to content

Implement voltage cutoffs#13

Closed
DavidMStraub wants to merge 1 commit into
pathsim:masterfrom
DavidMStraub:voltage_cutoffs
Closed

Implement voltage cutoffs#13
DavidMStraub wants to merge 1 commit into
pathsim:masterfrom
DavidMStraub:voltage_cutoffs

Conversation

@DavidMStraub
Copy link
Copy Markdown
Collaborator

Fixes #11.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds explicit voltage cut-off termination behavior to the PyBaMM-backed cell blocks so PathSim simulations stop when the terminal voltage hits PyBaMM’s lower/upper voltage limits (addressing Issue #11’s “simulation never stops on under/over-voltage” problem).

Changes:

  • Add termination_events() to _CellBase and _CoSimCellBase to stop the simulation on under-/over-voltage.
  • Store voltage cut-off values (_v_lower, _v_upper) from the active PyBaMM parameter set for both non-CoSim and CoSim blocks.
  • Improve CoSim initial outputs so the t=0 placeholder voltage is physically meaningful, and add tests covering under-voltage stop behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/pathsim_batt/cells/pybamm_cell.py Adds voltage cut-off values and termination events for both integrated and co-simulated PyBaMM cell blocks; adjusts CoSim initial output computation and termination wiring.
tests/cells/test_pybamm_cell.py Adds termination event integration tests to ensure simulations stop early at voltage cut-offs (primarily under-voltage scenarios).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +221 to +225
over_voltage = ZeroCrossingDown(
func_evt=lambda t: v_upper - float(outputs[0]),
func_act=lambda t: sim.stop(),
)
return [under_voltage, over_voltage]
Comment on lines +402 to +406
def _over_cb(V: float) -> None:
if V >= v_upper:
sim.stop()

self._term_callbacks.extend([_under_cb, _over_cb])
if V >= v_upper:
sim.stop()

self._term_callbacks.extend([_under_cb, _over_cb])
Comment on lines +362 to +364
if self._just_stepped:
self._just_stepped = False
V = float(self.outputs[0])
Comment on lines +640 to +652
PathSim does not stop on its own, and the voltage diverges wildly.
"""
cell = CellElectrical(initial_soc=0.02)
sim = self._run_without_events(cell, current=10.0, T_input_port="T_cell", T_value=298.15)
V_final = float(cell.outputs[0])
# Without events the simulation runs the full 600 s
self.assertAlmostEqual(sim.time, 600.0, delta=10.0)
# And the voltage should have diverged to a physically impossible value
self.assertLess(
V_final,
0.0,
"expected voltage divergence without termination events, got "
f"V={V_final:.3f} V — the bug may have been fixed elsewhere",
@DavidMStraub
Copy link
Copy Markdown
Collaborator Author

Closing as it wasn't a good design I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simulation does not stop on under-/overvoltage

2 participants