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.18/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)...
13:58:47 - INFO - LOGGING (log: True)
13:58:47 - INFO - BLOCKS (total: 4, dynamic: 1, static: 3, eventful: 0)
13:58:47 - INFO - GRAPH (nodes: 4, edges: 5, alg. depth: 2, loop depth: 0, runtime: 0.093ms)
13:58:47 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s)
13:58:48 - INFO - --------------------   1% | 0.2s<18.6s | 9.9 it/s
13:58:48 - INFO - ####----------------  20% | 0.9s<1.9s | 10.6 it/s
13:58:48 - INFO - ###########---------  56% | 1.0s<0.3s | 10.7 it/s
13:58:48 - INFO - #################---  88% | 1.1s<0.1s | 10.6 it/s
13:58:49 - INFO - #################### 100% | 1.2s<--:-- | 10.8 it/s
13:58:49 - INFO - FINISHED -> TRANSIENT (total steps: 13, successful: 13, runtime: 1229.95 ms)
Python
Loading...
Running DFN (co-simulation)...
13:58:49 - INFO - LOGGING (log: True)
13:58:49 - INFO - BLOCKS (total: 4, dynamic: 0, static: 4, eventful: 1)
13:58:49 - INFO - GRAPH (nodes: 4, edges: 5, alg. depth: 2, loop depth: 0, runtime: 0.062ms)
13:58:49 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s)
13:58:50 - INFO - --------------------   1% | 0.8s<27.9s | 6.4 it/s
13:58:51 - INFO - ##------------------  13% | 1.8s<6.9s | 22.4 it/s
13:58:51 - INFO - ####----------------  20% | 2.3s<6.2s | 23.1 it/s
13:58:53 - INFO - #######-------------  38% | 3.3s<3.3s | 33.7 it/s
13:58:53 - INFO - ########------------  40% | 3.4s<3.2s | 34.1 it/s
13:58:54 - INFO - ###########---------  58% | 4.4s<2.2s | 33.6 it/s
13:58:54 - INFO - ############--------  60% | 4.5s<2.1s | 33.2 it/s
13:58:55 - INFO - ###############-----  79% | 5.5s<1.1s | 35.0 it/s
13:58:55 - INFO - ################----  80% | 5.5s<1.0s | 34.4 it/s
13:58:56 - INFO - ###################-  98% | 6.5s<0.1s | 34.7 it/s
13:58:56 - INFO - #################### 100% | 6.6s<--:-- | 34.4 it/s
13:58:56 - INFO - FINISHED -> TRANSIENT (total steps: 180, successful: 180, runtime: 6555.07 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)...
13:58:57 - INFO - LOGGING (log: True)
13:58:57 - INFO - BLOCKS (total: 5, dynamic: 1, static: 4, eventful: 1)
13:58:57 - INFO - GRAPH (nodes: 5, edges: 7, alg. depth: 2, loop depth: 0, runtime: 0.198ms)
13:58:57 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s)
13:58:57 - INFO - --------------------   1% | 0.2s<10.2s | 5.8 it/s
13:58:57 - INFO - ####----------------  20% | 0.4s<1.1s | 44.6 it/s
13:58:57 - INFO - ########------------  40% | 0.7s<0.8s | 45.2 it/s
13:58:58 - INFO - ############--------  61% | 1.0s<0.5s | 45.5 it/s
13:58:58 - INFO - ################----  80% | 1.2s<0.3s | 45.3 it/s
13:58:58 - INFO - #################### 100% | 1.5s<--:-- | 44.6 it/s
13:58:58 - INFO - FINISHED -> TRANSIENT (total steps: 60, successful: 60, runtime: 1486.40 ms)
Running DFN co-sim with external thermal (dt =  5 s)...
13:58:58 - INFO - LOGGING (log: True)
13:58:58 - INFO - BLOCKS (total: 5, dynamic: 1, static: 4, eventful: 1)
13:58:58 - INFO - GRAPH (nodes: 5, edges: 7, alg. depth: 2, loop depth: 0, runtime: 0.146ms)
13:58:58 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s)
13:58:59 - INFO - --------------------   1% | 0.2s<11.2s | 31.9 it/s
13:59:00 - INFO - ##------------------  13% | 1.2s<6.9s | 45.1 it/s
13:59:00 - INFO - ####----------------  20% | 1.7s<6.4s | 44.8 it/s
13:59:01 - INFO - ######--------------  32% | 2.7s<5.4s | 45.0 it/s
13:59:02 - INFO - ########------------  40% | 3.3s<4.9s | 44.0 it/s
13:59:03 - INFO - ##########----------  52% | 4.3s<3.8s | 45.0 it/s
13:59:03 - INFO - ############--------  60% | 5.0s<3.2s | 44.5 it/s
13:59:04 - INFO - ##############------  72% | 6.0s<2.2s | 44.9 it/s
13:59:05 - INFO - ################----  80% | 6.5s<1.6s | 44.9 it/s
13:59:06 - INFO - ##################--  92% | 7.6s<0.6s | 45.4 it/s
13:59:07 - INFO - #################### 100% | 8.1s<--:-- | 45.1 it/s
13:59:07 - INFO - FINISHED -> TRANSIENT (total steps: 360, successful: 360, runtime: 8128.81 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.