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.16/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)... 12:03:34 - INFO - LOGGING (log: True) 12:03:34 - INFO - BLOCKS (total: 4, dynamic: 1, static: 3, eventful: 0) 12:03:34 - INFO - GRAPH (nodes: 4, edges: 5, alg. depth: 2, loop depth: 0, runtime: 0.056ms) 12:03:34 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s) 12:03:34 - INFO - -------------------- 1% | 0.1s<9.3s | 19.8 it/s 12:03:34 - INFO - ####---------------- 20% | 0.4s<1.2s | 19.3 it/s 12:03:34 - INFO - ###########--------- 56% | 0.6s<0.3s | 15.9 it/s 12:03:34 - INFO - #################--- 88% | 0.7s<0.1s | 14.7 it/s 12:03:35 - INFO - #################### 100% | 0.8s<--:-- | 14.1 it/s 12:03:35 - INFO - FINISHED -> TRANSIENT (total steps: 13, successful: 13, runtime: 770.48 ms)
Running DFN (co-simulation)... 12:03:35 - INFO - LOGGING (log: True) 12:03:35 - INFO - BLOCKS (total: 4, dynamic: 0, static: 4, eventful: 1) 12:03:35 - INFO - GRAPH (nodes: 4, edges: 5, alg. depth: 2, loop depth: 0, runtime: 0.045ms) 12:03:35 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s) 12:03:36 - INFO - -------------------- 1% | 0.7s<30.2s | 5.9 it/s 12:03:37 - INFO - ##------------------ 10% | 1.7s<10.2s | 15.8 it/s 12:03:38 - INFO - ###----------------- 18% | 2.8s<9.6s | 15.3 it/s 12:03:38 - INFO - ####---------------- 20% | 3.0s<9.4s | 15.4 it/s 12:03:39 - INFO - ######-------------- 31% | 4.0s<4.7s | 26.1 it/s 12:03:40 - INFO - ########------------ 40% | 4.6s<4.4s | 24.5 it/s 12:03:41 - INFO - ##########---------- 54% | 5.6s<3.2s | 25.8 it/s 12:03:41 - INFO - ############-------- 60% | 6.0s<2.8s | 25.7 it/s 12:03:42 - INFO - ###############----- 75% | 7.1s<1.7s | 25.8 it/s 12:03:43 - INFO - ################---- 80% | 7.4s<1.4s | 25.8 it/s 12:03:44 - INFO - ##################-- 94% | 8.4s<0.4s | 25.8 it/s 12:03:44 - INFO - #################### 100% | 8.8s<--:-- | 25.8 it/s 12:03:44 - INFO - FINISHED -> TRANSIENT (total steps: 180, successful: 180, runtime: 8785.06 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)... 12:03:44 - INFO - LOGGING (log: True) 12:03:44 - INFO - BLOCKS (total: 5, dynamic: 1, static: 4, eventful: 1) 12:03:44 - INFO - GRAPH (nodes: 5, edges: 7, alg. depth: 2, loop depth: 0, runtime: 0.091ms) 12:03:44 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s) 12:03:45 - INFO - -------------------- 1% | 0.1s<8.1s | 7.3 it/s 12:03:45 - INFO - ####---------------- 20% | 0.3s<0.8s | 57.4 it/s 12:03:45 - INFO - ########------------ 40% | 0.5s<0.6s | 59.6 it/s 12:03:45 - INFO - ############-------- 61% | 0.8s<0.4s | 59.9 it/s 12:03:45 - INFO - ################---- 80% | 0.9s<0.2s | 60.0 it/s 12:03:46 - INFO - #################### 100% | 1.1s<--:-- | 57.8 it/s 12:03:46 - INFO - FINISHED -> TRANSIENT (total steps: 60, successful: 60, runtime: 1140.35 ms) Running DFN co-sim with external thermal (dt = 5 s)... 12:03:46 - INFO - LOGGING (log: True) 12:03:46 - INFO - BLOCKS (total: 5, dynamic: 1, static: 4, eventful: 1) 12:03:46 - INFO - GRAPH (nodes: 5, edges: 7, alg. depth: 2, loop depth: 0, runtime: 0.092ms) 12:03:46 - INFO - STARTING -> TRANSIENT (Duration: 1800.00s) 12:03:46 - INFO - -------------------- 1% | 0.2s<8.6s | 41.5 it/s 12:03:47 - INFO - ###----------------- 17% | 1.2s<4.9s | 59.9 it/s 12:03:47 - INFO - ####---------------- 20% | 1.3s<4.8s | 59.6 it/s 12:03:48 - INFO - #######------------- 36% | 2.3s<3.8s | 60.8 it/s 12:03:48 - INFO - ########------------ 40% | 2.5s<3.6s | 59.8 it/s 12:03:49 - INFO - ###########--------- 56% | 3.5s<2.6s | 59.9 it/s 12:03:50 - INFO - ############-------- 60% | 3.8s<2.4s | 58.8 it/s 12:03:51 - INFO - ###############----- 76% | 4.8s<1.4s | 57.5 it/s 12:03:51 - INFO - ################---- 80% | 5.0s<1.2s | 59.1 it/s 12:03:52 - INFO - ###################- 96% | 6.0s<0.2s | 58.1 it/s 12:03:52 - INFO - #################### 100% | 6.2s<--:-- | 59.2 it/s 12:03:52 - INFO - FINISHED -> TRANSIENT (total steps: 360, successful: 360, runtime: 6196.86 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.