Skip to content

The Nitsche condition's continuity-row term is assembled (#1072) - #1145

Merged
lmoresi merged 3 commits into
developmentfrom
bugfix/nitsche-continuity-term-is-assembled-1072
Nov 13, 2026
Merged

lmoresi merged 3 commits into
developmentfrom
bugfix/nitsche-continuity-term-is-assembled-1072

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member

What this does

A Stokes solve with add_nitsche_bc now assembles the Nitsche term in the continuity rows, with the sign the continuity residual needs. Before, that term was built and never integrated, and a closed box with Nitsche on some walls and essential conditions on the others did not converge (#1072).

This changes what a solver in petsc_generic_snes_solvers assembles, so it is row 17 of the solver register. Louis Moresi signed that row off on 2026-11-13, as relayed to us by the dev hub (the session that tracks PRs and merges). It has been run on one rank only. It merges on the parallel check at 2 and 4 ranks listed under "What was not run", and green CI.

Every Stokes answer with a Nitsche condition whose direction is not tangential to the wall changes, including solves that converged before.

Cause

add_nitsche_bc builds two wall terms: one for the momentum rows and one, fn_p, for the continuity rows, with the Jacobian blocks of both. The condition was registered with PETSc as one boundary entry on the velocity field. PETSc integrates a boundary entry only for the field it is registered with (DMPlexComputeBdResidual_Internal and DMPlexComputeBdJacobian_Internal take the row field from the entry), so the residual and the pressure-velocity Jacobian block that were attached to that entry for field 1 were never assembled. The velocity-pressure block was, so the assembled matrix lost the relation between its two off-diagonal blocks.

The sign of fn_p was also wrong, which had no effect while the term was not assembled.

The sign

The momentum residual is $\int \nabla v : \sigma - \int_\Gamma v\cdot(\sigma n) - \int v\cdot f$ with $\sigma = \tau - pI$, so its pressure part in the volume is $-\int p,\nabla\cdot v$. The continuity residual in this code is $+\int q,\nabla\cdot u$. The pressure-velocity block of the volume terms is therefore minus the transpose of the velocity-pressure block.

Nitsche's consistency term in the momentum rows is $-\int_\Gamma (v\cdot d),(\sigma n\cdot d)$ for a constraint along $d$, and its pressure part is $+\int_\Gamma (v\cdot d)(n\cdot d),p$ (in the code, f0 += p (n.d) d). For the wall terms to stand in the same relation as the volume terms, the continuity rows must carry $-\int_\Gamma q,(n\cdot d)(u\cdot d - g)$. The code had $+$.

With that sign, summing the continuity residual over a constant $q$ gives $\int \nabla\cdot u - \int_\Gamma (u\cdot n - g)$ on a wall where $d = n$: the flux through the other walls plus $\int_\Gamma g$. In a closed box with essential conditions on the other walls and data of zero net flux this is zero for any velocity, so the constant pressure is again a left null vector of the Jacobian and the right-hand side is compatible with it. That is the property the stalled solves lacked.

The change

src/underworld3/cython/petsc_generic_snes_solvers.pyx, Stokes solver only:

  • fn_p = -(n.d)(u.d - g).
  • Each Nitsche condition registers a second boundary entry, on the pressure field, named <boundary>_continuity. The multiplier constraints are already registered twice for the same reason.
  • The continuity-row residual and the pressure-velocity boundary Jacobian (and its preconditioner copy) are attached to that entry. A natural condition that is not Nitsche has no second entry and is wired as before.
  • compute_boundary_residual_fields(boundary, residual_field_id=1) returns the continuity-row term of a Nitsche wall. It raised ValueError before, because it looked for a condition registered on field 1.
  • The verbose view of the boundary weak forms prints the second entry.

There is no tolerance and no coordinate comparison in the library change. A condition is identified by its position in the solver's list of natural conditions and by the id PETSc returns for the boundary entry; the entry's name is not used to find it.

Not changed: the velocity-row terms, the penalty scale, gamma, the vector solver's Nitsche condition (it has no pressure), the zero pressure-pressure boundary block.

The published form

Underworld technical note 2026-016 (boundary conditions on non-planar boundaries) writes the symmetric Nitsche term as $-\int_\Gamma (n\cdot\sigma(w)\cdot n)(u\cdot n)$, with $w$ the test function. Read with $\sigma(w) = 2\eta,\varepsilon(w) - qI$, the stress of the velocity and pressure test functions together, it splits into $-\int_\Gamma 2\eta,(n\cdot\varepsilon(w)\cdot n)(u\cdot n) + \int_\Gamma q,(u\cdot n)$. The second piece is the continuity-row term the code never assembled. Its sign agrees with this fix: the note's single form carries continuity as $-q,\nabla\cdot u$, and the code carries it as $+q,\nabla\cdot u$, so the code's term is $-q,(n\cdot d)(u\cdot d - g)$. The equation in the note stands. In the code theta scales the viscous half of the symmetric term only; the pressure half is always on.

Tests

tests/test_1060_nitsche_freeslip.py:

  • test_the_continuity_row_carries_the_nitsche_term: on the assembled Jacobian of the free-slip box, the pressure-velocity block is minus the transpose of the velocity-pressure block.
  • test_the_continuity_residual_sums_to_zero_in_a_closed_box: at a random velocity and pressure, the continuity residual summed over the pressure unknowns is zero.
  • test_the_boundary_residual_diagnostic_returns_the_continuity_row_term: for $u = (0, x(1-x))$ the diagnostic's pressure rows sum to minus the flow out of each wall, $\mp 1/6$.
  • test_nitsche_converges loses its xfail.
  • test_nitsche_matches_essential: the bound on the difference from the essential answer goes from 0.01 to 1.5e-3.

On this branch the file gives 10 passed. On development (at 70b240c with #1137) the same file gives 5 failed, 5 passed: the three new tests, test_nitsche_converges and test_nitsche_matches_essential.

Measurements

All on one rank, macOS, 12-core Apple M4. "Before" is development at 70b240c with the refusal of #1137 (the solver file is otherwise development's); "after" is this branch. Reason is the SNES converged reason (2 converged on the residual, 4 stopped on a small step, -3 linear solve failed, -6 line search failed).

Free-slip box, cell size 1/8 (the fixture of test_1060; difference from the essential answer, relative):

After Before
Pressure-velocity block against minus the transpose of the velocity-pressure block (norm of the sum; the block norm is 0.863) 2.2e-17 0.2826
Nitsche, default gamma 12.5 1.1704e-03, reason 2 3.3603e-03, reason -6
Nitsche, gamma 10 1.9754e-03, reason 2 5.9359e-03, reason -6
Penalty at 1e4 1.5155e-03 1.5155e-03

Manufactured solution (stream function $\sin\pi x,\sin\pi y$, free slip on four walls, P2/P1, tolerance 1e-9; errors are $L_2$ norms of $u - u_e$ and $p - p_e$):

Cells across Essential (and rotated) Nitsche after Nitsche before
8 1.2607e-03 / 4.5154e-03 1.2176e-03 / 4.4975e-03, reason 2, 1 Newton step 1.3194e-03 / 1.9975e-02, reason -6, 17 steps
16 1.6520e-04 / 1.1137e-03 1.6268e-04 / 1.1086e-03, reason 2, 1 step 1.7667e-04 / 3.9107e-03, reason -6, 16 steps
32 2.0780e-05 / 2.7563e-04 2.0621e-05 / 2.7529e-04, reason 2, 1 step 2.2646e-05 / 7.5796e-04, reason -6, 21 steps

After the fix the velocity error falls at order 2.9 to 3.0 and the pressure error at order 2.0, as with the essential condition. The largest $|u\cdot n|$ on the walls is 4.5e-03, 5.9e-04 and 7.4e-05 at the three sizes, the same to 1 % before and after.

Other routes (difference from the strong condition's answer unless said):

Case After Before
Inflow $u_y = 0.1\sin 2\pi x$ on Top, no slip on the sides, 8 cells reason 2, 1 step; 1.432e-03 reason -3, 6 steps, 109 linear iterations; 2.503e-03
Free slip on Top and Bottom, no slip on Left, nothing on Right, 8 / 16 cells reason 2; 1.275e-03 / 1.732e-04 reason 2; 2.479e-03 / 3.355e-04
Box, then the load doubled and solved again reason 2 both; second answer is twice the first to 5.0e-11 reason -6 both
3-D box, 4 cells reason 2, 1 step; 3.201e-02 reason -6, 3 steps; 4.951e-02
Annulus, no slip inside, Nitsche outside (strong = rotated free slip), 8 / 16 cells reason 2; 1.231e-03 / 1.867e-04 reason 2; 1.601e-03 / 2.329e-04
Geometric multigrid, one / two refinements reason 2, 1 step; 1.135e-04 / 1.057e-05 reason -6; 4.312e-04 / 5.458e-05
Multiplier wall on Top (Stokes_Constrained), Nitsche on Bottom reason 2; 8.315e-04 reason 2; 2.466e-03
Rotated free slip on Top, Nitsche on Bottom reason 2; 8.315e-04 raises KSP_DIVERGED_PCSETUP_FAILED
theta 0 / -1 reason 2; 9.014e-04 / 9.739e-04 reason -3; 1.413e-03 / 1.036e-03
A tangential direction (n.d = 0, no continuity-row term) 8.946e-05 8.946e-05

A datum with net flow into a closed box has no solution; the strong condition and Nitsche both stop with reason -3 at zero iterations.

SolCx of the technical note (viscosity contrast 1e6, Nitsche free slip on Top, gamma 10, tolerance 1e-9; stress error is relative to the analytic solution):

Cells across Condition Reason, Newton steps Velocity error Stress error
16 essential 2, 1 1.41e-04 1.05e-01
16 Nitsche after 2, 1 2.38e-03 1.09e-01
16 Nitsche before 4, 16 8.70e-03 8.34e+01
32 essential 2, 1 8.84e-06 7.56e-02
32 Nitsche after 2, 1 2.15e-04 7.61e-02
32 Nitsche before 4, 10 1.09e-03 1.34e+01
64 essential 2, 1 5.46e-07 5.39e-02
64 Nitsche after 2, 2 1.92e-05 5.40e-02
64 Nitsche before -3, 2 1.38e-04 1.23e+02

Two of the three solves before the fix report convergence (reason 4) with a stress error of order ten to a hundred. After the fix, at 32 cells and contrasts from 10 to 1e6, every Nitsche solve converges in one step with a stress error within 1.1 % of the essential one; with gamma from 1 to 1000 the stress error is between 7.56e-02 and 7.87e-02.

Before the fix, at 32 cells: no contrast from 10 to 1e4 converged (reasons -6, -6, -6 and -5, the last at the cap of 50 steps), with stress errors of 426, 9.8, 10.5 and 3.3. With gamma at 1, 10, 12.5, 100 and 1000 the stress error was 2.57 (reason -5), 13.4, 3.86, 0.239 and 0.0837 (reason 4): only where the penalty dominates did the answer approach the essential one (0.0756).

Spherical shell response (the Zhong kernel fixture of tests/test_1064_constrained_spherical_shell_response.py, Nitsche route, one linear solve; error against the analytic topography response):

gamma After: surface / core-mantle boundary Before: surface / core-mantle boundary
10 0.076 % / 0.157 % 0.061 % / 0.321 %
12.5 0.069 % / 0.119 % 0.093 % / 0.186 %

The linear solve converged in all four runs (KSP reason 2 or 3, residual 1.1e-09 or less).

The default gamma

The boundary-condition rulings say a gamma of 10 "was a cliff, a hundred times worse than 12.5" after the cell size was redefined (#734), and the default is 12.5. On the shell fixture today there is no cliff between the two values, before or after this change (table above), and the linear solve converges in every run, so those numbers were not taken from a stalled solve. The cliff recorded in #734 (2.36 % and 5.67 % at gamma 10) was measured at an earlier definition of the cell size; we did not rebuild that commit, so we cannot say whether that measurement came from a stalled solve. After the fix the two values differ by less than 0.04 % of the response on the shell and by 0.08 % of the velocity on the box (0.20 % against 0.12 %). Nothing here asks for the default to move from 12.5.

Published and recorded numbers this changes

  • Technical note 2026-016 says of SolCx that "Nitsche has no column in this table" because no converged solution was reached. That was this defect; the table above is that column.
  • The same note's annulus tables for Nitsche (flow through the wall, stress error, the window of usable gamma, the timing row) were produced with the term missing. They need a rerun; the scripts need the assess package, which the machine used here does not have.
  • docs/advanced/curved-boundary-conditions.md quoted the box difference as 0.08 % at gamma=10, which neither build gives. It now says 0.20 % at gamma 10 and 0.12 % at the default.
  • docs/developer/CHANGELOG.md has the entry.
  • docs/developer/design/CONVERGENCE_REFERENCE_POLICY.md says a weak datum contributes gamma mu/h g to the residual at zero. A datum normal to the wall now also puts (n.d) g in the continuity rows. Read, not measured; not edited here.

Tolerances and coordinate matches

In the library change: none.

In the tests added or changed: mismatch < 1e-12 * scale on the block relation (measured 2.6e-17 relative; 0.33 with the term absent); abs(net) < 1e-12 * size on the summed continuity residual (5.3e-17; 4.6e-2 with the term absent); the guards scale > 0.5 and size > 1e-3 that the quantity compared against is not zero; diff < 1.5e-3 on Nitsche against essential (1.17e-3 measured; 3.36e-3 with the term absent; 1.98e-3 at gamma 10); < 1e-12 and == 0.0 in the diagnostic test. Unchanged and older than this change: the penalty bound 0.01, the wall-flow bounds 0.1 and 1e-12, and the one coordinate comparison, which picks the wall nodes by abs(y - 1) < 1e-10.

What was run

Serial only, on macOS (12-core Apple M4).

What Result
tests/test_1060_nitsche_freeslip.py 10 passed (5 failed, 5 passed on development)
The Nitsche, rotated-wall and solver-contract files at the committed source: test_0010_cell_size_geometry, test_0016_solver_description_contract, test_0028_convergence_reference, test_0030_capability_guides, test_0052_collective_guard_scan, test_0641_wave_c_api_shims, test_1060_nitsche_freeslip, test_1064_constrained_spherical_shell_response, test_1065_nitsche_local_h, test_1065_rotation_gauge_freeslip, test_1066_rotated_meets_essential, test_1066_stokes_jacobian_layout 103 passed, 1 xfailed (the xfail is test_fast_schur_constrained_matches_zhong_velocity_response, older than this change and not a Nitsche case)
scripts/check_test_coverage.py all 446 test files reachable
Docs build no warning from the two pages edited

The branch is based on development at 70b240c. development has since gained #1137 (d66c7da), which touches the same solver file; the two merge without conflict, and the build tested here does not contain #1137.

In-memory changes to the fixed build, on the box: with the old sign assembled the solve ends with reason -6 and a block mismatch of 0.655 of the block norm; with the term absent, reason -6 and 0.327. Registration on the wrong field cannot be made in memory (the registration is compiled); the build before the fix is that case.

A solver that is set up again (a changed body force or viscosity, the rewire flag, a second solve) gives the same answer as a new solver and registers nothing twice.

What was not run

  • More than one rank. The parallel desk (a 96-thread Linux workstation, single system image) is asked for tests/test_1060_nitsche_freeslip.py at 2 and 4 ranks, including a partition where some rank holds no facet of the Nitsche wall (the new entry on the pressure field is registered on every rank), and tests/parallel/test_1069_boundary_normal_parallel.py.
  • Linux with conda-forge PETSc, other than through CI. The xfail removed from test_nitsche_converges recorded that one host stopped at the pressure sub-solve's iteration cap.
  • The technical note's annulus sweep (needs assess).
  • A Nitsche wall on a mesh with a fault add-on or its patch; internal boundaries; the kernel-route adjoint; the Navier-Stokes and viscoelastic subclasses; convergence orders in 3-D.

Found beside the change, not fixed here

  • sensitivity() reads only the value term of a natural or Nitsche condition, not its flux term, and not the continuity-row term this PR assembles: sensitivity() leaves out the flux and continuity-row terms of a natural or Nitsche condition: wrong-signed gradient for a Nitsche datum #1143.
  • tests/test_1060_nitsche_freeslip.py sets its tier for the whole module, where the style charter wants one tier on each test, and one test repeats tier_b. The tests added here carry their own mark; the module line is left.
  • docs/advanced/curved-boundary-conditions.md passes gamma=10 in its examples and recommends Nitsche where the rulings prefer rotated free slip; docs/developer/guides/adaptive-meshing.md records Nitsche diagnoses made with the term missing. These pages go to the curved-walls desk with the technical note's correction.

Issue state

An adversarial review was made before this PR opened; its record is in the first comment.

Solver register: row 17.

Underworld development team with AI support from Claude Code

Stokes add_nitsche_bc built a wall term for the continuity rows and its
Jacobian blocks, but registered the condition as one boundary entry on the
velocity field. PETSc integrates a boundary entry only for the field it is
registered with, so the term never reached the pressure rows. Its sign was
also opposite to the one the +q div(u) continuity residual needs.

Each Nitsche condition now registers a second boundary entry on the
pressure field; the continuity-row residual and the pressure-velocity
boundary Jacobian are wired to it, and the term is -(n.d)(u.d - g).
compute_boundary_residual_fields(residual_field_id=1) returns that term,
and the verbose view prints the second entry.

test_1060 gains three tests (the block relation, the summed continuity
residual in a closed box, the diagnostic), loses the xfail on
test_nitsche_converges, and bounds Nitsche against essential at 1.5e-3.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 13, 2026 08:06

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Adversarial review, before the PR opened

Made by a fresh reviewing agent for W1 (the integration session, which owns the solver code) on the uncommitted branch, then the fixes below were applied and the build and tests rerun. Run on macOS (12-core Apple M4), serial only: nothing here was run on more than one rank. "Before" is development at 70b240c with #1137; "after" is this branch. Mutants were made in memory.

Result. The sign and the registration hold on every route we could reach on one rank. Six findings were fixed in the branch. One is not fixed here and is filed (#1143).

Findings

1. sensitivity() does not read the term this PR assembles, nor the flux term (not fixed here; #1143). It adds a facet part from fn_f only. Against a central difference of J, half the integral of |u|^2, on the box at cell size 1/8:

Parameter sensitivity() Central difference Gap With the missing parts added
Nitsche datum normal to the wall (inflow on Top, Right open), this branch 1.58094967e-05 3.04923796e-03 99.5 % 1.9e-11
Nitsche datum along the wall (lid), either build -7.33323802e-02 +4.52367906e-02 wrong sign 5.5e-12
Viscosity beside a Nitsche wall, this branch -8.00122848e-05 -8.00650091e-05 6.6e-4 2.0e-8

The fn_F omission is on development already. Before this branch the normal-datum gradient was also wrong (5.79666191e-03 against 3.04995814e-03), so the branch does not turn a right gradient into a wrong one. The forward change adds the need for a fn_p part against the pressure adjoint.

2. compute_boundary_residual_fields could not return the continuity-row term (fixed). residual_field_id=1 raised ValueError in both builds, because the lookup wanted a condition registered on field 1. It now finds the second entry, and a test asserts the returned rows sum to minus the flow out of the wall.

3. Two sentences of the CHANGELOG entry (fixed). The sentence on the flow through the wall and the sentence on answers that change now carry the measured numbers.

4. Comments (fixed). The comments in the changed code were reworded to state what the code is for.

5. The verbose view did not print the second entry (fixed). A verbose solve now prints a second weak form for each Nitsche wall, with boundary_residual_f0 (0, 1) and boundary_jacobian_g0/g1 (1, 0).

6. Docs. docs/advanced/curved-boundary-conditions.md quoted a box difference neither build gives (fixed to the measured values). Its examples pass gamma=10 and docs/developer/guides/adaptive-meshing.md records Nitsche diagnoses made with the term missing (not fixed here; outside this change). CONVERGENCE_REFERENCE_POLICY.md describes a weak datum's part of the residual at zero without the continuity rows (read, not measured, not edited).

7. Tests (fixed). The new tests had no tier of their own (the module sets one for every test, which the charter does not want; the module line is older and left). The bound in test_nitsche_matches_essential was 2e-3, which the gamma 10 answer (1.98e-3) would pass; it is 1.5e-3.

What holds

  • Block relation and compatibility. After: the sum of the pressure-velocity block and the transpose of the velocity-pressure block is 2.238e-17 against a block norm of 0.8632, in the Jacobian and in the preconditioner matrix; the continuity residual at a random state sums to -3.6e-16 of 6.80. Before: 0.2826, and +0.3217 of 6.93.
  • Mutants on the box. Fixed: reason 2, 1 Newton step, relative mismatch 2.6e-17, difference from essential 1.1704e-03. Old sign assembled: reason -6, 7 steps and 173 linear iterations, mismatch 0.655, 6.6798e-03. Term absent: reason -6, 3 steps and 45 linear iterations, mismatch 0.327, 3.3603e-03 (the number the build before the fix gives).
  • Set up again. A changed body force, a changed viscosity, the rewire flag, is_setup = False and a second solve all match a new solver (difference 0; 2.7e-12 for the second solve). The record of second entries is rebuilt by _setup_discretisation, which both callers of _setup_solver go through, so no entry is registered twice and none is stale.
  • Every reader of the boundary entries addresses them by the stored id.
  • Variants, after | before (reason; difference from the strong answer; block mismatch where measured):
Variant After Before
Tangential direction 8.946162e-05 8.946162e-05
Oblique direction mismatch 1.5e-17 0.1413
Masked part of a wall 9.9e-18 0.1398
theta 0 reason 2; 9.013578e-04 reason -3; 1.412706e-03
theta -1 reason 2; 9.739431e-04 reason -3; 1.036153e-03
Inflow datum with an open wall 2.2e-17; 5.801650e-04 0.2841; 9.031136e-04
Nitsche on four walls reason 2; 4.732103e-03 reason -6
Two Nitsche conditions on one wall 2.7e-17; 4.732103e-03 reason -6
Beside add_natural_bc on other walls 2.2e-17; 1.540390e-03 0.2841; 2.490039e-03
Beside add_natural_bc on the same wall reason 2; 2.095678e-03 reason -6; 4.089876e-03
With the pressure null space declared reason 2; 1.170447e-03 reason -6, 12 steps; 3.369553e-03
Geometric multigrid, one refinement reason 2, 1 step; 1.7e-17; 1.135289e-04 reason -6; 0.2020; 4.312292e-04
Geometric multigrid, two refinements reason 2, 1 step; 1.4e-17; 1.056740e-05 reason -6; 0.1436; 5.457561e-05
3-D box, 4 cells reason 2; 6.1e-18 of 0.3255 reason -6; 0.1017
3-D box, 8 cells reason 2, 1 step; 3.3e-18 of 0.2510 not run
Stokes_Constrained, multiplier on Top, Nitsche on Bottom reason 2; 1.7e-17 of 0.8781; 8.314952e-04 reason 2; 0.1998; 2.465771e-03
Rotated free slip on Top, Nitsche on Bottom reason 2; 1.7e-17; 8.314952e-04 raises KSP_DIVERGED_PCSETUP_FAILED
  • Tests. tests/test_1060_nitsche_freeslip.py: 10 passed after, 5 failed and 5 passed before. scripts/check_test_coverage.py: every test file reachable.

Tolerances and coordinate matches

Library change: none; a condition is found by its position in the list of natural conditions and the id PETSc returned. Tests: listed in the PR body. The one coordinate comparison (abs(y - 1) < 1e-10, picking wall nodes) is older than the change.

Not checked

More than one rank: the new entry on a rank that holds no facet of the wall, tests/parallel/test_1069_boundary_normal_parallel.py, the random-state test under a partition. Linux with conda-forge PETSc. A Nitsche wall with a fault add-on or its patch. Internal boundaries. The kernel-route adjoint. The Navier-Stokes and viscoelastic subclasses. A curved-wall continuity sum. Convergence orders in 3-D. The technical note's annulus sweep.

Issue verdicts

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Parallel check at e4f879c: the library change is READY. The continuity-row entry is assembled collectively and correctly on every rank, including ranks that hold no facet of the Nitsche wall. Two of the new or changed tests are not rank-safe; fix them in this PR (conditions below). Measured by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)) on the branch built at e4f879c, with development built at d66c7da for comparison. MPI jobs ran under the supervisor. Logs are kept by the reviewer.

1. A rank with no facet of the Nitsche wall

test_1060's box (cell 1/8, Nitsche on Top and Bottom) was run under the natural partition and a shell layout that puts the cells into horizontal bands by centroid height. The band layout leaves the middle ranks with no Top or Bottom facet. Facets held per rank as (cells, Top, Bottom):

np natural band
2 (82, 0, 8), (80, 8, 0) (87, 0, 8), (75, 8, 0)
3 (55, 0, 8), (53, 4, 0), (54, 4, 0) (62, 0, 8), (49, 0, 0), (51, 8, 0)
4 (42, 0, 4), (38, 0, 4), (41, 4, 0), (41, 4, 0) (46, 0, 8), (41, 0, 0), (38, 0, 0), (37, 8, 0)

So every rank lacks at least one of the two walls, and at np 3 and 4 band some ranks hold neither.

The library, measured directly. This is a rank-safe form of test_the_boundary_residual_diagnostic_returns_the_continuity_row_term: the same velocity (0, x(1−x)) and the same compute_boundary_residual_fields(wall, residual_field_id=1) call on both walls, with the wall sums reduced over the ranks.

np, layout Top: Σ pressure rows + 1/6 Bottom: Σ pressure rows − 1/6 max |velocity rows| nonzero pressure rows per rank (Top / Bottom)
1 5.6e-17 −8.3e-17 0 [9] / [9]
2 natural 2.8e-17 −8.3e-17 0 [0, 9] / [9, 0]
2 band 2.8e-17 −8.3e-17 0 [0, 9] / [9, 0]
3 band 2.8e-17 −8.3e-17 0 [0, 0, 9] / [9, 0, 0]
4 natural 5.6e-17 −5.6e-17 0 [0, 0, 5, 5] / [5, 5, 0, 0]
4 band 2.8e-17 −8.3e-17 0 [0, 0, 0, 9] / [9, 0, 0, 0]
  • Every rank, those with no facet included, takes part in the boundary assembly. Nothing hangs, and the wall integrals are exact at every rank count.
  • compute_boundary_residual_fields is collective: when one rank skips a call, the job stops in MPI (see condition 1).

The rest of test_1060 (everything except the diagnostic test), on every rank:

np, layout e4f879c d66c7da
2 natural 18 passed 8 failed, 10 passed
3 band 27 passed 10 failed, 16 passed
4 natural 36 passed 16 failed, 20 passed
4 band 35 passed, 1 failed (condition 2) 14 failed, 22 passed

On development, the new continuity tests fail on every rank as intended.

2. tests/parallel/test_1069_boundary_normal_parallel.py

np e4f879c d66c7da
2 7 passed, 1 skipped 7 passed, 1 skipped
4 7 passed, 1 skipped 7 passed, 1 skipped

Conditions (tests only)

  1. test_the_boundary_residual_diagnostic_returns_the_continuity_row_term is not rank-safe.
    • It asserts on each rank's own sum of the wall's pressure rows. At np 2 natural, the rank with no Top facet reads 0 against −1/6, and it fails.
    • It then skips the Bottom call that the other rank makes, so the job stops in MPI: "Message truncated" under -q, or a hang until the supervisor under the band layout.
    • np.abs(rows["velocity"]).max() also raises on a rank with no wall rows.
    • Fix: max(initial=0.0), and an allreduce of both quantities before asserting. That is the form measured above.
    • CI runs tests/ serially, so CI does not see this. But the file is otherwise rank-safe, and this is the one test that exercises the collective.
  2. test_nitsche_matches_essential compares each rank's own nodes. At np 4 band one rank measures 1.587e-3 against the 1.5e-3 bar; the global difference is not what is measured.
    • Reduce the two sums over the ranks.
    • Also, the docstring says "within 2e-3" while the assertion is 1.5e-3.

3. The note's annulus scripts (UWTN 2026-016), serially, before and after

  • Scripts: the note repository at 39335ce (articles/boundary-conditions-on-non-planar-boundaries/examples), unmodified. md5 of leak.py, stress.py and timing.py are kept with the logs.
  • Builds: development d66c7da, and this branch at e4f879c.
  • Host: the workstation named above, with each script pinned to one logical CPU. Every gamma listed converged on both builds; the scripts check the SNES reason.

Leak against the facet normal (leak.py sweep). Only the Nitsche column moves. Penalty, node penalty, multiplier ("constraint") and rotated are identical on both builds.

cell size Nitsche, d66c7da Nitsche, e4f879c penalty penalty_node constraint rotated
0.150 4.14e-03 4.09e-03 4.51e-03 3.31e-03 8.37e-04 7.28e-11
0.100 2.49e-03 2.45e-03 2.49e-03 2.71e-03 2.32e-04 5.69e-11
0.075 1.81e-03 1.79e-03 8.48e-04 2.62e-03 5.50e-05 1.04e-10
0.050 6.07e-04 6.06e-04 9.51e-04 2.59e-03 1.18e-05 9.73e-11

Leak against gamma (leak.py params):

gamma 1 10 100 1000 1e4 1e5
d66c7da 9.15e-03 1.81e-03 3.34e-04 2.84e-05 3.53e-05 1.55e-05
e4f879c 1.11e-02 1.79e-03 3.34e-04 2.84e-05 3.53e-05 1.46e-05

Surface stress error against the exact Kramer CylindricalStokes answer (stress.py sweep): exact σ_rr = 0.1506696429 cos 2θ on r = 1.

cell size Nitsche, d66c7da Nitsche, e4f879c penalty_node constraint rotated rotated (reaction) multiplier
0.150 7.80e-02 7.48e-02 2.54e-02 2.44e-02 2.44e-02 6.82e-03 8.57e-03
0.100 3.33e-02 3.25e-02 1.08e-02 9.89e-03 9.87e-03 3.27e-03 8.46e-04
0.075 1.98e-02 1.94e-02 7.26e-03 6.33e-03 6.30e-03 2.08e-03 1.70e-03
0.050 8.58e-03 8.44e-03 3.64e-03 2.69e-03 2.68e-03 1.08e-03 1.41e-03

The controls are identical on both builds.

Nitsche gamma at cell 0.075 (stress.py params), as leak / velocity error / stress error:

gamma d66c7da e4f879c
1 6.24e-03 / 4.97e-03 / 1.94e-03 8.55e-03 / 3.10e-03 / 1.57e-03
10 2.24e-03 / 4.95e-03 / 1.98e-02 2.28e-03 / 2.55e-03 / 1.94e-02
100 4.06e-05 / 2.38e-03 / 6.77e-03 4.07e-05 / 2.43e-03 / 6.76e-03
1000 9.96e-06 / 2.42e-03 / 6.35e-03 9.97e-06 / 2.43e-03 / 6.35e-03
1e4 9.28e-06 / 2.40e-03 / 6.31e-03 9.28e-06 / 2.40e-03 / 6.31e-03
  • The velocity error at gamma 1 and 10 drops by about half, to the level of the larger gammas. That is the continuity term now being assembled.
  • From gamma 100 up the two builds agree to the printed digits.
  • No gamma in 1 to 1e4 diverged on either build. Within the range the script sweeps, there is no divergence to report.
  • The penalty tables are identical on both builds.

Control (stress.py control), identical on both builds: free slip gives leak 8.47e-01, velocity error 5.76, stress error 9.96e-01. Rotated gives 9.67e-11, 2.42e-03, 6.30e-03.

Timing (timing.py), seconds for solve / recover:

cell size velocity nodes build penalty_node Nitsche constraint rotated
0.020 28 362 d66c7da 0.68 / 0.829 0.72 / 0.853 1.06 / 0.011 0.45 / 0.027
0.020 28 362 e4f879c 0.68 / 0.793 0.72 / 0.845 1.04 / 0.011 0.44 / 0.027
0.013 71 400 d66c7da 1.76 / 2.121 1.86 / 2.245 2.74 / 0.023 1.16 / 0.043
0.013 71 400 e4f879c 1.73 / 2.050 1.86 / 2.223 2.72 / 0.024 1.17 / 0.044
  • The Nitsche solve costs the same with the continuity term assembled.
  • The timing ran with nothing else of the reviewer's on the machine. Other users' jobs were running (load average about 15 on 96 threads), so differences of a few per cent are not significant.

Checks

  • Attribution: the commit and the PR body end with the repository line, with no trailer and no emoji.
  • scripts/check_test_coverage.py: OK (446 files).

Underworld development team with AI support from Claude Code

Two tests asserted on each rank's own part of a quantity that is only
meaningful over the whole mesh. The boundary-residual test summed the
continuity-row term over the rank's own entries, so a rank holding no
facet of the wall read 0 against -1/6, failed, and left the other rank
alone in the next collective call. The comparison with the essential
solution took the L2 difference over the rank's own nodes, which at
np 4 read 1.587e-3 on one rank against the bound of 1.5e-3.

Both now reduce over every rank before asserting, and the comparison
with the penalty solution uses the same helper. The docstring of the
Nitsche comparison gives the bound the test asserts (1.5e-3). Serial
values are unchanged: 1.1704e-03 and 1.5155e-03; 10 passed.

Found by the parallel check of this branch at np 2 to 4 on a 96-thread
Linux workstation; not run on more than one rank here.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

At 321cdda: the two tests named in the parallel check above now reduce over every rank. Tests only; no library file changed.

  • test_the_boundary_residual_diagnostic_returns_the_continuity_row_term: the momentum rows' largest entry and the continuity rows' sum are reduced over every rank before either is asserted, so a rank that holds no facet of the wall makes the call, joins the reduction and asserts the same number.
  • test_nitsche_matches_essential: the two sums of squares are reduced over every rank, and the docstring gives the bound the test asserts (1.5e-3). test_penalty_matches_essential had the same per-rank form and uses the same helper. The sums run over each rank's local nodes, so a node held by two ranks is counted by both; on more than one rank the number is close to the serial one, not equal to it.

Serial, on macOS (12-core Apple M4): 10 passed, with 1.1704e-03 (Nitsche) and 1.5155e-03 (penalty) unchanged. Not run by us on more than one rank; the re-check at np 2 to 4 is the parallel desk's.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Re-check at 321cdda (tests only): READY. Both conditions are met. test_1060 passes on every rank at np 1 to 4, under the natural partition and the band layout, and the matched-solution bounds keep their margin. Measured by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)) on the e4f879c build with 321cdda's test_1060, the only file changed. MPI jobs ran under the supervisor.

np, layout test_1060 (every rank) Nitsche vs essential (bound 1.5e-3) penalty vs essential (bound 1e-2)
1 10 passed 1.1704e-3 1.5155e-3
2 natural 20 passed (10 per rank) 1.1387e-3 1.4849e-3
2 band 20 passed 1.1192e-3 1.4661e-3
3 band (rank 1 holds no wall facet) 30 passed 1.1185e-3 1.4831e-3
4 natural 40 passed 1.0967e-3 1.4580e-3
4 band (ranks 1 and 2 hold no wall facet) 40 passed 1.0630e-3 1.4637e-3
  • The diagnostic test reduces both walls over every rank. It passes at every layout, including ranks with neither wall, with no MPI stop and no hang.
  • The double-counting W1 warned of. The parallel value of the Nitsche difference drifts down from the serial 1.1704e-3, to 1.063e-3 at np 4 band: shared nodes count more than once, and the drift is about 9 %. The margin against 1.5e-3 is at least 22 % at every layout, and the drift moves away from the bound. So the local-node form is adequate here; the owned-node form would make the number partition-independent if that is wanted later.
  • The penalty comparison is far inside its 1e-2 bound.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 90e686d into development Nov 13, 2026
10 checks passed
lmoresi pushed a commit that referenced this pull request Nov 13, 2026
…pressure adjoint (#1143)

Since #1145 a Stokes Nitsche condition's continuity-row term fn_p, -(n.d)(u.d - g), is
assembled on the pressure field. A parameter in a normal datum enters it, and its part
of the gradient is d(fn_p)/dm tested against the pressure adjoint lam. Without it, a
normal datum's gradient was 2.85e-5 against a central difference of 1.68e-3. Now they
agree to 1e-6. Called without lam, sensitivity refuses, naming lam, instead of dropping
the term; the decision depends on the condition and the arguments alone, so it is the
same on every rank.

Underworld development team with AI support from Claude Code
jcgraciosa pushed a commit to jcgraciosa/underworld3 that referenced this pull request Nov 17, 2026
…ed Nitsche condition

The curved-boundary page recommended Nitsche with gamma=10 for free slip.
The project ruling is rotated strong free slip first, Nitsche for a
condition that must change during the run. The page now leads with
add_rotated_freeslip_bc, says what gamma does and what to choose it
against, and its Nitsche numbers on the Cartesian box are rerun on the
code with the continuity-row term assembled (underworldcode#1072, underworldcode#1145).

The Nitsche row of the elliptical-annulus comparison is removed: a rerun
does not reproduce it, and the methods split into two groups on that
geometry (stated on the page).

adaptive-meshing: the ruling is stated, and the Nitsche diagnoses made
before underworldcode#1145 are marked as not re-verified.

free-surface-convection: a link into a session memory is replaced by
what local_h does.

Underworld development team with AI support from Claude Code
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