Skip to content

The exterior cover's fallback leaves out internal surfaces and refuses shared faces - #1235

Merged
lmoresi merged 2 commits into
developmentfrom
bugfix/exterior-cover-fallback-is-disjoint
Nov 19, 2026
Merged

lmoresi merged 2 commits into
developmentfrom
bugfix/exterior-cover-fallback-is-disjoint

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member

A follow-up to the review of #1211. No issue is filed; the defect was found in that review.

What changes

Mesh._boundaries_covering_the_exterior_once() is the list of boundaries that the EulerianSUPG inflow and the LevelSetSolver far field put their condition on. Where All_Boundaries marks faces, it is All_Boundaries alone, as before. When All_Boundaries marks none, the fallback returned every boundary that marks faces. Those can share faces (an internal patch and its halves, for example) and can include internal surfaces. So a whole-boundary condition could count a face twice, or act inside the domain. Those are the two defects #1211 removed for meshes that have All_Boundaries.

Now the fallback:

  • leaves out internal surfaces, using Mesh._boundary_is_internal, which already exists;
  • refuses with a ValueError when the remaining boundaries share a face, or when none remain.

No stock mesh takes the fallback: the reviewer's survey of 20 stock meshes found All_Boundaries faces on every one. The behaviour on every stock mesh is unchanged.

Tolerances and coordinate matches

None. Faces are counted as height-1 points of UW_Boundaries. Internal surfaces are found by support size.

Tests

Added to tests/test_1069_boundary_wrapper_checks_and_replaces.py. Each fixture removes the All_Boundaries stratum from UW_Boundaries.

test previous head this branch
box: the cover is the four sides passes passes
BoxInternalBoundary: Internal is left out fails (Internal included) passes
box with Top's faces also given Bottom's value: refused fails (returned) passes

The first test guards the ordinary case; the other two fail first.

Serial run on this branch, which is development 246d6ce plus this commit: test_1069, 1055, 1059, 1105 and 0502. 91 passed, 1 skipped (shapely is not installed). Not run in parallel. _boundary_is_internal and the overlap check each reduce over the ranks.

Adversarial review (author's pass)

  • Parallel rank asymmetry.

    • The list of face-marking boundaries is reduced over the ranks, so every rank calls _boundary_is_internal, which is collective, for the same boundaries in the same order.
    • The overlap flag is found per rank over local faces, ghosts included, then reduced with a logical OR. So both refusals are the same on every rank.
  • Not covered:

    • Gaps. The fallback does not check that the cover reaches every exterior face. An exterior face in no named boundary gets no condition.
    • Mixed boundaries. A boundary that is partly internal and partly exterior is left out whole, exterior faces included.

    No stock mesh reaches this path, so we have not added these checks.

Issue state

No issue is open for this.

Underworld development team with AI support from Claude Code

…s shared faces

When All_Boundaries marks no face, Mesh._boundaries_covering_the_exterior_once
returned every boundary that marks faces. Those can overlap (an internal patch
and its halves) and can include internal surfaces, so a whole-boundary
condition could count a face twice or act inside the domain, the two defects
#1211 removed for meshes with All_Boundaries. The fallback now leaves out
internal surfaces (_boundary_is_internal), and refuses when the rest share a
face or when nothing is left. No stock mesh takes the fallback; the tests
remove the All_Boundaries stratum to reach it.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 19, 2026 21:23

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 19, 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

Head 6fbe204: changes requested.

What works:

  • The fallback is right in serial.
  • Both refusals are collective.
  • Stock meshes are unchanged.

What does not:

  1. Whether a boundary is internal is read from each rank's local support sizes, so an internal surface that lies on a partition boundary is taken for an exterior one.
  2. The new share-faces test segfaults on a rank that holds no Top face.

Build. The merge base is development 246d6ce (#1211 merged). The only changes since the #1211 head 6f0bfdd are the two .py files, and there are no compiled differences. We copied the head's discretisation_mesh.py over the 6f0bfdd build and checked that every installed .py file matches the head's source.

Results

All five meshes are tested with the All_Boundaries stratum removed from UW_Boundaries. "Exterior faces" comes from markBoundaryFaces into a scratch label, which is collective.

case np 1 np 2 np 3 with an empty rank
Annulus(0.3, 1, 0.1) Lower, Upper; 84 of 84 exterior faces, none extra the same the same
AnnulusInternalBoundary (Internal at r = 0.65) Lower, Upper (Internal left out); 84 of 84 the same the same
AnnulusWithSpokes Lower, Upper; 51 of 51. LowerPlus, UpperPlus and Spokes are left out as internal, so the rest is disjoint and nothing is refused the same the same
UnstructuredSimplexBox Bottom, Top, Right, Left; 40 of 40 the same the same
3-D BoxInternalBoundary the six walls; 384 of 384 the same the same
Box with Left removed too accepted, Bottom, Top, Right: 30 of 40, 10 faces missing (finding 3) the same
3-D BoxInternalBoundary with every exterior wall removed refused, "no boundary that marks exterior faces", the same text on every rank the same
New tests, -k without_all_boundaries 3 passed (the whole file: 11 passed) the internal-surface test fails on both ranks (finding 1); 2 passed the internal-surface test fails on all ranks; the share-faces test segfaults (finding 2)
Stock meshes: _boundaries_covering_the_exterior_once() [All_Boundaries] on all five the same the same
Doubling variants on the Annulus: default against B and C, A and D default = B = C bit for bit; it differs from A and D by 5.449e-2

Findings

1. Medium: an internal surface on a partition boundary is classified as exterior

_boundary_is_internal() asks whether any local facet of the boundary has support size 2, then takes the MAX over ranks. With no overlap, a facet on a partition boundary has one local cell on each side, so its support is 1 on both ranks.

  • Measured: the new test's 2-D BoxInternalBoundary(4 x 4, zintCoord=0.5).
    • At np 1, Internal's 4 facets have support 2, and Internal is found to be internal.
    • At np 2 the partition runs along y = 0.5. Each rank holds the same 4 facets with support 1, and Internal is found to be exterior.
  • Consequence: the fallback's cover becomes Bottom, Top, Right, Left, Internal, and the inflow term would go on Internal. That is the case The boundary-condition wrapper checks its label and PETSc's answer; a rewire replaces boundary kernels (#1138, #1069) #1211 round 4 measured as a real error.
  • Under emptyband at np 3 the same test fails on all ranks.
  • Proposed fix: decide "exterior" from markBoundaryFaces, which is partition-aware, for example "every face of the boundary is in the exterior label". Do not decide it from local support.
  • Also in another caller: the same helper decides, in _resolve_boundary_normals(), whether mesh.Gamma is replaced by the declared normal on a boundary. So at np 2 this mesh's Internal is treated as an exterior wall there too.
    • We measured one integral, the integral of Gamma_y over Internal: 1.0 at np 1 and np 2. So this case does not show a different answer.
    • It is older than this PR; an issue may be the place for it.

2. Medium: the share-faces test segfaults on a rank without Top faces

label.getStratumIS(top).getIndices() is called on every rank. On a rank that holds no Top face, getStratumIS returns a null IS, and getIndices() on it is a segmentation fault (Fatal Python error, np 3 under emptyband).

  • Fix: guard the call with if label.getStratumSize(top):, as the helper itself does.
  • The helper itself: its share-faces refusal is computed with an allreduce, and it gave one text on every rank in every case where it raised.

3. Low: the fallback does not check that the cover covers

A cover that misses exterior faces is accepted: on the box with Left removed, it returns Bottom, Top, Right, which holds 30 of the 40 exterior faces. A whole-boundary condition (the EulerianSUPG inflow) would then be missing on Left without a word.

The data for a check is already there. Counting the faces of the exterior label that are not in the cover, with one allreduce, would let the helper refuse this as it refuses overlaps.

What was run

  • The new tests at np 1 (the whole file: 11 passed), at np 2, and at np 3 with an empty rank (the partition hook, copied with a guard so the JIT build's child process skips it).
  • The fallback probe on five meshes at np 1, 2 and 3 (empty rank), plus the uncovered and no-exterior cases at np 1 and 2.
  • The classification diagnostic at np 1 and 2.
  • The doubling variants A to D.
  • Logs are kept by the reviewer.

Not run: 3-D meshes with an internal surface on a partition boundary; np 4.

Underworld development team with AI support from Claude Code

…st reach every one (review of #1235)

_boundary_is_internal read local support sizes, so an internal surface a
partition boundary runs along looked exterior on every rank holding it
(BoxInternalBoundary at np 2) and entered the cover; the same helper picks
the Gamma replacement in _resolve_boundary_normals. It now reads
Mesh._exterior_face_mask(), the faces markBoundaryFaces marks, which is the
same at any rank count. The fallback cover is also refused when it leaves an
exterior face in no boundary, and its stratum reads are guarded on ranks
without the value.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

Response to the review (head of this push)

1. The internal surface on a partition boundary.

  • New helper: Mesh._exterior_face_mask() marks, on every rank, the faces markBoundaryFaces finds (a scratch label, removed afterwards). Those are the faces with one cell in the whole mesh.
  • _boundary_is_internal now calls a boundary internal when any of its facets is not in that mask, reduced with MAX. It no longer reads local support sizes, so the answer is the same at any rank count.
  • Gamma: the rule that picks the mesh.Gamma replacement in _resolve_boundary_normals uses the same helper, so it changes with it. Serially the answer is unchanged.

2. The null IS. The fallback's stratum reads are now guarded by getStratumSize, and so is the test fixture that copies Top's faces.

3. Coverage. The fallback now also refuses when the union of the cover leaves an exterior face in no boundary. The ranks decide it with a sum. New test: the box with Left removed too, so Bottom, Top and Right are disjoint and miss Left's faces.

Serial runs here:

  • test_1069: 12 passed.
  • The 27 boundary-normal, rotated, Nitsche, internal-boundary and traction files: 239 passed, 1 skipped (an x86-only OpenBLAS case).

At np 2 and 3, including the empty-rank case, the reviewer re-checks.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 19, 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.)

Recheck at 6f071f1: ready to merge on green from this review. All three findings of the first review (at 6fbe204) are fixed, and the fix also makes the choice of Gamma on an internal surface independent of the partition. I have no new findings.

The PR changes only .py files. The merge base is 246d6ce (development, with #1211). An existing build's compiled sources match it exactly. The .py files of the merge base and of the PR head were each laid over a copy of that install, and underworld3.__file__ was checked to resolve to the overlay. The mesh is a 2-D BoxInternalBoundary(elementRes=(4, 4), zintCoord=0.5, simplex=True) throughout, unless stated otherwise. The empty-rank runs use a shell partition into horizontal bands, with the last rank given no cells.

Items

item check development (merge base) PR
1 Internal on a partition boundary, np 2: each rank holds 4 Internal faces, all with a local support of 1 classed exterior (internal=False) classed internal on every rank
2 Same, np 3 with an empty rank (cells 22 / 22 / 0) classed exterior classed internal on every rank, including the empty one
3 All_Boundaries removed: the cover, np 1, 2 and 3 (empty rank) not compared (the probe's coverage count uses the PR's new exterior mask) [Bottom, Top, Right, Left] on every rank; Internal left out; summed over ranks, 0 exterior faces uncovered, 0 covered faces not exterior, 0 faces covered twice
4 All_Boundaries and Left removed cover [Bottom, Top, Right, Internal]: the gap is filled with the internal surface refused on every rank with the same message ("leave some exterior faces in no boundary"), at np 1, 2 and 3 (empty rank)
5 Gamma choice, All_Boundaries intact, np 1, 2 and 3 (empty rank) Internal: Gamma kept, so petsc_n is used Internal: [0, 1], the declared normal, at every np; the four walls and All_Boundaries keep Gamma at every np
6 ∫Γ·n over Internal (x, y) np 2: (0, +1.0); np 3, empty rank: (0, −1.0) (0, +1.0) at np 1, 2 and 3 (empty rank)
7 ∫Γ over the walls (x, y) Top (0, 1), Bottom (0, −1), Left (−1, 0), Right (1, 0) the same, at every np
8 Stock meshes: UnstructuredSimplexBox, StructuredQuadBox, Annulus, BoxInternalBoundary — [All_Boundaries] for each, at every np
9 test_1069, whole file, serial — 12 passed
10 The PR's four new tests at np 2 — 4 passed on each rank
11 The PR's four new tests at np 3, empty rank (that rank holds no Top faces) — 4 passed on each rank, no segfault

On development, the sign of ∫Γ_y over Internal flips with the partition (row 6). This is the partition dependence that _resolve_boundary_normals exists to remove, and reading the exterior from markBoundaryFaces over the whole mesh removes it here.

Findings

None.

Not run

  • The full serial and parallel suites.
  • 3-D meshes.
  • Anything above np 3.

Logs kept by the reviewer.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 2a41d49 into development Nov 19, 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.

2 participants