Skip to content

Label shell Inner/Outer cells by connectivity, not centroid radius - #1100

Merged
lmoresi merged 2 commits into
developmentfrom
bugfix/shell-internal-region-labels
Nov 12, 2026
Merged

lmoresi merged 2 commits into
developmentfrom
bugfix/shell-internal-region-labels

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 12, 2026

Copy link
Copy Markdown
Member

SphericalShellInternalBoundary labels its Inner and Outer cells by comparing each cell's centroid radius with radiusInternal. That is wrong for a cell that lies outside the faceted internal surface but has its centroid inside the sphere. This PR labels the cells by connectivity instead: start from the cells on the Lower and Upper walls and spread, never crossing an Internal facet.

The fix is @gthyagi's, cut out of #1033 as a unit of its own (his commit 2da28433, cherry-picked onto development with authorship kept; it touched only these three files). He found the case on Gadi: a tetrahedron with four vertices at r = 2 and its centroid at r = 1.99706.

The defect on development

On unrefined meshes we could not reproduce it on our host (12 shells, no mislabelled cell). With two refinements it is systematic: refinement leaves new Internal vertices on the chords of the coarse surface, so cells just outside it have centroids below radiusInternal.

Shell 0.547 / 0.8 / 1.0, cell size 0.3, refinement=2 (98,112 cells, 4,096 Internal facets):

Inner cells Internal facets with Inner cells on both sides
development 37,267 1,363
this branch 35,904 (= 64 × 561, the unrefined count) 0

extract_region("Inner") on development therefore returns 1,363 cells from the wrong side.

What we added

  • A test on that mesh asserting two exact properties: every Internal facet separates an Inner cell from an Outer cell, and the Inner count is 64 times the unrefined one. On development it fails (assert 2733 == 4096), in serial and at np 3.
  • The test file moved to tests/parallel/test_1175_shell_region_labels.py (1107 is taken on development) with a serial batch line as well; its assertions do not depend on the rank count.

What changes for users

Every SphericalShellInternalBoundary now runs the connectivity labelling at construction, in parallel too. It raises, collectively, if a wall or Internal label is missing, if the Internal surface does not separate the walls, or if a region is empty. Unrefined meshes we probed get the same labels as before.

Verification (hyperion, PETSc int32, MPICH 5.0.1, head 8b60c56)

check result
tests/parallel/test_1175 at np 1, 2, 3, 4, 5 6 passed on every rank
new mesh test on development, serial and np 3 fails, 2733 of 4096 facets separate
seven serial files using this mesh or extract_region (test_0001, 0502, 0771, 0772, 1018_rotated_freeslip, 1064, 1070) 89 passed
six parallel files using them, np 3 pass, except test_0770_submesh_extract_mpi (2 failures)
test_0770 at np 3 on development the same 2 failures, so not from this change; it passes at np 2 on both
scripts/check_test_coverage.py all 428 test files reachable

Not reviewed in depth yet: the cost of the labelling at large rank counts (it exchanges Python lists with alltoall each sweep), and np above 5.

Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)

  • I have read the Style Charter and followed it over the surrounding code (S2)
  • No drive-by refactors, renames, or "while I was here" cleanups (S9)
  • Bug fixes ship the regression test, written first, with level_* and tier_* markers (S8)
  • No hedging names (maybe_ / try_ / do_) and no commented-out code (S3, S4)
  • Every exception swallow states its sanctioned failure mode in a comment (S4)
  • New data access uses .array / mesh.X.coords — no with ....access(...), no mesh.data (S7)
  • Parallel safety considered — np2/np4 checked where swarm/mesh/solver dispatch is touched (S11)
  • No pixi.toml / pixi.lock or other dependency changes riding in an unrelated PR
  • AI-assisted work carries the attribution line below

Underworld development team with AI support from Claude Code

gthyagi and others added 2 commits November 12, 2026 18:54
Replace centroid-radius classification with wall-seeded connected components blocked by the tagged internal surface. Exchange partition-facet/component data without gathering the mesh; preserve overlap and empty-rank consistency and reject invalid topology.

Gadi reproduced a real outer tetrahedron with all four vertices on r=2 and centroid r=1.99706. Raw Gmsh tags are correct; the prior classification was not. Five synthetic tests pass serial/MPI8 through source bootstrap, and the exact failing raw mesh gives 64410 inner and 38484 outer cells with all 7968 interface faces separating regions on both partitions. Fresh installed-package gates follow.

Underworld development team with AI support from Claude Code

(cherry picked from commit 2da2843)
… in parallel

Two refinements of SphericalShellInternalBoundary leave new Internal vertices
on the chords of the coarse surface. A cell just outside that surface has its
centroid below radiusInternal, and development's radius test labels it Inner:
1363 cells on the test mesh, so 1363 Internal facets have Inner cells on both
sides. The new test asserts two exact properties: every Internal facet
separates an Inner cell from an Outer cell, and the Inner count is 64 times
the unrefined one.

The file moves to tests/parallel/ under a free number (1175; 1107 is taken on
development) and gets a serial batch line too: its assertions do not depend
on the rank count.

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

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 merged commit 01b06c9 into development Nov 12, 2026
10 checks passed
@lmoresi

lmoresi commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Adversarial review of #1100 (H3, second review desk)

Verdict: READY at 8b60c56, on green CI (one shard was still running). The connectivity labelling is correct and collective-safe in every case we built. Two Low test gaps.

Reviewed against development f8c60140. Logs and probes are in runs/2026-11-12-h3review/1100/.

Findings

  1. Low. No test needs more than one exchange round. A mutant that stops after the first sweep passes all 6 tests at np 3 and np 5.

    On a 10-cell column (Lower, Internal, Upper), split one layer pair per rank at np 5, two cells sit two ranks from their wall seed. There the head labels all 10 correctly. The mutant raises, collectively, "a component connected to neither wall". So the guard catches too few sweeps, and the result is a loud failure, never a silent wrong label. Adding that column as a test would pin multi-sweep propagation. The probe is mut/column.py.

  2. Low. The duplicated-cell keys (has_ghosts) are unpinned. Dropping them passes every test at np 3 and np 5. It also gives identical labels on the column with distributeOverlap(1). Either they are redundant (ghost cells join through facet keys), or the case that needs them is not built.

C1's three checks

  • The test fails on development for the stated reason: the refined-shell test alone, serially, gives assert 2733 == 4096. That is, 2,733 of 4,096 Internal facets separate an Inner cell from an Outer one. At the head: 6 passed on every rank at np 1, 2, 3, 4 and 5.

  • Collective safety. By reading:

    • every alltoall and allreduce is reached on all ranks, the loop's exit included;
    • each raise follows a global allreduce;
    • has_ghosts is decided globally.

    By running:

    • the toy shell (built on rank 0, then distributed, with and without overlap) at np 1 to 5;
    • the 5-rank column, where ranks hold cells of one side only and the region spans three ranks: 0 mislabelled, with and without overlap.
  • Nothing reads the old membership. The shell's Inner and Outer labels are read only by extract_region and this test. None of the 7 tests or 3 examples that build SphericalShellInternalBoundary reads them. The box's centroid labelling in cartesian.py has a planar interface, which the facets represent exactly.

Attacks that failed

  • Mutant: colour passing through Internal facets gives 3 failed at np 3.
  • Cost: 98,112 cells at two refinements, 1.53 s at np 1 and 0.40 s at np 5.
  • Neighbours:
    • serial (test_0001, 0502, 0771, 0772, 1018_rotated_freeslip, 1070): 89 passed;
    • the shell cases of test_1064_rotated_freeslip_parallel and test_1071: pass at np 3 and np 5.

Issues

We found no open issue for the mislabelling. #1033 (gthyagi's) carries the same commit.

Not tested

Ranks above 5; a 3-D shell where a region has no wall facet on any rank except via many hops; the 42-minute test_1064 serial file.

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.

4 participants