Skip to content

Nitsche free-slip BC: inconsistent Jacobian for anisotropic (transverse-isotropic) constitutive models #239

Closed

Description

@lmoresi

Summary

SNES_Stokes(_SaddlePt).add_nitsche_bc (and the SNES_Vector version) produces a boundary Jacobian that is inconsistent with its residual when the constitutive model is anisotropic (e.g. TransverseIsotropicFlowModel). The residual is correct, so solves still reach the right answer — but Newton degrades to a slow defect-correction (tens of oscillating SNES steps instead of 1–2), because the linearisation it follows is wrong by a few percent. The bulk Jacobian, derive_by_array, and the JIT are all correct; the error is confined to the Nitsche boundary terms for anisotropic stress.

Reproduce

snes_test_jacobian on a minimal TI Stokes (tilted director, η₁ ≠ η₀), varying only the boundary condition / geometry:

configuration ‖J − J_fd‖/‖J‖
box + TI 3e-11 ✓
annulus + Dirichlet + TI 2e-9 ✓
annulus + field-varying viscosity + TI 3e-11 ✓
annulus + penalty free-slip (add_natural_bc) + TI 6.7e-11 ✓
annulus + Nitsche + isotropic 2e-9 ✓
annulus + Nitsche + TI 0.069 (7%) ✗

The failure is precisely the Nitsche × anisotropy intersection. Amat and Pmat are equally wrong, and the ratio is invariant to pressure-nullspace on/off, monolithic-lu vs fieldsplit-Schur — so it is the tangent the BC contributes, not solver configuration.

A self-contained reproducer is scripts/jac_minimal_box.py (on the feature/fault-convection worktree); it sweeps GEOM/BC/VISC/NOWEAK and runs snes_test_jacobian. Happy to upstream a trimmed version as a regression test.

Mechanism (likely a small fix)

  1. Consistency term → f0 gradient dependence. Nitsche injects the gradient-dependent traction σ(u)·n into the f0 (value) boundary residual, so the boundary Jacobian g1 = ∂f0/∂L is nonzero and is exercised for the first time anywhere — the bulk f0 is just body force (∂f0/∂L = 0), so this assembly path is never tested in the bulk. The boundary assembly (cython/petsc_generic_snes_solvers.pyx ~L5665–5686) reuses the bulk (0,2,1,3) index permutation/reshape, which is not correct for the anisotropic boundary traction.

  2. Symmetry term uses scalar viscosity. The Nitsche symmetry term hardcodes mu = constitutive_model.viscosity (= shear_viscosity_0) rather than the full C : ε̇(v) response (add_nitsche_bc, vector ~L2864 / saddle ~L4557). Correct for isotropic, wrong for TI.

Impact

Latent for every anisotropic model under Nitsche — TI viscous, TI-VEP, anisotropic diffusion. For the fault-convection work it presented as "TI Stokes is intractable" (≈23 oscillating Newton steps); it is in fact a regression introduced when free-slip was switched from penalty (add_natural_bc) to add_nitsche_bc (penalty never exercises the bad path).

Workaround

Use penalty free-slip add_natural_bc(KFS · v·n̂ · n̂) instead of add_nitsche_bc for anisotropic rheologies — verified to give an exact Jacobian (6.7e-11).

Acceptance / regression gate

snes_test_jacobian on annulus + Nitsche + TI goes from 0.069 to ~1e-8, with isotropic + Nitsche unchanged. Add scripts/jac_minimal_box.py (trimmed) to the test suite.


Underworld development team with AI support from Claude Code

Activity

  1. added
    bug
    on Jun 15, 2026
  2. lmoresi commented on Jun 24, 2026

    @lmoresi
    MemberAuthor

    Relationship to #258 (consistent Jacobian tangent)

    Checked against the open PRs. #258 directly targets this issue's mechanism but should be verified before closing:

    Open question (needs the reproducer): #258's unwrap fixes the η(grad v) gradient dependence. This issue also flags the anisotropic (TI) tensor specifics — the symmetry term using scalar viscosity instead of the full C:ε̇(v), and the boundary g1 index permutation. Whether #258's unwrapped derive_by_array(bd_F1) also yields the correct anisotropic tangent depends on whether bd_F1 already encodes the full anisotropic stress σ(u)·n.

    Recommended: run this issue's snes_test_jacobian matrix (esp. annulus + Nitsche + TI, currently 0.069) with #258 applied. If it drops to ~1e-9, #258 closes this and the TI+Nitsche case should be added as a regression alongside #258. If a residual remains, it's the anisotropic symmetry-term / index-permutation part, to fix on top.

    Leaving open and linking to #258 pending that check (best done by whoever lands #258, since the reproducer + consistent_jacobian API live there).

  3. lmoresi commented on Jul 2, 2026

    @lmoresi
    MemberAuthor

    #258 merged (consistent-Jacobian infrastructure: symbolic_keep_constants unwrap + Picard→Newton continuation, opt-in/default-off). That addresses the bulk F1 tangent. The Nitsche boundary anisotropic terms this issue is about are still outstanding — the fix here is to route the boundary Jacobian through the same unwrap-before-differentiate path. Verification: snes_test_jacobian on the minimal TI+Nitsche case with consistent_jacobian enabled. Keep open.

    Underworld development team with AI support from Claude Code

  4. lmoresi commented on Aug 3, 2026

    @lmoresi
    MemberAuthor

    PR #493 (merged 2026-08-03) fixed the Stokes natural-BC uu_G3/uu_G2 assembly, which was the MAJOR TRANSPOSE of the true tangent (see #457 — same defect class, invisible to major-symmetric tangents). The Nitsche × transverse-isotropy boundary Jacobian reported here ran through exactly that path, so the 7% inconsistency measured before #493 conflates the transpose with any genuine bd_F1 tangent gap. Re-measure against current development before pursuing the #258-style unwrap routing — the residual defect may be smaller or gone.

  5. lmoresi commented on Aug 8, 2026

    @lmoresi
    MemberAuthor

    Re-measured on current development (post-#493, at d39dbb7). The defect is gone.

    snes_test_jacobian (Amat line), linear TI (director 30°, η₀=1, η₁=0.1), small meshes:

    configuration pre-#493 (issue table) now
    box + Dirichlet + TI 3e-11 3.6e-09 ✓
    annulus + Nitsche + isotropic 2e-9 1.8e-11 ✓
    annulus + Nitsche + TI 0.069 2.4e-11 ✓
    box + Nitsche (one flat wall) + TI — 6.3e-11 ✓

    Newton on the annulus+Nitsche+TI case now converges in 1 SNES iteration to ‖F‖≈3e-13 (both default tangent and consistent_jacobian=True — linear TI has a frozen C, so Picard = Newton), versus the ~23 oscillating steps that motivated this issue.

    Diagnosis. The 7% was mechanism 1 in one specific form: the boundary uu_G1 (= ∂bd_f0/∂L, carrying the Nitsche consistency traction σ(u)·n) was assembled as its fc/gc transpose by the old permutedims((0,2,1,3)) translation — the same defect class as #457's bulk uu_G3, and invisible for isotropic stress because that block is fc/gc-symmetric. #493's explicit-index boundary loops fixed it.

    Mechanism 2 (symmetry/penalty terms use scalar constitutive_model.viscosity rather than the full C:ε̇(v)) is real but is not a residual/Jacobian inconsistency: the boundary residual fn_F and its Jacobian are derived from the same expression, so they agree (confirmed by the 1e-11 FD comparison above). It makes add_nitsche_bc a non-standard (adjoint-inconsistent) Nitsche variant for anisotropic stress — a consistency-order/symmetry question, not a Newton-convergence one, and the penalty scaling only needs a positive scalar. We're leaving that as documented behaviour; rotated strong free-slip remains the recommended default for TI.

    Regression added (tests/test_1066_stokes_jacobian_layout.py::test_nitsche_boundary_uu_g1_matches_fd_oracle, TI + isotropic control): pins the assembled Nitsche boundary uu_G1 against an FD oracle of the boundary residual, read through PETSc's [fc*Nc+gc, dg] convention, with a guard that the TI oracle block is genuinely fc/gc-asymmetric (a transposed assembly reads 0.65 rel error — verified). Closing.

    Underworld development team with AI support from Claude Code

  6. lmoresi commented on Aug 8, 2026

    @lmoresi
    MemberAuthor

    Closing: resolved by #493; regression test lands via PR #509.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions