Skip to content

Make the storage take exactly the flux law's heat at its wall (F-056) - #51

Merged
brosaplanella merged 1 commit into
mainfrom
fix-storage-boundary-conductivity
Oct 31, 2026
Merged

brosaplanella merged 1 commit into
mainfrom
fix-storage-boundary-conductivity

Conversation

@brosaplanella

Copy link
Copy Markdown
Contributor

Fixes the bumps in the packed-bed fluid temperatures seen in the tutorials: during a charge, the fluid at each height rose, fell by 1.2 K to 2.1 K, then rose again. Model flaw (numerics), logged as F-056; DESIGN D6 updated.

Cause

The storage's heat-flux condition turned the flux law's flux into a gradient with the conductivity at the extrapolated wall enthalpy, k(H_surf). The heat that enters the storage is k grad(T) on the wall face, where PyBaMM extrapolates the node values of k. The two agree when k varies smoothly. The default paraffin melts at a sharp point and its conductivity drops from 0.4 to 0.15 W.m-1.K-1, so while the cells by the wall melted, the capsules took only 19 % to 29 % of the flux law's heat. That sent a pulse of overly warm fluid up the bed.

Energy stayed exactly conserved (the ledger counts the heat that actually crosses), so no test could see it, and the coupling's docstring said the two "differ slightly". D6 had accepted the factor k_face / k_surface as harmless.

It was numerics, not physics: the dips grew as the capsule mesh was refined (0.5 K on 10 cells, 3 K on 160), and vanished with equal solid and liquid conductivities or with a 2 K melting range.

Fix

One line in EnthalpyStorage: the condition divides by pybamm.boundary_value(k), the conductivity k grad(T) uses on the wall face, so exactly the flux law's flux enters.

Before After
Heat the capsules take while their surface melts 19 % to 29 % of the flux law's exactly the flux law's
Largest dip in the fluid temperature (default mesh) 1.2 K to 2.1 K none (0.04 K on 40 cells, 0 from 80)
Nallusamy (2007) fluid RMS at ¼, ½, ¾, full height 1.09, 0.92, 1.63, 2.05 K 0.98, 0.68, 1.41, 1.85 K
Energy conservation exact exact (3e-8 J of 8.3 MJ)
Finned tubes move by at most 0.006 K

Changes

  • src/pytes/submodels/storage.py: the fix, with a comment.
  • src/pytes/submodels/coupling.py: the docstring now says the fluid's heat is the flux times the wall area.
  • Tests in tests/models/test_packed_bed.py (both fail before the fix): the fluid's heat equals the flux law's flux over the capsule surface at every position and time; the default charge heats the fluid monotonically at four heights.
  • tests/data/reference_regression.npz regenerated (finned-tube results move by up to 0.006 K).
  • docs/design/findings.md (F-056) and DESIGN D6.
  • Changelog: 51.breaking.md (packed-bed results change) and 51.fix.md.

Not in this PR

The example notebooks' saved outputs show the old curves, and some of their text quotes numbers that may move (the packed-bed RMS, the lumped capsule's charge time, the design study's delivered fraction). Re-running them is a follow-up after #47 and #48 merge, since the tutorials live there.

Locally: 769 fast tests and the slow test pass, ruff is clean.

🤖 Generated with Claude Code

The storage's heat-flux condition divided the flux law's flux by the
conductivity at the extrapolated wall enthalpy, while the heat entering
it is k grad(T) on the wall face, with k extrapolated from the nodes.
While the PCM by the wall melted, with a sharp melting point and a
conductivity dropping from 0.4 to 0.15 W.m-1.K-1, the packed bed took a
fifth of the flux law's heat, and its fluid temperatures overshot and
fell by 1 K to 2 K during a charge. Energy stayed exactly conserved, so
no test saw it.

The condition now divides by the face conductivity itself. The charge
is monotonic and converges with the capsule mesh, the Nallusamy fit
improves at every height, and the finned tubes move by at most
0.006 K, so the regression reference is regenerated (F-056, DESIGN D6).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@brosaplanella brosaplanella added the bug Something isn't working label Oct 31, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 PyTES | 🛠️ Build #35544255 | 📁 Comparing be89a9d against latest (5757c11)

  🔍 Preview build  

6 files changed · ± 6 modified

± Modified

@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff            @@
##              main       #51   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           47        47           
  Lines         1768      1767    -1     
  Branches       157       157           
=========================================
- Hits          1768      1767    -1     
Files with missing lines Coverage Δ
src/pytes/submodels/coupling.py 100.00% <ø> (ø)
src/pytes/submodels/storage.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brosaplanella
brosaplanella merged commit 3b5acbe into main Oct 31, 2026
19 of 20 checks passed
@brosaplanella
brosaplanella deleted the fix-storage-boundary-conductivity branch October 31, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant