Skip to content

Implement cosimulation cells (fixes #7)#8

Merged
DavidMStraub merged 10 commits intopathsim:masterfrom
DavidMStraub:cosimulation_cell
May 5, 2026
Merged

Implement cosimulation cells (fixes #7)#8
DavidMStraub merged 10 commits intopathsim:masterfrom
DavidMStraub:cosimulation_cell

Conversation

@DavidMStraub
Copy link
Copy Markdown
Collaborator

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.

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 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 CellCoSimElectrical and CellCoSimElectrothermal as 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.

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

Comment thread src/pathsim_batt/__init__.py
Comment thread src/pathsim_batt/cells/__init__.py
Comment thread src/pathsim_batt/cells/pybamm_cell.py Outdated
@DavidMStraub DavidMStraub merged commit 6578242 into pathsim:master May 5, 2026
5 checks passed
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