This example requires external dependencies and cannot be run in the browser.

High-Fidelity DFN Simulation via Co-Simulation

The Doyle–Fuller–Newman (DFN) model produces a DAE system after discretisation and cannot be used with the monolithic ODE blocks. The co-simulation blocks (CellCoSimElectrothermal, CellCoSimElectrical) let PyBaMM step the DAE internally while PathSim receives zero-order-held outputs between macro-steps.

Why Co-Simulation?

The DFN model resolves spatial gradients in both the solid and electrolyte phases. The phase-potential equations are algebraic, so after spatial discretisation the DFN becomes a DAE — incompatible with CellElectrical / CellElectrothermal.

The co-simulation blocks call pybamm.Simulation.step() internally on a fixed macro-step dt and expose zero-order-held outputs to PathSim. This supports any PyBaMM model.

Brosa Planella et al., arXiv:2203.16091 (2022).

Python
Loading...
/opt/hostedtoolcache/Python/3.11.17/x64/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

Part 1: SPMe vs DFN with Built-in Thermal

Both models use PyBaMM's lumped thermal sub-model. SPMe runs as a monolithic ODE in PathSim; DFN runs via co-simulation with a 10 s macro-step.

Python
Loading...
Python
Loading...
Running SPMe (monolithic)...
22:12:53 - INFO - LOGGING (log: True)
22:12:53 - INFO - BLOCKS (total: 4, dynamic: 1, static: 3, eventful: 0)
22:12:53 - INFO - GRAPH (nodes: 4, edges: 5, alg. depth: 2, loop depth: 0, runtime: 0.056ms)
22:12:53 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s)
22:12:54 - INFO - --------------------   1% | 0.1s<13.0s | 14.1 it/s
22:12:54 - INFO - ####----------------  20% | 0.6s<1.3s | 15.7 it/s
22:12:54 - INFO - ###########---------  56% | 0.7s<0.2s | 15.8 it/s
22:12:54 - INFO - #################---  88% | 0.8s<0.0s | 15.8 it/s
22:12:54 - INFO - #################### 100% | 0.8s<--:-- | 15.9 it/s
22:12:54 - INFO - FINISHED -> TRANSIENT (total steps: 13, successful: 13, runtime: 844.66 ms)
Python
Loading...
Running DFN (co-simulation)...
22:12:55 - INFO - LOGGING (log: True)
22:12:55 - INFO - BLOCKS (total: 4, dynamic: 0, static: 4, eventful: 1)
22:12:55 - INFO - GRAPH (nodes: 4, edges: 5, alg. depth: 2, loop depth: 0, runtime: 0.052ms)
22:12:55 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s)
22:12:55 - INFO - --------------------   1% | 0.5s<15.2s | 11.7 it/s
22:12:56 - INFO - ###-----------------  17% | 1.5s<4.6s | 32.7 it/s
22:12:56 - INFO - ####----------------  20% | 1.6s<4.4s | 32.5 it/s
22:12:57 - INFO - #######-------------  38% | 2.7s<3.3s | 33.2 it/s
22:12:57 - INFO - ########------------  40% | 2.8s<3.3s | 32.5 it/s
22:12:58 - INFO - ###########---------  56% | 3.8s<3.2s | 24.8 it/s
22:12:59 - INFO - ############--------  60% | 4.0s<2.2s | 31.7 it/s
22:13:00 - INFO - ###############-----  78% | 5.0s<1.2s | 32.2 it/s
22:13:00 - INFO - ################----  80% | 5.1s<1.1s | 32.5 it/s
22:13:01 - INFO - ###################-  98% | 6.1s<0.1s | 33.0 it/s
22:13:01 - INFO - #################### 100% | 6.2s<--:-- | 32.5 it/s
22:13:01 - INFO - FINISHED -> TRANSIENT (total steps: 180, successful: 180, runtime: 6240.64 ms)
Python
Loading...
Output

Part 2: DFN with External Thermal Model

Same feedback topology as notebook 02, but with CellCoSimElectrical instead of CellElectrical. We compare two macro-step sizes to illustrate ZOH approximation error.

Python
Loading...
Python
Loading...
Running DFN co-sim with external thermal (dt = 30 s)...
22:13:02 - INFO - LOGGING (log: True)
22:13:02 - INFO - BLOCKS (total: 5, dynamic: 1, static: 4, eventful: 1)
22:13:02 - INFO - GRAPH (nodes: 5, edges: 7, alg. depth: 2, loop depth: 0, runtime: 0.111ms)
22:13:02 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s)
22:13:02 - INFO - --------------------   1% | 0.2s<11.4s | 5.2 it/s
22:13:02 - INFO - ####----------------  20% | 0.5s<1.2s | 41.5 it/s
22:13:02 - INFO - ########------------  40% | 0.7s<0.9s | 42.3 it/s
22:13:03 - INFO - ############--------  61% | 1.1s<0.5s | 42.1 it/s
22:13:03 - INFO - ################----  80% | 1.3s<0.3s | 42.8 it/s
22:13:03 - INFO - #################### 100% | 1.6s<--:-- | 41.9 it/s
22:13:03 - INFO - FINISHED -> TRANSIENT (total steps: 60, successful: 60, runtime: 1609.10 ms)
Running DFN co-sim with external thermal (dt =  5 s)...
22:13:04 - INFO - LOGGING (log: True)
22:13:04 - INFO - BLOCKS (total: 5, dynamic: 1, static: 4, eventful: 1)
22:13:04 - INFO - GRAPH (nodes: 5, edges: 7, alg. depth: 2, loop depth: 0, runtime: 0.113ms)
22:13:04 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s)
22:13:04 - INFO - --------------------   1% | 0.3s<12.3s | 28.9 it/s
22:13:05 - INFO - ##------------------  11% | 1.3s<8.0s | 39.6 it/s
22:13:06 - INFO - ####----------------  20% | 2.0s<6.7s | 43.1 it/s
22:13:07 - INFO - ######--------------  32% | 3.0s<5.6s | 43.8 it/s
22:13:07 - INFO - ########------------  40% | 3.6s<5.1s | 42.7 it/s
22:13:08 - INFO - ##########----------  52% | 4.6s<4.0s | 43.2 it/s
22:13:09 - INFO - ############--------  60% | 5.3s<3.3s | 43.3 it/s
22:13:10 - INFO - ##############------  72% | 6.3s<2.3s | 43.6 it/s
22:13:11 - INFO - ################----  80% | 6.9s<1.7s | 43.6 it/s
22:13:12 - INFO - ##################--  92% | 8.0s<0.6s | 43.1 it/s
22:13:12 - INFO - #################### 100% | 8.6s<--:-- | 42.9 it/s
22:13:12 - INFO - FINISHED -> TRANSIENT (total steps: 360, successful: 360, runtime: 8620.04 ms)
Python
Loading...
Output

Summary

Block Model Thermal
CellElectrothermal SPMe / SPM (ODE) Built-in
CellCoSimElectrothermal Any incl. DFN (DAE) Built-in
CellElectrical SPMe / SPM (ODE) External (LumpedThermal)
CellCoSimElectrical Any incl. DFN (DAE) External (LumpedThermal)
  • DFN resolves spatial gradients in both phases but produces a DAE — use the co-simulation blocks.
  • A smaller macro-step dt reduces ZOH error at the cost of more PyBaMM step() calls.
  • The external thermal loop extends naturally to multi-cell pack models.