Skip to content

Implement voltage cutoffs#14

Draft
DavidMStraub wants to merge 4 commits into
pathsim:masterfrom
DavidMStraub:voltage_cutoffs
Draft

Implement voltage cutoffs#14
DavidMStraub wants to merge 4 commits into
pathsim:masterfrom
DavidMStraub:voltage_cutoffs

Conversation

@DavidMStraub
Copy link
Copy Markdown
Collaborator

This uses the new StopSimulation exception to stop the simulation when hitting over- or undervoltage.

Temporarily pins pathsim to master; will merge when next version is released.

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

Adds automatic simulation termination when PyBaMM cell voltage crosses configured over-/undervoltage cutoffs, leveraging PathSim’s new StopSimulation exception so users don’t need to wire termination logic manually.

Changes:

  • Raise StopSimulation from both continuous (_CellBase.func_alg) and co-sim (_CoSimCellBase._discrete_step) cell blocks when voltage exceeds cutoffs.
  • Improve co-simulation initial outputs to compute t=0 open-circuit outputs via CasADi evaluation (instead of placeholder zeros).
  • Add termination-focused tests and temporarily pin pathsim to a specific Git commit that includes StopSimulation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/pathsim_batt/cells/pybamm_cell.py Introduces voltage cutoff extraction, termination via StopSimulation, and improved co-sim initial outputs.
tests/cells/test_pybamm_cell.py Adds integration tests asserting simulations stop early at voltage cutoffs and that cutoff values match PyBaMM parameters.
pyproject.toml Temporarily pins pathsim to a Git commit to access StopSimulation.
Comments suppressed due to low confidence (1)

src/pathsim_batt/cells/pybamm_cell.py:229

  • Same as above: direct indexing into parameter_values for voltage cut-offs can raise KeyError for custom/alternate parameter sets. Please add an explicit check with a clear error message (or fallback defaults) to keep the constructor failure mode predictable for API consumers.
        self._model = model
        self._parameter_values = _prepare_parameter_values(parameter_values)
        self._v_lower = float(
            self._parameter_values["Lower voltage cut-off [V]"]
        )
        self._v_upper = float(
            self._parameter_values["Upper voltage cut-off [V]"]
        )

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

Comment thread src/pathsim_batt/cells/pybamm_cell.py Outdated
Comment thread src/pathsim_batt/cells/pybamm_cell.py
Comment thread src/pathsim_batt/cells/pybamm_cell.py
Comment thread pyproject.toml
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

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

Comments suppressed due to low confidence (1)

src/pathsim_batt/cells/pybamm_cell.py:321

  • Same as above: the stop condition uses V = outputs[0], which relies on _pybamm_output_vars always having terminal voltage at index 0. To avoid fragile ordering dependencies, fetch the terminal voltage by its PyBaMM variable name or add an explicit assertion/lookup so future subclasses can’t accidentally trigger cut-offs based on the wrong output.
        V = outputs[0]
        if V <= self._v_lower:
            raise StopSimulation(f"undervoltage: V={V:.4f} V <= {self._v_lower} V")
        if V >= self._v_upper:
            raise StopSimulation(f"overvoltage: V={V:.4f} V >= {self._v_upper} V")

Comment thread src/pathsim_batt/cells/pybamm_cell.py Outdated
Comment thread pyproject.toml
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

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

Comment thread src/pathsim_batt/cells/pybamm_cell.py
Comment thread pyproject.toml
@DavidMStraub
Copy link
Copy Markdown
Collaborator Author

Ready to merge once new PathSim version is released.

Fixes #11.

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.

2 participants