Skip to content

[Bug]: Total lithium in electrolyte [mol] multiplies by the full-cell length L_x in half-cell models #5746

Description

@repowazdogz-droid

PyBaMM Version

main at 258fdc8 (2026-09-05); same code on v26.4.1 (d9e5afb)

Python Version

3.12.13

Describe the bug

Split out from #5700 at @NicolaCourtier's suggestion.

Total lithium in electrolyte [mol] is defined as

L_x = self.param.L_x
A = self.param.A_cc
eps_c_e_av = pybamm.yz_average(pybamm.x_average(eps_c_e))
variables = {"Total lithium in electrolyte [mol]": L_x * A * eps_c_e_av}

(base_electrolyte_diffusion.py, lines 130-135), and L_x = n.L + s.L + p.L unconditionally (geometric_parameters.py, line 34). With {"working electrode": "positive"} the electrolyte lives on whole_cell_domains = ["separator", "positive electrode"], and x_average averages over that domain, but the multiplier is still the three-layer length. In Xu2019 the average is over L_s + L_p = 67 µm and the multiplier is L_n + L_s + L_p = 767 µm, so the electrolyte lithium is overstated by a factor 11.4478.

Effect (Xu2019 half-cell, DFN({"working electrode": "positive"})):

  • At t = 0 the electrolyte concentration is uniform, so the electrolyte lithium is exactly A * c_e0 * (eps_s * L_s + eps_p * L_p) = 3.642e-6 mol. The variable reports 4.170e-5 mol.
  • Total lithium [mol] = Total lithium in particles [mol] + Total lithium in electrolyte [mol], so it reports 1.356e-4 mol at t = 0 against 9.754e-5 mol from a direct sum (39 % high). Total lithium in particles [mol] is unaffected; a direct sum matches it with coefficient 1.
  • Because only the electrolyte term carries the factor, any time variation in Total lithium [mol] that comes from the electrolyte is also scaled by 11.45× relative to the particle term.
  • Variables derived from Total lithium [mol], such as Total lithium lost [mol] and Loss of lithium inventory, including electrolyte [%], presumably inherit the factor. I have not checked them individually.

Two reasonable resolutions, and the current state is neither:

  1. Multiply by the length of whole_cell_domains rather than L_x (or compute the electrolyte total as an integral over x rather than length × average, which removes the dependence on L_x altogether).
  2. Document Total lithium in electrolyte [mol] and Total lithium [mol] as full-cell-only and leave them undefined in half-cell models.

Steps to Reproduce

Run against main 258fdc8; the output is under "Relevant log output".

import pybamm

model = pybamm.lithium_ion.DFN({"working electrode": "positive"})
pv = pybamm.ParameterValues("Xu2019")
sim = pybamm.Simulation(model, parameter_values=pv)
sol = sim.solve([0, 1])

A = pv["Electrode width [m]"] * pv["Electrode height [m]"] * pv["Number of electrodes connected in parallel to make a cell"]
c0 = pv["Initial concentration in electrolyte [mol.m-3]"]
expected = A * c0 * (pv["Separator porosity"] * pv["Separator thickness [m]"]
                     + pv["Positive electrode porosity"] * pv["Positive electrode thickness [m]"])
reported = sol["Total lithium in electrolyte [mol]"].entries[0]
L_x = pv["Negative electrode thickness [m]"] + pv["Separator thickness [m]"] + pv["Positive electrode thickness [m]"]
L_e = pv["Separator thickness [m]"] + pv["Positive electrode thickness [m]"]
print(f"reported at t=0 : {reported:.6e} mol")
print(f"direct sum      : {expected:.6e} mol")
print(f"ratio           : {reported / expected:.6f}   (L_x / (L_s + L_p) = {L_x / L_e:.6f})")

Relevant log output

reported at t=0 : 4.169742e-05 mol
direct sum      : 3.642408e-06 mol
ratio           : 11.447761   (L_x / (L_s + L_p) = 11.447761)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions