Skip to content

Add Clement interpolation on domain interior - #12

Merged
joewallwork merged 13 commits into
mainfrom
10_clement
Nov 12, 2026
Merged

joewallwork merged 13 commits into
mainfrom
10_clement

Conversation

@joewallwork

@joewallwork joewallwork commented Jan 13, 2026 •

Copy link
Copy Markdown
Member

Closes #10.
Merges into #19

This PR ports the interior Clement interpolation functionality of Animate over to adapt_common.

Edit: I'll do the boundary case in a follow-up PR.

Checklist

  • get_function_space util
  • Clement interpolant
  • Supporting mesh utils
  • Tests for Clement
  • Tests for mesh utils
  • Docstring for get_function_space
  • Open issue for upstreaming and link in code

@joewallwork joewallwork self-assigned this Jan 13, 2026
@joewallwork joewallwork added the enhancement New feature or request label Jan 13, 2026
@joewallwork joewallwork changed the title Add Clement interpolation Add Clement interpolation on domain interior Mar 6, 2026
@joewallwork
joewallwork marked this pull request as ready for review March 10, 2026 07:42
@joewallwork
joewallwork changed the base branch from main to 7_quality November 6, 2026 16:58
@joewallwork
joewallwork added this pull request to stack #20 November 6, 2026 17:28

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

Nice. Just some queries, also fine with it as is. Given the parloops depend on a correct halo exchange (I think it should do the right thing already) maybe add a parallel test?

Comment thread adapt_common/mesh.py Outdated
Comment on lines +33 to +37
patch_vol = fd.Function(fd.FunctionSpace(mesh, "Lagrange", 1))
domain = "{[i]: 0 <= i < patch.dofs}"
instructions = "patch[i, 0] = patch[i, 0] + vol[0, 0]"
keys = {"vol": (cell_volume(mesh), fd.READ), "patch": (patch_vol, fd.RW)}
fd.par_loop((domain, instructions), ufl.dx(domain=mesh), keys)

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.

If you want to avoid a parloop you could also do patch_vol.interpolate(CellVolume(mesh), access=fd.INC)

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.

Oh, nice! I wasn't aware of that. Done in a6d3b8e.

Comment thread adapt_common/transfer.py Outdated
Comment on lines +129 to +138
# Take the weighted average of the source function over the neighbouring cells
block_size = getattr(Vs, "block_size", 1)
domain = f"{{[i, j]: 0 <= i < out.dofs and 0 <= j < {block_size}}}"
instructions = "out[i, j] = out[i, j] + vol[0, 0] * f[0, j]"
keys = {
"f": (source, fd.READ),
"vol": (cell_volume(mesh), fd.READ),
"out": (target, fd.RW),
}
fd.par_loop((domain, instructions), ufl.dx(domain=mesh), keys)

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.

Similarly here I think you could do: target.interpolate(CellVolume(mesh)*source, access=fd.INC)

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.

Done in a6d3b8e.

Comment thread adapt_common/transfer.py Outdated
def clement_interpolant(source, target=None):
r"""Compute the Clement interpolant of a :math:`\mathbb P0` source field.

i.e. take the volume average over neighbouring cells at each vertex. See

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.

Out of interest: is this the same as a lumped P0 - P1 projection? (i.e. with a lumped mass matrix) ?

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.

Yes, you're right, it does. Added a note in 3fd7cfd.

Base automatically changed from 7_quality to main November 9, 2026 17:33
@joewallwork
joewallwork merged commit 58d1994 into main Nov 12, 2026
1 check passed
@joewallwork
joewallwork deleted the 10_clement branch November 12, 2026 09:25
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

2 participants