Skip to content

Add implementation of Hessian recovery using Clement interpolant - #23

Merged
joewallwork merged 13 commits into
mainfrom
22_clement-hessian
Nov 20, 2026
Merged

joewallwork merged 13 commits into
mainfrom
22_clement-hessian

Conversation

@joewallwork

Copy link
Copy Markdown
Member

Closes #22.

This PR ports over the Hessian computation functionality from Animate that goes via the Clement interpolant. Boundary case to be handled separately.

@joewallwork joewallwork self-assigned this Nov 16, 2026
@joewallwork joewallwork added the enhancement New feature or request label Nov 16, 2026

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

Yeah sorry I'm a little unsure about these different cases tbh: for degree 2 and DG1 I'm not sure it's consistent (and for degree>2 it's not doing any Clement in the first place). For degree 2 I would be a bit more confident if the first gradient was done with a L2 projection into CG1 - I might well be wrong about this, is there some literature to compare with?

Comment thread adapt_common/recovery.py Outdated
# Recover gradient
if degree <= 1:
V = fd.VectorFunctionSpace(mesh, "DG", 0)
g = clement_interpolant(fd.project(ufl.grad(f), V))

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 would say with DG1 this is still dubious: you only get a good approximation of the gradient if the discontinuities are neglible - which in general is very hard to guarantee

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.

Fair point. To be honest, I'm not sure how this ended up going into Animate (although it was likely my fault!). Restricted to P1 in 1d56a17

Comment thread adapt_common/recovery.py Outdated
g = recover_gradient_l2(f, target_space=V)

# Recover Hessian
if degree <= 2:

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.

For degree==2 I'm also not entirely convinced this is safe. If f is CG2 but for some reason your numerical scheme doesn't give you a 2nd order accurate, but a 1st order accurate approximation of some analytical continuous truth, i.e. f could just be in CG1 (as a subset of CG2), then g in DG1 would actually be DG0, and thus H=0 - this may sound arbitrary, but I think it means that any arbitrary 2nd order error in the computation of f would make the Hessian inconsistent.

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.

Restricted in 1d56a17.

@joewallwork

Copy link
Copy Markdown
Member Author

Decided to add gradient recovery using Clement here, too. Also grouped the gradient recovery tests in one file since they use some of the same fixtures.

@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, all looks good - one suggestion

Comment thread adapt_common/recovery.py Outdated
:rtype: :class:`firedrake.function.Function`
"""
val_err = (
"Clement interpolation can only be used to compute gradients of Lagrange"

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.

Maybe add the word "continuous" - if you supply a DG1 field it's not immediately obvious what's wrong (especially if you're used to "DG", 1 instead of "Discontinuous Lagrange", 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.

Good point. Done in 1dd1a0c.

@joewallwork
joewallwork merged commit 1f9d503 into main Nov 20, 2026
1 check passed
@joewallwork
joewallwork deleted the 22_clement-hessian branch November 20, 2026 15:16
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-based recovery

2 participants