Conversation
Boundary extrapolation read the second node spacing in both directions unconditionally, so any 2D mesh with fewer than 3 nodes in either direction raised IndexError. Spacings are now looked up lazily and a DiscretisationError is raised when the mesh is too coarse for the requested extrapolation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…boundary-value # Conflicts: # CHANGELOG.md
Contributor
|
| Project | PyBaMM |
| Branch | fix/fv2d-coarse-mesh-boundary-value |
| Testbed | bare-metal |
🐰 View full continuous benchmarking report in Bencher
⚠️ WARNING: Truncated view!The full continuous benchmarking report exceeds the maximum length allowed on this platform.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5839 +/- ##
=======================================
Coverage 98.09% 98.09%
=======================================
Files 346 346
Lines 35354 35355 +1
=======================================
+ Hits 34680 34681 +1
Misses 674 674 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
FiniteVolume2D.boundary_value_or_fluxread the second and second-last node spacings in both directions (d_nodes_lr[1],d_nodes_lr[-2],d_nodes_tb[1],d_nodes_tb[-2]) before branching on side and extrapolation order. Any 2D submesh with fewer than 3 nodes in either direction therefore raisedIndexError: index 1 is out of bounds for axis 0 with size 1for every boundary operator, including a plainBoundaryValue(var, "right")orBoundaryIntegral(var, "right")that only extrapolates in lr.Reproduce on
main:pybamm.lithium_ion.BasicDFN2D()with itsz_2dvar_pts set to 2, solved viapybamm.Simulation.Spacings are now looked up lazily through a local
node_spacing(direction, index)helper, called only by the branch that uses them. When the mesh has too few nodes for the requested extrapolation, it raises apybamm.DiscretisationErrornaming the order, variable, direction, and required vs. available node count.Meshes with at least 3 nodes in both directions use the same spacings as before, so their results are unchanged.
Not covered here: with
z_2dset to 1, the model gets past boundary extrapolation and then fails inharmonic_mean, which is a separate bug.Type of change
Tests
TestExtrapolationCoarseMesh2Dintests/unit/test_spatial_methods/test_finite_volume_2d/test_extrapolation.py: with 2 tb nodes, linear and quadratic left/right values and the right boundary integral are exact; six too-coarse combinations raiseDiscretisationError. All 8 fail onmain.🤖 Generated with Claude Code