Skip to content

Add BoundaryPiece and NormalDerivative fallbacks for trace syntax - #144

Merged
xtalax merged 4 commits into
SciML:masterfrom
xtalax-droid:forge/boundary-2-fallbacks
Oct 28, 2026
Merged

xtalax merged 4 commits into
SciML:masterfrom
xtalax-droid:forge/boundary-2-fallbacks

Conversation

@xtalax-droid

@xtalax-droid xtalax-droid commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

The FiniteElementMethod.jl design (PDEBase as the shared boundary layer) writes boundary conditions as traces u(t, Γ) on named boundary pieces, and normal-derivative conditions as NormalDerivative(Γ)(u(t, Γ)). Both names are proposed upstream: NormalDerivative in JuliaSymbolics/Symbolics.jl#2115, and BoundaryPiece/boundarypiece/boundarypieces in a pending DomainSets proposal. This PR adds src/fallbacks.jl, which defines each name only when the installed upstream package lacks it (@static if !isdefined(...)). Once upstream releases, PDEBase imports and re-exports the upstream name, and the fallback disappears.

Added (all exported)

  • NormalDerivative{D <: Domain} <: SymbolicUtils.Operator, with the same semantics as Symbolics#2115: it builds a term whose operation is the operator and whose single argument is the trace, preserving symtype and shape. It has Num and Arr call methods, isbinop = false, equality and hashing by piece, and prints as Dn_wall(u(t, Γ_wall)). There is no custom Substituter; the generic one handles it.
  • BoundaryPiece{T, P, G} <: DomainSets.Domain{T} with fields parent, name and geometry (an analytic sub-domain or nothing). parent(p) returns the parent domain, it prints as Γ_<name>, and it compares and hashes structurally, so separately built identical pieces give equal traces.
  • boundarypieces(::HyperRectangle) names the faces in DomainSets' components(boundary(d)) order: :bottom, :right, :top, :left for a rectangle, and :x1_lo, :x1_hi, :x2_lo, … (lower then upper per axis) in other dimensions. boundarypiece(d, name) looks a piece up by name and errors with the list of valid names.

Known gaps of the fallback (gone once Symbolics#2115 is released)

Two behaviours of Symbolics#2115 depend on changes inside Symbolics with no dispatch hook: executediff treats every Operator application as constant, and symdiff_substitute_filter admits only Differential. A downstream package cannot reproduce them without overwriting Symbolics methods, which is piracy and is rejected during precompilation. Under the fallback, therefore:

  • expand_derivatives(Differential(t)(Dn(u(t, Γ)))) returns 0 instead of staying unevaluated;
  • Symbolics.substitute_in_deriv does not descend into Dn(...).

Both are documented in the NormalDerivative docstring. Their tests are written as @test ... broken = !UPSTREAM_DN, so they become ordinary tests automatically when upstream is present. Later PRs in this series add the mitigations: a substitute_traces that descends into Differential and NormalDerivative, and an assertion that no trace remains before any derivative expansion. Boundary equations holding traces are never derivative-expanded.

Tests (test/boundary_syntax.jl)

  • A port of Symbolics#2115's "NormalDerivative" testset: construction, printing and recovery (including Arr), equality and hashing, expand_derivatives leaving Dn(u(t, Γ)) untouched, mismatched pieces not being an error at this level, and substitution.
  • A gating check that PDEBase.NormalDerivative and PDEBase.BoundaryPiece resolve to the upstream type when upstream defines it, and to PDEBase's own otherwise.
  • BoundaryPiece construction, show, equality and hashing; rectangle and 3D-box faces, whose geometry equals DomainSets' faces; the bad-name error; trace syntax inside a PDESystem.

QA is configured to accept the four names as intentional re-exports for the day upstream defines them, and to accept qualified access to DomainSets.HyperRectangle, because DomainSets declares nothing public. Core and QA groups pass locally.

BoundaryPiece defines isless as a lexicographic comparison of (name, hash(parent), hash(geometry)), a strict weak order consistent with isequal, so Symbolics can order sums of traces such as u(t, Γa) - u(t, Γb). Known limitation: pieces with empty-interval geometries (2..1 vs 3..1) are isequal but hash differently in IntervalSets, so they can order inconsistently.

Follow-up commits 1fc8917 and 8a3372d were reviewed by an independent Claude Opus subagent (Codex workspace out of credits) and then by Codex (8a3372d approved, 1 minor, the limitation above).


🤖 Posted by an AI agent · harness: Claude Code 2.1.310 · model: claude-opus-5-5
Review: unreviewed
Session: e5d08c60-db9f-4954-946c-272b70ca9edb

The FiniteElementMethod boundary layer writes conditions as traces u(t, Γ) on named boundary pieces and as NormalDerivative(Γ)(u(t, Γ)). Both names are proposed upstream (JuliaSymbolics/Symbolics.jl#2115 and a DomainSets proposal); PDEBase defines each only while the installed package lacks it, so the fallback disappears when upstream releases. boundarypieces names the faces of a HyperRectangle in DomainSets' boundary order.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: e5d08c60-db9f-4954-946c-272b70ca9edb
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
xtalax and others added 2 commits October 26, 2026 16:20
SymbolicUtils orders the terms of a sum by comparing same-typed constant arguments with <, so u(t, Γa) + u(t, Γb) threw a MethodError for isless(::BoundaryPiece, ::BoundaryPiece). Order pieces by name, then by printed parent and geometry, consistently with isequal.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: e5d08c60-db9f-4954-946c-272b70ca9edb
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
The printed-key order with an isequal shortcut was not a strict weak order: Rectangle(0..1, 0..1) and Rectangle(0.0..1.0, 0.0..1.0) are isequal but print differently, so a third piece could sort between them. Compare (name, hash(parent), hash(geometry)) instead, which is lexicographic, consistent with isequal through hash, and needs no repr.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: e5d08c60-db9f-4954-946c-272b70ca9edb
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
xtalax-droid pushed a commit to xtalax-droid/PDEBase.jl that referenced this pull request Oct 26, 2026
Default printing showed the whole backend mesh, and SciML#144 orders boundary pieces by repr(parent) when names tie, so sorting traces printed entire meshes. MeshDomain now prints as MeshDomain{MeshType}(2D) and Region as Region(MeshDomain{MeshType}(2D), :name), for both show and text/plain.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: e5d08c60-db9f-4954-946c-272b70ca9edb
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
xtalax-droid pushed a commit to xtalax-droid/PDEBase.jl that referenced this pull request Oct 27, 2026
Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: a20a681b-e8cc-4c82-a40d-a5b8349014e2
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
xtalax-droid pushed a commit to xtalax-droid/PDEBase.jl that referenced this pull request Oct 27, 2026
Default printing showed the whole backend mesh, and SciML#144 orders boundary pieces by repr(parent) when names tie, so sorting traces printed entire meshes. MeshDomain now prints as MeshDomain{MeshType}(2D) and Region as Region(MeshDomain{MeshType}(2D), :name), for both show and text/plain.

Agent-Harness: Claude Code 2.1.310
Agent-Model: claude-opus-5-5
Agent-Session: e5d08c60-db9f-4954-946c-272b70ca9edb
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
SymbolicUtils at its lowest compat orders mixed-type sum arguments by typeof(a) < typeof(b), and Base has no isless for two types, so u(t, Γa) + u(t, 0.5) + u(t, Γb) threw a MethodError. Add isless methods on types with BoundaryPiece in the signature: every other type sorts before a piece type.

Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: a20a681b-e8cc-4c82-a40d-a5b8349014e2
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
@xtalax
xtalax merged commit fefd4d3 into SciML:master Oct 28, 2026
27 checks passed
xtalax-droid pushed a commit to xtalax-droid/PDEBase.jl that referenced this pull request Oct 28, 2026
Integration only: master now contains SciML#141, SciML#142, SciML#143, SciML#144 and SciML#160.

Agent-Harness: Claude Code 2.1.312
Agent-Model: claude-sonnet-5-5
Agent-Session: a20a681b-e8cc-4c82-a40d-a5b8349014e2
Agent-Review: unreviewed
Co-authored-by: Claude Code <[email protected]>
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