Repository navigation
Description
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)
-
Consistency term →
f0gradient dependence. Nitsche injects the gradient-dependent tractionσ(u)·ninto thef0(value) boundary residual, so the boundary Jacobiang1 = ∂f0/∂Lis nonzero and is exercised for the first time anywhere — the bulkf0is 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. -
Symmetry term uses scalar viscosity. The Nitsche symmetry term hardcodes
mu = constitutive_model.viscosity(=shear_viscosity_0) rather than the fullC : ε̇(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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsActive
Activity
lmoresi commentedon Jun 24, 2026
Relationship to #258 (consistent Jacobian tangent)
Checked against the open PRs. #258 directly targets this issue's mechanism but should be verified before closing:
_jacobian_source= unwrap + smooth-kink, thenderive_by_array) to the Nitsche boundarybd_F1, not just the bulk flux — i.e. it makes the Nitsche boundary Jacobian source Newton-consistent (the comment in the diff: 'Nitsche gradient-traction depends on eta(grad v); unwrap + smooth-kink the Jacobian source so its tangent is Newton-consistent'). That is exactly the 'boundary Jacobian inconsistent with its residual' complaint here.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
viscosityinstead of the fullC:ε̇(v), and the boundaryg1index permutation. Whether #258's unwrappedderive_by_array(bd_F1)also yields the correct anisotropic tangent depends on whetherbd_F1already encodes the full anisotropic stress σ(u)·n.Recommended: run this issue's
snes_test_jacobianmatrix (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).
lmoresi commentedon Jul 2, 2026
#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_jacobianon the minimal TI+Nitsche case withconsistent_jacobianenabled. Keep open.Underworld development team with AI support from Claude Code
lmoresi commentedon Aug 3, 2026
PR #493 (merged 2026-08-03) fixed the Stokes natural-BC
uu_G3/uu_G2assembly, 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.lmoresi commentedon Aug 8, 2026
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:3e-113.6e-09✓2e-91.8e-11✓0.0692.4e-11✓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 oldpermutedims((0,2,1,3))translation — the same defect class as #457's bulkuu_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.viscosityrather than the full C:ε̇(v)) is real but is not a residual/Jacobian inconsistency: the boundary residualfn_Fand its Jacobian are derived from the same expression, so they agree (confirmed by the 1e-11 FD comparison above). It makesadd_nitsche_bca 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 boundaryuu_G1against 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
lmoresi commentedon Aug 8, 2026
Closing: resolved by #493; regression test lands via PR #509.
Pin the Nitsche boundary tangent for anisotropic stress (issue #239) (#…
Guides: Nitsche free-slip is not ruled out with transverse isotropy