Skip to content

Add functionality for Clement on the boundary - #21

Merged
joewallwork merged 23 commits into
mainfrom
15_clement-boundary
Nov 16, 2026
Merged

joewallwork merged 23 commits into
mainfrom
15_clement-boundary

Conversation

@joewallwork

Copy link
Copy Markdown
Member

Closes #15
Merges into #12

Extends the support for Clement on the boundary, as well as domain interior. Once merged, we can remove the duplicated Clement functionality from Animate.

@joewallwork joewallwork self-assigned this Nov 6, 2026
@joewallwork
joewallwork added this pull request to stack #20 November 6, 2026 17:31
@joewallwork joewallwork added the enhancement New feature or request label Nov 6, 2026
@joewallwork
joewallwork marked this pull request as ready for review November 9, 2026 09:20
Comment thread adapt_common/transfer.py Outdated

@PETSc.Log.EventDecorator()
def clement_interpolant(source, target=None):
def clement_interpolant(source, target=None, boundary=False):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this really need to be an option argument? Why not just have a clement_interpolant() and a boundary_clement_interpolant()? There's a bit of overlap, but not that much, and I can't really see a situation where you wanted the calling code to easily switch between the two: for the boundary version you end up with a function that you know only has values on the specified boundary, so presumably you're going to do something else with it than in the case of the non-boundary clement_interpolant

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. Addressed in latest merge/commits.

Comment thread adapt_common/mesh.py Outdated
return facet_area


# TODO: Upstream as a cached_property of MeshGeometry in Firedrake (#17)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suspect this doesn't quite do the right thing for "corner elements", cells with more than one exterior facet - e.g. the 2 corner triangles in a RectangleMesh: a vertex adjacent to such a corner triangle will receive the corner element value weighted by the edge length of both exterior edges of that corner element.

Out of interest, how are you planning to use this? The issue of corner elements (much more common in 3D) also raises the question of whether you actually want the multiple facets to have multiple values - in which case storing it as P0 field, i.e. in the subset of cells near the boundary, rather than in the facets, doesn't seem the right thing.

Could you do this using "submesh"? i.e. generate a submesh for the provided surface id, then if you do have a P0 volume field as source (i.e. single valued in corner elements) you can project/interpolate to a P0 (surface) field on the submesh, and then you should be able to use the non-boundary clement interpolation you already have, which gives you a P1 (surface) field on the submesh - which you could interpolate back to a P1 volume field if you wanted to...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could you do this using "submesh"? i.e. generate a submesh for the provided surface id, then if you do have a P0 volume field as source (i.e. single valued in corner elements) you can project/interpolate to a P0 (surface) field on the submesh, and then you should be able to use the non-boundary clement interpolation you already have, which gives you a P1 (surface) field on the submesh - which you could interpolate back to a P1 volume field if you wanted to...

Good suggestion. I've implemented it that way in recent commits.

I suspect this doesn't quite do the right thing for "corner elements", cells with more than one exterior facet - e.g. the 2 corner triangles in a RectangleMesh: a vertex adjacent to such a corner triangle will receive the corner element value weighted by the edge length of both exterior edges of that corner element.

The revised implementation should address this I think, although the tolerances are quite large in the tests.

Out of interest, how are you planning to use this? The issue of corner elements (much more common in 3D) also raises the question of whether you actually want the multiple facets to have multiple values - in which case storing it as P0 field, i.e. in the subset of cells near the boundary, rather than in the facets, doesn't seem the right thing.

The only current use cases is for the Hessian recovery on the boundary (currently in Animate) that is used in some formulations of anisotropic goal-oriented mesh adaptation. I think the approximate method here should be sufficient for that.

Base automatically changed from 10_clement to main November 12, 2026 09:24

@stephankramer stephankramer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very nice, and some thorough testing!

Comment thread adapt_common/transfer.py Outdated
target, is_cofunction = _process_target(Vs, target)
rank = len(Vs.value_shape)
if rank not in (0, 1, 2):
raise ValueError(f"Rank-{rank + 1} tensors are not supported.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why the rank + 1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Huh, I'd always thought a rank-1 tensor was a vector but it seems I'm wrong (https://en.wikipedia.org/wiki/Tensor_(intrinsic_definition)).
Fixed in 5f564cd. Note that there are a couple of places in Animate where this needs updating.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I misremembered - actually it's fine in Animate now.

Comment thread adapt_common/transfer.py Outdated

# Interpolate back onto the P1 target on the volume mesh. Degrees of freedom not
# defined on the submesh are left unchanged, so zero the target first; submesh
# vertices which are not volume-mesh boundary vertices can still leak values

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might be obvious, but I can't immediately picture a situation where the submesh would have vertices that are not boundary vertices of the volume mesh - would you mind expanding/giving an example?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah I think the code is correct but the explanation was wrong - see d185434.

@joewallwork
joewallwork merged commit f9c1bc8 into main Nov 16, 2026
1 check passed
@joewallwork
joewallwork deleted the 15_clement-boundary branch November 16, 2026 12:48
joewallwork added a commit to mesh-adaptation/animate that referenced this pull request Nov 20, 2026
Functionality here is now duplicated in `adapt_common` following merging
mesh-adaptation/adapt_common#12 and
mesh-adaptation/adapt_common#21, so can be
removed from Animate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Clement recovery on the boundary

2 participants