Skip to content

tests: cover SNES_Scalar.constant_nullspace#235

Merged
lmoresi merged 1 commit into
developmentfrom
feature/constant-nullspace-test
Jun 13, 2026
Merged

tests: cover SNES_Scalar.constant_nullspace#235
lmoresi merged 1 commit into
developmentfrom
feature/constant-nullspace-test

Conversation

@lmoresi

@lmoresi lmoresi commented Jun 12, 2026

Copy link
Copy Markdown
Member

What

Adds a tier_a / level_1 regression test for SNES_Scalar.constant_nullspace, which currently has no test coverage on development (it was added in 074a660 for the Monge-Ampère smoother's pure-Neumann solve).

The test is salvaged from the now-closed #201, which proposed a duplicate petsc_use_constant_nullspace flag. #201 was closed as redundant — development already provides this capability as constant_nullspace (with the cached nullspace object that review on #201 had suggested). This PR keeps the useful part of #201: its test, renamed to the native attribute.

Coverage

  • Canonical solution — a pure-Neumann Poisson (-Δu = x − ½, no Dirichlet BCs) is singular up to a constant. With constant_nullspace=True, PETSc returns the minimum-norm (discrete zero-mean) solution. The test asserts convergence, that the non-constant part matches the analytic solution u = -x³/6 + x²/4 + C to FE accuracy, and that the mean drops relative to the no-nullspace solve.
  • Property setter — round-trip and default.

Verified against current development: constant_nullspace=True → mean 3.7e-16 vs −0.224 drift when off (2 passed locally).

A small follow-up worth noting: development's constant_nullspace setter doesn't set is_setup = False, so toggling it after a solve won't re-attach the nullspace. Not addressed here (test-only PR), but flagging it.

Underworld development team with AI support from Claude Code

Development's constant_nullspace (added in 074a660 for the Monge-Ampere
smoother's pure-Neumann solve) had no test coverage. This adds a tier_a/level_1
regression test salvaged from the now-closed #201 (which proposed a duplicate
petsc_use_constant_nullspace flag):

- a pure-Neumann Poisson (-Δu = x - 1/2, no Dirichlet BCs) is singular up to a
  constant; with constant_nullspace=True PETSc returns the minimum-norm
  (discrete zero-mean) solution. The test checks convergence, that the
  non-constant part matches the analytic solution to FE accuracy, and that the
  mean drops vs the no-nullspace solve;
- property-setter round-trip and default.

Verified against current development: constant_nullspace=True gives mean 3.7e-16
vs -0.224 drift when off.

Underworld development team with AI support from Claude Code
Copilot AI review requested due to automatic review settings June 12, 2026 23:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds tier_a/level_1 regression coverage for SNES_Scalar.constant_nullspace by exercising a pure-Neumann Poisson solve and verifying the solver’s “canonical” (minimum-norm / near-zero-mean) behavior when the constant nullspace is declared.

Changes:

  • Add tests/test_1056_constant_nullspace.py covering a canonical pure-Neumann Poisson case with/without constant_nullspace.
  • Add a small property round-trip/default test for constant_nullspace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +96 to +100
mean_on = T_on.data[:, 0].mean()
assert abs(mean_on) < abs(mean_off), (
f"with nullspace declaration, |mean(T)| should drop; "
f"got |mean_off|={abs(mean_off):.3e}, |mean_on|={abs(mean_on):.3e}"
)
@lmoresi lmoresi merged commit 4b55df6 into development Jun 13, 2026
2 checks passed
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