Add PETSc nullspace support to Stokes - #91
Merged
lmoresi merged 2 commits intoMar 25, 2026
Conversation
Contributor
Author
|
Copying the reviewer-response summary from #90 here for reference: Addressing the review items directly:
The current fork branches |
lmoresi
approved these changes
Mar 25, 2026
lmoresi
left a comment
Member
There was a problem hiding this comment.
Good - I'm happy to see this generalised to introduce null spaces into the stokes solver for velocity as well. We should add these to the individual meshes, since those are the places where we actually know what the null space should be.
lmoresi
added a commit
that referenced
this pull request
Mar 25, 2026
Setting stokes.petsc_use_nullspace = True enables: 1. Constant-pressure nullspace (petsc_use_pressure_nullspace) 2. Velocity rotation modes from mesh.nullspace_rotations This auto-populates petsc_velocity_nullspace_basis from the mesh geometry, so users don't need to construct rotation modes manually. For annulus: 1 pressure + 1 rotation = 2 modes For spherical shell: 1 pressure + 3 rotations = 4 modes For box: 1 pressure + 0 rotations = 1 mode Existing PR #91 tests pass unchanged. Underworld development team with AI support from Claude Code
lmoresi
added a commit
that referenced
this pull request
Mar 31, 2026
Setting stokes.petsc_use_nullspace = True enables: 1. Constant-pressure nullspace (petsc_use_pressure_nullspace) 2. Velocity rotation modes from mesh.nullspace_rotations This auto-populates petsc_velocity_nullspace_basis from the mesh geometry, so users don't need to construct rotation modes manually. For annulus: 1 pressure + 1 rotation = 2 modes For spherical shell: 1 pressure + 3 rotations = 4 modes For box: 1 pressure + 0 rotations = 1 mode Existing PR #91 tests pass unchanged. Underworld development team with AI support from Claude Code
lmoresi
added a commit
that referenced
this pull request
Apr 7, 2026
Setting stokes.petsc_use_nullspace = True enables: 1. Constant-pressure nullspace (petsc_use_pressure_nullspace) 2. Velocity rotation modes from mesh.nullspace_rotations This auto-populates petsc_velocity_nullspace_basis from the mesh geometry, so users don't need to construct rotation modes manually. For annulus: 1 pressure + 1 rotation = 2 modes For spherical shell: 1 pressure + 3 rotations = 4 modes For box: 1 pressure + 0 rotations = 1 mode Existing PR #91 tests pass unchanged. Underworld development team with AI support from Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds generalized PETSc nullspace support to the Underworld Stokes saddle-point solver.
What changed
petsc_use_pressure_nullspaceto register the constant-pressure gauge mode on the coupled Stokes operator.petsc_velocity_nullspace_basisto register one or more exact velocity nullspace modes alongside the pressure mode.setFromOptions()reconfiguration.(-y, x)(0, -z, y),(z, 0, -x),(-y, x, 0)tests/test_1013_stokes_pressure_nullspace.pytests/test_1014_stokes_shell_nullspace.pyWhy this is important
Incompressible Stokes pressure is only defined up to an additive constant. Making singular Stokes systems solvable by imposing a pressure Dirichlet condition, especially on an entire boundary, is stronger than the mathematical requirement and can change the solution.
This PR follows the standard PETSc approach instead:
This matters for annulus and spherical-shell benchmarks, including cases like the Thieulot
k=0branch, where pressure gauge freedom is real and boundary-wide pressure pinning is not the right tool. It also provides a clean path for exact shell rigid-rotation nullspaces when the PDE and boundary conditions truly admit them.PETSc precedent
This follows the same pattern used in PETSc Stokes examples, where PETSc builds and attaches a nullspace instead of forcing pressure pointwise on a boundary:
CreatePressureNullSpace()CreatePressureNullSpace()Validation
pixi run -e amr-dev pytest tests/test_1013_stokes_pressure_nullspace.py tests/test_1014_stokes_shell_nullspace.py -qThese tests pass locally and cover both the pressure-only nullspace path and shell-style pressure-plus-rotation nullspace bases.