Fix Poisson solver natural (Neumann) boundary conditions#60
Merged
lmoresi merged 1 commit intodevelopmentfrom Feb 28, 2026
Merged
Fix Poisson solver natural (Neumann) boundary conditions#60lmoresi merged 1 commit intodevelopmentfrom
lmoresi merged 1 commit intodevelopmentfrom
Conversation
Two bugs prevented natural BCs from working in the scalar Poisson solver (SNES_Scalar), while the Stokes solver (SNES_Vector) worked correctly: 1. _setup_discretisation registered natural BCs with per-boundary labels (e.g., "Bottom") instead of the consolidated "UW_Boundaries" label that _setup_solver expects. 2. _setup_solver had a placeholder comment but no code to register the compiled boundary residual/jacobian functions with PETSc via UW_PetscDSSetBdResidual/BdJacobian/BdJacobianPreconditioner. The fix mirrors the working SNES_Vector pattern. Verified against an analytical solution (T = x²y) on simplex and quad meshes. Closes #25 Underworld development team with AI support from Claude Code
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes natural (Neumann/flux) boundary-condition handling for the scalar Poisson SNES solver (SNES_Scalar), aligning it with the existing (working) natural-BC setup used by the vector/Stokes SNES solvers and re-enabling the previously skipped regression test.
Changes:
- Use the consolidated PETSc DMLabel
"UW_Boundaries"when adding natural BCs inSNES_Scalar._setup_discretisation. - Register compiled boundary residual/Jacobian functions with PETSc in
SNES_Scalar._setup_solver(previously missing). - Unskip and re-enable
test_1000_poissonNaturalBC.py.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
tests/test_1000_poissonNaturalBC.py |
Re-enables the natural-BC Poisson regression test. |
src/underworld3/cython/petsc_generic_snes_solvers.pyx |
Fixes scalar natural BC label usage and adds PETSc DS boundary term registration for compiled natural-BC functions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
_setup_discretisationused per-boundary names ("Bottom") instead of the consolidated "UW_Boundaries" label_setup_solvermethod was missing the code to register compiled boundary residual/jacobian functions with PETSc — the SNES_Vector (Stokes) solver had this code, but SNES_Scalar did not@pytest.mark.skipfrom the Poisson natural BC test, which now passes on all mesh typesTest plan
test_1000_poissonNaturalBC.py— 3/3 pass (simplex regular, simplex irregular, quad)test_1000_poissonCart.py— 7/7 pass (Dirichlet-only Poisson, no regression)test_1010_stokesCart.py— 6/6 pass (Stokes solver, no regression)test_1011_stokesSph.py— 3/3 pass (Stokes with natural BCs, no regression)Closes #25
Underworld development team with AI support from Claude Code