Skip to content

Preserve physical query positions near exact-cell faces - #859

Open
gthyagi wants to merge 2 commits into
underworldcode:developmentfrom
gthyagi:bugfix/exact-cell-point-evaluation
Open

gthyagi wants to merge 2 commits into
underworldcode:developmentfrom
gthyagi:bugfix/exact-cell-point-evaluation

Conversation

@gthyagi

@gthyagi gthyagi commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Queries close to an exact-cell face can be evaluated at the wrong physical position. The loose cell-wall tolerance admits a neighbouring cell, then PETSc reference-coordinate clamping moves the query onto that face. An exactly representable continuous P1/P2 field with an interface-aligned gradient jump consequently shows a maximum error of 5.806e-6 in both serial and MPI16; tightening containment reduces it below 8e-17.

Use roundoff-scale containment for full-dimensional, geometrically exact cells. Preserve the previous tolerance for approximate warped faces and embedded manifolds. Add P1/P2 kink and global-polynomial regressions, including queries exactly on and on both sides of a shared face. This changes the existing locator's tolerance, without extending its geometric authority.

Validation on Gadi with PETSc int32: 22 UW3 tests pass in serial and on each of 16 MPI ranks; 272 annulus components and the existing exact-transfer gates also pass. The tested feature implementation is ef62a45; this review branch applies only the two-file point-evaluation change onto current development. Four matched complete h=1/32 annulus workflows (case1/case2, serial/MPI16) also pass: velocity, pressure, topography and potential fields remain unchanged within 1.4e-14 relative difference; native potential coefficients agree with independent affine-P2 interpolation on the same physical-circle grid within 3.4e-16 of reference magnitude. The independent audit separately refines angular quadrature.

Review follow-up (29 October 2026)

Clarified _robust_owning_cells: a manifold's exact capability establishes intrinsic cell-wall classification authority, not roundoff-level ambient surface coincidence. Its wider tolerance remains deliberate until an off-surface projection contract is defined. This follow-up changes documentation only.

Caller audit: function.functions_unit_system.evaluate requests the extrapolation mask internally and forwards it to _warn_if_points_are_not_owned, so marginally outside points may now produce a warning. The compiled global_evaluate_nd local-query and fallback calls also consume that mask when routing unmatched points; public callers requesting check_extrapolated=True receive the changed classification. This documents the behavior change identified in the review without suppressing it or restoring clamped FE values.

Rebuilt in an isolated native Mac environment. The existing exact-cell regression file passes all 4 tests in serial and on every MPI3 rank (continuous gradient jumps and exactly represented P1/P2 polynomials). No solver settings changed.

Underworld development team with AI support from Claude Code

Tighten full-dimensional exact-cell containment so neighbouring-cell hints cannot shift continuous-field probes through reference-coordinate clamping. Keep approximate warped-face and embedded-manifold tolerances unchanged.

Validation: Gadi int32 installation at feature ef62a45, 22 native regressions in serial and on each of 16 ranks, 272 annulus components, and exact submesh-transfer gates passed. Prior-runtime serial/MPI reproducer has 5.806e-6 error; tight tolerance reduces it below 8e-17. Four matched annulus workflows are being independently audited.
@lmoresi

lmoresi commented Oct 28, 2026

Copy link
Copy Markdown
Member

Adversarial review

We attacked this one hardest, because it reverts a tolerance a previous PR set
for a stated reason and the deleted comment names a prior incident
(project_pr207_loose_boundary_clash). The concern was that a point no rank
claims is flagged extrapolated and valued by local RBF rather than FE
interpolation (_function.pyx:664-690), and that stranding partition-seam node
queries would reintroduce partition dependence. Both attacks failed, and the
second supports the change.

Probe 1 — node queries, the case stranding would hit. np=3,
UnstructuredSimplexBox h=1/16, P2, an exactly representable linear field,
querying the global set of all ranks' node coordinates (1293 points), so each
rank's seam nodes are queried by every rank:

tol=1e-2    0 stranded   max|err| 2.663e-12   118 of 1293 above 1e-12
tol=1e-10   0 stranded   max|err| 6.695e-13     0 of 1293 above 1e-12

Tightening strands nothing and is strictly more accurate.

Probe 2 — the case the deleted comment actually names ("query coordinates
slightly off the face, e.g. RBF-shifted node points"): the 132 boundary nodes
nudged outward along the wall normal.

nudge    tol=1e-2                        tol=1e-10
1e-6     0 stranded, max|err| 5.000e-6   132 stranded, max|err| 8.734e-6
1e-4   132 stranded, max|err| 8.675e-4   132 stranded, max|err| 8.675e-4
1e-3   132 stranded, max|err| 8.130e-3   132 stranded, max|err| 8.130e-3

At a 1e-6 nudge the old tolerance claims all 132 points as inside
(outside=False) and returns a face-clamped value wrong by about
|grad| x d. The new tolerance reports them as outside. The two values carry
the same order of error; the difference is that the old one misreports a point
it did not locate. That is the thesis of this PR, and it holds.

One behaviour change for the record, not a defect. For queries marginally
outside the mesh, check_extrapolated now returns True where it returned False
— 132 of 132 at a 1e-6 nudge — and the value route changes from a clamped FE
interpolation to local RBF. Any caller that queries marginally-outside points
and branches on that flag changes behaviour. Worth naming those callers before
this lands; the magnitudes above say the values do not get worse, only the
classification changes.

One asymmetry worth a sentence in the docstring. The gate is

self.dim == self.cdim and self._location_capability() == "exact"

but _location_capability returns "exact" for manifold meshes precisely
because "PETSc's own in-cell test is the unreliable party" there. So manifolds
are audited exact yet keep the loose tolerance. The description says this is
deliberate; the docstring should say why, since the gate now disagrees with the
capability it queries.

Nothing here blocks.

Distinguish intrinsic classifier capability from ambient off-surface query handling without changing locator behavior.

Underworld development team with AI support from Claude Code
@gthyagi

gthyagi commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @lmoresi. Addressed the documentation point in c4ec1bfd: _robust_owning_cells now distinguishes the manifold classifier's intrinsic authority from ambient off-surface query handling, explaining why the wider manifold tolerance remains deliberate.

The caller audit identifies functions_unit_system.evaluate and _warn_if_points_are_not_owned, plus the local-query/fallback paths in global_evaluate_nd, as consumers of the extrapolation mask. Marginally outside points can therefore change warnings, routing, and the mask returned to callers requesting check_extrapolated=True. This behavior change is now recorded in the description.

After an isolated native Mac rebuild, all 4 existing exact-cell tests pass in serial and on every MPI3 rank. This follow-up changes documentation only.

@gthyagi
gthyagi marked this pull request as ready for review October 29, 2026 12:46
@gthyagi
gthyagi requested a review from lmoresi as a code owner October 29, 2026 12:46
@lmoresi

lmoresi commented Nov 6, 2026

Copy link
Copy Markdown
Member

Adversarial review of #859

Verdict: not ready until the tolerance scales. The fix is real at unit scale and closes #799's symptom, but the new tolerance is absolute and sits below the discriminator's roundoff once model-unit coordinates reach about 10. There the PR silently loses or misvalues points that development handles correctly. A scaling that keeps the gain looks small; see the merge conditions.

Reviewed at head c4ec1bfd. Its base 7222caf3 is 344 commits behind development eddab707; git merge-tree is clean. Finding 1's annulus row was reproduced separately: L=100, 144 of 9144 unclaimed; L=1, 0 of 9120.

Findings

  1. High. On-face points go unclaimed at model size of about 10 or more, because the tolerance is absolute. The face test is diff > -tol*sep2, which is d < tol*1e-3 with a fixed 1e-3 control-point offset, so d < 1e-13 in model units. The noise in diff grows with cell size times coordinate size (our estimate, about eps*h*L). Share of on-edge points claimed by no cell:

    mesh res this PR development
    box3 L=10 6 0.72% not run
    box3 L=1000 6 3.44% 0
    annulus L=10 8 0.32% not run
    annulus L=100 16 1.57% 0
    shell L=5 6 0.008% not run
    shell L=10 6 2.06% not run
    shell L=20 6 8.84% not run
    shell L=100 16 8.71% not run

    Annulus losses are all on the domain boundary; in the shell (L=10, res 8), 153 of 781 were away from both boundaries. A comment in _get_closest_local_cells_internal cites a mesh 6371 across as measured, so these sizes are in use.

  2. High. The wrong values are silent in serial. P2 field holding an exact quadratic, off-node on-edge points, check_extrapolated=True: annulus L=100, 144 of 9144 wrong, max error 1.56e-2, outside_flag=0 (development 0 wrong, max 6.2e-15). Shell L=100, 51107 of 586744 wrong, max 4.4e-2, outside_flag=0. At np=4 the annulus L=100 case flags 135 such points as outside, max error 1.6e-2 (development 0 flagged, max 6.2e-15).

  3. High. Swarms lose particles sitting on faces in the closed domain. Kept after add: annulus L=100, 8966/9144 at np=2, 8944/9144 at np=4; shell L=100, 31469/35824 at np=2, 30982/35824 at np=4. Development keeps all. At L=1 both keep 9120/9120.

  4. High. Exposure follows the choice of reference length, not the physics. Same annulus, R=6000 km, h=375 km, unclaimed: reference 6000 km, 0; 1000 km, 0; 100 km, 1.16%; 10 km, 1.69% (development 0); 1 km, 1.55%. "Relative to the control-point separation" is an absolute length in model units.

  5. Medium. The serial classifier and the new locator disagree just outside a wall. points_in_domain still uses the -1e-12 floor; the locator uses d < 1e-13. Box L=1, np=1, off-node points on the wall offset by d=1e-12 or 1e-10: this PR gives in_domain=200, outside_flag=0, max error 1.13e-2; development 3e-12 and 3e-10.

  6. Medium. The earlier record's "values do not get worse" holds only at nodes, where the RBF fallback is near exact. Off-node, box L=1, np=2, d=1e-6: this PR 1.13e-2 (flagged outside), development 3.0e-6. The classification is now honest, but the value is about 3800 times worse in that band. The PR body should say so.

  7. Medium. The test does not pin the tolerance and looks only one way. It fails on the old code for its stated reason, but mutants at tol=1e-4 down to 1e-14 and 0 all pass; only tol >= 1e-3 fails. It uses one axis-aligned face at L=1, where roundoff vanishes, so it cannot see finding 1.

  8. Low. Charter section 8: test_1090_evaluation_near_interface.py has no level or tier marker.

  9. Low. Charter section 7: the test writes field.data[:,0]. The CI pattern scan covers src/ only.

  10. Low. Stale or false text. The _get_closest_local_cells_internal docstring says "mesh-spacing-relative" and "wider than" the -1e-12 floor; it is now 4e-16 against 1e-12. The points_in_domain comment and _robust_owning_cells promise a valid cell for any on-face point. The "exactly one rank" comment beside _EVAL_FACE_TOL is false: 388 of 2500 points had 2 owners at np=4, L=1.

  11. Low. Charter section 4: the docstring narrates history and addresses the reviewer.

Attacks that failed

  • Test against the old code: on development, 4 of 4 fail at np=1, 2, 4, with 419/2500 points mismatched, max 5.806e-6, matching the PR's number. On this PR, 4 of 4 pass at np=1, 2, 4, 8.
  • Unit-scale on-face and node queries: L=1 box2, annulus and shell, 0 unclaimed, max error at most 4.9e-15.
  • Near-face at small and unit scale: L=1e-3 np=4 from 4.68e-2 on development to 2.22e-15; L=1 np=4 from 1.39e-5 to 2.22e-15. A real gain; at L=1e-3 the old slab was the larger defect.
  • Ownership: 0 unowned at L=1 and L=1e-3 at np=4; multiply-owned points at L=1 fell from 1164 to 388, all consistent with the exact-on-face row.
  • Quads and hexes: StructuredQuadBox 2-D and 3-D at L=1 and L=100, np=1 and 2: 0 unclaimed, max 9.4e-13.
  • Rank asymmetry: a hex warped in one half gives capability ['continuous','exact'] at np=2, so tolerance differs by rank, but the value digest matched serial to 12 decimals.
  • Regressions, with the PR logic applied in process to eddab707: serial locator, evaluate, swarm and rotated free-slip files, 90 passed, 2 skipped on both builds; 11 of 12 np=2 batches over tests/parallel/test_*.py gave identical counts (see below).
  • CI reach: test_1090 is in the parallel batch at np=2, where it fails without the fix.

Issues

Merge conditions

  • Scale the slab so it stays above discriminator roundoff, with a measure that is not rank-dependent and needs no collective in the locator. A candidate tested in serial only: tol = 1e-10*max(1, L*h), with L and h rank-local there, gave 0 unclaimed on all 8 annulus, shell and box3 cases up to L=6371, with slab/L at or below 1.4e-10, and equals this PR's tolerance whenever L*h <= 1. That shows a fix exists; it is not a final form, and near-face accuracy was not re-measured with it.
  • Add a regression at L >= 100 on non-axis-aligned faces, for both global_evaluate and swarm retention.
  • Add near-face offsets below 1e-6 to pin the tolerance, and level and tier markers.
  • Resolve the serial band in finding 5.
  • Correct the stale text, add Closes #799, and record finding 6 in the body.

Could not test

  • np=2 batch 9 (around test_1095 to test_1106) printed no pytest summary on either build, so it is uninformative; the cause was not investigated.
  • The PR's near-interface geometry at L >= 100: BoxInternalBoundary took 144 to 214 s to mesh at L=100 and the probe timed out.
  • Curved-coordinate simplices. The manifold and warped-hex carve-outs keep 1e-2 by construction; not measured.
  • Gadi and the PR's annulus workflows, multi-node runs and np above 8.
  • A build of the merge: results on eddab707 used the PR logic patched in process, which matched the PR build on simplex meshes wherever both ran.

Underworld development team with AI support from Claude Code

This branch has not been deployed

No deployments
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.

2 participants