Repository navigation
Facet restore: the side test uses the normal where the nearest point lies, including at corners - #1193
Conversation
…ner, and inside a reentrant corner Underworld development team with AI support from Claude Code
…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 #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
Underworld development team with AI support from Claude Code
… a nearest point at a vertex is that vertex The nearest-point search now reports which of the facet's vertices span the point it found (one: a vertex; two: a 3-D edge), from the same clamped values that place it, so the side test agrees with the point. The corner normals are computed for all points at once, which keeps the restore's cost where it was. Underworld development team with AI support from Claude Code
…umber, each facet once The gathered facets now carry their vertices' global numbers, and a facet two ranks both hold is kept once, so a corner's normal counts each facet meeting there once and no vertex is identified by its coordinates. Underworld development team with AI support from Claude Code
Underworld development team with AI support from Claude Code
No conflicts. Underworld development team with AI support from Claude Code
|
Verdict: READY with conditions at d625dff. Every rank returns the same answer, bit for bit, at points near corners and edges that sit on partition seams. This holds at np 2 to 6, in 2-D and 3-D, on generated, file-built and reloaded meshes. In 2-D every outside point near a corner is restored and no inside point moves. The 4-entry cache refreshes after The conditions are text, not code:
Parallel review of #1193 (follows #1192)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.
Check 1: corners and edges on a partition seamMeshes. Each one reaches the facet restore. The check asserts this on every run.
Base points.
Query points. Each base point is offset by 1e-12, 1e-9, 1e-6 and 1e-3 of the smallest cell radius. The directions:
What is checked.
Branch: between ranks. All 55 parallel runs give bit-identical returned coordinates on every rank, and no point whose in/out differs between ranks.
* The wedge layout put no corner of the reloaded 2-D box on a seam. The random layouts did. Base (development) on the same points.
3-D: what the branch still gets wrong, and where it depends on the partition.
The global vertex numbers.
Check 2: the 4-entry cache after
|
| mesh | now restored (truly outside / on / inside) | now left (outside / on / inside) | wrong verdicts: development, branch | restored by both, to a different place; largest move |
|---|---|---|---|---|
| annulus | 0 | 0 | 0, 0 | 730; 2.2e-6 (9.8e-5 of the cell radius) |
| 2-D box, 4 cells | 135 (135 / 0 / 0) | 2 (0 / 0 / 2) | 137, 0 | 529; 6.0e-5 (1.0e-3) |
| 2-D box, cell 0.05 | 40 (40 / 0 / 0) | 1 (0 / 0 / 1) | 41, 0 | 460; 7.1e-7 (7.1e-4) |
| 3-D box | 124 (124 / 0 / 0) | 8 (0 / 0 / 8) | 132, 0 | 805; 4.3e-5 (1.0e-3) |
| shell | 0 | 1 (0 / 1 / 0) | 0, 0 | 1,915; 3.2e-5 (4.7e-4) |
- Now restored: all 299 points on the boxes were truly outside.
- Now left: all 11 points on the boxes were strictly inside. The 1 point on the shell is on the wall.
- Restored positions: every point the branch restores lands strictly inside. On development, 461, 531 and 804 restored points on the three boxes landed on or beyond a wall.
- Positions at vertices move by at most 1.0e-3 of the smallest cell radius, matching the PR's 1.4e-3 bound.
- Agreement with the PR's numbers: these sets are mine, not the PR's, so the counts differ from its 182 and 9. The direction and the classification agree.
- What this sample does not reach: the 3-D residual of Check 1 needs points on an edge's line, which a random sample does not hit.
Check 4: cost against #1192 (development aee3fa6)
Setup.
- Mesh:
SphericalShell(radiusOuter=1, radiusInner=0.5), scaled to 0.9 bydeform. - Timing: maximum over ranks, best of 3.
- Rebuild: clear the cache, then gather.
- Restore: every local node, scaled by 1.02 or by 0.98.
| cell, np | cells | facets gathered | arrays per rank: dev / branch | rebuild: dev / branch | restore ×1.02: dev / branch | restore ×0.98: dev / branch | one point: dev / branch | no points: dev / branch |
|---|---|---|---|---|---|---|---|---|
| 0.06, np 4 | 82,829 | 10,882 | 1.00 / 1.25 MiB | 0.031 / 0.037 s | 0.364 / 0.428 s | 0.369 / 0.432 s | 3.6 / 9.7 ms | 3.5 / 9.4 ms |
| 0.03, np 8 | 628,454 | 42,134 | 3.86 / 4.82 MiB | 0.072 / 0.109 s | 2.10 / 2.31 s | 2.22 / 2.42 s | 15.3 / 41.4 ms | 15.0 / 41.1 ms |
Memory.
- The vertex numbers add 25 % to the gathered arrays, which are 4.8 MiB per rank at 628 k cells.
- No duplicate facets were found: the gathered count equals the sum of the ranks' own facets.
- Peak resident memory is unchanged across the rebuild, to 1 MiB.
Time.
- A full restore costs 10 to 18 % more.
- The fixed cost of a call is 2.7 times what it was, with or without points. On every call,
_outward_normals_at_nearest_pointsruns auniqueover all gathered vertex numbers and accumulates angle-weighted normals over every facet. In 3-D it also runs auniqueover the facet edges whenever a nearest point lies on an edge. - This matters only to a caller that restores small batches many times. Caching the vertex (and edge) normals with the facets, in the same 4-entry cache, would remove it.
Check 5: the issue probes
| probe | development aee3fa6, np 1 / 2 / 4 / 8 | branch, np 1 / 2 / 4 / 8 |
|---|---|---|
return_probe.py, by deform and by a direct write: r = 0.95 → 0.90, r = 0.47 untouched |
correct on every rank | correct on every rank |
caller_probe.py, interior departure points moved, rotations 0.05, 0.2, 0.4, 0.8 and 1.6 rad |
0 at every np and rotation | 0 at every np and rotation |
Both stay fixed. The branch leaves #1192's fix intact.
Check 6: tests
| what | result |
|---|---|
tests/test_1193_facet_restore_corner_normal.py and tests/test_1176_facet_restore_whole_boundary.py, serial |
7 passed |
| the new serial file on development | 3 failed, 1 passed (the L-shape guard), as the PR reports |
tests/parallel/test_1193_…_parallel.py with tests/parallel/test_1176_facet_restore_agrees_across_ranks_parallel.py, np 2, 3, 4, 5, 6 |
5 passed on every rank |
| the same two files, band np 4; emptyband np 3 and np 4 (a rank with no cells); wedge np 4; rand2 np 6 | 5 passed on every rank |
| the new parallel file on development, np 2 | 2 failed on both ranks |
#1192's 17 parallel files (swarm advection, semi-Lagrangian and SUPG history, deform, the movers, 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: the same as on #1192:
- np 2: tests that need 4 ranks, and the multigrid hierarchy case in test_1172;
- np 4: the hierarchy case only.
What passed
- Corners and edges on seams: one answer per point on every rank, bit for bit, in 55 parallel runs.
- Scope: np 2 to 6; corners held by up to 4 ranks; generated, file-built and reloaded meshes; offsets from 1e-12 to 1e-3 of the cell radius.
- 2-D: identical to np 1, bit for bit, on the boxes. On the L-shape the in/out matches np 1, and positions differ by at most 1.7e-3 of a cell.
- Verdicts: no outside point is left in 2-D, and no inside point moves anywhere.
- The global vertex numbers: consistent in every run, including a file-built mesh and reloads. They differ by partition, and the restore does not depend on their values.
- The 4-entry cache: after
deformor a direct write, every rank holds the new facets, normals, vertex numbers and vertex normals, equal to a fresh mesh's, including when only some ranks moved. - One-process changes: every changed verdict is a correction on five meshes. Wrong verdicts go from 41, 137 and 132 to 0 on the three boxes.
- The issue probes, the PR's tests and Facet restore: one answer on every rank, from the whole mesh's boundary (#1176) #1192's tests: all pass.
Not run
- More than 8 ranks, and machines other than the one above.
- A free-surface or advection run in parallel at a cornered boundary.
- The PR's exact point set: Check 3 used an independent set.
- The full suite,
level_3andtier_c. - A non-simplicial mesh, and a mesh without
All_Boundaries. - A reentrant corner in 3-D.
Underworld development team with AI support from Claude Code
…pologically; corner normals built once per geometry _nearest_on_facets_3d now decides which region of a triangle holds the nearest point (a vertex, an edge or the inside) from the signs of the point's offsets from the vertices along the edges, then takes that vertex, the projection onto that edge, or the projection onto the plane. A point beyond a corner along an edge's line is in the vertex's region and gets the vertex itself, so the side test uses the vertex normal; the clamp it replaces could return a point a rounding error off the vertex. _nearest_on_facets_2d decides an end the same way. The coordinate match for the vertex and its TODO(BUG) are gone. The vertex and edge normals are built with the gathered facets and cached with them, under the same collective rebuild, instead of on every call (the parallel review of #1193). Underworld development team with AI support from Claude Code
No conflicts. Underworld development team with AI support from Claude Code
|
The parallel review desk's two points, fixed in this PR as the dev hub asked, at bb6b0ea (fix 6bc317b, tests 5f37ef7, development 918c4ba merged in):
Also run: 114 neighbouring serial files 1060 passed, 9 skipped; #1192's tests serially and at np 2 to 6; guard scan 6 passed; coverage all 472 reachable. Note for the integration desk's probe: the facet cache is still four entries, but the fourth is now the corner normals, not the vertex numbers. Please re-check these two points. Underworld development team with AI support from Claude Code |
|
Verdict: READY with conditions at bb6b0ea. Both round-1 conditions are met in code:
Every rank still returns the same answer, bit for bit. The cached corner normals are rebuilt after The conditions are text, not code:
Re-check of #1193 after round 2 (follows the parallel review at d625dff)This is the re-check by H1 (review and parallel test runs on a 96-thread Linux workstation (Intel Xeon Gold 6240R, AVX-512; MPICH)). It repeats the parallel review's checks 1, 2, 4 and 5 and its tests, with the same scripts, meshes, partitions and query points. What was run.
Round-1 condition 1: the 3-D residual
Met.
Round-1 condition 2: the fixed cost per callCheck 4 used
The round-1 columns are from the round-1 record, measured against development aee3fa6. The development numbers for 918c4ba agree with aee3fa6's to within 2 % for the restore and 8 % for the rebuild.
Check 1 again: corners and edges on a partition seam (55 parallel runs, plus np 1)The meshes, base points, offsets (1e-12 to 1e-3 of the smallest cell radius) and directions are round 1's. The runs are 5 meshes × 11 layouts: default np 2 and 4; wedge np 2 to 6; rand1 np 4; rand2 np 6; band np 4; emptyband np 4.
The 2-D points that now land on a wall.
Check 2: the cache after
|
| probe | development 918c4ba, np 1 / 2 / 4 / 8 | head bb6b0ea, np 1 / 2 / 4 / 8 |
|---|---|---|
return_probe.py, by deform and by a direct write: r = 0.95 → 0.90, r = 0.47 untouched |
correct on every rank | correct on every rank |
caller_probe.py, interior departure points moved, rotations 0.05, 0.2, 0.4, 0.8 and 1.6 rad |
0 at every np and rotation | 0 at every np and rotation |
Tests
| what | result |
|---|---|
tests/test_1193_facet_restore_corner_normal.py and tests/test_1176_facet_restore_whole_boundary.py, serial |
8 passed |
| the new serial file on development | 4 failed, 1 passed (the L-shape guard), as the PR reports. The new edge-line case is among the 4 |
tests/parallel/test_1193_…_parallel.py with tests/parallel/test_1176_facet_restore_agrees_across_ranks_parallel.py, np 2, 3, 4, 5, 6 |
6 passed on every rank |
| the same two files, band np 4; emptyband np 3 and np 4 (a rank with no cells); wedge np 4; rand2 np 6 | 6 passed on every rank |
| the new parallel file on development, np 2 | 3 failed on both ranks |
#1192's 17 parallel files (swarm advection, semi-Lagrangian and SUPG history, deform, the movers, remaps after a move, #1176's multigrid transfer), np 2 |
60 passed, 8 skipped per rank |
| the same 17 files, np 4 | 66 passed, 2 skipped per rank |
The pass and skip counts are the same as round 1's. Nothing failed, so nothing needed checking against development for #1182.
Not run
- Check 3 (the one-process verdict changes against a brute-force inside test) was not repeated.
- The change to the bounding-surface restore, which now uses the same search, was not checked independently.
- The cached 3-D edge normals after a move. Check 2 runs on a 2-D mesh.
- More than 8 ranks, and machines other than the one above.
- A free-surface or advection run in parallel at a cornered boundary.
- The full suite,
level_3andtier_c. - A non-simplicial mesh, a mesh without
All_Boundaries, and a reentrant corner in 3-D.
Underworld development team with AI support from Claude Code
|
Round 3, body only (head unchanged, bb6b0ea):
No code changed. Underworld development team with AI support from Claude Code |
Follows #1192 (merged). The integration desk's review of #1192 found the defect; there is no issue, and this body is the report. Review: the parallel review desk.
What changed and why
Mesh.return_coords_to_boundson a deformed mesh, or on any mesh read from a file, is the facet restore. It finds the nearest point on the boundary facets, and decides whether a query is outside by the sign of (query − nearest point) along an outward normal. The semi-Lagrangian trace-back and swarm advection use it for their departure points and midpoints.The normal was taken from the wrong facet. It came from the facet whose centroid is nearest the nearest point, not from the facet the search found. At a corner where the two walls' facets differ in length, that is the other wall's facet, so points just outside the mesh were judged inside and left where they were.
The integration desk's case: a 2-D unit box, cell size 0.05, deformed by y → y³. 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 the right wall's top facet, 10 were left outside, up to 0.020 below the corner. After: none.
Beyond a corner one facet's normal is not enough either. There the nearest point is the corner vertex, which two or more facets share. The vector from the corner to the query can lie along one wall, square to the other wall's normal. A point at (1.03, 1.0), beyond the corner along the top wall's line, was left there whichever facet's normal was used.
What the side test does now:
deformor a direct write to the coordinates). They were rebuilt over the whole boundary on every call. (Added in round 2.)The 3-D nearest point is now exact in a triangle's edge and vertex regions. The previous search clamped barycentric coordinates and rescaled them, which is not the nearest point there, and could return a point a rounding error off a vertex. Round 1 of this PR identified a vertex by comparing the returned point with the facet's vertices; the parallel review found 7 to 9 of 11,884 outside points beyond a box corner, along an edge's line, that this missed, and which ones depended on the partition. The comparison and its
TODO(BUG)are gone: the feature comes from the region test.The bounding-surface restore (
BoundingSurface.restorefor afacetsurface) calls the same two searches, so its results change where the old search was not the nearest point. On the inputs it gives them (each surface's facets; points within 0.3 of the smallest cell radius of every facet vertex and centroid): an annulus, 380 points, none differ; a spherical shell, 51 of 2,644 differ, by up to 2.6e-4; a 3-D box, 9 of 599, by up to 3.5e-3. On every one of these 60 the new point is nearer the query than the old (by up to 5.4e-3 of the smallest cell radius), and on none farther. There is one search, not a copy, so nothing is retired beyond the approximation.What a user's run gets now
One process: results change at graded corners and next to vertices. Measured against the previous side test (nearest-centroid normal, otherwise the same restore) on the five meshes of #1192's comparison: random points around and far from each mesh, points on facet vertices and on facet centroids.
Every changed verdict is a correction. The boxes keep their walls straight under the grading, so the truth is exact: inside if every coordinate is in [0, 1].
points_in_domain.points_in_domainis 10 points on the annulus and 160 on the shell.The position changes: points restored at a vertex now go inward along the corner's normal, not along one facet's. They move by at most 1.4e-3 of the smallest cell radius.
Cost per call, after round 2. The parallel review measured round 1's fixed cost per call at 2.7 times #1192's (3.6 to 9.7 ms at np 4, 15 to 41 ms at np 8), from rebuilding the corner normals on every call. Measured here: the median of 20 calls of 10 points per rank, the facet cache already built, slowest rank, before (round 1, d625dff) and after (round 2):
np 6, not np 8: the host share for this work is 6 cores. The normals are now built once when the cache is (re)built.
Round 1's comparison against #1192 (best of three, the same 4,000-odd points per mesh, one process). Round 2 does change the per-point cost in 3-D, so this table is round 1's only:
Per-point cost in 3-D after round 2 (the parallel review's measurement, at bb6b0ea). The exact region test in
_nearest_on_facets_3dcosts 105 to 133 µs per point against 48 to 62 µs on development (one process, 8 to 128 candidate triangles). A full restore on the spherical shell therefore takes 1.85 times development's time at np 4 (0.68 s against 0.37 s) and 1.56 times at np 8 (3.25 s against 2.08 s). Rebuilding the cached facets and normals costs 2.5 to 3.5 times development's rebuild, once per geometry. This is the price of the exact answer and is accepted for now; the follow-up is to vectorise the region test over points and candidate triangles. The 2-D search is unchanged in cost.Where a restored point lands. A point outside lands inside the mesh, near its nearest wall: that is the contract. A point beyond a corner that lies on the line of one of the corner's walls to rounding lands 1e-3 of a cell inside the nearest wall and on the other wall's plane, not strictly inside both (the parallel review: 8 of 368 such points on the 2-D box, 8 of 488 on the L-shape, 48 to 60 in 3-D). On the other wall's plane counts as inside, so this meets the contract.
Left: where a tied point lands can depend on the partition. Whether a point is restored does not. Where the nearest point is equidistant from two facets, the search takes the first in the gathered order, and that order follows the partition. The parallel review found, across its partitions, up to 124 points moving by up to 7.1e-4 of a cell, and up to 36 of them (one partition at np 4) strictly inside in one layout and on a wall in another. Breaking the tie by the lowest global facet or vertex number does not cure it: those numbers come from the partition too (
dm.getVertexNumbering()numbers each rank's owned vertices in rank order). A partition-independent key would have to come from the geometry (for example the facet's sorted vertex coordinates), which is more than a tie-break line and is not done here. Between the ranks of one run every point is bit-identical.Parallel: every rank gathers the same facets and vertex numbers, so the answer is the same on every rank. Round 2, a sweep after the parallel review's check 1 on the graded 3-D box (cell 0.2): the 56 boundary vertices on box edges and corners, each offset by 1e-12 to 1e-3 of the smallest cell radius in 46 directions (the 26 lattice directions and 20 random), 10,304 queries of which 6,928 outside. At np 1, 2, 4 and 6: no outside point left outside, no strictly inside point moved, every rank bit-identical. Four outside points land on a wall to rounding (at most 2.8e-17 beyond it), counted as on the wall as in the parallel review; between np 1 and np 6, 12 points differ by at most 6.8e-21. The integration desk's facet-order check from the #1192 review (five random facet orders) gives at most 6 of 5,198 and 21 of 5,200 points differing, by at most 5.6e-17, as on #1192.
Tests
tests/test_1193_facet_restore_corner_normal.py(serial,level_1,tier_b), five cases:test_points_beyond_a_corner_along_an_edge_line_are_returned_inside).tests/parallel/test_1193_facet_restore_corner_normal_parallel.py(level_1,tier_b): the 2-D and 3-D corner points at np > 1, and (round 2) the same 96 edge-line points (test_points_beyond_a_corner_along_an_edge_line_come_back_inside_on_every_rank). Each must come back inside, and every rank must return the same coordinates, bit for bit.Failed first on #1192's code (c996762):
What was run
deform, the semi-Lagrangian or swarm advection, free surfaces, the bounding surfaces or the nearest-point search (not level_3 and not tier_c, 4 workers)scripts/check_test_coverage.pydeform, the semi-Lagrangian or swarm advection, free surfaces, the bounding surfaces, the movers or the nearest-point search (not level_3 and not tier_c, 4 workers)tests/test_0052_collective_guard_scan.py;scripts/check_deprecated_patterns.pyscripts/check_test_coverage.pyWhat was not run
Above np 6 (round 2) and np 4 (round 1); the 27 parallel neighbour files were run in round 1 only; the parallel review's own probe set (11,884 points) was not rerun here, a sweep after it was; a free-surface or advection run in parallel; the full suite;
level_3andtier_c; macOS.Checklist (UW3 Style Charter — docs/developer/UW3_STYLE_CHARTER.md)
level_*andtier_*markers (S8)maybe_/try_/do_) and no commented-out code (S3, S4).array/mesh.X.coords, nowith ....access(...), nomesh.data(S7). The facet gather's existing read ofself.datais unchanged.pixi.toml/pixi.lockor other dependency changes riding in an unrelated PRUnderworld development team with AI support from Claude Code