Skip to content

Mesh.multigrid_levels: the mesh's multigrid hierarchy, coarsest first - #915

Merged
lmoresi merged 4 commits into
developmentfrom
feature/mesh-multigrid-levels
Oct 31, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
feature/mesh-multigrid-levels

Conversation

@lmoresi

@lmoresi lmoresi commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Mesh.multigrid_levels is a read-only property: the mesh's multigrid hierarchy as meshes, coarsest first, ending with the mesh itself. That is the coarse tail a custom multigrid hierarchy is built from. Until now it was reached through the private _coarse_level_meshes() and an index trick in scripts, tests and the place_fault_ribbon example. The example now uses the property.

What it returns

The levels come in the order the solver's own multigrid uses them:

  • the coarse tail the mesh owns, if it has one (an adapt child's, which its solvers pick up without a set_custom_fmg call), followed by the mesh;
  • otherwise the refinement or coarsening hierarchy;
  • for an unrefined mesh, the mesh alone, without building a wrap.

The levels are built once and are not rebuilt when the mesh is deformed or remeshed. The first access is collective. Coarsened levels carry no boundary labels. The docstring says all three.

The name follows set_custom_fmg and CustomMGHierarchy.level_meshes: coarsest first, the solver's mesh last.

Tests

test_1016_mesh_multigrid_levels checks:

  • the levels against dm_hierarchy, with the four-to-one cell count of a uniform triangle refinement;
  • that the mesh is the last level, the levels are built once and the property is read-only;
  • the native refine pair on every consecutive refinement level, before and after reading the property on each level;
  • that no wrap is built for an unrefined mesh;
  • a coarsening hierarchy (serial only, because PETSc coarsens a distributed 2-D mesh through ParMmg, which is 3-D only);
  • an adapt child, whose levels are its tail and match the multigrid its solver picks up;
  • a custom FMG Poisson solve on levels[:-1] with one PCMG level per entry.

On this head, with development fc67b65 merged in, test_1016, test_1010 and test_1022 pass: 40 tests.

Review

The adversarial review (185da98) is in the first comment.

Underworld development team with AI support from Claude Code

…irst

A read-only property that returns the mesh's hierarchy levels as a tuple,
coarsest first and ending with the mesh itself:
tuple(self._coarse_level_meshes()[:-1]) + (self,).

That is the coarse tail a custom multigrid hierarchy is built from. Until now
it was reached through the private _coarse_level_meshes() and an index trick,
`_coarse_level_meshes()[:-1] + [mesh]`, in scripts, tests and the
place_fault_ribbon example. The example now uses the property.

The name follows set_custom_fmg and CustomMGHierarchy.level_meshes (coarsest
first, the solver's mesh last); on a Mesh, "multigrid_levels" says which
hierarchy is meant.

test_1016_mesh_multigrid_levels checks:
- the levels against dm_hierarchy, with the four-to-one cell count of a uniform
  triangle refinement;
- that the mesh itself is the last level;
- that the levels are built once and the property is read-only;
- that an unrefined mesh is its own single level;
- a custom FMG Poisson solve on levels[:-1] with one PCMG level per entry.

Underworld development team with AI support from Claude Code
…docstring

From the adversarial review.

The property now resolves the levels in the solver's own order:
- the coarse tail the mesh owns (an adapt child's, which its solvers pick up
  with no set_custom_fmg call), followed by the mesh;
- else the refinement or coarsening hierarchy.

On an adapt child it used to return the child alone while the child's
solvers ran four levels.

A single-level mesh returns itself without going through
_coarse_level_meshes. That call wrapped the mesh into a hidden duplicate and
re-tagged it, so reading the property on a coarse level of another hierarchy
took that level out of its refine family and lost the pair its exact nested
transfer.

The docstring now says:
- coarsened levels carry no boundary labels;
- the first access is collective;
- the levels are built once and are not rebuilt when the mesh is deformed or
  remeshed.

It drops the claim that every consecutive pair transfers exactly. Its ribbon
example uses a 3-D base, as place_fault_ribbon requires.

The tests now cover:
- the native refine pair on every consecutive refinement level, before and
  after reading the property on each level;
- no wrap built for an unrefined mesh;
- a coarsening hierarchy (serial: PETSc coarsens a distributed 2-D mesh
  through ParMmg, which is 3-D only);
- an adapt child, whose levels are its tail and match the levels of the
  multigrid its solver picks up.

Marks: level 2 on the module, since the tests solve; the tier on each test.

Underworld development team with AI support from Claude Code
The fault-split integration (#889, #890) and the 150 commits before it.
Clean merge.

Underworld development team with AI support from Claude Code

lmoresi commented Oct 31, 2026 •

Copy link
Copy Markdown
Member Author

Adversarial review (fixes in 185da98)

Reviewed by a separate agent against docs/developer/guides/adversarial-review.md.

Findings and what was done

  1. Wrong levels on an adapt child. The property returned the child alone while the child's solvers ran four levels.
    Resolution: it resolves the levels in the solver's own order: the coarse tail the mesh owns (an adapt child's, which its solvers pick up with no set_custom_fmg call), followed by the mesh; otherwise the refinement or coarsening hierarchy.
  2. A side effect on an unrefined mesh. A single-level mesh went through _coarse_level_meshes, which wrapped it into a hidden duplicate and re-tagged it. Reading the property on a coarse level of another hierarchy took that level out of its refine family and lost the pair its exact nested transfer.
    Resolution: a single-level mesh returns itself.
  3. The docstring.
    Resolution: it says that coarsened levels carry no boundary labels, that the first access is collective, and that the levels are built once and not rebuilt when the mesh is deformed or remeshed. It no longer claims every consecutive pair transfers exactly. Its ribbon example uses a 3-D base, as place_fault_ribbon requires.
  4. Tests.
    Resolution: test_1016 covers the native refine pair on every consecutive refinement level, before and after reading the property on each level; no wrap for an unrefined mesh; a coarsening hierarchy (serial: PETSc coarsens a distributed 2-D mesh through ParMmg, which is 3-D only); and an adapt child, whose levels are its tail and match the multigrid its solver picks up. Level 2 on the module, since the tests solve; the tier on each test.

On the head (development fc67b65 merged in), test_1016, test_1010 and test_1022 pass: 40 tests.

Underworld development team with AI support from Claude Code

Copilot AI balanced review requested due to automatic review settings October 31, 2026 20:13

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.

PETSc coarsens a mesh through its mmg adaptor. conda-forge's PETSc
3.25.3, which CI runs, is built without mmg, and the test failed there
with "Grid adaptor mmg not registered" (error 63). It is now skipped when
PETSc.Sys.hasExternalPackage("mmg") is False. It still runs on the custom
PETSc builds (amr), where test_1016's 6 tests pass.

Underworld development team with AI support from Claude Code
@lmoresi
lmoresi merged commit 25d6281 into development Oct 31, 2026
8 checks passed
lmoresi added a commit that referenced this pull request Oct 31, 2026
…patch on the split finest level (ruling of 2026-11-01)

The fault-multigrid guide drops the chain as what production runs and
states the ruled tail with its counts from the tail sweep on #912's
build; its configuration rule on the blocks now says FAC blocks are LU
and records that the rotated path ran them as ILU(0) from 2026-09-03
until #912 (#892). The split-level section says the library merged
(#889, #890) and keeps the chain as the measured alternative.
Mesh.multigrid_levels (#915) replaces the private accessor.

The faults-in-convection guide's hierarchy section, code and table are
rewritten to the welded tail, with the chain labelled as the alternative
and the ILU-era table retired to the journal. The guide is added to the
developer toctree it was missing from.

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.

2 participants