Implement cosimulation cells (fixes #7)#8
Merged
DavidMStraub merged 10 commits intopathsim:masterfrom May 5, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds co-simulation-based PyBaMM cell blocks that let PathSim use PyBaMM’s internal stepping instead of exporting a pure ODE, which broadens model support to DAE-based cells such as DFN while keeping the existing monolithic cell blocks in place.
Changes:
- Refactors shared PyBaMM setup into helpers and introduces a new
Wrapper-based co-simulation cell base. - Adds
CellCoSimElectricalandCellCoSimElectrothermalas new public cell types. - Updates tests and README to cover/document the new co-simulation workflow and DFN support.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/pathsim_batt/cells/pybamm_cell.py |
Refactors existing cell setup and adds the new co-simulation cell implementations. |
src/pathsim_batt/cells/__init__.py |
Re-exports cell classes from the cells package. |
src/pathsim_batt/__init__.py |
Updates top-level package exports for the public API. |
tests/cells/test_pybamm_cell.py |
Adds coverage for co-simulation cells and DFN-related behavior. |
README.md |
Documents the new co-simulation cell variants and usage guidance. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+216
to
+235
| """Create and build a fresh ``pybamm.Simulation`` with default inputs.""" | ||
| sim = pybamm.Simulation( | ||
| self._model, | ||
| parameter_values=self._parameter_values, | ||
| solver=self._pybamm_solver, | ||
| ) | ||
| sim.build(initial_soc=self._initial_soc, inputs=_DEFAULT_INPUTS) | ||
| return sim | ||
|
|
||
| def _initial_outputs(self) -> npt.NDArray[np.float64]: | ||
| """Return placeholder outputs for t=0 before the first solver step. | ||
|
|
||
| The co-simulation takes its first real sample at t=dt, so this | ||
| placeholder is only held for one macro-step. All outputs are zero | ||
| except SOC, which is set to the user-supplied initial value. | ||
| """ | ||
| out = np.zeros(len(self._pybamm_output_vars) + 1, dtype=np.float64) | ||
| out[-1] = self._initial_soc # SOC is always the last output | ||
| return out | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an alternative implementation of the PyBaMM cell classes (electrical & electrothermal) that uses PyBaMM's built-in solvers for cosimulation instead of full integration into PathSim. This allows using models with algebraic equations (e.g. DFN), but is also useful independently. The fully integrated versions are left unchanged, just refactored slightly to be DRY.