Skip to content

SubmeshHierarchy#5083

Open
pefarrell wants to merge 14 commits into
releasefrom
pefarrell/submesh-multigrid
Open

SubmeshHierarchy#5083
pefarrell wants to merge 14 commits into
releasefrom
pefarrell/submesh-multigrid

Conversation

@pefarrell
Copy link
Copy Markdown
Contributor

@pefarrell pefarrell commented May 7, 2026

This PR was generated almost entirely by Claude Code (and then almost entirely rewritten by @pbrubeck).

Description

Introduces SubmeshHierarchy that simply wraps HierachyBase(Submesh) to enable geometric multigrid on multidomain problems with Submesh

This PR also adds the first demo explaining Submesh and Measure intersection.

@pefarrell pefarrell requested a review from pbrubeck May 7, 2026 06:19
Comment thread firedrake/mesh.py Outdated
Comment thread firedrake/mg/mesh.py Outdated
Comment thread tests/firedrake/multigrid/test_submesh_mg.py Outdated
@pbrubeck
Copy link
Copy Markdown
Contributor

pbrubeck commented May 7, 2026

I think some discussion must happen before opening such involved AI-generated PRs. In particular I am not sure if this is the intended way of composing MeshHierarchy and Submesh.

What happens if one creates the Submesh on the base mesh instead?

     base = UnitSquareMesh(4, 4) 
     sbase = Submesh(base, subdim=1, subdomain_id=3)
     mixed_base = MixedMesh([base, sbase])
     mh = MeshHierarchy(mixed_base, 1) 
     mesh, smesh = mh[-1]

@pefarrell
Copy link
Copy Markdown
Contributor Author

Updated the PR to address Pablo's review feedback. Summary of changes:

mesh.py: Dropped _create_submesh_raw entirely (as Pablo suggested). The body is back inline in Submesh, with three new attributes added at the end (_submesh_label_name, _submesh_label_value, _submesh_ignore_halo) so that MeshHierarchy can replay the same filter at each refinement level.

mg/mesh.py: Replaced the _build_submesh_hierarchy_for_level / _submesh_coarse_to_fine_cells helpers with Pablo's architectural approach from PR #5084:

  • MeshSequence dispatch at the top of MeshHierarchy (builds independent hierarchies for each component, wraps fine meshes in MeshSequenceGeometry)
  • submesh_parent branch: re-applies dmcommon.submesh_create to each level of the pre-existing parent hierarchy rather than refining the submesh DM directly
  • coarse_to_fine_cells for submesh pairs delegates to the same impl.coarse_to_fine_cells as volume meshes (correct because submesh_create preserves the consecutive child-numbering invariant)

test: Updated to use the explicit MeshHierarchy(submesh, nref) API — build the volume hierarchy first, then build the submesh hierarchy.

All three GMG tests (hierarchy construction, fieldsplit GMG, monolithic GMG) pass.

Comment thread tests/firedrake/multigrid/test_submesh_mg.py Outdated
Comment thread firedrake/mg/mesh.py Outdated
Comment thread firedrake/mg/mesh.py
Comment thread firedrake/mg/ufl_utils.py Outdated
Comment thread tests/firedrake/multigrid/test_submesh_mg.py
Comment thread tests/firedrake/multigrid/test_submesh_mg.py
Comment thread tests/firedrake/multigrid/test_submesh_mg.py Outdated
Comment thread tests/firedrake/multigrid/test_submesh_mg.py Outdated
Comment thread tests/firedrake/multigrid/test_submesh_mg.py Outdated
Comment thread tests/firedrake/multigrid/test_submesh_mg.py Outdated
Comment thread firedrake/mg/mesh.py Outdated
Comment thread tests/firedrake/multigrid/test_submesh_mg.py Outdated
Comment thread tests/firedrake/multigrid/test_submesh_mg.py Outdated
Comment thread demos/submesh_reaction_diffusion/submesh_reaction_diffusion.py.rst
Comment thread demos/submesh_reaction_diffusion/submesh_reaction_diffusion.py.rst Outdated
@pbrubeck pbrubeck force-pushed the pefarrell/submesh-multigrid branch from b321a34 to 7afa595 Compare May 8, 2026 10:22
Comment thread firedrake/mg/mesh.py Outdated
@pbrubeck pbrubeck force-pushed the pefarrell/submesh-multigrid branch 2 times, most recently from 53763cd to b67e66d Compare May 8, 2026 12:00
Comment thread tests/firedrake/demos/test_demos_run.py Outdated
@pbrubeck pbrubeck mentioned this pull request May 8, 2026
@pbrubeck pbrubeck changed the title Add geometric multigrid support for Submesh SubmeshHierarchy May 8, 2026
Comment thread firedrake/dmhooks.py Outdated
Copy link
Copy Markdown
Member

@dham dham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the couple of things we discussed in the demo, this is good to go.

We agreed that strictly additive features like this can go to release.

@pbrubeck pbrubeck changed the base branch from main to release May 12, 2026 16:05
@pbrubeck pbrubeck changed the base branch from release to main May 12, 2026 16:06
@pbrubeck pbrubeck changed the base branch from main to release May 12, 2026 16:28
pefarrell and others added 12 commits May 12, 2026 17:31
Replace the implicit Submesh(mh[-1], ...) approach with Pablo's explicit
MeshHierarchy(submesh, nref) API.  Three architectural changes:

* mesh.py: Drop _create_submesh_raw; inline the body back into Submesh and
  store _submesh_label_name / _submesh_label_value / _submesh_ignore_halo so
  that MeshHierarchy can replay the same filter on each parent level.

* mg/mesh.py: Add MeshSequence support at the top of MeshHierarchy (builds
  independent hierarchies for each component, wraps fine meshes in
  MeshSequenceGeometry).  Add submesh_parent branch: for a Submesh, re-apply
  dmcommon.submesh_create to each level of the pre-existing parent hierarchy
  rather than refining the submesh DM directly.  Remove the now-superseded
  _build_submesh_hierarchy_for_level and _submesh_coarse_to_fine_cells helpers.
  The coarse_to_fine_cells computation for submesh pairs is delegated to the
  same impl.coarse_to_fine_cells call as for volume meshes, which works
  because submesh_create preserves the consecutive child-numbering property.

* test: Update test_submesh_mg.py to use the new explicit API (build parent
  hierarchy first, then call MeshHierarchy(submesh, nref)).

The dmhooks.py / mg/embedded.py / mg/ufl_utils.py fixes from the previous
commit are kept unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
@pbrubeck pbrubeck force-pushed the pefarrell/submesh-multigrid branch from 37668d7 to d9f3b48 Compare May 12, 2026 16:32
@pbrubeck pbrubeck self-requested a review May 12, 2026 16:53
pbrubeck
pbrubeck previously approved these changes May 12, 2026
@pbrubeck pbrubeck force-pushed the pefarrell/submesh-multigrid branch from 5be65fa to 77f8efc Compare May 12, 2026 16:56
pbrubeck
pbrubeck previously approved these changes May 12, 2026
@pbrubeck pbrubeck enabled auto-merge (squash) May 12, 2026 21:42
@pbrubeck pbrubeck disabled auto-merge May 12, 2026 22:16
Comment thread demos/submesh_reaction_diffusion/submesh_reaction_diffusion.py.rst Outdated
Comment thread demos/submesh_reaction_diffusion/submesh_reaction_diffusion.py.rst Outdated
Comment thread demos/submesh_reaction_diffusion/submesh_reaction_diffusion.py.rst Outdated
Comment thread demos/submesh_reaction_diffusion/submesh_reaction_diffusion.py.rst Outdated
Comment thread demos/submesh_reaction_diffusion/submesh_reaction_diffusion.py.rst Outdated
Co-authored-by: Pablo Brubeck <brubeck@protonmail.com>
@pbrubeck pbrubeck enabled auto-merge (squash) May 12, 2026 23:53
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.

3 participants