Skip to content

points_in_domain uses the exact locator on simplex meshes: a swarm's claims agree with global_evaluate - #1213

Merged
lmoresi merged 3 commits into
developmentfrom
bugfix/points-in-domain-exact-locator
Nov 16, 2026
Merged

lmoresi merged 3 commits into
developmentfrom
bugfix/points-in-domain-exact-locator

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

points_in_domain uses the exact locator on straight-sided simplex meshes, so a swarm's claims agree with global_evaluate's ownership. This is the swarm follow-up #1175 named, and Style Charter section 12's rule: no boundary-face sign test standing in for containment.

The defect. points_in_domain, which a swarm's migration reads, decided a point far from the local boundary by the sign of the nearest boundary face's control point. Only points near the boundary were checked against cells. On #1123's sheared mesh the sign test calls contained points exterior. Measured on the structured sheared box (tests/parallel/sheared_box_fixture.py), at points 1e-8 to 1e-4 off every edge midpoint:

At np 2 that point is in a cell of rank 0's own, and the exact locator finds it. But it is farther from rank 0's boundary (dist² 7.9e-3) than 2·max_radius² (6.7e-3), so only the sign test was consulted, and it said outside.

The fix (Mesh._classify_points_in_domain).

Claims change only by contained points. Measured on unsheared meshes (a 2-D box, a 3-D box, an annulus), with random points, every vertex, and points 1e-9 to 1e-5 off vertices:

  • migration's claims (strict_validation=True): identical to development at np 1, 2 and 4;
  • serially: every variant identical;
  • the non-strict variant at np 2 and 4: 1 to 20 points per rank on the 3-D box are no longer claimed. No local cell contains any of them, and each is still claimed by another rank: 0 points inside the domain are left owned by no rank.

Points just outside the domain boundary (W1's case). 400 points on the x = 1 wall of a 2-D (1/24) and a 3-D (1/8) box, moved outward by a gap from 1e-7 to 1e-4. Claims are identical to development at every gap, and no point is claimed twice:

  • serially: none is claimed, at any gap (the cell-wall test's own tolerance);
  • at np 2: all 400 are claimed up to a gap of 5e-6, and none from 1e-5, which is the parallel face tolerance's slab of about 1e-5.

That serial/parallel difference was already on development, and this PR keeps it.

Double claims dropped. The 1 to 20 non-strict points per rank no longer claimed (above) were claimed twice on development: its non-strict path took the boundary sign without a cell check. One claim per point, by the rank that contains it, is the intended semantics (W1's review).

Swarm migration. A swarm in solid rotation on an annulus (cell size 1/16, populate fill 3, 20 steps of 0.05, second-order advection) keeps all 15,200 particles at every step, at np 1, 2 and 4. That is the same as development; the 20 steps are slightly faster (6.2, 4.0 and 2.5 s against 7.7, 4.8 and 2.9 s).

Cost. points_in_domain on 1e6 points in total, 1/96 2-D and 1/20 3-D boxes, development → this branch, at a machine load of about 14:

case np 1 np 4
2-D, all inside 2.74 → 1.51 s 0.44 → 0.57 s
2-D, half outside 1.85 → 2.01 s 0.37 → 0.58 s
3-D, all inside 8.81 → 2.21 s 1.66 → 1.78 s
3-D, half outside 7.07 → 7.50 s 1.16 → 1.56 s

Serially, interior points are 1.8 to 4 times cheaper. At np 4 most points are foreign to each rank. A foreign point within reach of a rank's cells is now walked to an exact answer where development took the sign, which costs up to +0.4 s per million.

Tests. tests/parallel/test_1213_points_in_domain_exact_parallel.py, tier B, on the structured sheared box (added here; the fixture PR builds on it):

  • every inside point is in some rank's domain under points_in_domain(strict);
  • a swarm seeded at the inside points keeps every one through migration with lost points deleted.

Development fails at np 1 (449) and np 2 (1). It passes at np 1, 2 and 4, and runs in batch 3 and under --p N. Also run:

  • serially: 434 swarm, evaluate, locator, migration, advection, remap and interpolation tests;
  • in parallel: 30 evaluate, swarm and locator files at np 2 (107) and np 4 (123);
  • the coverage gate.

Measured on a 96-thread Linux workstation (single system image; Intel Xeon Gold 6240R, AVX-512; MPICH). W1 reviewed the code (comment 6909604089); the docstrings of points_in_domain and _classify_points_in_domain now say what strict_validation and cells mean on a simplex mesh. H1 runs it in parallel.

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): the collective get_max_radius is still reached first on every rank; the rest is rank-local; 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

…claims agree with global_evaluate

points_in_domain, which a swarm's migration reads, decided a point far from the local
boundary by a boundary-face sign test standing in for containment (Style Charter
section 12). On #1123's sheared mesh it called contained points exterior: serially 449
of 3825 near-edge points, and at np 2 one inside point owned by no rank, whose
particle a swarm then lost, while global_evaluate's ownership (the exact locator,
#1175) had it. On a straight-sided simplex mesh a point is now in a rank's domain
when a local cell contains it; a point no local cell contains takes the face
tolerance development applied near the boundary (the evaluation tolerance in
parallel, the cell-wall test's own serially), and only within 2 max_radius^2 of the
local boundary, as before.

Claims change only by contained points: on unsheared 2-D and 3-D boxes and an
annulus, the strict claims (migration's) are identical to development at np 1, 2
and 4, and serially every variant is. A swarm in solid rotation on an annulus keeps
all 15200 particles over 20 steps at np 1, 2 and 4, as on development.

tests/parallel/test_1209_points_in_domain_exact_parallel.py (with the structured
sheared box, tests/parallel/sheared_box_fixture.py): development leaves 449 and 1
inside points in no domain at np 1 and 2; none here, and a swarm keeps every one.

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 16, 2026 06:36

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.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

Code review (W1, the integration session; read at 74164de, not run)

The change is sound. Swarm claims now rest on containment, as Charter §12 asks. The measurements answer the three questions asked of this review. Four points, none blocking; 1 and 2 are documentation the change makes stale.

1. On a simplex mesh strict_validation no longer has any effect, and the docstring still describes it.

  • Both values take the walk plus the face tolerance.
  • That is why the non-strict variant changed at np 2 and 4. Development's non-strict path took the boundary sign without a cell check, so a point near a partition face could be claimed by a rank whose cells do not contain it.
  • The 1 to 20 points per rank on the 3-D box, each still claimed by its owner, were therefore claimed twice on development. Dropping them is the intended semantics: one claim per point, by the rank that contains it.
  • No library caller passes strict_validation=False: migration (swarm.py 4403, 4506) uses the default, and the other two pass True. So the change reaches only users who call it.
  • Please say in the points_in_domain docstring that on a simplex mesh the claim is containment either way, and that strict_validation matters only on other meshes.

2. The _classify_points_in_domain docstring is stale on cells. It says an interior point has -1, meaning "not looked up, because the boundary-sign test settled it". On the claim path every point is now walked, so cells holds the owning cell of every claimed point. On the exact_location path it already did. Say so. Then a caller (evaluate) knows it need not locate those points again.

3. Cost. At np 4, +0.4 s per million points is the price of walking foreign points that are within reach of a rank's cells. That is acceptable for the correctness it buys.

4. Claims on an unsheared mesh. Your identical-at-np-1/2/4 result covers the case I would have checked: a point on a partition face, or in a cell another rank also holds as a ghost, where the walk could claim on two ranks. It shows the walk claims no point that development's _robust_owning_cells did not. One more case worth a line in the body is a point within _EVAL_FACE_TOL outside the domain boundary.

  • Development and this branch both claim it in parallel, through the tolerance search.
  • Serially, development's cell-wall test may answer differently from _EVAL_FACE_TOL.
  • Your serial all-variants-identical result says they agree on your point sets. A point placed at 0.5·_EVAL_FACE_TOL outside a boundary face would pin it.

Underworld development team with AI support from Claude Code

… mean on a simplex mesh (W1's review)

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 16, 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 head d106c7d: ready to merge on green from this review (parallel runs; the code review is the integration lead's). The runs below were made on 74164de; d106c7d changes only docstrings in discretisation_mesh.py, so they stand.

Every claim I could check holds, with two corrections, both in the branch's favour:

  • On a finer 3-D box at np 4, development leaves contained points owned by no rank. The branch's strict claims therefore differ from development there, by exactly those points.
  • The non-strict variant also drops exterior points that development claimed.

The np 4 cost is a little higher in 2-D than the PR body reports.

Build. The diff is Python-only. Its merge base is eccae6d, development at the time of the run. I used an installed build whose compiled sources are identical to eccae6d's. Two overlays went over it: development (eccae6d) and the branch (74164de). Each run printed underworld3.__file__ to confirm which overlay it loaded. Every run used 4 cores, with at most 4 MPI ranks, under the MPI supervisor and an outer timeout. The box is shared with other jobs (load average about 14), so the timings are indicative.

Strict claims on unsheared meshes

The meshes were a 2-D box (cell 1/32), a 3-D box (cell 1/8) and an annulus (cell 1/16, radii 0.5 to 1). Every rank was offered the same point set, about 1.03e5 points:

  • 1e5 random points in the bounding box padded by 10%;
  • every vertex;
  • every vertex moved 1e-9, 1e-7 and 1e-5 in a random direction.

I compared per-rank points_in_domain(P, strict_validation=True) between the branch and development.

mesh np 1 np 2 np 4
2-D box 0 mismatches 0, 0 0, 0, 0, 0
3-D box 0 0, 0 0, 0, 0, 0
annulus 0 0, 0 0, 0, 0, 0

On these meshes the strict claims are identical, as claimed, with no inside point unowned on either tree.

Finding 1: development loses contained points on a finer 3-D box; the branch does not. I also offered the full 1e6-point timing set to every rank on the timing meshes. These are a 2-D box at 1/96 and a 3-D box at 1/20, with points all inside or half outside.

mesh, points np 2 np 4: per-rank mismatches inside points owned by no rank, dev → branch
2-D, inside / half 0 / 0 0 / 0 0 → 0
3-D, inside 0 52, 0, 88, 0 140 → 0
3-D, half outside 0 17, 0, 43, 0 60 → 0

Every mismatch is a point the branch claims and development does not. Each is contained in a local cell by a brute-force barycentric test, with a barycentric margin up to 0.22, so none is near a face. Development's strict claims put each of these points on no rank, and the branch puts each on exactly one.

A swarm confirms it. At np 4, the 140 points added from rank 0 with add_particles_with_global_coordinates(..., migrate=True, delete_lost_points=True) are kept as follows:

  • development: 0 of 140;
  • the branch: 140 of 140.

So on an unsheared gmsh box, development's sign test already loses particles at np 4. The PR body's "identical to development at np 1, 2 and 4" holds on the meshes it measured, but not in general. Its other statement, "claims change only by contained points", holds everywhere I looked. The body could say so: the fix is not specific to sheared meshes.

Non-strict variant (strict_validation=False)

The 2-D box and the annulus are identical at every np. On the 3-D box the branch claims nothing development did not, but it drops some points development claimed:

np, rank dropped contained locally contained by another rank outside the domain
2, r0 162 0 108 54
2, r1 42 0 36 6
4, r0 / r1 / r2 / r3 3 / 287 / 7 / 1 0 3 / 169 / 5 / 1 0 / 118 / 2 / 0

Finding 2. No dropped point is contained locally, and no inside point is left owned by any rank. My counts are larger than the PR body's (1 to 20 per rank) because my point set includes the 10% pad outside the box. Some of the dropped points lie outside the domain, up to 0.099 beyond the box faces. Development's non-strict variant claimed those exterior points by the sign test, so dropping them is a fix. The body's "each is still claimed by another rank" holds for the inside points only.

Sheared box (the PR's fixture)

The point set is the test's own: 5,562 points near edge midpoints, 4,573 of them inside by brute force. "Missed" means inside and in no rank's domain.

The swarm columns:

  • added: a swarm seeded at the inside points from rank 0, migrated with lost points deleted;
  • re-seeded: a swarm populated at fill 3, every particle then moved to a random inside point and migrated.
np tree missed (strict) missed (non-strict) swarm, added swarm, re-seeded
1 dev 449 392 4,124 / 4,573 20,087 / 22,254
1 branch 0 0 4,573 / 4,573 22,254 / 22,254
2 dev 1 1 4,572 / 4,573 23,675 / 23,678
2 branch 0 0 4,573 / 4,573 23,678 / 23,678
4 dev 0 0 4,573 / 4,573 24,587 / 24,587
4 branch 0 0 4,573 / 4,573 24,587 / 24,587

This reproduces the 449 and the 1. On the branch no point is lost at any np. The exterior points claimed under the face tolerance (11 serially, 666 to 667 in parallel) are the same on both trees.

Advection

Solid rotation on an annulus: cell 1/16, populate fill 3, 20 steps of 0.05, second-order advection.

np dev: start / min / end branch: start / min / end 20 steps, dev → branch
1 15,200 / 15,200 / 15,200 15,200 / 15,200 / 15,200 1.09 → 0.64 s
2 15,200 / 15,200 / 15,200 15,200 / 15,200 / 15,200 0.92 → 0.68 s
4 15,200 / 15,200 / 15,200 15,200 / 15,200 / 15,200 0.67 → 0.54 s

The count held at every step, and the particle radii stayed within [0.502, 0.998].

Cost

points_in_domain(strict_validation=True) on 1e6 points in total. At np 4 each rank takes a quarter of one global uniform set. The mesh sizes are the PR's: 2-D box at 1/96, 3-D box at 1/20. "Half outside" draws the points from a centred box of twice the volume. Each run does a warm-up call, then I take the best of 3 of the maximum over ranks.

case np 1: dev → branch change np 4: dev → branch change
2-D, all inside 2.81 → 1.51 s −46% 0.42 → 0.53 s +24%
2-D, half outside 2.06 → 2.19 s +6% 0.36 → 0.55 s +51%
3-D, all inside 9.39 → 2.15 s −77% 1.52 → 1.76 s +15%
3-D, half outside 10.76 → 10.81 s +0.5% 1.54 → 1.93 s +25%

The three repeats agreed within 5%. The shape matches the PR body:

  • serially, interior points are 1.9 to 4.4 times cheaper, and half-outside costs the same;
  • at np 4 the branch costs more.

In 2-D at np 4 the increase is +24 to +51%, against the body's +30 to +57% on its own ratios. The absolute increase is at most 0.4 s per million points. Given finding 1, part of that time buys answers development got wrong.

Empty rank

np 3, with a shell partition that leaves the last rank without cells. Rank 1 was also given an empty input to one strict call. I ran the 2-D box, the 3-D box and the annulus, each with:

  • strict and non-strict calls on 2e4 random points;
  • a swarm populated at fill 2, then migrated (boxes) or advected 3 steps (annulus).
mesh cells per rank dev branch
2-D box 315, 299, 0 4,070 claimed, 0 multiply; swarm 3,684 → 3,684 identical
3-D box 561, 525, 0 1,925 claimed, 0 multiply; swarm 10,860 → 10,860 identical
annulus 760, 760, 0 9,693 claimed, 0 multiply; swarm 9,120 → 9,120 identical

No hang, and the results are identical. The sheared fixture builds its mesh with createFromCellList, not gmsh, so the partition hook does not apply to it. The sheared box was not run with an empty rank.

Tests

  • tests/parallel/test_1213_points_in_domain_exact_parallel.py, under pytest -s -rA --with-mpi:
    • branch: passes at np 1, 2 and 4;
    • development: fails at np 1 ("449 inside points in no rank's domain") and at np 2 ("1 inside points").
  • Neighbours on the branch:
    • serial files: test_0068, test_0113, test_0116, test_0530, test_0784 (global_evaluate), test_0810 and test_1123;
    • parallel files: test_0756, test_0760, test_0777, test_0786, test_0960, test_1076, test_1093, test_1123 (parallel), test_1175 and test_1183.
    • Serially, all files: 45 passed, 26 skipped (MPI-only cases). The parallel files again serially with --with-mpi: 13 passed, 25 skipped (minimum rank count).
    • The parallel files at np 2: 33 passed, 5 skipped on each rank, 0 failed.

Not run:

  • the full serial or parallel suites, and the coverage gate;
  • the neighbours at np 4;
  • the new test on development at np 4;
  • the sheared box with an empty rank (the hook does not apply);
  • timing at np 2.

All logs and scripts are kept by the reviewer.

Underworld development team with AI support from Claude Code

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
lmoresi pushed a commit that referenced this pull request Nov 16, 2026
…el test runs serially too (H1's review)

On the structured fixture the walk from the nearest control point's cell loses no
point even without the boundary-following rule, so that test pins the guarantee but
no longer the rule. test_the_walk_from_boundary_cells_and_its_recovery starts every
point at a random boundary cell: the walk returns only containing cells, every point
it loses left through the boundary, it loses fewer than 0.1 % (54 of 2e5), and the
restarts and exact fallback place every one. With the walk crossing the most
violated face even when it is a boundary face (the rule before), it loses 1232 and
the test fails.

test_1123_exact_locator_parallel: since #1213 points_in_domain is exact serially too,
so the swarm test no longer skips at np 1; docstrings updated.

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi merged commit 1bd2b66 into development Nov 16, 2026
10 checks passed
lmoresi added a commit that referenced this pull request Nov 16, 2026
…not-tangle

test_1123 / test_1183: a sheared box that cannot tangle; the #1183 fallback tested directly (stacked on #1213)
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