Skip to content

fix(meshing): mmpde metric — monotone RBF bake from nodal values#266

Merged
lmoresi merged 1 commit into
developmentfrom
bugfix/mmpde-metric-rbf-monotone
Jun 22, 2026
Merged

fix(meshing): mmpde metric — monotone RBF bake from nodal values#266
lmoresi merged 1 commit into
developmentfrom
bugfix/mmpde-metric-rbf-monotone

Conversation

@lmoresi

@lmoresi lmoresi commented Jun 22, 2026

Copy link
Copy Markdown
Member

Restores the intended RBF metric-eval robustness for the mmpde mover (a design decision that had been undercut by an FE bake).

Problem

The mover's metric_eval="rbf" path baked the metric via an FE evaluation at the fixed reference cloud ref, then Shepard-interpolated. On a deformed mesh that FE evaluation mis-locates points and the P1 density — strictly positive by construction — comes back negative (measured ≈ −3, even at a field's own DOF coords). A negative density is a non-SPD metric, which the mover either NaN-bails on (a hidden stall) or, with the #259 SPD-floor, acts on as "coarsen hard here" → giant cells / holes / divergence in the adapted mesh.

Fix

Bake the metric at the current mesh NODES (its own DOF locations) and Shepard-interpolate from there:

  • Monotone: a Shepard (positive-weight, convex) average of positive nodal values is guaranteed ≥ 0 — the eval can never produce a non-SPD metric.
  • Robust + fast: nodes are always inside the mesh (no drift/out-of-domain), and Shepard needs no per-step cell location. RBF doesn't need high-precision eval.
  • ref is kept for the _edge_mats reference frame.

Relationship to #264

Best paired with #264 (deformed-mesh point-location fix), which makes the nodal FE bake exact. With both, the adapted mesh stays clean under forced every-step adaptation at R=5 (folded=0, cell-area-ratio flat, vrms→18, Nu→1.86) where it previously tore holes (area-ratio spikes 189/96/875).

One-line source change; validated in a sibling worktree. CI runs the full mover suite.

Underworld development team with AI support from Claude Code

Restores the intended "RBF metric eval" robustness. The mmpde mover's
RBF/Shepard metric path baked the metric via an FE evaluation at the FIXED
reference cloud `ref`; on a deformed mesh that reference can mis-locate / drift
outside the deformed interior and the FE evaluation returns garbage (the P1
density — strictly positive by construction — comes back NEGATIVE, even at a
field's own DOFs). A negative density is a non-SPD metric, which the mover then
either NaN-bails on (a hidden stall) or, with the #259 SPD-floor, acts on as
"coarsen hard here" → giant cells / holes / divergence in the adapted mesh.

Fix: bake the metric at the CURRENT mesh NODES (its own DOF locations) and
Shepard-interpolate from there. A Shepard (positive-weight, convex) average of
the positive nodal values is GUARANTEED >= 0 (monotone) — the metric can never
go non-SPD from the eval — and nodes are always inside the mesh (no
out-of-domain / drift) and need no per-step cell location (fast). `ref` is kept
for the _edge_mats reference frame.

Best paired with #264 (deformed-mesh point-location fix), which makes the nodal
FE bake exact; together the adapted mesh stays clean under forced every-step
adaptation at R=5 (folded=0, cell-area-ratio flat) where it previously tore
holes. Validated in a sibling worktree (this is a one-line source change; CI
runs the full mover suite).

Underworld development team with AI support from Claude Code
Copilot AI review requested due to automatic review settings June 22, 2026 00:01

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.

Pull request overview

Adjusts the MMPDE mover’s metric_eval="rbf" fast-path to improve robustness on deformed meshes by changing where the metric is sampled (“baked”) before Shepard (k-NN inverse-distance) interpolation.

Changes:

  • Bake the analytic metric at the current mesh node coordinates (coords) instead of the cached fixed reference cloud (ref).
  • Build the k-NN tree from the node coordinates and interpolate metric values from those samples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3152 to +3155
# * MONOTONE: a P1 density is positive by construction; Shepard is a convex
# (positive-weight) average of the sampled node values, so the result is
# GUARANTEED positive — no negative/non-SPD garbage, the SPD floor / NaN
# bail never has to fire.
Comment on lines 3161 to +3164
if metric_eval == "rbf":
from scipy.spatial import cKDTree
M_ref = _eval_M_analytic(ref) # one analytic pass
_tree = cKDTree(ref)
M_src = _eval_M_analytic(coords) # nodal values (positive)
_tree = cKDTree(coords)
@lmoresi

lmoresi commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

This is a minor detail - the metric evaluation for the adaptive meshing needs to be 1) fast and 2) monotonic ... rbf is a good choice, especially since it does not require the full mesh interpolation infrastructure to be valid during mesh movement (a difficult task to sequence correctly)

@lmoresi lmoresi merged commit 4513209 into development Jun 22, 2026
2 checks passed
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