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).
/opt/hostedtoolcache/Python/3.11.15/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.
Running SPMe (monolithic)... 02:24:52 - INFO - LOGGING (log: True) 02:24:52 - INFO - BLOCKS (total: 4, dynamic: 1, static: 3, eventful: 0) 02:24:52 - INFO - GRAPH (nodes: 4, edges: 5, alg. depth: 2, loop depth: 0, runtime: 0.043ms) 02:24:52 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s) 02:24:52 - INFO - -------------------- 1% | 0.1s<11.0s | 16.7 it/s 02:24:53 - INFO - ####---------------- 20% | 0.5s<1.2s | 17.5 it/s 02:24:53 - INFO - ###########--------- 56% | 0.6s<0.2s | 17.8 it/s 02:24:53 - INFO - #################--- 88% | 0.7s<0.0s | 17.8 it/s 02:24:53 - INFO - #################### 100% | 0.7s<--:-- | 17.9 it/s 02:24:53 - INFO - FINISHED -> TRANSIENT (total steps: 13, successful: 13, runtime: 739.70 ms)
Running DFN (co-simulation)... 02:24:54 - INFO - LOGGING (log: True) 02:24:54 - INFO - BLOCKS (total: 4, dynamic: 0, static: 4, eventful: 1) 02:24:54 - INFO - GRAPH (nodes: 4, edges: 5, alg. depth: 2, loop depth: 0, runtime: 0.059ms) 02:24:54 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s) 02:24:54 - INFO - -------------------- 1% | 0.5s<24.6s | 7.2 it/s 02:24:55 - INFO - ##------------------ 12% | 1.5s<8.0s | 19.7 it/s 02:24:56 - INFO - ####---------------- 20% | 2.2s<7.3s | 19.7 it/s 02:24:57 - INFO - ######-------------- 31% | 3.3s<6.2s | 19.8 it/s 02:24:58 - INFO - ########------------ 40% | 4.1s<6.8s | 15.8 it/s 02:24:59 - INFO - #########----------- 48% | 5.2s<4.7s | 19.5 it/s 02:25:00 - INFO - ############-------- 60% | 6.2s<3.7s | 19.6 it/s 02:25:00 - INFO - ############-------- 61% | 6.3s<3.6s | 19.6 it/s 02:25:01 - INFO - ##############------ 72% | 7.3s<2.5s | 20.0 it/s 02:25:02 - INFO - ################---- 80% | 8.0s<1.8s | 19.8 it/s 02:25:03 - INFO - ##################-- 91% | 9.1s<0.8s | 19.1 it/s 02:25:03 - INFO - #################### 100% | 9.9s<--:-- | 20.1 it/s 02:25:03 - INFO - FINISHED -> TRANSIENT (total steps: 180, successful: 180, runtime: 9857.40 ms)
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.
Running DFN co-sim with external thermal (dt = 30 s)... 02:25:04 - INFO - LOGGING (log: True) 02:25:04 - INFO - BLOCKS (total: 5, dynamic: 1, static: 4, eventful: 1) 02:25:04 - INFO - GRAPH (nodes: 5, edges: 7, alg. depth: 2, loop depth: 0, runtime: 0.113ms) 02:25:04 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s) 02:25:04 - INFO - -------------------- 1% | 0.2s<9.7s | 6.1 it/s 02:25:04 - INFO - ####---------------- 20% | 0.4s<1.1s | 42.6 it/s 02:25:05 - INFO - ########------------ 40% | 0.7s<0.8s | 43.8 it/s 02:25:05 - INFO - ############-------- 61% | 1.1s<0.5s | 42.0 it/s 02:25:05 - INFO - ################---- 80% | 1.4s<0.3s | 42.5 it/s 02:25:06 - INFO - #################### 100% | 1.7s<--:-- | 42.7 it/s 02:25:06 - INFO - FINISHED -> TRANSIENT (total steps: 60, successful: 60, runtime: 1671.95 ms) Running DFN co-sim with external thermal (dt = 5 s)... 02:25:06 - INFO - LOGGING (log: True) 02:25:06 - INFO - BLOCKS (total: 5, dynamic: 1, static: 4, eventful: 1) 02:25:06 - INFO - GRAPH (nodes: 5, edges: 7, alg. depth: 2, loop depth: 0, runtime: 0.119ms) 02:25:06 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s) 02:25:06 - INFO - -------------------- 1% | 0.2s<11.6s | 30.8 it/s 02:25:07 - INFO - ##------------------ 13% | 1.3s<7.2s | 43.4 it/s 02:25:08 - INFO - ####---------------- 20% | 1.8s<6.6s | 43.3 it/s 02:25:09 - INFO - ######-------------- 32% | 2.8s<5.6s | 43.7 it/s 02:25:10 - INFO - ########------------ 40% | 3.5s<4.9s | 43.8 it/s 02:25:11 - INFO - ##########---------- 52% | 4.5s<3.9s | 43.7 it/s 02:25:11 - INFO - ############-------- 60% | 5.1s<3.3s | 43.4 it/s 02:25:12 - INFO - ##############------ 72% | 6.2s<2.3s | 43.9 it/s 02:25:13 - INFO - ################---- 80% | 6.8s<1.6s | 43.7 it/s 02:25:14 - INFO - ##################-- 92% | 7.8s<0.6s | 43.7 it/s 02:25:14 - INFO - #################### 100% | 8.4s<--:-- | 43.6 it/s 02:25:14 - INFO - FINISHED -> TRANSIENT (total steps: 360, successful: 360, runtime: 8429.14 ms)
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
dtreduces ZOH error at the cost of more PyBaMMstep()calls. - The external thermal loop extends naturally to multi-cell pack models.