Skip to content

Locator: an exact fallback finds the contained points the walk misses (#1183) - #1190

Merged
lmoresi merged 3 commits into
developmentfrom
bugfix/locator-closure-1183
Nov 14, 2026
Merged

lmoresi merged 3 commits into
developmentfrom
bugfix/locator-closure-1183

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Fixes #1183.

The defect. On #1123's sheared 3-D mesh a few points that a rank's own cell contains were owned by no rank. The face-crossing walk, its restarts from the four nearest centroids, and the face-tolerance search over the 50 nearest centroids all missed them. H1's probe found 2 per million at np 2 (H1 is the parallel review desk), some well inside their cell (smallest barycentric coordinate 0.009). That mesh is valid: every cell keeps its orientation.

The fix. A point the walk and its restarts do not place is tested against every local cell whose bounding box holds it.

  • SimplexLocator.cells_containing builds a uniform bin grid over the local cells' bounding boxes, once, on first use, with the bin size the median box size. Each bin lists the cells whose box overlaps it.
  • Complete: a containing cell's box always holds the point, so the point is found.
  • Exact: the same barycentric test and ROUNDOFF guard as the walk; ties go to the lowest cell in the entity's star, as before.
  • Cheap: only the points the walk missed reach it, and they are tested as (point, candidate) pairs in one vectorised call.
  • Bounded: the bin count is capped at the local cell count. Otherwise a mesh whose cells sit mostly in a thin band or a corner (refined toward a fault) would build (extent / median cell)^dim bins, 1e6 to 1e8 per rank. Above the cap, bins hold more candidates and the search stays complete. Measured: a 3-D box with most of its cells packed into a corner would need 84,604,519 bins uncapped for 2,615 cells, and builds 2,197. The test asserts the cap and that every contained point is still found, at np 1, 2 and 4.

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

Tests. tests/parallel/test_1183_contained_points_owned_parallel.py, tier B, the sample above. Development fails at np 2 (2 lost); this branch passes at np 1, 2 and 4. It runs in batch 3 and under --p N. Also run:

  • the locator's serial set (72);
  • the parallel evaluate, swarm and locator files at np 2 and 4 (100 and 116);
  • the test-coverage gate.

Not here: #1178, the seam claim, is a separate defect. This PR changes only whether a contained point is found by its own rank.

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 (S11): rank-local, no collective added; np 1, 2, 4 checked
  • No mesh entity or rank identified by coordinates; any remaining tolerance is named, relative and says what it bounds (S12)
  • 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

…#1183)

On #1123's sheared mesh the face-crossing walk, its restarts from the nearest
centroids, and the face-tolerance search could all miss a point a local cell
contains: 2 per million at np 2, some well inside their cell. A point the walk and
its restarts do not place is now tested against every local cell whose bounding
box holds it, through a uniform bin grid over the cells' boxes (built once, on first
use). That search is complete, so a contained point is found; it is exact (the same
barycentric test and ROUNDOFF guard); and it runs only for the points the walk
missed, vectorised over (point, candidate) pairs.

tests/parallel/test_1183_contained_points_owned_parallel.py: 1e6 points sampled in
local cells (a quarter within 1e-9 of an entity); development loses 2 at np 2, this
loses none at np 1, 2 and 4. Claims are unchanged on unsheared meshes at np 2 to 4.
Serial evaluation of 1e6 mostly exterior points: 5.7 s against development's 6.1 s.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 14, 2026 05:33

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

Copy link
Copy Markdown
Member Author

Parallel review of #1190 at 7ce22e0: READY. From H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)).

The PR's test (tests/parallel/test_1183_contained_points_owned_parallel.py):

np branch development
1 passed passed
2 passed on both ranks failed on both ranks
4 passed on every rank passed

That matches the body: development loses its two points at np 2 only.

1. Claims made by agreed ownership are unchanged.

  • Case: a fixed point set, the same on every rank: 4,000 random points spanning the domain and beyond, 2,000 points within 1e-7 of vertices, and 1,000 vertices.
  • Measured: points_in_domain (strict and not) and _robust_owning_cells, gathered per rank.
  • Result: 0 differing (rank, point) entries between the branch and development, out of 14,000 at np 2 and 28,000 at np 4, on each of a 2-D box (1/24), a 3-D box (1/8) and an annulus (0.04).
  • Why: the fallback runs only for points the walk and its restarts leave unplaced.

2. The grid's size and memory (built on demand, serial; it is rank-local):

mesh cells grid h dims bins owner entries memory build
3-D box, cellSize 1/24 63,611 5.85e-2 18³ 5,832 393,287 3.0 MiB 0.14 s
3-D box 1/16, graded x³ (a mover-like concentration) 19,031 1.36e-1 8³ 512 66,356 0.5 MiB 0.04 s
the same, graded x⁶ 19,031 1.39e-1 8³ 512 66,493 0.5 MiB 0.07 s
  • The bin count is (extent / median cell box)^dim. A mesh whose median cell is much smaller than the domain therefore grows it as that ratio to the dimension. For example, most cells in a thin refined band at 1/200 of a unit cube would give 8e6 bins, 64 MiB of offsets.
  • On a graded mesh like the two above, the median stays near the coarse size. The cost is then more candidates per bin (about 130 cells per bin at x⁶), paid only by the few points that reach the fallback.
  • A one-line cap on the dims, or a note in the docstring, would cover the band case. Not a condition.

3. The grid is rebuilt when the mesh moves.

  • The grid was built on a 2-D box, then the box was deformed (x → 2x + 0.3y).
  • After the deform, _simplex_locator() returns a new locator object, whose grid is unbuilt until first use.
  • cells_containing then locates all 20,000 points sampled in the moved domain (smallest barycentric coordinate 2.7e-6).
  • The grid lives on the locator, and the locator is keyed to the mesh's index, which a deform rebuilds. So a stale grid cannot be read.

Not run:

  • the serial locator set, and the parallel evaluate and swarm files (the author's 72, 100 and 116);
  • the exterior timing;
  • a mesh with a thin refined band at many ranks.

Underworld development team with AI support from Claude Code

…ew of #1190)

The grid's bin size was the median cell box, so its bin count was (extent / median)^dim.
On a mesh whose cells mostly sit in a thin band or a corner (refined toward a fault),
that is 1e6 to 1e8 bins on every rank. The bin size is now scaled up until the count
is at most the local cell count. Larger bins hold more candidates, but the search
stays complete: the cap bounds the cost and never changes the answer.

test_1183: a 3-D box with each axis mapping [0, 0.9] onto [0, 0.01] packs about 73 %
of its cells into a corner; uncapped it would build 84,604,519 bins for 2,615 cells,
capped 2,197. Every contained point is still found, at np 1, 2 and 4.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

Re-check of #1190's bin cap (91a1224, in head 45bf6cf): READY. From H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)). The PR's _simplex_locator.py at the head is laid over the build used for the first review. The cap is confined to that file.

mesh cells grid dims bins memory contained points found
3-D box, each axis mapping [0, 0.9] onto [0, 0.01] (packed corner) 8,074 20³ 8,000 (uncapped: 292,754,944) 1.5 MiB 20,000 of 20,000 sampled inside its cells
3-D box, cellSize 1/24 63,611 18³ 5,832 (below the cap, unchanged) 3.0 MiB –
3-D boxes graded x³ and x⁶ 19,031 8³ 512 (unchanged) 0.5 MiB –
  • The cap holds at the local cell count, and the search stays complete: every contained point is found.
  • The rebuild after a deform is unchanged: a new locator, then 20,000 of 20,000 moved-domain points located.
  • test_1183_contained_points_owned_parallel.py at this head: 2 passed at np 1, and on every rank at np 2 and np 4.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 88d98ac into development Nov 14, 2026
10 checks passed
lmoresi pushed a commit that referenced this pull request Nov 16, 2026
…fallback tested directly

The sheared fixture was gmsh's box with #1123's shear and sine terms of amplitude
0.03. gmsh builds differ (1094 cells on macOS against 1086 on Linux), and on one
macOS build a cell was turned over, so the locator tests had no right answer.

tests/parallel/sheared_box_fixture.py (from #1213): a structured box of cubes split
into six tetrahedra, independent of gmsh, with the sine amplitude at 0.025: the sine
gradient's norm (2 pi 0.025 = 0.157) is below the linear shear's smallest singular
value (0.175), so the map is invertible, and the fixture asserts, collectively, that
no cell turned over. test_1123 (serial and parallel) and test_1183 use it.

Regression power on it: before #1175, test_1123 fails at np 1, 2 and 4 (116 to 125
inside points classified exterior per distance; 392, 47 and 10 owned by no rank).
#1183's 2 per million lived in near-degenerate cells of one gmsh build and no valid
fixture reproduces them; test_1183 tests the fallback directly instead: with the walk
forced to miss every point, the fallback must find them all, which before #1190
loses 1200 to 1427 of 2e4.

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.

3 participants