Skip to content

A solve after a move of a refined mesh runs on the moved geometry (#1037) - #1044

Merged
lmoresi merged 4 commits into
developmentfrom
bugfix/moved-mesh-hierarchy-coords
Nov 12, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
bugfix/moved-mesh-hierarchy-coords

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Fixes #1037. On a mesh built with refinement, a scalar solve after a move (mesh.deform, any mover, relax()) assembled on the pre-move coordinates. For Poisson at refinement 2 that is 51 % off, whether the solver was made before or after the move. Stokes was already right.

Cause. _deform_mesh gave the new coordinates to mesh.dm only. On a refined mesh, mesh.dm is a clone of the finest hierarchy level, and solvers build on a clone of mesh.dm_hierarchy. The finest level kept the old coordinates. It also kept its coordinate field (cell geometry), so a solver already built before the move stayed wrong even after it was given the new coordinates.

Change (Mesh._sync_hierarchy_finest_coordinates, called from _deform_mesh):

  • The finest level gets its own copy of the moved coordinates, global and local. It's a duplicate, so a later write through mesh.dm can't move the hierarchy behind the mesh's back.
  • Its coordinate field is rebuilt the way nuke_coords_and_rebuild rebuilds mesh.dm's.
  • The coarse levels keep their geometry: their transfers are topological, and they only precondition.
  • Every mover and relax() reach it, because they all move through _deform_mesh.

Test (test_1172, serial and tests/parallel at np 2; written first). Poisson on a box built on [0, 1.5] × [0, 1], against a [0, 1]² box stretched there:

  • refinement 0, 1 and 2;
  • default PC and FMG;
  • solver made before and after the move;
  • relax() on a refined annulus, with an FMG Poisson solve after it;
  • the coarse levels unchanged, and the finest level holding its own vector.
Build test_1172 serial test_1172 np 2
development 526edb9 10 failed, 2 passed (the refinement-0 cases; H1's count) —
this branch 12 passed, 2 skipped 12 passed, 2 skipped

The 36 mesh-move test files (deform, movers, remesh, adapt, NVB, relax, smoothing, FMG, custom MG): 200 pass. One test, test_1060, takes 47 minutes, so it ran on its own; it passes with and without this change.

Not in this PR. The advection-diffusion solvers (SLCN, SUPG) and Stokes are right after a move on development, so the defect is in Poisson-type solves and the multigrid preconditioners. Whether published moved-mesh results are affected is being checked separately: the June 2026 code has an older defect of its own after a move.

Files run for the review round (f4ae8a3), 230 passed, 8 skipped: test_0001_sphere_refinement_folds.py, test_0004_checkpoint_fmg_hierarchy.py, test_0056_projected_normals_deform.py, test_0057_deformed_domain_membership.py, test_0505_projection_smoothing_length.py, test_0751_mmpde_graded_area_floor.py, test_0752_mesh_shape_relaxation.py, test_0764_node_redistribution.py, test_0764_petsc_index_boundary_conditions.py, test_0766_mover_refreshes_mesh_vector.py, test_0773_surface_smoother.py, test_0820_deform_mesh_solver_rebuild_regression.py, test_0825_deform_mesh_cache_invalidation.py, test_0826_deform_capability_gate.py, test_0830_mesh_adapt_variable_transfer.py, test_0834_adapt_legacy_call_guard.py, test_0835_sbr_adapt_on_top.py, test_0836_nvb_graded_adapt.py, test_0837_nvb_native_transform.py, test_0838_nvb_graded_native.py, test_0839_nvb_parallel_adapt.py, test_0840_nvb_3d_serial_adapt.py, test_0841_nvb_tet_transform.py, test_0842_nvb_3d_parallel_adapt.py, test_0843_edge_split_adapt.py, test_0845_relax_pinned_band.py, test_0847_mesh_hierarchy_plot.py, test_0850_mesh_smoothing.py, test_0867_place_sheet_adapted_3d.py, test_1016_custom_mg_hierarchy.py, test_1020_fmg_single_field_lockout.py, test_1022_composed_ribbon_fmg.py, test_1055_yield_smoother.py, test_1060_stress_store_smoothing.py, test_1111_rotated_fmg_coarse_shifted_lu.py, test_1113_rotated_fmg_one_coarse_factorisation.py, test_1146_custom_mg_after_deform.py, test_1149_custom_mg_hierarchy_lifecycle.py, test_1151_first_solve_after_a_mesh_move.py, test_1172_moved_refined_mesh_solves_on_moved_geometry.py. test_1172 was also run at np 2 (13 passed).

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 — np2/np4 checked where swarm/mesh/solver dispatch is touched (S11)
  • 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

🤖 Generated with Claude Code

)

The move gave the new coordinates to mesh.dm only. On a refined mesh,
mesh.dm is a clone of the finest hierarchy level, and solvers build on a
clone of the hierarchy, so scalar solvers assembled on the pre-move
coordinates: 51 % off for Poisson at refinement 2, whether the solver was
made before or after the move. _deform_mesh now gives the finest level its
own copy of the moved coordinates and rebuilds its coordinate field, as
nuke_coords_and_rebuild does for mesh.dm. The coarse levels keep their
geometry. Every mover and relax() go through _deform_mesh.

Test: refinement 0, 1 and 2, default PC and FMG, solver made before and
after the move, relax() on a refined annulus; serial and np 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lmoresi lmoresi added the bug Something isn't working label Nov 10, 2026
Copilot AI balanced review requested due to automatic review settings November 10, 2026 14:37

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 10, 2026

Copy link
Copy Markdown
Member Author

Adversarial review record for #1044, at a836387

Verdict: request changes. The core fix works. After every mover tried, scalar solves on the branch match a single-level mesh on the moved DM to 1e-12, where development is 0.08–16% off. That holds at refinement 1 and 2 and at np 1, 2 and 4.

Two things block the merge:

  • H1: adapt() after a move gets a pre-move multigrid tail whenever the coarse-level cache already exists. The answers stay right, but iterations go up 2–4×, on the move-fault, re-refine, add-patch cycle.
  • H2: test_0764 now fails, serially and at np 2.

Paths under runs/ are on hyperion.


Adversarial review: PR #1044 (bugfix/moved-mesh-hierarchy-coords at a836387, fixes #1037)

Base: development 526edb9 (wt-dev526). Branch: wt-1044. Probes, logs and summarisers are in
runs/2026-11-11-1044/review/ (corr.py, q1.py, q2probe.py, q2direct.py, q3adapt.py, q3cycle.py,
aux.py, mutate.py; logs/, corr_summary.txt, mv_summary.txt). Anything marked [read] was read, not run.

Verdict

Request changes. The core fix is right. After every mover we tried, at refinement 1 and 2 and at np 1, 2
and 4, scalar solves on the branch agree with a single-level mesh wrapping the moved DM to 1e-12 or better.
Development is 0.08 % to 16 % off on the same cases. The hierarchy, snapshot restore and ephemeral_coords
are all consistent, and test_1172 discriminates. Two things block the merge, though:

  • (H1) The fix silently turns off the moved-geometry path in adapt(), so the multigrid tail of an adapt
    child keeps the pre-move geometry. Iterations go up 2–4x, and this lands on the move-fault, re-refine,
    add-patch cycle.
  • (H2) One existing test, test_0764, now fails serially and at np 2. That breaks the PR's claim that the
    mesh-move suite passes.

There is also a per-move leak of PETSc objects at np 2 (M1).

The author's questions

Q1: coarse levels keep their geometry. Is that right for geometric MG, and does FMG still converge?

For PETSc geometric MG (pc_type mg), yes: the coarse geometry has no effect at all. UW3 forces Galerkin
RAP (_enforce_galerkin_for_geometric_mg) [read]. We scrambled the coarse levels' coordinates non-affinely by
30 % before the solve (q1.py coarsepert). The integral and the iteration count came out bit-identical:
4.392974825611e-02 and 4 iterations, with and without the scramble, at refinement 1 and 2, np 1 and 2. The
nested interpolator is topological, so the boundary mismatch between the coarse and fine levels does not enter.

FMG iterations, moved against built in place (q1.py stretch, P2 Poisson, rtol 1e-10). Each cell gives
built / unit box before the move / moved:

case np 1 np 2
L=1.5, ref 2, FMG 4 / 4 / 5 4 / 4 / 4
L=4, ref 2, FMG 5 / 4 / 5 4 / 4 / 6
L=4, ref 2, V-cycle 5 / 4 / 7 4 / 4 / 8
annulus, MMPDE (max disp 0.034 at ref 1, 0.018 at ref 2), FMG 4 → 4 3 → 4

The moved solution matches LU on the moved mesh to 1e-14 in every case.

Custom-P FMG (set_custom_fmg) is different. Its transfers are coordinate-based, so unmoved coarse levels do
cost iterations after a large move.
Before → after the move:

case np 1 np 2
L=1.5, ref 1 3 → 9 4 → 11
L=1.5, ref 2 3 → 16 4 → 18
L=4, ref 2 2 → 27 4 → 33

The answers stay right (1e-12 against LU), and development shows the same counts (corr matrix cfmg:
28/33 on both builds), so this is not a regression. But the new docstring says "their transfers are
topological, and a coarse level only preconditions". That is true only for PETSc MG, and it should say so.

Q2: degree-2 coordinate meshes at refinement 1

  • The new sync code cannot be reached through any public mover for a degree-2 mesh, and it was not reachable
    before.
    mesh.X.coords holds the vertices only: (534, 2) on the annulus, against 2020 degree-2 nodes. So
    mesh.deform and redistribute_nodes raise a broadcast ValueError on both builds (q2_annulus_*_1044.log,
    q2sizes.py).
  • The finest level never had degree-2 coordinates. mesh.dm holds 4040 coordinate entries, but
    dm_hierarchy[-1] and the solver DM hold 1068 (P1), with or without a move, on both builds. So even with no
    move, a solve on a refined degree-2 mesh runs on P1 geometry. It makes no numerical difference here, because
    the "degree-2" nodes sit on chord midpoints, not on the circle: r_min is 0.49846 on the r=0.5 boundary. The
    unmoved solve matches a degree-2 single-level reference to 1.6e-14. This is pre-existing.
  • Through a direct _deform_mesh with the full node array (q2direct.py, scale ×1.2):
    • At refinement 0, both builds are right: the integral ratio is 2.0736, as expected.
    • At refinement 1, the branch raises the new RuntimeError, but only after mesh.dm has been moved and
      rebuilt. The mesh is left half-moved: mesh.dm max|x| is 1.2, the finest level 1.0, and the next solve's
      ratio is 1.44 where 2.0736 is expected. That is the same wrong answer development gives silently.
    • The spherical shell is the same: ratio 1.728 against 2.488.
    • The result is identical at np 2.
  • Boundary curvature: there is none to keep. See above.

Q3: NVB path, _moved decided "equal" after a move

[read] When the levels compare equal, base_finest = self.dm_hierarchy[-1] is used directly: there is no clone
and no duplicate vector. That is safe for the refinement itself:

  • the native NVB path clones before labelling (d = current_dm.clone());
  • SBR and edge-split take it as input;
  • write_tagged_state_label now seeds on the moved geometry, which is correct.

It is not safe for the multigrid tail. coarse_tail = self._coarse_level_meshes() is a cache built once.
If it was built before the move, by any earlier adapt, multigrid_levels or set_custom_fmg(mesh.multigrid_levels…),
its last entry wraps the pre-move finest level. Development replaced that entry with _moved_wrap because
_moved was True. The branch never takes that branch any more, which also makes it dead code.

Measured (q3adapt.py: stretch ×1.5, refinement 1, metric band at x=1.2, child Poisson with its automatic
tail):

case branch: tail base-finest xmax, MG its development: tail base-finest xmax, MG its
no cache before the move, nvb / sbr, np 1 1.5, 4 / 4 1.5, 4 / 4
cache before the move, nvb, np 1 / 2 / 4 1.0, 17 / 19 / 19 1.5, 4 / 5 / 5
cache before the move, sbr, np 1 / 2 / 4 1.0, 15 / 17 / 18 1.5, 4 / 5 / 5
adapt → move → adapt (q3cycle.py), L=1.5, np 1 / 2 1.0, 10 / 12 1.5, 5 / 6
adapt → move → adapt, L=3, np 1 / 2 1.0, 17 / 21 3.0, 7 / 8
  • Values are right. The child's MG solve equals LU to 1e-13 or better, and LU matches the exact solution to
    2.0e-6. The child's xmax is 1.5 or 3.0 in every case.
  • Nothing is shared that shouldn't be. No coordinate handle of the child or the tail equals the parent's
    dm or dm_hierarchy[-1]. A later parent move left the child and the tail unmoved (0.0). A child move left
    the parent's finest level equal to mesh.dm and its coarse level unmoved (0.0).

Findings

ID Severity Finding Evidence
H1 High adapt() after a move gives the child a multigrid tail whose base-finest level has the pre-move geometry whenever _coarse_level_meshes_cache exists. The fix makes _moved False, and that drops the moved wrap. This is the move-fault, re-refine, add-patch cycle (#1017 ruling). The answer stays right; iterations go up 2–4x, more as the move grows. Q3 table; discretisation_mesh.py ~9234 and ~9726 [read]
H2 High (merge gate) test_0764::TestEngineLessAdapt::test_redistribute_then_adapt_composition fails on the branch serially and at np 2, and passes on development. It asserts dm_hierarchy[-1] is unchanged after redistribute_nodes, which the PR now changes on purpose. The PR's "200 pass" list did not include it. logs/ser_1044_test_0764*, logs/rep_*_test_0764*
M1 Medium Each move adds 6 more entries to petsc4py's deferred-destroy list at np 2 than development does: 12 per move against 6, both with and without a solve per move. Rank-0 max RSS over 10 moves rose 367 → 390 MB (branch) against 371 → 380 MB (development). Development's own 6 per move is pre-existing. The two duplicated Vecs are replaced straight away by createCoordinateSpace (see L1), so they are likely part of the waste. logs/aux_leak*_np2.log
M2 Medium The layout check raises after mesh.dm has been moved and nuke_coords_and_rebuild has run, so the mesh is left half-committed (Q2). The check is also rank-local before a collective: a rank holding no cells compares 0 == 0, goes on into createCoordinateSpace, and hangs against the ranks that raised [read; not run, since there is no public route]. q2direct_1044_r1.log; _sync_hierarchy_finest_coordinates
L1 Low Two mutants survive test_1172: shared (the finest level takes mesh.dm's own Vecs) and globalonly (no local copy). Both give 12 passed at np 1 and np 2, because the rebuild replaces the vectors anyway. The handle-inequality assertion therefore cannot fail, and the local duplicate/copy is redundant. The essential mutants are caught: noop and nocopy fail 10 tests, and norebuild fails the 4 solver_before_move cases. logs/mut_*
L2 Low The docstring and commit say "their transfers are topological, and a coarse level only preconditions". That holds for PETSc MG, not for custom-P (Q1). Q1
L3 Low adapt's _moved branch, and its comment that "redistribute_nodes moves mesh.dm's coordinates while the static base hierarchy keeps the originals", are now dead or false. [read]
O1 Observation (pre-existing) On development the stale finest level depends on the path taken. After any earlier solve, a new variable and solver built after the move see the moved coordinates (why.py: solver xmax 1.5 with a pre-move solve, 1.0 without). So my "kept" matrix columns pass on development and cannot discriminate there. The discriminating evidence is the isolated runs below and test_1172. We did not find the mechanism. why.py, logs/corr_dev526_* against logs/iso_dev526_*
O2 Observation (pre-existing, file separately) An AdvDiffusion solver kept across a mesh.deform stretch differs from a fresh one by an amount that depends on the rank count: 5.8e-4 at np 1, 1.1e-2 at np 2, 3.1e-1 at np 4. It does so at refinement 0 too (0.26 at np 4), identically on both builds. The MMPDE and spring movers give a flat 1.3–1.6e-3. Part of the difference is the solver's history by design; the dependence on rank count is not. corr_summary.txt, rows deform * kept advdiff
O3 Observation The issue's scope sentence names the advection-diffusion solvers. In isolation (iso_dev526_*_advdiff) development's AdvDiffusion was right (3e-12) for all three movers; Poisson with FMG, custom FMG and FAC were not. logs/iso_*

Attacks that failed (the fix holds)

  • Correctness after a move, against a single-level mesh wrapping the moved DM, solved with LU
    (corr.py, unstructured box with regular=False):
    • Movers: deform (x ×1.5), spring (smooth_mesh_interior, 10 iterations) and MMPDE (redistribute_nodes).

    • Refinement 1 and 2, np 1, 2 and 4.

    • Solvers: Poisson with the default PC, Poisson with FMG, Stokes, AdvDiffusion (3 steps), custom FMG, and
      custom FMG with fac_zone.

    • The branch gives relative error of 1e-12 or better for every fresh solver (108 rows), and for every kept
      solver except AdvDiffusion (O2, identical on development).

    • Isolated, one solver per process at refinement 2 and np 2, development is wrong for:

      solver deform MMPDE spring
      FMG 1.1e-1 3.5e-3 8e-4
      custom FMG 1.6e-1 1.1e-1 1.2e-2
      FAC 1.6e-1 1.1e-1 1.2e-2

      Development's Stokes is right (4e-13), as reported. The branch is right for all of them.

    • Refinement 0 is the same on both builds.

  • Coordinates in parallel (aux.py coords, MMPDE, refinement 2, np 1, 2 and 4, with 74 and 158 ghost
    coordinate entries at np 2 and 4):
    • For mesh.dm, the finest level and the solver DM, the local vector equals a global-to-local scatter of the
      global vector, to 0.0.
    • The finest level equals mesh.dm, local and global, to 0.0, and so does the solver DM.
    • Development is off by 1.3e-2.
  • ephemeral_coords (np 1, 2 and 4):
    • Inside the scope, the finest level equals mesh.dm and a solve sees the moved area of 1.5. Development is
      off by 0.5 inside the scope, and gives 7.91e-2 where 1.285e-1 is right.
    • On exit, the finest level, mesh.dm and the solve are restored exactly (rel 0).
  • Snapshot restore after a mover (save_state, redistribute_nodes, load_state; np 1, 2 and 4): the
    restore succeeds, the finest level, mesh.dm and the solver DM all return to the original coordinates
    (0.0), and the solve matches the pre-snapshot value to 1e-16.
  • nuke_coords_and_rebuild is reached only through _deform_mesh, so the sync always follows it [read].
    The direct callers, extract_region (~2583) and remesh (~10087), replace self.dm outright [read].
  • test_1172:
    • Development gives 10 failed, 2 passed, 2 skipped serially and at np 2. The PR body says 9; at 526edb9 the
      relax-annulus test fails as well.
    • The branch gives 12 passed, 2 skipped serially and at np 2.
  • Mesh-move suite, np 2, one file per mpirun (--with-mpi):
    • We ran 51 files (movefiles.txt) on both builds and got identical outcomes in 49.
    • test_0764 differs (H2).
    • test_1014 is apparent only: rank 1 fails pytest.warns on both builds.
    • Failing on both builds: 0004, 0840, 0841, 0843, 0867, 1015 and 1016_custom_mg_hierarchy.
    • test_1111 hangs on both. test_1087 was still running on both at the time of writing.
  • After a mesh move, solves see the remapped field; a move is decided over all ranks #959 is in the base (526edb9), and test_0766, serial and parallel, passes on both.
  • Custom-P hierarchy state no longer outlives a change to its solver or mesh (#1019, #1020, #1017, #1012) #1036 (merged after the base, at 03c33e2) [read; no build contains it]:
    • Its hunks do not overlap the PR's, and GitHub reports blocked, not dirty.
    • _move_version is bumped in remesh_with_field_transfer, not in _deform_mesh. So the sync runs on trial
      moves inside ephemeral_coords without bumping it, which is consistent.
    • The FAC kill reads the custom-P level meshes, which this PR does not touch.
    • Swarm and kd-tree sync are unchanged: the kd-tree is rebuilt from mesh.dm before the sync [read].

Merge conditions

  • Fix H1: on every move, refresh the cached base-finest wrap (_coarse_level_meshes_cache[-1]), keeping its
    _refine_slot and _mg_static. Alternatively, decide adapt's _moved against that wrap. Then remove or
    rewrite the dead _moved branch and its comment. Add a regression test: build the cache (via adapt or
    multigrid_levels), move, adapt, and assert that the tail's base-finest coordinates equal mesh.dm's and
    that the iteration count matches a run with no cache.
  • Update test_0764's assertion to the new contract: the coarse levels are unchanged and the finest level equals
    the moved mesh.dm. List every file actually run in the PR body.
  • Make the layout check collective, run it before mesh.dm is touched, and state that degree-2 refined meshes
    are not supported (M2).
  • Bring the deferred-destroy growth per move at np 2 back to development's level, or justify it (M1). Drop the
    redundant duplicate Vecs, or make the test able to tell them apart (L1).
  • Correct the docstring on topological transfers (L2).

What we could not test

  • The PR merged onto current development (e7fdcb2, with Custom-P hierarchy state no longer outlives a change to its solver or mesh (#1019, #1020, #1017, #1012) #1036): no build exists and we did not rebuild. That
    interaction is [read] only.
  • Degree-2 coordinates through any public mover (deform and MMPDE fail earlier on both builds), and true
    curved degree-2 boundaries (the meshes do not generate them).
  • 3-D beyond the degree-2 shell through a direct _deform_mesh.
  • Stokes with custom FMG (field_id=0) after a move.
  • The rank-local hang in M2 (no public route reaches it).
  • test_1060 (47 min) and test_1087 (did not finish). CI's xdist batching.
  • We did not run the issue's p_hier2.py or the round-3 p6mv.py probes themselves. corr.py and q3adapt.py
    cover the same ground.

Underworld development team with AI support from Claude Code

… the moved mesh

- _coarse_level_meshes re-wraps its cached finest level when a move has
  changed dm_hierarchy[-1], keeping its _refine_slot and _mg_static. adapt's
  _moved branch could no longer fire, so it and its comment are gone (H1, L3).
- test_0764 asserts the new contract: the finest level carries the move, the
  coarse levels keep the original (H2).
- The layout check runs before mesh.dm is touched and is collective; a
  refined mesh with degree-2 coordinates raises (M2).
- The sync copies the global coordinates only, the local vector is
  regenerated, and the old coordinate space it releases is freed with a
  collective garbage_cleanup: two deferred entries in all, against twelve
  a move (M1, L1). The always-true handle assertion is gone.
- The docstring says the coarse geometry is free for PETSc MG only (L2).
- test_1172 gains the adapt-after-a-move case and joins scripts/test.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lmoresi

lmoresi commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

Review answered at f4ae8a3: development e7fdcb2, with #1036, is merged in. Point by point:

  • H1, adapt after a move. _coarse_level_meshes() now re-wraps its cached finest level whenever a move has changed dm_hierarchy[-1], keeping _refine_slot and _mg_static. The staleness check is collective, and it stays False when nothing has moved. Adapt's _moved branch could no longer fire, so it and its comment are gone (L3).
    • New test, test_an_adapt_after_a_move_starts_its_multigrid_tail_from_the_moved_mesh: it builds the cache with multigrid_levels, stretches the mesh, adapts, and solves on the child with its automatic tail. It asserts that the tail's base-finest coordinates equal the moved mesh.dm, and that the iteration count matches a run with no cache.
    • Mutant: with the re-wrap disabled, the tail is the pre-move geometry and the solve takes 17 iterations. With it, the solve takes 4, the same as with no cache.
  • H2, test_0764. It now asserts the new contract: the finest level equals the moved mesh.dm, and the coarse level is unchanged.
  • M1, deferred destroys. Your aux.py leak 1 at np 2 now gives [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], with rank-0 RSS flat at 389 MB. Before, it was 12 a move on this branch and 6 a move on development. The sync's rebuild of the level's coordinate space releases the old one to the deferred list. The move is collective, so the sync now ends with PETSc.garbage_cleanup, which also clears development's own six.
  • M2, layout check. _finest_level_takes_moved_coordinates() runs in _deform_mesh before mesh.dm is touched, and it is an allreduce. A refined mesh with degree-2 coordinates raises there, and nothing is moved.
  • L1, redundant vectors. The sync gives the level a copy of the global coordinates only; the local vector is regenerated from it. The handle assertion that could not fail is removed.
  • L2, docstring. It now says the coarse geometry costs nothing for PETSc MG (topological interpolation, Galerkin coarse operators). Custom-P transfers are built from coordinates, so unmoved coarse levels cost them iterations, not accuracy.
  • CI. test_1172 is in scripts/test.sh, batch 4; check_test_coverage.py passes.
  • O3. Thanks for that one. I've corrected the issue's scope to Poisson and the multigrid preconditioners, not advection-diffusion. O2, the rank-dependent AdvDiffusion difference across a deform, is pre-existing; I'll file it separately after an issue search.

Tests run locally on the pushed tree, serial unless marked:

  • test_1172: 13 passed, 2 skipped, serial and at np 2.
  • 40 files, 230 passed, 8 skipped (-n 12, one-hour per-test timeout): every tests/test_*.py whose name matches deform|mover|remesh|adapt|hierarch|nvb|relax|smooth|mmpde|fmg|refine, plus test_0764_node_redistribution, test_1151 and test_1149.

The full list is in the PR body. I haven't run your one-file-per-mpirun np 2 sweep of 51 files.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Re-check of PR #1044 (fix for #1037) at f4ae8a3 and at the merged head b5fa806

READY. This covers f4ae8a3 and the merged head b5fa806. All seven round-1 conditions are met, measured on both heads, and nothing blocks the merge. Three low-severity items remain and can be follow-ups (N1–N3).

Round 1 is runs/2026-11-11-1044/review/1044-review.md (a836387). This round's probes, job lists and logs are in runs/2026-11-12-1044/review/ (logs/, jobsA–D.txt).

How the runs were done:

  • Builds: wt-1044b (f4ae8a3), wt-1044c (b5fa806) and wt-dev5ce (development 5ce73fd). We checked that each installed discretisation_mesh.py matches its source.
  • Tests ran from git archive copies (arch1044b, arch1044c, archdev5ce), with PYTHONDONTWRITEBYTECODE=1 and -p no:cacheprovider. MPI runs went through mpi_supervisor.py --silence 600.
  • At most 8 cores were busy at once, with at most one np 4 job.
  • [read] marks anything we read in the code but did not run.

Status of the round-1 findings

H1 (high): resolved

_coarse_level_meshes() now re-wraps the cached base-finest level whenever its coordinates differ from dm_hierarchy[-1]'s, and the comparison is an allreduce. The re-wrap keeps the level's _refine_slot and _mg_static.

q3adapt.py (stretch ×1.5, refinement 1, adapt, then a Poisson solve with multigrid on the child) on f4ae8a3:

case tail base-finest = mesh.dm base-finest xmax MG its, np 1 / 2 / 4 rel(MG − LU)
nvb, cache built before the move True 1.5 4 / 5 / 5 ≤ 1.1e-14
nvb, no cache True 1.5 4 / 5 / 5 ≤ 1.1e-14
sbr, cache built before the move True 1.5 4 / 5 / 5 ≤ 2.8e-15
sbr, no cache True 1.5 4 / 5 / 5 ≤ 2.8e-15
  • Round 1 measured a836387 with a cache at 17 / 19 / 19 iterations (nvb) and 15 / 17 / 18 (sbr), with the base-finest level at xmax 1.0.
  • Development 5ce73fd gives 4 / 5 with a cache at np 1 / 2.
  • Nothing is shared that should not be: a later parent move moves neither the child nor the tail (0.0), and a child move moves neither the parent's finest level nor its coarse level (0.0).

q3cycle.py (adapt, move, adapt):

  • L=1.5: 5 / 6 / 6 iterations at np 1 / 2 / 4.
  • L=3: 7 / 8 iterations at np 1 / 2.
  • Development gives the same, 7 / 8 at L=3. Round 1's a836387 gave 10 / 12 and 17 / 21.
  • The tail's base-finest xmax is 1.5 and 3.0, as it should be.

Regression test. test_1172 has a new test, test_an_adapt_after_a_move_starts_its_multigrid_tail_from_the_moved_mesh, in both the serial and the parallel file.

  • To emulate a836387, the norewrap mutant patches _cached_finest_wrap_is_stale to always return False.
  • Under it, the test fails at np 1 and np 2 (logs/mut_norewrap_np*.log: 1 failed, 12 passed), on the coordinate-equality assertion.
  • Without the mutant it passes.

The #1017 cycle (cycle1017.py):

  1. Build the cache on a refinement-2 box (test_1152's _coarse_level_meshes()[:-1] + [base]).
  2. Place a split fault and solve Stokes with custom FMG.
  3. Move the base by MMPDE or by a non-affine deform.
  4. Move the fault by +0.05 in y.
  5. Re-refine with base.adapt.
  6. Place the moved fault on the child, register child.multigrid_levels, and solve.

Results:

  • Branch: the tail's base-finest level equals the moved base.dm (0.0). |v| is bit-identical to the no-cache reference at np 1, 2 and 4 (for example, 2.1659038487e+01 at np 2 with MMPDE), with 4 velocity iterations.
  • a836387 emulation (norewrap): at np 1 the tail is stale (3.3e-2 with MMPDE, 4.4e-2 with deform), though the solve still matches. At np 2 and np 4 the cycle fails outright: RuntimeError: addon_partition: 14 (16) fine cell(s) have no local parent cell on the level below. So the fix also unblocks this cycle in parallel.
  • Caveat on the fixture: every variant warns that the fault could not be carried onto add-on level 0 ("snapping inverted 2 cell(s)"), so the add-on level stays welded. The comparison between variants is still like for like.

H2 (high): resolved

test_0764 now asserts the new contract: the finest level equals the moved mesh.dm, and the coarse level is unchanged.

  • Serially: 10 passed.
  • At np 2: 9 passed, 1 failed. The failure is test_slip_normals_are_outward_on_every_wall, followed by an MPI abort at exit in PetscGarbageKeySortedIntersect ("too big for PetscInt"). Development 5ce73fd fails in exactly the same way (and development 526edb9 did in round 1), so this is pre-existing. test_redistribute_then_adapt_composition passes at np 2.

M2 (medium): resolved

_finest_level_takes_moved_coordinates() runs at the top of _deform_mesh, before mesh.dm is touched, and it is an allreduce (LAND).

q2direct.py (direct _deform_mesh with the full degree-2 node array):

  • At refinement 1 on the annulus (np 1 and np 2) and on the shell (np 1), it raises RuntimeError and nothing moves. mesh.dm and the finest level both keep max|x| = 1.0, and the next solve gives a ratio of 1.000. Round 1 found the mesh half-moved, with a wrong ratio of 1.44.
  • At refinement 0, the move works: the ratio is 2.0736, as expected.

The rank-with-no-cells case is now constructed and run (m2empty.py, np 4). An UnstructuredSimplexBox with cellSize 2.0 and refinement 1 has 8 / 0 / 8 / 0 cells per rank.

  • Degree 2: all four ranks raise RuntimeError, including the two holding no cells. There is no hang, and mesh.dm moves by 0.0. On development the same run reports success but is silently wrong: an integral ratio of 1.44 where 2.0736 is right, with the finest level at max|x| 1.0.
  • Degree 1, same layout: the move works, the volume ratio is 1.44 and the integral ratio 2.0736. The sync and garbage_cleanup complete with empty ranks.

The degree-2 limitation is stated in the RuntimeError's text and in the private method's docstring. It is not in any public docstring (deform, the mesh constructors) [read]. See N2.

M1 (medium): resolved

The sync now ends with PETSc.garbage_cleanup(self.dm.getComm()). Measured with leak2.py at np 2 over 40 moves, and with round 1's aux.py leak at np 2 over 10 moves:

build deferred entries per move rank-0 max RSS over 40 moves deform time per move
f4ae8a3 0 (the list stays flat at 2) 372 → 374 MB 0.108 s
f4ae8a3 with a solve each move 0 (flat at 2) 375 → 378 MB —
development 5ce73fd 6 375 → 412 MB 0.104 s
development with a solve each move 6 373 → 411 MB —
f4ae8a3 without the cleanup (noclean) 12 377 → 463 MB 0.107 s
  • The cleanup is what removes the growth. It also frees development's own 6 entries a move.
  • Its cost is within the noise, about 4 % of a move.
  • aux.py leak agrees: the branch is flat at [0, 2, 2, …], against development's [0, 6, 12, …, 60].

L1 (low): partly resolved

The local duplicate is gone: the sync copies the global coordinates only, which makes it the round-1 globalonly mutant plus the cleanup. The handle assertion that could not fail has been removed.

Mutants against test_1172 (mutate.py; each count is the same at np 1 and np 2):

mutant what it changes outcome
none — 13 passed, 2 skipped
noop no sync 11 failed
nocopy rebuild without copying the coordinates 11 failed
norebuild copy without rebuilding the coordinate field 4 failed
norewrap the cached tail is never refreshed 1 failed
shared the finest level takes mesh.dm's own vectors survives (13 passed)
globalonly the old global-only copy survives, as expected now
noclean no garbage_cleanup survives

Two of these survivors are the residual: nothing tests that the finest level holds its own Vec (shared), or that the cleanup happens (noclean). See N1.

L2 (low): resolved

The _sync_hierarchy_finest_coordinates docstring now says that the coarse geometry costs nothing for PETSc's geometric MG (topological interpolation, Galerkin coarse operators). It also says that custom-P transfers are built from coordinates, so they pay in iterations, not in accuracy. This matches round 1's Q1 measurements.

L3 (low): resolved

adapt's _moved branch, the _moved_wrap substitution and the false comment are all removed. base_finest = self.dm_hierarchy[-1] now carries the moved geometry.

  • For 3-D NVB, the refinement-state seed is written on self.dm_hierarchy[-1] (line ~9110), which has the moved coordinates, so dropping the re-seed is consistent [read].
  • 3-D NVB after a move was not run.

Correctness matrix (corr.py, refinement 2, f4ae8a3)

Solvers: Poisson with the default PC, Poisson with FMG, Stokes, custom FMG, and FAC. Movers: deform (x ×1.5), spring and MMPDE, each at np 1, 2 and 4. The reference is a single-level mesh wrapping the moved DM, solved with LU.

  • Over all 45 solver/mover/np cases, kept and fresh, the worst relative error is 6.7e-12 (Stokes, spring, np 1). Every other case is 5e-12 or better.
  • Kept and fresh solvers give the same iteration counts, except FAC at deform np 1 and np 4 (18/16 and 21/19).
  • The solver DM's coordinates equal mesh.dm's to 0.0 in every case.

Regressions

f4ae8a3:

test serial np 2
test_1172 13 passed, 2 skipped 13 passed, 2 skipped
test_1172, parallel file — 13 passed, 2 skipped
test_1146 4 passed 4 passed
test_1149 12 passed 12 passed
test_1149, parallel file — 2 passed
test_1151 2 passed 2 passed
test_1152, parallel file — 2 passed (also on development)

test_0764 is covered under H2.

Mesh-move suite at np 2, one file per mpirun. We ran round 1's movefiles.txt on f4ae8a3 and on development 5ce73fd, without test_1111 (it hangs on both) and test_1087 (it did not finish in round 1). That leaves 49 files, and 46 have identical outcomes. The three that differ:

  • test_0764: same outcome on both builds; only the exit code differs, 142 against 63, both from the pre-existing garbage-intersect abort.
  • test_1014: apparent only. Both builds have one rank fail the two pytest.warns tests; the summariser read different ranks' lines. Same as round 1.
  • test_0835 test_wedge_metric_funnels_finest_level_to_feature: fails on f4ae8a3 (6.0 < 6.0) and passes on development. It is not caused by this PR. Development's test sums the marked counts over the ranks (test_0835 wedge-metric test compares rank-local marked-cell counts and fails at np 2 on rank 0 #1043, which landed after e7fdcb2), and f4ae8a3's test is older. On the merged head it passes at np 2 (10 passed).

Failing on both builds, all pre-existing: 0004, 0840, 0841, 0843, 0867, 1015 and 1016_custom_mg_hierarchy.

Checkpoint reload (ckpt.py, serial):

  • A moved refinement-1 box written and reloaded gives the finest level equal to mesh.dm on the branch (xmax 1.5, 0.0). On development the finest level is 1.0 against 1.5. So the reload's deferred stamp, which goes through _deform_mesh, now carries the move into the hierarchy.
  • A refined degree-2 annulus fails to reload with PETSc error 62 on both builds. This is pre-existing; the new degree-2 guard is not reached.

Merged head b5fa806

  • Is it the same PR? b5fa806's parents are f4ae8a3 and development 6a2b04e, and 6a2b04e contains c5e5900. git diff 6a2b04ed b5fa806f touches only the PR's five files. The patch-ids of discretisation_mesh.py, test_0764 and both test_1172 files are identical to the e7fdcb2..f4ae8a3 delta.
  • The conflict is gone. At f4ae8a3, a read-only git merge-tree against c5e5900 conflicted only in scripts/test.sh, and discretisation_mesh.py merged automatically. The merged head resolves the conflict.
  • What development changed nearby. Development's changes to discretisation_mesh.py in that range are Reload a refined mesh's checkpoint correctly on any rank count (#690) #1063's refined-reload rework. Its reference coordinates come from dm_hierarchy[0], which this PR leaves unmoved, and its deformed stamp still goes through _deform_mesh [read].

Results on wt-1044c, from git archive b5fa806f tests:

check result
test_1172, serial 13 passed, 2 skipped
test_1172, np 2 13 passed, 2 skipped
test_1172, np 4 13 passed, 2 skipped
test_1172 parallel file, np 2 13 passed, 2 skipped
test_1172 parallel file, np 4 13 passed, 2 skipped
test_1172 parallel file, serial 15 skipped (by design: it needs MPI)
test_0764, serial 10 passed
test_0764, np 2 9 passed, 1 failed (the pre-existing slip-normals failure and abort, as on development)
test_1146, serial / np 2 4 / 4 passed
test_1149, serial / np 2 12 / 12 passed; parallel file 2 passed
test_1151, serial / np 2 2 / 2 passed
test_0835, np 2 10 passed
q3adapt np 2, nvb and sbr, cache / no cache tail = mesh.dm True; 5 / 5 its; rel(MG − LU) ≤ 2.9e-15
q3cycle L=3, np 2 tail xmax 3.0; 8 its
cycle1017 (MMPDE, np 2) tail = moved base (0.0); 4 velocity its; |v| 2.1659038487e+01, the same as f4ae8a3

New findings (none blocking)

ID Severity Finding
N1 Low Nothing catches the shared and noclean mutants (table under L1). A deferred-entry count after a few moves (PETSc.garbage_view) would guard M1 in CI.
N2 Low Degree-2 refined meshes are stated as unsupported only in the error text and a private docstring. Public deform/mover docs do not mention it [read].
N3 Low [read] multigrid_levels and _coarse_level_meshes() now do an allreduce on every access once the cache exists. Before, only the first access was collective. The multigrid_levels docstring still says "built on the first access, which is collective". We found no rank-conditional caller (we searched src, tests and docs), but the docstring should say that every access is collective.
O1 Observation Each re-wrap builds a new Mesh for the base-finest level. That is one per adapt after a move, which development's _moved_wrap also did, so it is not a new cost.

Not tested

  • 3-D NVB adapt after a move.
  • Degree-2 coordinates through any public mover. They fail earlier, as in round 1.
  • test_1111 and test_1087.
  • CI's xdist batching.

Evidence index

check logs
H1 logs/q3_*, q3cycle_*, cyc1017_*, mut_norewrap_*
H2 logs/ser_*_test_0764*, rep_*_test_0764*
M2 logs/q2direct_1044b_*, m2empty_*
M1 logs/leak2*, aux_leak*
L1 logs/mut_*
Correctness matrix logs/corr_1044b_*
Mesh-move suite logs/mv_*
Checkpoint reload logs/ckpt_*
Merged head logs/c_*

Underworld development team with AI support from Claude Code

gthyagi pushed a commit to gthyagi/underworld3 that referenced this pull request Nov 13, 2026
…worldcode#978)

The degree argument of Mesh and of the uw.meshing constructors set the
degree of the coordinate field. Particle location, cell sizes, boundary
normals, mesh motion and the multigrid hierarchy all read the coordinates
as straight-sided cells, and a degree-2 mesh failed in each. It did not
curve a boundary either: the edge nodes sat on the chords.

- Mesh._require_straight_sided_cells raises ValueError unless degree is
  the integer 1. Mesh.__init__ calls it first, and each of the 20
  uw.meshing constructors calls it before generating anything, so every
  rank refuses together and rank 0 never starts gmsh.
- mesh.degree is a read-only property returning 1.
- Removed what existed only for degree-2 coordinates: the quadrature cell
  sizer petsc_fem_get_local_cell_sizes and its PETSc declarations (underworldcode#983),
  the degree guard in _compute_geometry_fvm, and the
  _finest_level_takes_moved_coordinates guard in _deform_mesh (underworldcode#1044).
- Docstrings of all constructors and docs/developer/subsystems/meshing.md
  say that the mesh degree is 1 and the variable carries the order.
- Tests: test_0782 (serial and parallel) now hold the refusal for every
  constructor found by signature, the strict check, the read-only
  property, and the degree-1 cell sizes that the degree-2 tests carried
  (manifold facets, empty rank, extracted region). The estimate_dt
  accuracy step keeps its closed-form baseline on a degree-1 mesh.

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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants