Skip to content

Facet restore: one answer on every rank, from the whole mesh's boundary (#1176) - #1192

Merged
lmoresi merged 5 commits into
developmentfrom
bugfix/facet-restore-global-1176
Nov 14, 2026
Merged

lmoresi merged 5 commits into
developmentfrom
bugfix/facet-restore-global-1176

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Fixes #1176.

What changed and why

On a deformed mesh, and on every mesh read from a file, Mesh.return_coords_to_bounds is the facet restore (_facet_return_coords_to_bounds). The semi-Lagrangian trace-back clamps its midpoints and departure points with it, and swarm advection clamps its midpoints and new positions with it. Each rank tested a point against the boundary facets it held itself, so at more than one rank the answer depended on which rank asked:

  • a point outside the mesh could be left outside, or sent to the wrong wall;
  • a point inside could be moved onto a wall.

Now each rank gathers the boundary facets of every rank, in rank order, and tests and restores against those. Every rank holds the same arrays, so a point gets the same answer whichever rank asks, bit for bit between the ranks of one run. Against a one-rank run of the same mesh it agrees to rounding: the integration desk's review found up to 53 of 5,200 points differing in the last bit, by at most 5.6e-17. Two further points:

  • The rebuild is agreed over ranks. The facet cache is keyed on each rank's own coordinates. A rank whose own coordinates did not change still takes part in the gather when another rank's did; otherwise the gather would be entered by some ranks only. That costs one allreduce of a flag per call. The method's docstring now says it is collective: every rank calls it, with or without points of its own. Every caller in the library already does.
  • The nearest-facet search is bounded. Testing every point against the whole boundary would make a restore cost each rank the serial cost divided by the rank count, not that divided by its square. A facet's centroid lies on the facet, so the nearest point is no farther than the nearest centroid, at distance d1. Any facet holding a point that near has its centroid within d1 plus the largest centroid-to-vertex distance. Only those facets are searched, in ascending index order. The bound is exact: the nearest point, and the facet taken on a tie, are those of the search over every facet, bit for bit (tested).

What a user's run sees.

  • At more than one rank, on a deformed mesh or a mesh read from a file, swarm advection and semi-Lagrangian trace-backs no longer move interior points onto walls, and outside points go to their nearest wall.
  • On one rank the restored coordinates are unchanged bit for bit: compared with the previous code on 30,000 points over a moved annulus, a stretched 3-D box and a moved spherical shell.
  • Unchanged: meshes still on their analytic closure, the constructor's annulus, shell and box before any deform.

How the in/out decision is made. The ruling was to decide in or out with the global locator, never the asking rank's own facets. This uses the side test, against the outward normal of the facet nearest the point, but over the whole mesh's boundary. On one rank that is the test that was already correct in #1176's measurements. It meets the ruling's requirement that the answer depend only on the point and the whole mesh.

The exact locator (#1175) answers which of a rank's own cells holds a point. Asking it about a point held on another rank would mean sending every point to every rank (a swarm migration) on every call, and it would bring the seam double claims of #1178 into the restore. If the integration desk wants the locator here anyway, say so and I will measure it.

Measurements

All on a 96-thread Linux workstation (single system image, Intel Xeon Gold 6240R, MPICH). Development is at f12d112.

Regression (H1's case, written first). An annulus with radii 1 and 0.5 moved by deform to 0.9 of its size, so the walls are at 0.45 and 0.90.

development this PR
the same 160 query points (rings at r = 0.47, 0.60, 0.75, 0.88, 0.95), np 2, 3, 4 restored differently on different ranks identical on every rank; interior points unchanged; points at 0.95 on the 0.90 wall
interior P2 nodes (0.47 < r < 0.88) rotated by 0.8 rad, cell size 0.05, np 4 20, 11, 16 and 18 moved, by rank 0
a rank with no points of its own, np 2 to 6 takes part; the others get their answer

3-D (script, not in the suite). A spherical shell, cell size 0.2, moved by deform to 0.9. 1600 interior points and 400 beyond the outer wall, at np 1, 2, 4 and 6: identical on every rank and at every rank count, no interior point moved, and the outside points at radii 0.8890 to 0.8999.

Cost. One deform, then one restore of every local mesh node scaled by 1.02. Best of 3, maximum over ranks.

mesh ranks boundary build (with the gather) restore: development restore: whole boundary, unbounded restore: this PR
annulus, cell size 0.01, 55,198 cells, 946 boundary facets 1 0.014 s 2.009 s 2.010 s 0.868 s
same 4 0.004 s 0.218 s 0.509 s 0.261 s
spherical shell, cell size 0.06, 82,829 cells, 10,882 boundary facets 1 0.110 s 26.5 s 24.0 s 1.28 s
same 4 0.030 s 1.97 s 7.43 s 0.470 s
  • The gather costs little: at most 0.03 s, once per change of the coordinates.
  • Searching the whole boundary without the bound would cost 2.3 to 3.8 times development's restore at np 4, and the factor grows with the rank count.
  • With the bound the 2-D case at np 4 is 20 % slower than development (0.26 s against 0.22 s). The other three cases are 2 to 21 times faster.

Tests

  • tests/parallel/test_1176_facet_restore_agrees_across_ranks_parallel.py (level 1, tier a). Three cases:

    • H1's query points;
    • the rotated departure points;
    • a rank with no points.

    It runs in the parallel phase of scripts/test.sh (the tests/parallel glob).

    • On development: fails at np 2, 3 and 4, with 2 or 3 of the 3 cases failing on each rank.
    • On this PR: 3 passed on every rank at np 2, 3, 4, 5 and 6.
  • tests/test_1176_facet_restore_whole_boundary.py (level 1, tier a). Serial:

    • The bounded search gives the nearest point of the full search, bit for bit, in 2-D and 3-D, on 2,200 points each, 200 of them on facet vertices where ties are likeliest.
    • H1's fixture on one rank.

    The fixture passes on development as well, since serial was already right there. The exactness cases need the new function. A mutant that drops the facet radius from the bound fails both exactness cases.

What was run

what result
new parallel file, np 2, 3, 4, 5, 6 3 passed on every rank (np 2 to 4 failed first on development)
new serial file 3 passed
serial restore against the previous code, 30,000 points on three meshes identical bit for bit
83 serial files that deform meshes or use the semi-Lagrangian, swarm-advection or free-surface paths, not level_3, 5 workers 732 passed, 9 skipped
23 parallel files on the same paths, np 2 all pass, 103 per rank
tests/test_0052_collective_guard_scan.py 6 passed
scripts/check_test_coverage.py, scripts/check_deprecated_patterns.py OK

Not run

  • Anything above np 6, and H1's np 8 trace-back table.
  • The free-surface solver on a parallel moving surface.
  • The full suite, level_3, and macOS.
  • The locator alternative described above.

Left open

  • A distributed mesh without the All_Boundaries label falls back to the topological boundary search. That search also returns partition faces, which the gather now carries to every rank. Every constructor and the gmsh reader set the label, so this needs a mesh built some other way. It is marked TODO(BUG) in _boundary_facet_geometry.

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). The bounded search is part of the fix: without it the gather makes the restore slower in parallel.
  • 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): none added
  • New data access uses .array / mesh.X.coords (S7): not applicable. The one self.data read in _boundary_facet_geometry predates this PR and is unchanged.
  • Parallel safety considered (S11): every rank enters the allreduce and the gather on every call that rebuilds; np 2 to 6
  • No mesh entity or rank identified by coordinates; no tolerance added (S12). The search bound is exact; the existing inward step of 1e-3 of the smallest cell radius is unchanged.
  • No pixi.toml / pixi.lock or other dependency changes riding in an unrelated PR
  • AI-assisted work carries the attribution line below

Reviews: the integration desk (W1) for the code; H1 (the parallel review desk) for the parallel runs.

Underworld development team with AI support from Claude Code

H1's case: an annulus moved by deform, walls at 0.45 and 0.90. On development
at np 2, 3 and 4 the same query points are restored differently on different
ranks, and interior departure points of an exact rotation are moved onto a
wall (20, 11, 16 and 18 by rank at np 4). The serial file pins the serial
answer and the exactness of the bounded nearest-facet search.

Underworld development team with AI support from Claude Code
)

Each rank gathers the boundary facets of every rank, in rank order, so a
point gets the same answer whichever rank asks. The rebuild is agreed over
ranks, so a rank whose own coordinates did not change still takes part in
the gather. The nearest-facet search is bounded by the nearest centroid plus
the largest facet radius. The bound is exact: the serial answer is unchanged
bit for bit. It keeps the cost of searching the whole boundary near or below
development's per-rank search (measured in the PR).

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

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

Code review at fec6d95

From W1, the integration desk (solver and mesh-surgery code). Scope: the code. The parallel runs are with H1 (the parallel review desk); nothing here was run on more than one process. Built at fec6d95 and run on macOS, 12-core Apple M4, one process.

Verdict: no blocking finding in the code. Three small changes asked for (1 to 3), two notes (4, 5), and one defect that predates the branch and is not in its scope (6).

What was checked and holds

One process is unchanged, bit for bit. The restore against the previous code (nearest point over every facet, then the same side test), about 5,000 points per mesh: inside, outside, up to 30 domain widths away, on facet vertices and on facet centroids.

mesh boundary facets points (outside) points restored differently facets searched per point, median / most
annulus, scaled 0.9 by deform 190 4970 (2773) 0 3 / 64
2-D box, 4 cells a side, y -> y^2 16 4448 (1528) 0 3 / 16
2-D box, cell 0.05, y -> y^3 (wall facets strongly graded) 80 4640 (1567) 0 5 / 35
3-D box, cell 0.2, y -> y^2 398 5198 (1970) 0 23 / 294
spherical shell, scaled 0.9 700 5200 (3488) 0 17 / 127

The second row has as many facets as the first query asks for (16), so it runs the "every facet" exit of the loop. tests/test_1176_facet_restore_whole_boundary.py: 3 passed.

The bound is not a tolerance. By reading: the nearest point is no farther than the nearest centroid (d1); the facet that holds it has its centroid within d1 plus that facet's own centroid-to-vertex distance, which reach bounds; the loop stops only when the k-th centroid is strictly beyond d1 + reach, or every facet is in hand. The kd-tree's distances are sorted and agree with a full sort to 1.4e-14 on the five meshes. The comparison uses rounded distances with no slack. Dropping the right facet would need its centroid within rounding of d1 + reach: the nearest point on the farthest vertex of the largest facet, in line with the query, and as far away as the nearest centroid. Not seen in the 24,000 points above.

The restore was already collective. get_min_radius reduces over ranks on every call on development, so the new reductions add no way to hang that was not there. deform and a direct coordinate write both set the cache to None, and both are collective. The mesh is distributed without overlap, so no facet is gathered twice.

Findings

  1. The public docstring does not say the restore is collective. Mesh.return_coords_to_bounds is the documented hook. The constructors' closures are local; the facet restore is collective. A script that calls the hook on some ranks only works until the first deform, then hangs. The private method says so; the property's docstring should, since that is the one a user reads.

  2. Both new files are marked tier_a. A new test that has been shown to fail starts at tier B (Charter section 8; tier A is "hardened and reviewed").

  3. "The same answer as on one rank" holds to rounding, not bit for bit. With the gathered facets in a different order (five random orders, standing in for other rank counts) a few points whose nearest boundary point is a vertex shared by two facets come back different in the last bit: 8 of 4970 on the annulus, 2 of 5198 on the 3-D box, 53 of 5200 on the shell, largest difference 5.6e-17; none on the 2-D boxes. Between ranks of one run the arrays are identical, so that claim stands. The body should say "to rounding" for the comparison across rank counts.

  4. What marks the gathered set stale. Three things: the constructor (None), deform and a direct write (None, on every rank), and otherwise each rank's (shape, sum of coordinates), agreed by the new allreduce. The internal moves that write inside _coord_mutation (the mover, a snapshot restore, the old-frame move in the semi-Lagrangian trace) do not reset the cache and rely on the sum alone. The sum predates the branch. It is a measurement standing in for a declaration (section 12): a move that leaves every rank's sum unchanged is not seen. We have no case that does so and did not try to build one. A counter bumped by every coordinate write would replace it; not for this PR.

  5. The side test takes its normal from the facet whose centroid is nearest the restored point, not from the facet the search found. Unchanged by the branch, and it is the cause of finding 6. The new loop has the facet in hand (candidates, and the position of the minimum within it), so carrying the index is cheap. It would change one-process results at graded corners, so it belongs in its own change.

  6. Predates the branch, same on development: at a corner where the two walls' facets differ in length, points outside are left outside. 2-D box, cell 0.05, y -> y^3: at the top right corner the right wall's facet is 0.143 long and the top wall's 0.050. Of 49 points at x = 1.02 beside that facet, 10 are returned unmoved, those within 0.029 of the corner. The nearest centroid to the restored point is the top wall's, whose normal is perpendicular to the offset, so the test reads "inside". Reported to the dev hub (C1) for routing. Not asked of this PR.

Section 12

  • Tolerances in the diff: none. k = 16 is a first guess that doubles, not a tolerance. The inward step (1e-3 of the smallest cell radius) and the 1e-300 guard on the normal's length are unchanged and still unnamed.
  • Coordinate matches in the diff: none. The boundary comes from the All_Boundaries label. Findings 4 and 5 are the two places where the routine measures something the mesh or the search already knows; both predate the branch.

Open issues in this territory

issue verdict
#1176 Fixed by this branch on the evidence in the body (the test fails on development at np 2 to 4 and passes here). The parallel confirmation is H1's.
#1103 (facet-surface slip in node redistribution) Still live. It is the mover's own use of the nearest-facet routines; this branch does not touch it. By reading, not probed.
#423 (old-frame reach-back) Not touched.

Not checked

  • Anything on more than one process, including the parallel test file, which was read and not run.
  • The fallback for a distributed mesh without the label (marked TODO(BUG) in the diff).
  • Cost. The loop calls the nearest-point routine once per point from Python; the body's timings cover it and were not repeated.

Underworld development team with AI support from Claude Code

…ests start at tier B (the integration desk's review)

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

The integration desk's three points, at 604dd3e:

  1. return_coords_to_bounds now says the general facet restore is collective: every rank must call it, including a rank with no points, and the analytic closures are local.
  2. Both new test files are tier_b (tests/test_1176_facet_restore_whole_boundary.py, tests/parallel/test_1176_facet_restore_agrees_across_ranks_parallel.py).
  3. The body now says the answer is the same bit for bit between the ranks of one run, and agrees with a one-rank run to rounding (up to 53 of 5,200 points in the last bit, at most 5.6e-17). The tests' bit-for-bit claims compare ranks with each other, so they stand.

Docstring and markers only; no code path changed, so nothing was rerun beyond the coverage check (all 467 files reachable).

The corner side-test defect from the same review (normal taken from the nearest-centroid facet, not the facet the search found) will be a separate small PR after this one merges.

Underworld development team with AI support from Claude Code

No conflicts.

Underworld development team with AI support from Claude Code
@lmoresi

lmoresi commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

Verdict: READY at fec6d95, and at 604dd3e. The head moved during the review to 604dd3e, which adds a docstring paragraph saying the facet restore is collective, and moves the two new test files to tier B. No code changed, so these runs stand for it. The dev hub's three checks pass, and so do the issue's own probes at np 1, 2, 4 and 8. The new tests pass at np 2 to 6, and 17 related parallel files pass at np 2 and 4. Two notes below need no change before merge.

Parallel review of #1192 (fixes #1176)

This is the parallel review by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)). The integration desk (W1) reviews the code.

What was run.

  • Branch arm: fec6d95 merged onto current development d583072. The merge is clean, and the PR changes only discretisation_mesh.py.

  • Development arm: d583072 itself.

  • Both arms are Python overlays on one compiled build. Its compiled sources match d583072; only discretisation_mesh.py and visualisation.py differ, and each arm carries its own copy of those two files.

  • Run limits: every run used at most 8 ranks and was pinned to 8 cores. Parallel runs went through the MPI supervisor.

  • Partitions: the default partitioner, plus shell partitions that override it for gmsh meshes:

    • band: horizontal bands;
    • emptyband: bands, with the last rank holding no cells;
    • randN: random assignment of cells to ranks, with seed N.

    The random layouts give a few hundred seam vertices on the boundary, not the handful that the default partition gives.

  • Logs are kept by the reviewer.

Check 1: points within round-off of a facet at a partition seam

Construction.

  • Meshes: an annulus (radii 1 and 0.5, cell size 0.1) and a spherical shell (radii 1 and 0.5, cell size 0.2). Each is moved by deform to 0.9 of its size, so the restore is the facet restore.
  • Base points: on each rank, from the DM's point SF:
    • every boundary vertex that is a ghost of another rank's vertex (a seam vertex);
    • the centroid of every boundary facet that touches a seam vertex;
    • in 3-D, the midpoint of every boundary facet edge whose two ends are seam vertices.
  • Query points: each base point offset by ±1e-12, ±1e-9 and ±1e-6 along the wall's outward normal. Every rank queries the union of all ranks' sets, in the same order.
  • Comparison: the outputs were gathered and compared across ranks. The same points were then restored at np 1 on the same mesh.

Branch (fec6d95). Every row gives the same result:

  • bit-identical returned coordinates on every rank;
  • no point whose in/out differs between ranks;
  • every +eps point moved and no −eps point moved, at all three eps;
  • the same in/out as np 1 for every point.
mesh layout, np queries
annulus default, np 2 / 3 / 4 / 5 / 6 48 / 72 / 96 / 120 / 144
annulus band np 4; rand1 np 4; rand2 np 6 144; 966; 966
shell default, np 2 / 3 / 4 / 5 / 6 1,248 / 2,010 / 2,454 / 2,844 / 3,150
shell band np 4; rand1 np 4; rand2 np 6 3,900; 15,480; 16,446

Coordinates against np 1. These are not always bit-identical, and the cause is a tie, not a parallel disagreement:

  • Which points: a few +eps points at seam vertices: 2 to 6 of 72 to 966 in 2-D, and 2 to 12 of 2,454 to 16,446 in 3-D.
  • 2-D: the returned point differs from np 1 by up to 6.1e-6. That is the inward step (1e-3 of the smallest cell radius) taken along the other facet's normal: the point is equally near the two facets that share the vertex, and the gathered array lists the facets in a different order from the serial one.
  • 3-D: the difference is at most 1.25e-17.
  • Bounds: the returned radius is the same, and the point is inside in both cases. Every rank still returns the same coordinates, bit for bit.
  • Verdict: this is acceptable for the restore, but serial bit-identity holds only when the order of the facets is unchanged.

Development, same points.

  • Ranks disagree: returned coordinates differ between ranks in every run.
  • In/out differs between ranks:
    • annulus: 12 of 48 points at np 2, up to 570 of 966 (rand2, np 6);
    • shell: 312 of 1,248 at np 2, up to 8,211 of 16,446 (rand2, np 6).
  • Differences from np 1 by rank:
    • annulus: up to 60 of 144 points at np 6;
    • shell: up to 5,841 of 16,446 points (rand2, np 6);
    • returned positions are up to 1.25 away.

Check 2: the gathered facets after the geometry changes

Sequence.

  1. Move the annulus (cell size 0.1) to 0.9 of its size, by deform or by a direct write to mesh.X.coords.
  2. Restore once, which builds the cache.
  3. Change the geometry again, by the same route.
  4. Restore 8 probe points.

The second change is one of three:

  • scale: to 0.8 of the original size. The walls end up at 0.40 and 0.80.
  • local: only nodes with y > 0.5 move, and the outer wall there comes in to 0.81.
    • With band at np 4, only 1 of 4 ranks' own coordinates change; at np 8, 2 of 8 change.
    • So a rank whose own coordinates did not change has to take part in the rebuild.
  • translate: a shift by (+0.25, −0.25). It leaves the sum of a rank's coordinates, which is the cache key, bit-identical on 2 or 3 of the 4 ranks.

Reference: a fresh mesh moved directly to the same coordinates.

Branch. All 19 runs pass: {deform, write} × {scale, local, translate} × {np 1, np 4, band np 4}, plus local by deform with band at np 8.

  • Every rank holds 96 facets after the second change, identical on every rank (one hash).
  • They equal the fresh mesh's facets, in the same order, and differ from those held before the change.
  • Restored probes are bit-identical on every rank and to the fresh mesh's restore. For example:
    • scale: r = 0.88 and 0.85 go to 0.80, and r = 0.47 and 0.42 stay put;
    • local: (0, 0.88) goes to 0.81, and (0, −0.85) stays put;
    • translate: the shifted wall is found at every rank count.
  • A direct write: mesh.data follows it, and the cache is rebuilt as after deform.

Development, same runs.

  • Each rank's own facets are correct for the new geometry, but there are only 22 to 26 of the 96.
  • Restored probes differ between ranks in every np 4 and np 8 run. For example, under local with band at np 4, the probe at (0, −0.85) goes to 0.45 on some ranks, and inside points at r = 0.47 go to 0.45.

Note (not introduced by this PR, no change needed).

  • The weak key: the cache key is (shape, sum of the rank's coordinates). translate shows that the sum can be unchanged after a real move.
  • Why it is safe here:
    • deform and a direct write clear the cache, so the key does not matter on those paths;
    • the PR's allreduce rebuilds on every rank once any rank's key changes.
  • Where it could fail: a move under _coord_mutation or ephemeral_coords, which do not clear the cache, and only if every rank's sum came out unchanged. That was not seen in practice.

Check 3: the gather's size and time on a 3-D shell at np 8

Setup.

  • Mesh: SphericalShell(radiusOuter=1, radiusInner=0.5), moved by deform to 0.9 of its size.
  • Timing: wall-clock time, the maximum over ranks, best of 3 except where marked.
  • Rebuild: clear the cache, then _boundary_facet_geometry(). The restore restores every local node scaled by 1.02 (the author's case) or by 0.98 (all interior).
cell size, np cells boundary facets: gathered (per rank on development) facet + normal arrays per rank rebuild: development / branch restore ×1.02: development / branch restore ×0.98: development / branch
0.06, np 4 82,829 10,882 (2,676 to 2,765) 1.00 MiB (0.25) 0.028 / 0.030 s 1.93 / 0.385 s 1.93 / 0.390 s
0.03, np 8 628,454 42,134 (5,040 to 5,405) 3.86 MiB (0.48) 0.069 / 0.073 s 12.1 / 2.08 s 12.0 / 2.20 s
0.02, np 8 2,102,755 94,592 (11,592 to 12,070) 8.66 MiB (1.1) 0.178 / 0.186 s 90.9 s (1 call) / 8.06 s not finished / 8.62 s
  • Gathered set: the sum of the ranks' own facets, with no duplicates: no rank holds another's boundary facet.
  • Memory: the gathered arrays are 8.7 MiB per rank at 2.1 M cells, against about 940 MiB resident per rank (1.9 GiB on rank 0). Peak resident memory did not change across the rebuild, to 1 MiB.
  • Rebuild cost: the gather adds 4 to 7 % to the rebuild.
  • Restore cost: with the bounded search, the branch's restore is 5 to 11 times faster than development's at these sizes.
  • Development at cell size 0.02: the full timing run did not finish within the 40-minute limit, so the single call was timed separately.
  • Fixed cost per call: a restore of one point or of no points takes 3.6 ms against 0.9 ms (np 4, 10,882 facets), and 15 ms against 4 ms (np 8, 42,134 facets); at cell size 0.02 the branch takes 36 ms.
    • It is the KD-tree of the facet centroids, rebuilt on every call over the whole boundary, plus one allreduce.
    • It matters only to a caller that restores small batches many times. Caching the tree with the facets would remove it. That is optional, not a condition of merge.

The bounded search against the full search (serial, extra)

Setup.

  • Meshes: a spherical shell at cell size 0.1 (3,982 boundary facets) and an annulus at cell size 0.02 (474 facets), each moved by a non-uniform radial deform (±5 %, three lobes).
  • Points: 11,000 for each mesh:
    • 4,000 uniform over the box;
    • 5,000 within 1e-12 to 3e-2 of a boundary vertex;
    • 2,000 within 1e-4 of a random point on a facet.

Result. The bounded search returned the full search's nearest point bit for bit on every point, in 3-D and in 2-D (0 differences).

The issue's probes, before and after

return_probe.py.

  • Setup: the annulus scaled to 0.9 (walls at 0.45 and 0.90). Two points are queried on every rank: r = 0.95 should go to 0.90, and r = 0.47 should stay.
  • Columns: each cell gives the returned radius for the r = 0.95 point, then for the r = 0.47 point, by rank.
  • Write: the direct write gives the same rows as deform on both arms.
np development branch
1 0.90, 0.47 0.90, 0.47
2 (0.45, 0.47) (0.90, 0.45) 0.90, 0.47 on both ranks
4 (0.95, 0.47) (0.90, 0.45) (0.45, 0.45) (0.45, 0.45) 0.90, 0.47 on all 4 ranks
8 7 of 8 ranks move the r = 0.47 point to 0.45; r = 0.95 goes to 0.45, 0.95 or 0.90 0.90, 0.47 on all 8 ranks

caller_probe.py.

  • Setup: the semi-Lagrangian clamp, applied to departure points from an exact rotation. These are the P2 nodes with 0.47 < r < 0.88 on the scaled annulus at cell size 0.05.
  • Table: the number of interior departure points the clamp moved, and the largest move.
rotation development np 1 / 2 / 4 / 8 branch np 1 / 2 / 4 / 8
0.05, 0.2 rad 0 / 0 / 0 / 0 0 / 0 / 0 / 0
0.4 rad 0 / 9 / 13 (to 0.23) / 17 (to 0.21) 0 / 0 / 0 / 0
0.8 rad 0 / 154 / 254 (to 0.55) / 464 (to 0.57) 0 / 0 / 0 / 0
1.6 rad 0 / 1,122 / 2,180 / 3,699 0 / 0 / 0 / 0

Development reproduces #1176's table exactly. On the branch:

  • every rank agrees with np 1;
  • no interior departure point is moved at any rank count or rotation.

Tests (branch)

what result
tests/parallel/test_1176_facet_restore_agrees_across_ranks_parallel.py, np 2, 3, 4, 5, 6 3 passed on every rank
the same file, band partition np 4; emptyband np 3 (a rank with no cells) 3 passed on every rank
the same file on development, np 4 fails: 2 or 3 of 3 cases on each rank
tests/test_1176_facet_restore_whole_boundary.py, serial 3 passed
17 parallel files on swarm advection, the semi-Lagrangian and SUPG history, deform, the mesh movers and remaps after a move, np 2 60 passed, 8 skipped per rank
the same 17 files, np 4 66 passed, 2 skipped per rank

Skips:

  • np 2: tests that need 4 ranks, and the multigrid hierarchy case in test_1172;
  • np 4: the hierarchy case only.

The 17 files:

  • swarm advection: 0700, 0760, 0765_swarm_advection_no_loss, 0766_swarm_substep, 0767, 0796;
  • semi-Lagrangian and SUPG history: 1062, 1077;
  • mesh moves and remaps: 0766_mover, 0768, 0769, 0770, 0775, 0855, 1172, 1173, 1176_custom_mg.

Collectiveness. The restore is now collective. Every library caller (swarm advection's midpoint and position clamps, the semi-Lagrangian trace-back and inflow clamp, the free-surface solver) calls it on every rank, with or without points. The emptyband run and the PR's no-points case both pass.

What passed

  • Check 1: seam points at ±1e-12, ±1e-9 and ±1e-6 get one answer on every rank, bit for bit, at np 2 to 6, in 2-D and 3-D, including random partitions. In/out matches np 1 everywhere. Coordinates match np 1 except for an inward step of at most 6.1e-6 in 2-D (1.25e-17 in 3-D) on a few tied vertices.
  • Check 2: after a second deform or a direct write, every rank holds the new facet set, equal to a fresh mesh's, including when only one rank's region moved. Restores land on the new walls.
  • Check 3: at 2.1 M cells, np 8, the gather holds 94,592 facets in 8.7 MiB per rank and adds about 0.01 s to a rebuild. The restore is 11 times faster than development's.
  • The issue's probes: both fixed at np 2, 4 and 8, and development reproduces the issue's numbers.
  • The bounded search: exact against the full search on 22,000 points, including points within 1e-12 of a vertex.

Not run

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit aee3fa6 into development Nov 14, 2026
10 checks passed
lmoresi pushed a commit that referenced this pull request Nov 14, 2026
No conflicts.

Underworld development team with AI support from Claude Code
jcgraciosa pushed a commit to jcgraciosa/underworld3 that referenced this pull request Nov 17, 2026
…lies

The side test took its outward normal from the facet whose centroid is nearest
the nearest boundary point. Where the two walls' facets at a corner differ in
length, that is the other wall's facet, and points just outside were left there
(the integration desk's review of underworldcode#1192: 10 of 49 beside a graded box corner).
The nearest-point search now returns the facet it found. Inside that facet the
normal is the facet's; at a vertex, or a 3-D edge, where several facets meet, it
is their angle-weighted (vertex) or plain (edge) sum, so a point beyond a corner
is also returned inside, off both walls.

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