Skip to content

fix: sum the electrochemical heat sources over every particle phase - #5770

Merged
BradyPlanden merged 1 commit into
mainfrom
fix/composite-phase-heat-sources
Sep 22, 2026
Merged

BradyPlanden merged 1 commit into
mainfrom
fix/composite-phase-heat-sources

Conversation

@BradyPlanden

@BradyPlanden BradyPlanden commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Description

BaseThermal._get_standard_coupled_variables builds the irreversible, reversible and hysteresis heat sources by zipping the phase names against the "open-circuit potential" option. That option stays a plain string when it is left at its default, so [ocp_options] had length one and

zip(["primary ", "secondary "], ["single"], strict=False)

silently truncated the loop after the primary phase. On a composite electrode the secondary phase contributed no Q_rxn, Q_rev or Q_hys at all.

A Chen2020 graphite electrode split into two identical half-volume-fraction phases — physically the same electrode — reported 13657 W.m-3 of volume-averaged irreversible heating against the 24371 W.m-3 of the equivalent single-phase electrode, and its lumped cell temperature ran 2 K cold over 1200 s. Declaring the option once per phase, as (("single", "single"), "single"), was a workaround and gave the right answer, which is what isolated the cause.

The bug dates to #4893. Found while reviewing #5769, which fixes the same class of omission in the heat of mixing — that PR is correct as it stands and needs nothing from this one.

Fixes # (issue)

Type of change

Add an entry under # [Unreleased] in CHANGELOG.md, in one of ## Breaking changes, ## Deprecated, ## Features, or ## Bug fixes (include PR number; breaking and deprecation entries need a one-line migration note). Internal-only PRs — refactor, docs, CI, tests — can skip this. See RELEASE.md for the full policy.

Important checks:

Please confirm the following before marking the PR as ready for review:

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • The documentation builds: nox -s doctests
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

`BaseThermal._get_standard_coupled_variables` builds `Q_rxn`, `Q_rev` and
`Q_hys` by zipping the phase names against the `"open-circuit potential"`
option. That option stays a plain string when it is left at its default, so
`[ocp_options]` had length one and

    zip(["primary ", "secondary "], ["single"], strict=False)

silently truncated the loop after the primary phase. On a composite electrode
the secondary phase contributed no irreversible, reversible or hysteresis heat
at all.

A Chen2020 graphite electrode split into two identical half-volume-fraction
phases reported 13657 W.m-3 of volume-averaged irreversible heating against the
24371 W.m-3 of the equivalent single-phase electrode, and its lumped cell
temperature ran 2 K cold over 1200 s. Passing the option once per phase, as
`(("single", "single"), "single")`, was a workaround and gave the right answer.

Padding a scalar option out to the phase count is the whole fix; the zips stay
non-strict, so the one remaining length mismatch — two open-circuit potential
options declared against a single particle phase, which the options validator
accepts today — keeps being ignored rather than raising from inside the thermal
submodel.

The bug dates to #4893. Found while reviewing #5769, which fixes the same class
of omission in the heat of mixing.
@BradyPlanden
BradyPlanden requested a review from a team as a code owner September 22, 2026 09:35
@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.15%. Comparing base (e490757) to head (83bf4e4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5770      +/-   ##
==========================================
- Coverage   98.15%   98.15%   -0.01%     
==========================================
  Files         341      341              
  Lines       33787    33787              
==========================================
- Hits        33165    33164       -1     
- Misses        622      623       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BradyPlanden
BradyPlanden merged commit 79fe1ef into main Sep 22, 2026
40 checks passed
@BradyPlanden
BradyPlanden deleted the fix/composite-phase-heat-sources branch September 22, 2026 10:21
mleot added a commit to mleot/PyBaMM that referenced this pull request Sep 25, 2026
The composite heat-of-mixing tests only built the model. Extend the
graphite/graphite heat-source comparison from pybamm-team#5770 so that splitting one
graphite phase into two identical halves must also reproduce the one-phase
"Volume-averaged heat of mixing [W.m-3]":

- run it with "heat of mixing": "true", for isothermal (heat source only)
  and lumped thermal models, comparing the temperature rise for the latter
- give Chen2020 the Ai2020 entropic changes; with zero dU/dT the reversible
  heat and the temperature dependence of U inside the heat of mixing were
  compared as zero against zero
- solve at rtol 1e-6: at the default rtol the ~300 K temperature state
  drifts by ~0.03 K, which is 1% of the rise and failed SPM + lumped

A heat of mixing that sums only the primary phase fails all four cases.

Add a Si/graphite smoke test (Chen2020_composite, lumped) checking the heat
of mixing stays positive and heats the cell. It supplies the per-layer
"Negative electrode density [kg.m-3]" the set lacks and swaps the cubic
Interpolant graphite OCP for the analytic Chen2020 fit, whose derivative
the solver can convert.

Also look up the electrode and phase parameters through
param.domain_params and options.phases instead of getattr.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants