Skip to content

Stokes_Constrained: keep the section's symmetries when the multipliers are pinned (P3 velocity 26% low) - #1250

Merged
lmoresi merged 1 commit into
developmentfrom
bugfix/constrained-stokes-p3
Nov 20, 2026
Merged

lmoresi merged 1 commit into
developmentfrom
bugfix/constrained-stokes-p3

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 20, 2026

Copy link
Copy Markdown
Member

Stokes_Constrained with a P3 velocity was wrong by about 26%; the rebuilt section lost its field symmetries.

Found by H1 (the session that reviews pull requests) in item 3 of the review of #1200, and present on development. Not filed: the maintainer asked for it to be fixed directly, so this text is the report.

The defect

Holding the side walls' normal velocity by add_constraint_bc poses the same problem as holding it by add_essential_bc((0.0, None), ...).

  • With a P2 velocity the two agree to 7 digits.
  • With a P3 velocity the constrained solve was far too slow.

Unit box, Bottom no-slip, Left and Right normal held, body force (0, cos(πx)(1+y)), P3 velocity and P2 pressure, on development:

mesh essential walls, max |v| constrained, P2 multiplier constrained, P3 multiplier
4 × 4 quads 0.11617866 0.08603145 0.08603164
simplices, cell size 0.25 0.11619834 0.05927407 0.05927501

How the deficit behaves:

  • Either wall: constraining only Left, or only Right, gives the same deficit.
  • Refinement: it doesn't close the gap. At 8 × 8 it is 0.0813 against 0.1168.
  • Quadrature: degree 6 changes nothing.
  • The constraint itself holds: the wall normal velocity is 1e-8 with a P3 multiplier.
  • The interior is wrong: the wall's tangential velocity is jagged from node to node (0.0043, 0.0094, 0.022, … against 0.0045, 0.016, 0.031, … for the essential walls).

The cause

_constrain_interior_multipliers_in_section pins the multipliers' dofs away from their boundary. It does this by building a new local section, field by field, from the old one, then calling dm.setLocalSection. It copied the dofs and the constraints, but not the section's symmetries.

A field's symmetry (PetscSectionSym, set from the dual space when the DS builds the section) orients the dofs of a point that a cell sees in reversed orientation.

  • A P2 edge has one dof, so it needs no symmetry; P2 is unaffected.
  • A P3 edge has two dofs. Without the symmetry, every cell next to an edge it sees reversed read that edge's two velocity dofs in the wrong order. On quads and on simplices alike, that is most interior edges.

With the reduction switched off (_reduce_interior_multiplier = False), the P3 constrained solve equals the essential solution. That isolates the cause to the rebuilt section.

The fix

A small cdef helper, copy_section_symmetries(source, target), in petsc_extras.pxi. It copies the section-level symmetry and each field's symmetry (PetscSectionGet/SetSym, PetscSectionGet/SetFieldSym; petsc4py does not expose them). The reduction calls it before setUp().

The other places that build a section by hand (fault_split, _vertex_section_dm, the smoothing graph) hold cell or vertex values only, so they have no multi-dof points to orient.

After the fix, as relative max velocity differences, constrained against essential:

mesh P2 multiplier P3 multiplier
quads 1.6e-6 1.1e-7
simplices 1.9e-6 9.7e-8
  • For comparison: the P2-velocity pair gives 1.5e-7 and 1.7e-7.
  • The default P2 multiplier holds a P3 trace only weakly: the wall normal velocity is 7e-6 where the P3 multiplier gives 1e-8. That is why its gap is 2e-6 and not 1e-7. This is a property of the discretisation, not a defect.

Test

tests/parallel/test_1200_constrained_stokes_p3_velocity_parallel.py, tier B, in batch 3 of scripts/test.sh. It compares the whole constrained velocity field against the essential-wall field, for quads and simplices, and for P2 and P3 multipliers. The tolerance is 1e-6 of the scale for the P3 multiplier and 1e-5 for the P2.

  • On development: all 4 cases fail (the numbers in the first table).
  • With the fix: they pass at np 1, 2 and 4.

Also in this PR

The SolverReset docstring now says that discretisation() (and so conditions()) drops the nullspace objects, a nit from the review of #1203.

Runs

  • The new test, with test_1169 (resets) and test_1167 (constrained, discontinuous pressure): np 1 (15 passed, 1 skipped), np 2, 3 and 4 (16 passed each). The branch is merged with development at c902390.
  • Serial constraint, Stokes, rotated, nullspace and fault files:
    • 745 passed, 2 xfailed, 1 skipped (a gmsh mesh that differs on this host).
    • Two exceptions:
      • test_1183 couldn't be collected on the build from before the merge. It passes on the rebuilt tree.
      • test_1061 failed; see the side finding below.
  • The coverage check passes.

Side finding, not this PR: test_1061_stress_forward_history::test_the_forward_history_with_its_read_back_smoothing_holds_the_maxwell_start_up fails on this host.

  • The failure: abs(0.5265 - 0.5185) = 0.0080, against a tolerance of 0.003, in 67 minutes. It failed twice, on the build before and after the merge.
  • Why not this PR: it solves NavierStokes without constraint conditions, so the changed section rebuild returns before it does anything.
  • Gating: the file is tier C, level 3, and its own marker says "reported not gated".
  • Development alone: not run here (over an hour per run on a shared machine).

Measured on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH).

Underworld development team with AI support from Claude Code

…s are pinned

The section rebuilt to constrain the multipliers' interior dofs copied dofs
and constraints field by field but not the field symmetries, which orient
the dofs of a point a cell sees reversed. A P3 edge has two dofs, so every
cell next to a reversed edge read its velocity in the wrong order: the
constrained solve with a P3 velocity was 26% below the essential-wall one
(found in the review of #1200). copy_section_symmetries gives the new section
the old one's. Also: the SolverReset docstring says discretisation() drops
the nullspace objects (#1203 review nit).

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 20, 2026 02:34

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 20, 2026

Copy link
Copy Markdown
Member Author

Review from the Underworld development team with AI support from Claude Code (H1: review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH))
(H1 is the session that reviews pull requests and runs the parallel tests.)

Verdict on 76c55a0: ready to merge on green from this review.

  • The cause is right, and so is the fix. With the section's symmetries copied, a P3 velocity held by the constraint is the essential-wall solution. That holds on quads and simplices, with a P2 or a P3 multiplier, at np 1, 2 and 3, and on a mesh where two of three ranks hold no cells.
  • P2 results do not change. Every P2 case is bit-identical to development.
  • No blocking findings. Three low-severity notes follow.

How it was run

Builds:

  • This branch: a fresh build of 76c55a0 in its own worktree. The three .pyx files that include petsc_extras.pxi were touched before the build. generic_solvers.so is dated after the touch, and it contains the new PetscSectionSetFieldSym calls.
  • Development: the PR's merge base, c902390, on a build of exactly that commit. Its installed Python matches its source.

Every parallel run was under the MPI supervisor with a timeout, pinned to four cores.

Findings

  1. Low: A stale comment in the new test. The tolerance comment says the default P2 multiplier leaves "the wall normal velocity is 7e-6". That is development's figure: we measure 7.4e-6 on development and 1.9e-7 on this branch (quads), 2.2e-7 (simplices). The tolerance itself is fine; only the number in the comment is from before the fix.

  2. Low: A stale line in _constrain_interior_multipliers_in_section's docstring. The scatter-back note says the multiplier index set "(for a scalar h, 1 dof/point) appends the local offset of every h-bearing point". Since Stokes_Constrained with a discontinuous pressure: copy every unknown of each field back (#1167) #1200, get_local_field_is takes every dof of each point, which is what makes a P3 multiplier (two dofs per edge) copy back correctly. Worth a one-line update while this function is open.

  3. Low: Not tested in 3-D. The symmetries also orient multi-dof faces in 3-D (P3 and up). The copy is generic, so it should cover them, but neither the new test nor our runs exercise a 3-D constrained P3 case. A follow-up test would pin it down; it is not needed for this PR.

1. The #1200 probe: constraint against essential walls

Setup:

  • one mesh per case;
  • Bottom no-slip;
  • Left and Right held normal, either by add_constraint_bc or by add_essential_bc((0.0, None), ...);
  • body force (0, cos(pi x)(1 + y)), tolerance 1e-10.

Measured: max |v| for each solve, and the L2 norm of the difference of the two velocity fields relative to the essential field's L2 norm. This branch's figures are identical at np 1, 2 and 3:

mesh, velocity multiplier development max |v| development rel. L2 this branch max |v| this branch rel. L2 essential max |v|
quads 4x4, P3 P2 (default) 0.08603145 2.8e-1 0.11617864 2.8e-7 0.11617866
quads 4x4, P3 P3 0.08603164 2.8e-1 0.11617865 5.9e-8 0.11617866
simplices, P3 P2 (default) 0.05927407 4.9e-1 0.11619832 4.7e-7 0.11619834
simplices, P3 P3 0.05927501 4.9e-1 0.11619834 4.6e-8 0.11619834
quads 4x4, P2 P2 0.11688890 9.3e-8 0.11688890 9.3e-8 0.11688890
simplices, P2 P2 0.11660111 7.8e-8 0.11660111 7.8e-8 0.11660112
  • Development: the figures are identical at np 1, 2 and 3, so the error was never partition-dependent.
  • Wall normal velocity on this branch: about 1e-8 with a P3 multiplier, and about 2e-7 with the default P2 multiplier.

Rank with no cells: we used the region held by rank 0 from test_0786 (42 cells; at np 2 and 3 the other ranks hold none), with a P3 velocity:

  • Development: constrained max |v| 0.00074499 against 0.00121739 essential (rel. L2 0.42), at np 1, 2 and 3.
  • This branch: 0.00121739 against 0.00121739 (rel. L2 5.5e-6 with the P2 multiplier, 3.2e-7 with the P3), the same at np 1, 2 and 3.

The rebuild and setUp() run on every rank, the empty ones included, with no hang.

2. No regression for P2

We reran the eight-case bit-identity comparison from the #1200 review, twice per build at np 1 and 2. It covers:

  • Stokes P2/P1 on simplices and quads, including residual fields and adjoint;
  • Stokes_Constrained with a continuous P1 pressure;
  • a discontinuous pressure;
  • 3-D;
  • rotated free slip;
  • the multigrid path;
  • one constrained P3-velocity case.

Results:

3. The symmetry copy

copy_section_symmetries copies the section's own symmetry and each field's, for every field of the old section (velocity, pressure and every multiplier):

  • Field count: Snew is built with setNumFields(Sold.getNumFields()), so the counts match.
  • A missing symmetry: a field with none gives NULL, and PetscSectionSetSym(target, NULL) simply leaves the target without one. P1/P2 scalar fields hit this path, and they are among the bit-identical cases above.
  • Communicator: PetscSectionSetSym references the symmetry, and checks that it shares the section's communicator. Snew is created on dm.getComm(), as Sold is.
  • Order: the copy is made before setUp(), which is where a section reads its layout.

The rebuild was the only place in the solvers that builds a DOF section field by field for an FE field. The other PETSc.Section().create sites hold vertex or cell data only.

4. Collectives

PetscSectionGet/SetSym and PetscSection.setUp() are not collective. The rebuild is reached on every rank, after the existing allreduce that decides whether any rank has interior multipliers to pin. The empty-rank runs above confirm this at np 2 and 3. So does test_0786 at np 3 (5 passed), which includes a constrained solve beside a rank without cells.

5. The SolverReset docstring line

It is accurate. _reset_discretisation calls _reset_stokes_nullspace and clears the constant nullspace object, and conditions() ends with _reset_discretisation(). So the nullspace objects go with the DM in both scopes.

What was run

run result
test_1200_constrained_stokes_p3_velocity_parallel.py, this branch, np 1 / 2 / 3 / 4 4 passed at each
the same test, development, np 2 4 failed (max |v| 0.0860 / 0.0593 against 0.1162)
constraint and Stokes test files, serial, this branch 125 passed
np 2 slice: test_0786, test_1017_custom_mg, test_1062, test_1063, test_1069, test_1167, test_1169 33 passed, 2 skipped (serial-only cases)
test_0786 at np 3 5 passed
P3 probe, both builds, np 1 / 2 / 3; empty-rank probe, both builds, np 1 / 2 / 3; bit-identity, both builds, np 1 / 2 (twice) as above

The 22 serial files were 0033, 0062, 0786, 0818, 1010, 1011, 1012, 1013 (x2), 1014 (x2), 1017, 1019, 1023, 1024, 1050, 1061, 1062, 1063, 1064, 1065 and 1066. They ran with -m "not tier_c" and three workers.

Not run:

  • 3-D constrained P3;
  • np above 4 (core budget on a shared machine);
  • macOS.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit bc59ebf into development Nov 20, 2026
10 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.

3 participants