Skip to content

Fix SUPG with an explicit coordinate-dependent b, a constant tau, and a quotient tau - #92

Open
xtalax-droid wants to merge 3 commits into
masterfrom
supg-fixes
Open

xtalax-droid wants to merge 3 commits into
masterfrom
supg-fixes

Conversation

@xtalax-droid

Copy link
Copy Markdown
Collaborator

Problem

Three test_space = SUPG(...) forms failed on a plain advection–diffusion system on a quadrilateral grid, while Galerkin worked on the same system:

  • An explicit b that names the coordinates (SUPG(0.05; b = [1 + y, x])) raised UndefVarError: y, because the PDESystem's coordinates were never mapped onto the kernel coordinate slots.
  • A quotient τ with a coordinate-dependent velocity read from the equation ((hK, b) -> hK / (2 * sqrt(b[1]^2 + b[2]^2))) raised "needs the Hessian slots or the element size", because the expand-based linearity check cannot cancel the quotient.
  • A constant τ (SUPG(0.05)) with constant b raised the same error, because the check leaves floating-point residue (about 1.7e-18).

Fix

  • compile_coeffs also accepts a term as linear when an arithmetic-only walk finds it vanishes with the trial slots zeroed and with the test slots zeroed. Together with the existing check that the coefficients are free of the slots, this implies the term is c·trial·w.
  • The front end rewrites τ and b onto the coordinate and time slots before building the weak form (_slotted).

Tests

A new testset in test/shared/frontend_tests/supg.jl compares operators(...).M and .K on an 8x8 quadrilateral grid against a Ferrite element assembly of the SUPG operator. It covers Galerkin and six SUPG forms (constant or quotient τ, with constant, equation-read, or explicit coordinate-dependent b). The three failing cases error before the fix and pass after. The Assembly, WeakForm, Kernels, Interface, Integration and Frontend test groups pass locally.

Codex review: approve, no findings.

Review notes

  • The linearity condition in compile_coeffs now applies to every non-nonlinear kind, not only sources. Soundness relies on the later coefficient-dependence check and on the walk being restricted to +, *, / of the slots.
  • _slotted wraps a function τ in a closure; code that calls test_weight directly with the original SUPG would still see unsubstituted coordinates.

🤖 Posted by an AI agent · harness: Claude Code 2.1.322 · model: claude-sonnet-5-5
Review: unreviewed
Session: 43e03fde-3384-4386-bae9-03e81f19ba7c

t and others added 3 commits November 12, 2026 21:56
compile_coeffs decided linearity by expand(ex - linear) == 0, which leaves floating-point residue for a constant tau (0.05 * 0.25 against its derivative) and cannot cancel a quotient tau such as hK / (2|b|) with coordinate-dependent b. Both fell through to the per-shape-function kernel, which rejects the Hessian slots and hK. The test now also accepts a term whose arithmetic-only expression vanishes when the trial slots, or the test slots, are zeroed, which together with the existing coefficient check implies it is c * trial * w.

Agent-Harness: Claude Code 2.1.322
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
SUPG(tau; b = [1 + y, x]) kept the PDESystem's independent variables, which the kernels cannot evaluate (UndefVarError on y). The front end now rewrites tau and b onto the coordinate and time slots before the weak form is built; a b read from the equation is already in slots.

Agent-Harness: Claude Code 2.1.322
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
Seven advection-diffusion discretizations on an 8x8 quadrilateral grid (Galerkin, and SUPG with constant or quotient tau, constant, equation-read and explicit coordinate-dependent b) are compared with a Ferrite element loop.

Agent-Harness: Claude Code 2.1.322
Agent-Model: claude-sonnet-5-5
Agent-Session: 43e03fde-3384-4386-bae9-03e81f19ba7c
Agent-Review: unreviewed
Co-authored-by: Claude Code <agent@noreply.juliahub.com>
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Results (Julia v1)

Time benchmarks
master 66da879... master / 66da879...
construction/heat P1 10x10 9.72 ± 1.5 ms 9.8 ± 1 ms 0.992 ± 0.19
construction/heat P1 20x20 12.3 ± 1.3 ms 12.6 ± 1 ms 0.979 ± 0.13
time_to_load 5.83 ± 0.041 s 5.82 ± 0.017 s 1 ± 0.0076
Memory benchmarks
master 66da879... master / 66da879...
construction/heat P1 10x10 0.0396 M allocs: 2.12 MB 0.0396 M allocs: 2.12 MB 1
construction/heat P1 20x20 0.0704 M allocs: 4.74 MB 0.0704 M allocs: 4.74 MB 1
time_to_load 0.2 k allocs: 11.8 kB 0.2 k allocs: 11.8 kB 1

@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #92

Reviewed head: 66da879
Raw SHA-256: d36bd5118600a2c7f346986315b88f4232a4c3d58fcc99fb7966d67c4a3dbe8b
Source SHA-256: fd046606f07efbbb2a2333b92e9fa9b4e575a6e056d475341b888ed3487f883e
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1d1f6-48f3-7171-96b1-f28f75011393
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes

Risk assessment

  • Risk: medium (M2)
  • Verdict: CHANGES
  • Reviewed head: 66da879

Review report

VERDICT: CHANGES
Round: 1
Head: 66da879
Slot: 1
CI: CI is not green
Session: 01a1d1f6-48f3-7171-96b1-f28f75011393

Risk

medium (M2: coordinate substitution changes numerical coefficients on an already-working SUPG path; confirmed regression)

Blocking findings

  • [P2] Protect the τ function's argument symbols from coordinate substitution — src/frontend.jl:158. The wrapper substitutes user coordinates into the result of space.τ(hK, b), including the supplied cell-size argument. A spatial coordinate declared with @variables hK equals TestSlots(1).hK, so to_slots rewrites the cell-size symbol to the physical coordinate slot. Consequently, SUPG((h,b) -> h/2) evaluates τ as X₁/2 instead of half the cell diameter. This silently changes both assembled operators.

    Confirmed by running: on four uniform Line cells over [0,1], assemble u_t = 0.01u_rr - u_r, with zero Dirichlet and initial data. Merely renaming r from z to hK produces norm(ΔM) = 0.32542706982944386 and norm(ΔK) = 3.335416016031582 at this head. For example, M[1,1] changes from approximately 0.0208333333333333 to 0.0625. The identical probe on base 42bbb1cd404c0cdb303d92258c4b7b6480ec687e gives zero discrepancies and passes all four assertions; the head passes two and fails two. Constant τ = 0.05 is an exact-match control on both revisions. See scratch/slot_collision.jl and its head/base logs.

    Suggested fix: protect the supplied hK and already-slotted b arguments with fresh symbols during coordinate substitution, and retain a coordinate-renaming regression test.

  • Verdict: CHANGES

  • Round: 1

  • Blocking priorities: P2

  • Deferred P2 issues: none

Non-blocking findings

None.

What I ran

AI reviewer: codex-cli 0.164.0, model gpt-6.1-sol; local session identified above, with no session URL available. Reviewed the code diff without reading PR metadata, author ratings, or other reviews. No root AGENTS.md or CLAUDE.md exists in this checkout.

Set the requested TMPDIR before commands and preserved JULIA_DEPOT_PATH. Used scratch snapshots, leaving the checkout clean. julia --version reported 1.13.2. No committed Julia manifest or interpreter pin exists; instantiated once and reused the resolved dependency manifests for head/base comparisons. Principal versions: Ferrite 1.7.0, PDEBase 0.1.41, Symbolics 7.48.0, ModelingToolkit 11.46.1.

  • GROUP=Frontend julia --project=../scratch/head -e 'using Pkg; Pkg.instantiate(); Pkg.test(; allow_reresolve=false)': exit 0; 803 passing assertions across 22 files, including Frontend/supg.jl 50/50 (scratch/frontend.log).
  • julia --compiled-modules=existing --project=../scratch/testenv ../scratch/affected.jl: exit 0; all files in Kernels, Assembly, Integration, and WeakForm, isolated in fresh modules; 962/962 pass, including 3D convergence (scratch/affected.log).
  • Head's SUPG test against the base package, using the same dependency versions: exit 1; the new seven-case reference test reports 9 passes, 8 errors. Explicit coordinate b raises UndefVarError: y; three other cases raise coefficient-form errors (scratch/before.log). These intended regressions pass at the head.
  • julia --compiled-modules=existing --project=../scratch/head ../scratch/probes.jl: 75/75 pass. Covers independent 1D assembly for coordinate τ expressions/closures, explicit b, steady/time-last systems, time-dependence rejection, and nonlinear/affine compiler guards. Maximum stiffness discrepancy against the independent assembly: approximately 1.28e-15.
  • singular_probe.jl under the same head environment: 4/4 pass for nonlinear rational integrands whose denominators vanish at the zero substitution point.
  • slot_collision.jl under ../scratch/head and then ../scratch/baseenv, with OPENBLAS_NUM_THREADS=1: head 2 pass / 2 fail; base 4/4 pass, as detailed above.
  • Runic --check and typos on all three changed files, plus git diff --check origin/master...HEAD: exit 0.
  • uv run --locked python --version: Python 3.15.0, with warning that --locked has no effect outside a project. This Julia repository has neither pyproject.toml nor uv.lock; no locked Python interpreter was available to verify.

What I did not verify

CI failure causes or green CI, other Julia/dependency versions, QA, documentation builds, or unlisted test groups. All commands I started have exited; no fixes, checkout edits, commits, pushes, or GitHub posts were made.

AUTHOR_GRADE: {"task":"bugfix","score":3,"difficulty":3,"rounds":1,"author_harness":"Claude Code 2.1.322","author_model":"claude-sonnet-5-5","note":"The intended SUPG regressions are reproduced on base and fixed at head; 1765 repository assertions pass. A targeted coordinate-renaming probe nevertheless confirms a new silent hK symbol-collision regression: two matrix comparisons fail at head and pass on base."}

Head link: 66da879


🤖 Posted by an AI agent — harness: codex-cli 0.164.0 · model: gpt-6.1-sol
Conversation: local session 01a1d1f6-48f3-7171-96b1-f28f75011393 (no session URL)

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