Research / PyBaMM BasicDFN

A battery model gained 2.44% of its lithium over one cycle.

MeasuredFixed upstream
Result
Counted independently, the model gained 2.44% of its lithium over one cycle. The cause was one missing equation term; the fix is released in PyBaMM 26.9.0.0.
Boundary
One library, one model variant, one protocol and one parameter set. The full DFN model conserved lithium.
Who did what
Measured and diagnosed by Warren, who submitted the fix (PR #5747); PyBaMM’s maintainers merged and released it. Nicola Courtier first raised the non-conservation in #5700 and suggested the separate issue.
Public evidence
Observed dataInside the cell, and the lithium count, through one cycle

Interactive figure. Every number it draws is stated in the record below.

Refinement does not move it

Observed dataRefinement does not move it: 21 runs per model

Chart of all 63 completed full-cell runs at the pull-request head; requires JavaScript. The range for the variable-transference model is 2.4407% to 2.4417%; both controls stay below 10⁻¹³.

The question

Does this battery model conserve the lithium it says it conserves?

PyBaMM is an open-source lithium-ion battery modelling library used in research and industry. A model that creates lithium carries a systematic error into any quantitative result built on it, and nothing about the run looks wrong: it completes normally whether or not lithium is conserved.

Reported or claimedEvery run completed normally: three revisions, seven mesh and tolerance settings.
Independent checkCounted independently, the lithium inventory grew by 2.44% over one 80-minute cycle. In a sealed cell it should not change at all.

Measured: A quantity was measured independently, with the instrument itself checked on known answers. Fixed upstream: The maintainers accepted a fix into the project. Who wrote it is stated on each case.

What was tested

  1. Froze three revisions: release v26.4.1 (d9e5afb), main (258fdc8), and the head of then-open pull request #5524 (719763b).
  2. Counted lithium from the mesh, the parameters and the raw concentrations, without using the library’s own totals. A second, loop-based implementation was checked against the first on every run.
  3. Ran 84 jobs: four model cases × three revisions × seven mesh and tolerance settings. A constant-transference model and the full DFN model served as controls.
  4. Checked the counter itself on synthetic arrays with known answers: an altered inventory, a reversed boundary sign, an omitted source and a wrong volume factor were each detected.
  5. Compared the measured rate of drift, instant by instant, with the rate predicted if one term were missing from the electrolyte equation.

What happened

  • With a concentration-dependent transference number, BasicDFN gained 2.44% of its initial lithium on every revision. Refining to 80 × 80 cells and tightening tolerance to 1e-10 moved the result only in the fourth significant figure (2.4417% to 2.4407%).
  • The measured rate matched the rate predicted from the missing transference-gradient term to within 1.2 × 10⁻¹⁷ mol/s in all 21 runs. The equation, not the discretisation, is the cause. A PyBaMM contributor confirmed the missing term on the original thread.
  • Then-open pull request #5524 produced byte-identical time series to main in all 24 run pairs that completed on both.
  • Separately, the half-cell diagnostic “Total lithium in electrolyte” multiplied by the full-cell length (767 µm) where the electrolyte occupies 67 µm, overstating that term by a factor of 11.45.

Challenge

The objections that would most easily undo the conclusion, and what answered each.

Could it be numerical error from the mesh or the time stepping?
No. Refining from 20 × 20 to 80 × 80 cells and from 1e-6 to 1e-10 tolerance changed the drift only in the fourth significant figure.
Could the independent counter be wrong?
It caught every planted error on synthetic arrays, a second implementation agreed with it, and it reported conservation to 10⁻¹⁴ mol on the two control models.
Is there a mechanism, or only a symptom?
The drift rate matched, instant by instant, the rate predicted from one missing equation term.
Does the fix already under review remove it?
No. Pull request #5524 left every compared output byte-identical.

What survived

Did not survive

  • BasicDFN conserves lithium when the transference number depends on concentration.Gained 2.44% per cycle. Fixed in pull request #5747, submitted by Warren and merged 18 September 2026.
  • The half-cell “Total lithium in electrolyte” diagnostic reports moles of lithium.Overstated by a factor of 11.45. Fixed by PyBaMM maintainers in pull request #5765.
  • Pull request #5524 changes the reported cases.Byte-identical output to main on all 24 completed pairs.

Survived

  • The full DFN model conserves lithium under this protocol.Largest deviation 3.5 × 10⁻¹⁴ mol across 21 runs.
  • BasicDFN with a constant transference number conserves lithium.Largest deviation 7.7 × 10⁻¹⁵ mol across 21 runs.
  • The independent counter is sound for the cases it was checked on.Synthetic controls detected each planted error. In the five published time series the two implementations agree to within 8.9 × 10⁻¹⁶ mol.

Not established, or not tested

  • Eleven half-cell runs failed inside the solver at tight tolerance, so no half-cell convergence order is claimed.
  • A contributor’s concern about finite-volume treatment of nonlinear source terms was not investigated. The parent thread, #5700, remains open.

Limits

One library, two model families, one protocol (rest, 1C discharge, rest, 1C charge, rest) and one parameter set (O’Regan 2022). The full DFN model conserved lithium; nothing here is said against it. No physical battery was measured.

Reproduce or inspect

Source
repowazdogz-droid/pybamm-5700-lithium-inventory
Revision
adaa877
Command
PYBAMM_DISABLE_TELEMETRY=true python minimal_reproducer.py --output reviewer-output
Expect
basic_variable: max |R| = 6.518391162e-3 mol, |R|/N(0) = 2.441742013e-2

Requires one of the three PyBaMM revisions importable. Under a minute on a laptop. Every file in the package is listed with its SHA-256 in PACKAGE-SHA256.json. The command is given as the repository documents it; it was not re-run for this page.

Public record

Have a question like this?