Skip to content

Newton tangent is NaN at rest for a fractional (non-half) power of the strain-rate invariant: the Jacobian guard covers half-integer powers only #841

Open

Description

@lmoresi

What happens. A viscosity written on the bare invariant with a fractional power, for example the bounded shear-thinning law

edot = stokes.Unknowns.Einv2          # a bare sqrt(g), not a named expression
eta = 1 / (1 + edot ** sympy.Rational(1, 3))

has a finite residual at rest, but its consistent (Newton) Jacobian is NaN there. SymPy merges sqrt(g)**(1/3) into g**(1/6); the guard in _jacobian_unwrap adds 1e-36 to the base of half-integer powers only (exp.q == 2, on both JIT routes: _jit_graph.guard_half_integer_powers and the expanded route's _guard_sqrts), so the derivative g**(-5/6) * dg/dL is Inf * 0 = NaN at v = 0. The solve raises PETSc error 77 ("Computed maximum singular value as zero"). The alpha-blended kernel inherits it at alpha = 0 (0 * NaN = NaN).

Measured (16-cell box, driven lid): consistent_jacobian=False converges in 5 iterations; True raises error 77 on both routes, J(0) norm nan. With the invariant wrapped in a named expression the graph route converges (its node body sqrt(g) is guarded) and the expanded route still raises.

Why it matters now. On development the Newton tangent is opt-in. PR #794 makes it the default (one automatic cold Picard step through the blended kernel), so every cold solve of such a law raises.

Fix. Guard every non-integer power whose base has free symbols, on both routes. In floating point x + 1e-36 == x for any base above about 1e-20, so values and tangents away from rest are unchanged; only kernels that contain such powers change text. Found by the adversarial review of the #794 merge.

Activity

  1. added 2 commits that reference this issue on Oct 11, 2026
  2. lmoresi commented on Oct 11, 2026

    @lmoresi
    MemberAuthor

    The fix is in PR #794 (4cdc00d): the guard covers every non-integer exponent on a base with free symbols, on both JIT routes; test_1067 carries the regression on both routes. Labelled fixed-in-PR until #794 merges.

  3. added
    fixed-in-developmentFix merged to development; the issue closes when it is released to main
    and removed
    fixed-in-PRA PR carries the fix; the issue names it
    on Oct 12, 2026
  4. lmoresi commented on Oct 12, 2026

    @lmoresi
    MemberAuthor

    Fixed by #794 (merged to development, c97eb9e).

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

    fixed-in-developmentFix merged to development; the issue closes when it is released to maintype:codeCode implementation review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions