Skip to content

Pair boundary quadrature points by face orientation on 3-D triangular faces (#1188) - #1195

Merged
lmoresi merged 5 commits into
developmentfrom
bugfix/boundary-quadrature-face-orientation-1188
Nov 15, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
bugfix/boundary-quadrature-face-orientation-1188

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

What this fixes

In 3-D, PETSc's boundary residual, boundary Jacobian and boundary integral pair two different points on a triangular face whose orientation in its cell is not 0. They read the coordinates at the physical point of face quadrature point q, and the basis and fields at the cell's tabulation point q. A triangle has six orientations. A refined mesh puts about a fifth of its wall faces at orientations other than 0, and an interior face assembled from its second cell sits at a negative one. On those faces, a term written in the coordinates (a load, a radial normal) is evaluated at one point and spread with the basis of another. The total of a load stays right but its moments do not, and an internal load depends on which of a face's two cells assembles it. In parallel, the partition decides which cell that is. 2-D is not affected: an edge has only two orientations, and the reversal PETSc applies is correct for it.

Issue #1188 has the diagnosis and a PETSc-only reproducer.

The change

src/underworld3/cython/uw_face_orientation.h wraps PETSc's own three boundary integrators (integratebdresidual, integratebdjacobian, integratebd) on each FE of a 3-D simplex mesh.

  • For each face at orientation o != 0, it rewrites the face's affine map so that face quadrature point q lands at the physical point of the cell's tabulation point q, and sets the face's orientation to 0.
  • It then calls PETSc's integrator and restores the face.
  • The six orientation maps come from PETSc's reference triangle (DMPlexOrientPoint on it).
  • Only the physical point reads the rewritten map. detJ and the normal are per face, and gradients use the support cells' Jacobians.
  • Faces at orientation 0 and 2-D meshes go through PETSc unchanged.
  • PETSc's integrators are wrapped, not copied: the jet evaluation they call is internal to PETSc. The wrapper stays correct over a PETSc that fixes the pairing, because it hands every face over at orientation 0.

It is installed after each createDS in the scalar, vector, multi-component and Stokes solvers, and on the BdIntegral sandbox. The coarse multigrid levels and the adjoint share these FE objects.

The install refuses two cases with PETSC_ERR_SUP, collectively on the mesh's communicator. The ranks first agree whether the mesh is a simplex mesh, since a rank with no cells does not see one:

Inside the wrapper, PETSc-internal assertions check what the install guarantees: affine faces, an auxiliary field on the cells, and orientations in range before any face is changed.

The TODO(BUG) on internal natural conditions in petsc_generic_snes_solvers.pyx described this defect: the 0.027 % in #265 was the 3-D internal-boundary shell. It is replaced by a statement of what now holds. docs/developer/guides/boundary-condition-rulings.md gains a paragraph saying the same, and that hexahedral faces are not covered.

Tests

tests/test_1188_boundary_terms_on_rotated_faces.py (level 1, tier B) has five checks. Each first asserts that its fixture has faces at orientations other than 0.

check exact value tolerance development (aee3fa6)
natural load f = x on the Top wall of a refined unit cube: b.x / b.1 2/3 1e-13 absolute 0.66567
Jacobian of f = x T, boundary part alone: (x.Mx) / (1.M1) 1/2 1e-13 absolute 0.49899
BdIntegral of T x with T = x over Top 1/3 1e-13 absolute 0.33283
Nitsche, radial normal, refined shell: rigid-rotation residual 0 1e-12 of the radial residual 1.5e-2
load on the Internal surface, supports of every Internal face swapped unchanged 1e-14 of the largest load 534 of 534 loaded nodes moved, up to 9.4e-3 against 1.9e-2

The test was committed first (35583db), and all five fail on development. The file runs serially and, from scripts/test.sh, under mpirun at np 4. A rank may hold none of a boundary's faces, so counts and maxima are taken over all ranks.

Coordinate matches: none in the library. The swap test compares rows by position after asserting that the two coordinate arrays are exactly equal, since both builds use one mesh. The internal-surface faces are selected by boundary label.

Not covered by the Python tests:

Measured, one rank, conda-forge PETSc 3.25.3, macOS on a 12-core Apple M4 (serial runs only)

  • PETSc-only reproducer with the wrapper, 135 runs. Largest error over the exact moments, for walls that are whole planes:

    walls runs development this branch
    exterior, orientations 0 to 2 45 5.2e-3 9.4e-16
    interior, with negative orientations 33 1.6e-2 7.8e-16
    interior, positive orientations only 6 6.5e-4 7.8e-16
    interior, all at 0 3 3.3e-16 3.3e-16

    2-D is unchanged.

  • Unit cube, natural load against the exact integral: 163 of 369 nodes wrong at refinement 1 and 864 of 1409 at refinement 2 on development. None are wrong on this branch.

  • Nitsche with a radial normal, rigid rotation on a shell: 1.5e-2 to 2.9e-16 at refinement 1, and 9.2e-3 to 5.4e-16 at refinement 2. The face-normal and default-normal results are unchanged.

  • Kramer, Davies & Wilson (2021), delta-forced Stokes on a shell with an internal surface (l = 2, m = 0, free boundaries):

    refinement velocity rms rel. error, development / this branch pressure, development / this branch Newton / outer Krylov, development / this branch
    1 1.2511e-1 / 1.2547e-1 6.1714e-1 / 6.1865e-1 1 / 3, 1 / 3
    2 4.8330e-2 / 4.8407e-2 4.5496e-1 / 4.5546e-1 1 / 8, 1 / 6

    The errors move by about 0.3 % of themselves. Discretisation error dominates this benchmark, so it does not show the defect, and no result we have published moves.

  • Cost: the boundary share of assembly (with loads on all three shell surfaces minus without), best of 5, at refinement 2 (153472 cells, 19200 boundary faces, 6270 not at 0):

    development this branch whole assembly
    Jacobian 11.76 s 11.79 s 108 s
    residual 0.20 s 0.19 s 4.4 s

    These are laptop wall times, and the differences are within the run-to-run spread.

  • Suites: 186 passed across the 3-D boundary, shell, Nitsche, rotated free-slip, multigrid, adjoint and boundary-flux files, and test_0052 (collective guard scan). check_test_coverage.py and check_deprecated_patterns.py pass.

Probes and outputs are in the campaigns repository, under issue-sweep/internal-face-orientation/ (including sideload/). The draft PETSc report, with this as its proposed fix, is under upstream/ and has not been sent.

Parallel

H1 (the session that runs our parallel checks on a 96-thread Linux workstation, MPICH) ran the branch at np 1 to 8. Its review is on this PR.

H1 set two conditions, both fixed in 5332029:

  • the test file segfaulted under mpirun on a rank with no faces of a boundary;
  • the triangle refusal returned early on a rank with no cells.

Issues

Underworld development team with AI support from Claude Code

Five exact checks of boundary terms on faces not at orientation 0 in their
cell: the first moment of a natural load, the moments of its Jacobian, the
moment of a boundary integral, a Nitsche condition with a radial normal under
a rigid rotation, and an internal load assembled from either support cell.
All five fail on development (aee3fa6): 0.66567 for 2/3, 0.49899 for 1/2,
0.33283 for 1/3, 1.5e-2 of the scale, and 534 of 534 loaded nodes moved.

Underworld development team with AI support from Claude Code
… faces (#1188)

PETSc's boundary residual, Jacobian and integral pair the physical point of
face quadrature point q with the cell's face tabulation at q (reversed for a
negative orientation). On a triangular face at any orientation other than 0
the two are different points, so a term written in the coordinates is
evaluated at one point and spread with the basis of another.

uw_face_orientation.h wraps PETSc's own three integrators on each FE of a 3-D
simplex mesh. For each face at orientation o != 0 it rewrites the face's
affine map so that q lands at the point of the cell's tabulation, hands the
face over at orientation 0, calls PETSc's integrator and restores the face.
The orientation maps come from PETSc's reference triangle. Faces at 0 and
2-D meshes are untouched. The install refuses, on every rank together, a 3-D
mesh with coordinates of degree other than 1 and a face cell type other than
a triangle.

The TODO(BUG) on internal natural conditions in the SNES solvers described
this defect (the 0.027 % of #265 was the 3-D internal-boundary shell); it is
replaced by a statement of what now holds.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 15, 2026 09:44

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

Copy link
Copy Markdown
Member Author

Adversarial review record, pre-PR. A fresh reviewer read the diff against the PETSc 3.25.3 and main sources (febasic.c, fe.c, fegeom.c, plexfem.c, dtds.c, dmfield.c) and ran its own probes. We applied its findings before the PR; each is listed with what was done.

  1. The source was unbuilt when reviewed. Rebuilt, and every result in the body is from the rebuilt env.
  2. The replacement for the TODO(BUG) overclaimed partition independence. It is narrowed to "the same from either cell".
  3. The tests did not check that their fixtures have faces at non-zero orientations. Each test now asserts it, and the swap test asserts that every Internal face is negative after the swap.
  4. Negative orientations reach the Jacobian and integral only through the C reproducer. This is named in the body.
  5. An unknown face cell type fell through silently. The install now refuses it, collectively.
  6. Aux-field gate. An auxiliary-field gate covered only some paths, and a check inside the wrapper could fail on one rank only. The gate is removed. The checks inside the wrapper are PETSc-internal assertions of invariants the install guarantees.
  7. A NULL original integrator would crash. The install refuses it.
  8. The orientation range was checked inside the remap loop. It now runs over all faces before any face changes.
  9. Hexahedral faces were not recorded. They are named in the header, the guide, the body and on 3-D boundary terms that depend on position are integrated with mispaired quadrature points on faces not at orientation 0 (refined meshes; interior surfaces at partition seams) #1188.
  10. The coordinate-degree check precedes the simplex check. Kept deliberately, so a rank with no cells still joins the collective refusal. It is unreachable since Mesh coordinates are degree 1: a mesh refuses any other degree (#978) #1088.

Confirmed by the reviewer:

  • the map is T_o, not its inverse;
  • the dispatch, including the Jacobian's FE lookup key.field / Nf, matches fe.c;
  • the coarse multigrid levels and the adjoint share the wrapped FE objects.

Points the hub raised, answered before the PR:

Issue state:

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

Verdict: READY with conditions at 7cc95a1. The fix does what it says in parallel. On the #1150 shell, np 8 now matches np 1 to round-off, including the face whose two cells sit on different ranks. Two random partitions that split up to 478 of the 540 Internal faces also match np 1 to round-off. 2-D is bit-identical to development. The conditions are small:

  1. The new test file crashes (SEGV) under mpirun at np 2 and above, on development too, because its fixture helper is not safe on a rank that holds no faces of the boundary. Guard the helper, or mark the file serial-only.
  2. The triangle-quadrature refusal is not collective on a rank that holds no cells. This path cannot be reached through underworld3 today. Either make the refusal collective or correct the comment that says it is.

Parallel review by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)), at 8 cores. Logs are kept by the reviewer.

Builds.

  • Branch: 7cc95a1.
  • Development arm: development 4b782b2, not the merge base aee3fa6. Between them, development changed only Python (the facet restore, the locator fallback, isSimplex agreed over ranks, the TI director, style gates). None of it is compiled code, assembly, or a file this PR touches.
  • The two builds give bit-identical internal loads at np 1, where every Internal face is at orientation 0 (5405 of 5405 nodes equal).

1. The PR's five tests

Serial, on the branch: 5 passed in 18 s.

Serial, on development (the branch's test file run on the development build): all 5 fail, as the PR says.

check development branch, np 2 / 4 / 8
natural load, ratio − 2/3 −9.97e-4 1.1e-16 / 0 / 0
natural Jacobian, ratio − 1/2 −1.01e-3 −2.2e-16 / 0 / −6.7e-16
BdIntegral, value − 1/3 −4.99e-4 1.7e-16 / 2.8e-16 / 2.2e-16
Nitsche radial normal, rotation / scale 1.46e-2 9.0e-16 at every np
Internal support swap, change / largest load 4.5e-1 (8.7e-3 against 1.9e-2) 5.4e-16 at every np

Parallel, file as committed: SEGV at np 2 and np 4, on both builds.

  • _orientations() calls getStratumIS(...).getIndices(), and the call crashes on a rank that holds no faces of Top. At np 2, rank 0 holds no Top faces: it dies there, while rank 1 has already counted 10 rotated faces of 56.
  • Development crashes in the same place: the helper is new in this file, so this is a test defect and not a library one.
  • The file is tier B, level 1, and not named _parallel, so CI probably runs it serially only. It should still not segfault under mpirun.

Parallel, with a parallel-safe copy. The table's np 2 / 4 / 8 columns come from a copy of the file with the test logic unchanged and these edits:

  • empty-IS guards in the fixture;
  • global (allreduce) counts of rotated faces, and allreduced maxima in the Nitsche and swap checks;
  • the swap applied only to faces with two local support cells (there were none with one at np 2 to 8 on this cell size 0.3 shell).

With those edits, all 5 pass at np 2, 4 and 8 with no change in tolerance.

The swap test on its own cannot reach a partition seam: on this mesh no Internal face is split at np ≤ 8. Section 2 covers the seam.

2. #1150's probes, np 1, 2, 4 and 8, both builds

Internal load by node (internal_load_by_face.py, cell size 0.2, 3241 cells, 540 Internal faces, 5405 velocity nodes; largest nodal load 1.0046e-2). Each run is compared with np 1 of its own build; nodes are matched by the exact bytes of their coordinates.

layout Internal faces split across ranks development: nodes > 1e-12 rel / max abs diff branch: nodes > 1e-12 rel / max abs diff
np 2, default 0 0 / 5e-20 0 / 5e-20
np 4, default 0 0 / 1.6e-19 0 / 5.4e-20
np 8, default 1 6 / 2.016e-4 (all 6 on the split face) 0 / 4.3e-19
np 4, random partition, seed 1 403 734 / 2.52e-3 0 / 5.2e-18
np 8, random partition, seed 1 478 810 / 3.39e-3 0 / 5.2e-18
np 4, random partition, seed 2 400 750 / 2.97e-3 0 / 5.2e-18
np 8, random partition, seed 2 459 812 / 3.00e-3 0 / 5.2e-18
  • The split face at np 8: on development its 6 nodes move by up to 2.0e-4 against node loads of about 2e-3, the same numbers as the Stokes_Constrained on a 3-D shell: np 8 differs from np 2 and 4 by 1.55e-5 (velocity L2), independent of solver tolerance (#651 item 1) #1150 reference. On the branch the largest difference on those 6 nodes is 4.3e-19 (4e-17 of the largest load). That is summation order: 85 of 5405 nodes are not bit-equal, all at the 1e-19 level.
  • Random partitions: these come from the shell-partition hook, which assigns gmsh-mesh cells at random under MPI. On development they move a third of the largest load. On the branch the worst node over all four runs differs by 5.2e-18 (5e-16 relative).

Multiplier unknowns and residual moments (multiplier_unknowns_by_rank.py, sections A to E).

  • Sections A to D are line-for-line identical between the two builds at np 1, 2, 4 and 8.
  • Section E, first velocity moment with every field zero (the load):
np 1 np 2 np 4 np 8
development 2.736318375214e-01 same same 2.736372332814e-01
branch 2.736318375214e-01 same same 2.736318375214e-01
  • On development, np 8 differs from np 1 by 5.4e-6 absolute in the first moment, and by 2.8e-6, 1.2e-7 and 7.2e-7 in the other three, as in the reference.
  • On the branch, all four zero-state velocity moments and the smooth-state velocity and pressure moments agree with np 1 at np 2, 4 and 8 to all 13 printed digits.

The #1150 headline solve (Stokes_Constrained, 3-D shell with an Internal surface, cell size 0.2, l = 2 load on Internal, multiplier free slip on both walls, tolerance 1e-7):

build, np L2 Ut Ub Lz
development, 4 1.8397226813e-02 1.0091610148e-02 1.2178638541e-02 −9.803e-07
development, 8 1.8396941062e-02 1.0091476784e-02 1.2178428079e-02 −1.067e-06
branch, 4 1.8397226818e-02 1.0091610162e-02 1.2178638531e-02 −9.803e-07
branch, 8 1.8397226489e-02 1.0091609845e-02 1.2178638307e-02 −9.803e-07

3. 2-D against development, np 2 and 4

Two cases:

  • Box: unit square, cell size 0.05, P2/P1. A traction (x sin πx, −cos πx) on Top, no slip on Bottom, Nitsche free slip on Left, and penalty free slip on Right (1e4 u_x).
  • Annulus: radii 0.5 and 1, cell size 0.05. A radial load cos 2θ on Upper, Nitsche with the radial normal on Upper, and no slip on Lower.

Results:

  • The assembled residual is bit-identical between the builds at np 2 and np 4, in both cases. This holds for the velocity and pressure rows, at the zero state (the load) and at a fixed smooth state (u = (sin 3x cos 2y, x y²), p = cos(x + 2y)), which brings in every Nitsche and penalty term.

  • The solved velocity and pressure are bit-identical at np 2.

  • At np 4 the solved fields are not reproducible from run to run on either build. Two development runs differ by:

    • box: 1.7e-15 in velocity and 1.5e-14 in pressure;
    • annulus: 6e-14 in velocity and 3.8e-8 in pressure.

    The branch varies by the same amounts. A development run and a branch run of the annulus at np 4 came out exactly equal. So the np 4 differences are solver nondeterminism, present before this PR, and not a 2-D change.

  • That annulus pressure at 3.8e-8 run to run is worth a separate look; it is not this PR.

4. Install-time refusals on a rank with no cells

There are three refusals, all PETSC_ERR_SUP (56):

  1. 3-D coordinates of degree other than 1;
  2. a face quadrature that is not on a triangle;
  3. a PetscFE without PETSc's boundary integrators. This one cannot be reached and was not triggered.

How they were triggered:

  • Mesh: a 3-D UnstructuredSimplexBox(cellSize=0.5, regular=False) at np 8. Its default partition leaves no rank empty (11 to 13 cells per rank), so the empty-band layout was used: cells per rank [22, 15, 3, 18, 4, 16, 22, 0].
  • Directly: UW_DMPairFaceQuadratureByOrientation is exported from the solver extension module, so it was called by symbol on a clone of the mesh DM.
  • Through a solver: the same refusal was also reached by building a Stokes solver on that mesh after making its coordinates degree 2.
case default layout, np 8 empty-band layout, np 8 (rank 7 empty)
control (P1 simplex FE) 0 on all 8 0 on all 8
coordinate degree 2, direct 56 on all 8 56 on all 8, including the empty rank
coordinate degree 2, through Stokes._build() 56 on all 8, as a RuntimeError from CHKERRQ 56 on all 8, including the empty rank; no hang (3 repeats)
tensor-cell FE (quadrilateral face quadrature), direct 56 on all 8 56 on ranks 0 to 6; 0 on the empty rank 7
  • The coordinate-degree refusal is collective, as claimed. Every rank, including the empty one, raises "Boundary terms on a 3-D mesh need coordinates of degree 1, not 2: curved faces are not paired (3-D boundary terms that depend on position are integrated with mispaired quadrature points on faces not at orientation 0 (refined meshes; interior surfaces at partition seams) #1188)". Nothing hangs.
  • The triangle refusal is not collective on a rank that holds no cells.
    • DMPlexIsSimplex is rank-local and returns false on a rank with no cells. That rank returns before it reaches the check, while every other rank raises.
    • In a real run, that rank would go on into the next collective alone and hang.
    • Underworld3 cannot reach this today: its FEs are built from the mesh's agreed isSimplex, so on a 3-D simplex mesh every face quadrature is a triangle.
    • The PR body says the refusals are "collectively on the mesh's communicator". The header comment says the empty rank "installs nothing", which is true, but it does not say that this rank also skips the triangle refusal.
    • Two fixes: agree simplex over the communicator (a logical-or allreduce) before the early return, or narrow the claim to the coordinate-degree check.
  • One run hung, and it was the reviewer's harness, not the PR. In the first empty-band attempt only rank 0 raised and the others hung. Rank 0 had failed in the solver's compile step, not at the install. That happens whenever the partition hook is active and the compile cache is cold: the same failure appears with no degree change at all. With a warm cache all 8 ranks raise the install refusal identically.

5. Custom multigrid on a refined 3-D shell

The case:

  • SphericalShell(radiusInner=0.55, radiusOuter=1.0, cellSize=0.3, refinement=1, qdegree=3): 5912 cells, two levels.
  • Stokes, P2/P1, an l = 2 radial traction on Upper (natural), no slip on Lower.
  • set_custom_fmg(..., builder="barycentric", field_id=0), with ksponly and tolerance 1e-9.
  • The quantities are integrals over the whole mesh.
build, np velocity MG its (outer) L2 ∫ u·(x², y², z²) ∫ u_r P2(cos θ) ∫ p z²
development, 1 8 (1) 1.197510890356e-01 −1.586140340e-04 −4.189956629075e-02 2.299394503093e-01
development, 4 8 (1) 1.197510890361e-01 −1.586140334e-04 −4.189956629156e-02 2.299394503094e-01
development, 8 8 (1) 1.197510890357e-01 −1.586140345e-04 −4.189956629079e-02 2.299394503095e-01
branch, 1 8 (1) 1.197833831118e-01 −1.438541226e-04 −4.192641680349e-02 2.306359418350e-01
branch, 4 8 (1) 1.197833831123e-01 −1.438541221e-04 −4.192641680431e-02 2.306359418352e-01
branch, 8 8 (1) 1.197833831121e-01 −1.438541231e-04 −4.192641680367e-02 2.306359418353e-01
  • On the branch the solution is the same at np 1, 4 and 8: 4e-12 relative in L2 and 7e-9 in the small second moment, the same spread as development.

  • The iteration counts do not change: 8 multigrid iterations on the velocity block at every np, on both builds.

  • The branch moves the answer away from development:

    • L2 by 2.7e-4 relative;
    • the l = 2 radial response by 6.4e-4;
    • the pressure moment by 3.0e-3;
    • the small x²-weighted moment by 9 %.

    On a refined shell about a fifth of the Upper faces sit at orientations 1 and 2. On those faces development spreads the load with the wrong basis, at every np.

  • On the coarse levels there is no boundary assembly to correct.

    • The custom hierarchy gives each coarse DM the solver's fields and DS (copyFields, copyDS, createDS), so the coarse DMs do hold the wrapped FE objects. They use them only for the section layout.
    • The coarse operators are Galerkin products, Pᵀ A P of the fine Jacobian (pc_mg_galerkin=both). The native refinement path forces Galerkin as well (_enforce_galerkin_for_geometric_mg), because underworld3 installs no residual or Jacobian callbacks on coarse DMs.
    • So every coarse operator inherits the corrected fine boundary Jacobian, and no coarse-level boundary residual is ever assembled to compare against.

Issues settled

What passed

  • The PR's 5 tests: serially as committed, and at np 2, 4 and 8 in the parallel-safe copy. All 5 fail on development.
  • The Stokes_Constrained on a 3-D shell: np 8 differs from np 2 and 4 by 1.55e-5 (velocity L2), independent of solver tolerance (#651 item 1) #1150 probes at np 1, 2, 4 and 8, and the random partitions at np 4 and 8 (two seeds): round-off agreement with np 1 everywhere.
  • The Stokes_Constrained solve at np 4 and 8: agreement at solver tolerance.
  • 2-D residuals bit-identical to development at np 2 and 4 (box and annulus), and 2-D solutions bit-identical at np 2.
  • The coordinate-degree refusal: identical on every rank, including an empty rank, with no hang, both called directly and through a solver.
  • Custom multigrid on a refined shell: the same answer and the same iteration counts at np 1, 4 and 8.

What was not run

  • The branch Stokes_Constrained solve at np 2: stopped by the 300 s supervisor silence rule while still solving.
  • The no-integrator refusal: it cannot be reached.
  • The triangle refusal through a solver: it cannot be reached through underworld3. It was shown not to be collective by a direct call.
  • Hexahedral meshes. The boundary Jacobian and boundary integral at negative orientations in parallel. The adjoint.
  • The rest of the test suite on the branch.
  • The development arm was 4b782b2, not the merge base aee3fa6. The difference is Python only and outside assembly.

Conditions

  1. The test file: make _orientations() and the per-rank maxima in tests/test_1188_boundary_terms_on_rotated_faces.py safe on a rank with no faces of the boundary, or mark the file serial-only, so that it does not segfault under mpirun.
  2. The triangle refusal: agree simplex over the communicator before the early return in UW_DMPairFaceQuadratureByOrientation, so that the triangle refusal is collective as the PR says. Otherwise, correct the PR body and the header comment to say that only the coordinate-degree refusal is collective.

Underworld development team with AI support from Claude Code

The test file segfaulted under mpirun at np 2 and above, on development as
well: a rank holding none of a boundary's faces called getIndices on an
empty stratum. It now guards the empty stratum, takes its counts and maxima
over all ranks, and swaps only the Internal faces whose two cells are on the
rank. scripts/test.sh runs it at np 4 in the test_* mpirun phase.

DMPlexIsSimplex is false on a rank with no cells, so that rank returned
before the triangle-quadrature refusal while the others raised. The ranks now
agree on the flag over the DM's communicator before the early return.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

Both conditions are fixed in 5332029.

  1. The test file at np >= 2. _faces() returns nothing on a rank whose label stratum is empty, instead of calling getIndices() on it.
    • The fixture checks (faces not at orientation 0), the largest residuals and the largest load difference are reduced over all ranks. So every rank asserts the same thing, and none goes on alone into a collective.
    • The swap reverses only the Internal faces whose two cells are both on the rank. The check that they are now negative is reduced over ranks, and asserts that some face was swapped somewhere.
    • scripts/test.sh runs the file at np 4 in the test_* mpirun phase, beside test_1184.
    • Serially, all five pass on the branch and all five fail on development (aee3fa6), at the same values as before.
    • We cannot run MPI on the macOS machine, so the np 2, 4 and 8 runs of this version are for H1 to re-check.
  2. The triangle refusal is collective. One MPIU_Allreduce (logical or, over the DM's communicator) agrees the simplex flag before the early return. A rank with no cells now goes on to the install, and refuses a non-triangle face quadrature together with the others. The header comment says so.
    • Serially: test_0052 (collective guard scan), test_0782 (degree-one refusals), test_0502, test_1060 and test_1014 all pass, 93 tests.
    • The coverage check passes.

The PR body now lists #1150 as fixed by this branch, citing H1's numbers.

Underworld development team with AI support from Claude Code

The default partition splits no Internal face of #1150's shell at np 4, so
CI never reached #1150's case. A sixth check deals the shell's cells to the
ranks at random (seeds 1 and 2, a shell partitioner set where the plex is
read, before distribution) and compares the moments of the Internal load,
summed over every rank, with the default partition's to 1e-13 of their
scale. Under MPI it asserts that each random partition splits some face.

The reference is taken in the same run: gmsh builds a slightly different
shell on different machines (3220 cells here, 3241 on our Linux
workstation), so a stored baseline would not hold. On one rank the three
partitions are one; with the supports swapped instead, the largest moment
moves by 3.4e-3 on development and 1.1e-16 on this branch.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

bfb9b6c adds a sixth check, so that CI reaches #1150's case: the default partition splits no Internal face of #1150's shell at np 4.

How it works.

  • The shell's cells are dealt to the ranks at random, with seeds 1 and 2. The test sets a shell partitioner where the mesh's plex is read, before distribution. This is the mechanism H1 (the session that runs our parallel checks on a 96-thread Linux workstation) used in its review.
  • The moments of the Internal load are summed over every rank's rows, weighted by every polynomial in the node coordinates up to degree 2. They are compared with the default partition's to 1e-13 of their scale.
  • Under MPI the test asserts that each random partition splits some Internal face. The count is summed over ranks, and a face counts as split when one of its two cells is a ghost or absent on the rank.

Why the reference is taken in the same run, not stored.

  • gmsh builds a slightly different shell on different machines: 3220 cells and 536 Internal faces on the macOS machine, 3241 and 540 on the Linux workstation. A stored serial baseline would fail on the mesh, not on the physics.
  • The default partition splits no face at np 4 and one at np 8, so it stands in for the serial load.
  • We did not compare node by node. Without a stored baseline, that would need the serial point numbers carried through the distribution's migration SF, P2 edge degrees of freedom included.

Sensitivity, one rank.

  • With every Internal face's supports swapped (the frame change a split face makes), the largest moment moves by 3.4e-3 on development and by 1.1e-16 on this branch, against a scale of 1.56.
  • On one rank the three partitions are the same, so the case passes serially on development too. It can fail only under MPI.
  • Serially on the branch: the file's 6 tests and test_0052 pass.

np 2, 4 and 8 on both builds is for H1 to run.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

Re-check of #1195 at bfb9b6c: READY. Both conditions are met. From H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)), on a build of the head.

The new partition case (test_an_internal_load_does_not_depend_on_the_partition: seeds 1 and 2 against the default partition, compared by moments to 1e-13 of the scale):

  • On development (the head's test file run on a development build, 4b782b2): it fails on every rank at np 2, 4 and 8. So the check has power.
  • On the branch: it passes on every rank at np 1, 2, 4 and 8.

The whole file on the branch (tests/test_1188_boundary_terms_on_rotated_faces.py, now parallel-safe): 6 passed at np 1, and on every rank at np 2, 4 and 8. There is no segfault at any rank count.

The install-time refusals at np 8, with a rank that holds no cells.

  • Mesh: a 3-D UnstructuredSimplexBox(cellSize=0.5, regular=False) under a shell partition that empties the last rank: cells per rank [22, 15, 3, 18, 4, 16, 22, 0].
  • Call: UW_DMPairFaceQuadratureByOrientation, called directly.
case outcome on all 8 ranks
control: P1 simplex FE 0 on every rank
tensor-cell FE (a face quadrature not on a triangle) 56 on every rank, the empty rank included
coordinates of degree 2 56 on every rank, the empty rank included

The triangle refusal is now collective: simplex is agreed over the communicator before the early return.

A note on how this was measured, so others don't fall into the same trap.

  • On this machine's local rebuilds, a change to the header alone (uw_face_orientation.h) did not recompile the Cython extension.
  • The incremental build reused the extension built from the previous head, so a first run of the refusal check still showed the old behaviour: rank 7 returned 0.
  • Forcing a recompile (touching petsc_generic_snes_solvers.pyx, which includes the header) gave the results above.
  • CI builds from scratch and is not affected. A local build that reuses a worktree should be forced after a header-only change.

#1150 stays settled, as measured at 7cc95a1. The only compiled change since is the simplex agreement on the install path.

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