Skip to content

Fix coarse-to-fine cell maps for hierarchies built on an adaptively refined mesh - #5321

Merged
pbrubeck merged 1 commit into
mainfrom
pbrubeck/fix-adaptive-hierarchy-cell-maps
Aug 5, 2026
Merged

Fix coarse-to-fine cell maps for hierarchies built on an adaptively refined mesh#5321
pbrubeck merged 1 commit into
mainfrom
pbrubeck/fix-adaptive-hierarchy-cell-maps

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Bugfix for a regression introduced by #5215.

Building a MeshHierarchy on a mesh returned by refine_marked_elements failed in parallel, asserting 0 <= ccell < ncoarse in mgimpl.coarse_to_fine_cells.

Root cause. coarse_to_fine_cells should reindex the coarse mesh's plex-to-Firedrake cell map from overlapped to non-overlapped cell numbering, which it does by sending every local cell through the overlapped local-to-global map and back through the non-overlapped one. It assumed that the cells surviving that round trip were the leading cells of the overlapped plex: it discarded the rest (MapMode.DROP) and sliced. Meshes distributed by DMPlexDistributeOverlap append their halo cells, so the assumption held for every mesh a hierarchy could be built on. #5215 added adaptive refinement, whose plex comes from DMPlexTransform; that numbers cells by refinement case and interleaves owned with halo cells, so the slice was the wrong permutation, cells were attributed to the wrong parent, and the assertion fired.

Fix. coarse_to_fine_cells now masks the absent cells (MapMode.MASK) and scatters each surviving entry to the non-overlapped number the round trip gives it. For a mesh whose owned cells do lead its plex, this yields the same permutation as before.

The docstring and comments of coarse_to_fine_cells are rewritten: numpydoc, and naming the three cell numberings the function moves between (Firedrake, overlapped plex, non-overlapped plex), none of which the ordering assumption was previously stated against. A test covers a uniform hierarchy built on an adaptively refined mesh.


AI was used for this change (Claude Code).

coarse_to_fine_cells assumed that the cells kept by the non-overlapped
plex were the leading cells of the overlapped one. That holds for a plex
distributed by DMPlexDistributeOverlap, which appends its halo, but not
for one built by DMPlexTransform, which numbers cells by refinement case
and so interleaves owned with halo cells. Mask the absent cells and
scatter each surviving entry to its non-overlapped number, rather than
dropping them and slicing.

Rewrite the docstring and comments of coarse_to_fine_cells to name the
three cell numberings it moves between.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pbrubeck
pbrubeck requested a review from connorjward August 4, 2026 12:18
@pbrubeck

pbrubeck commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

#5215 did not touch the uniform refinement code (which is assuming that halo cells are always ordered last). An adaptively refined mesh interleaves owned and halo cells (nowhere else in firedrake we assume any ordering of the owned/halo cells). Therefore breaking the assumption in the uniform refinement routine is the right fix.

Comment thread firedrake/cython/mgimpl.pyx

@connorjward connorjward 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.

This is good

@pbrubeck
pbrubeck enabled auto-merge (squash) August 4, 2026 22:25
@pbrubeck
pbrubeck merged commit 2e98a9c into main Aug 5, 2026
25 of 28 checks passed
@pbrubeck
pbrubeck deleted the pbrubeck/fix-adaptive-hierarchy-cell-maps branch August 5, 2026 07:41
leo-collins pushed a commit that referenced this pull request Aug 6, 2026
)

coarse_to_fine_cells assumed that the cells kept by the non-overlapped
plex were the leading cells of the overlapped one. That holds for a plex
distributed by DMPlexDistributeOverlap, which appends its halo, but not
for one built by DMPlexTransform, which numbers cells by refinement case
and so interleaves owned with halo cells. Mask the absent cells and
scatter each surviving entry to its non-overlapped number, rather than
dropping them and slicing.

Rewrite the docstring and comments of coarse_to_fine_cells to name the
three cell numberings it moves between.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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