Skip to content

Name the minimum grid size when a boundary stencil does not fit - #714

Merged
xtalax merged 3 commits into
SciML:masterfrom
xtalax:stencil-length-error
Oct 19, 2026
Merged

xtalax merged 3 commits into
SciML:masterfrom
xtalax:stencil-length-error

Conversation

@xtalax

@xtalax xtalax commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

A non-periodic axis needs at least derivative order + approx_order points to hold the one-sided boundary stencils. A shorter axis made discretization fail with a BoundsError from whichever stencil first indexed past the end. For example, heat at approx_order = 4 on 5 points failed in boundary_value_maps. Failing is the expected outcome; this PR makes the failure an ArgumentError that says what is needed:

ArgumentError: Differential(t, 1)(u(t, x)) - Differential(x, 2)(u(t, x)) ~ 0 has an order 2 derivative in x.
At approx_order = 4 its one-sided boundary stencil needs at least 6 grid points in x, but there are 5.
Use a finer grid in x or a lower approx_order.

Change

validate_boundary_stencil_length runs once per PDE in construct_var_equation_mapping, next to the existing "domain is too small" check. For each axis of the PDE's variable it:

  • skips the axis when the PDE has no derivative in that direction, or when both ends are periodic or interfaces;
  • otherwise requires n ≥ d + approx_order, where d is the PDE's highest derivative order in that direction.

d + approx_order is the boundary_stencil_length of CompleteCenteredDifference. MethodOfLines builds the centered boundary maps for every derivative order at each boundary, even when that order is upwinded in the interior, so the bound applies to odd orders too.

Verification

I ran a battery of 124 small-grid systems on master and on this branch:

  • 1D heat with Dirichlet, 1D heat with Neumann, upwind advection, a two-variable system where one variable has no boundary conditions, and 1D periodic heat, each at approx_order 2, 4 and 6 with 1 to 8 cells;
  • 2D heat at approx_order 4 with 3 to 6 cells.
Outcome on master This branch Count
discretizes discretizes 68
BoundsError the new ArgumentError 38
BoundsError BoundsError 9
"domain is too small" error unchanged 9

No system that discretizes on master is rejected. The 9 remaining BoundsErrors have two causes:

  • Six are a different bug, now fixed on master by Skip zero-extent BC extrapolation on small grids #708. The extrapolation stencil was evaluated on axes too short for it. I checked all six on current master (53855c9), and each one now discretizes.
  • Three are degenerate periodic grids, with 2 or 3 points at approx_order 4 or 6, where the interior stencil wraps around the period more than once. They are not covered here.

Test: Components, interiormap_test.jl, "Test 02". Heat at approx_order = 4 throws the ArgumentError, naming 6 needed points against 5, on 4 cells. It discretizes on 5 cells, and a periodic axis with 2 cells is not rejected.

Test runs

Local runs on this branch (Julia 1.12.6, GROUP=<g> julia --project -e 'using Pkg; Pkg.test()'): 10 groups exit 0 — Components (including the new testset), Discretization, Higher_Order, Wave_Eq_Staggered, Complex, Complex_Indexing, Diffusion_NU, Nonlinlap_ADV, Sol_Interface and MOL_Interface2. No test hit the new error. I stopped the local run there; CI covers the remaining groups.

🤖 Posted by an AI agent · harness: Claude Code 2.1.296 · model: claude-opus-5-5
Review: unreviewed
Session: 644ed0ff-c8c9-4cc3-b4c6-f326231a4030

xtalax and others added 3 commits October 13, 2026 16:56
A non-periodic axis shorter than derivative order + approx_order points cannot
hold the one-sided boundary stencils, and discretization failed with a
BoundsError from whichever stencil first indexed past the end. Check it per
PDE in construct_var_equation_mapping and throw an ArgumentError naming the
derivative, approx_order and the number of points needed.

Agent-Harness: Claude Code 2.1.296
Agent-Model: claude-opus-5-5
Agent-Session: 644ed0ff-c8c9-4cc3-b4c6-f326231a4030
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
Agent-Harness: Claude Code 2.1.296
Agent-Model: claude-opus-5-5
Agent-Session: 644ed0ff-c8c9-4cc3-b4c6-f326231a4030
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
PseudospectralDiscretization has no approx_order, so the check threw a
FieldError on every Pseudospectral system. Other discretizations now skip it.

Agent-Harness: Claude Code 2.1.299
Agent-Model: claude-opus-5-5
Agent-Session: 644ed0ff-c8c9-4cc3-b4c6-f326231a4030
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
@xtalax
xtalax merged commit 210279a into SciML:master Oct 19, 2026
88 of 89 checks passed
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.

1 participant