Skip to content

Interpolate - #515

Closed
schnellerhase wants to merge 5 commits into
mainfrom
schnellerhase/interpolate
Closed

schnellerhase wants to merge 5 commits into
mainfrom
schnellerhase/interpolate

Conversation

@schnellerhase

@schnellerhase schnellerhase commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Supporting FEniCS/ffcx#881.

Comment thread ufl/core/interpolate.py
Comment on lines +161 to +168
def target_space(self) -> AbstractFunctionSpace:
"""Return the function space that the expression is interpolated into.

Unlike `ufl_function_space` this does not depend on the argument
numbering, so it stays correct when the interpolated expression holds an
argument of the enclosing form.
"""
return self._function_space

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.

What does this mean for the adjoint, i.e. Interpolate(Argument, Cofunction)?

Comment thread ufl/core/interpolate.py
raise ValueError("Same argument numbers in first and second operands to interpolate.")
if expr_arg_numbers | dual_arg_numbers not in [set(), {0}, {0, 1}]:
argument_numbers = expr_arg_numbers | dual_arg_numbers
if argument_numbers and argument_numbers != set(range(len(argument_numbers))):

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.

why do we need this check? I think the main purpose is to ensure unique argument numbers, but we should not be constraining the arguments to always start from 0 and be contiguous.

Comment thread ufl/core/interpolate.py
n = 1 if expr_arg_numbers == {0} else 0
# Take the lowest free number, so that an expression linear in
# several arguments stays representable.
n = min(set(range(len(expr_arg_numbers) + 1)) - expr_arg_numbers)

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.

We should add tests for this

of its target space, and the expression it interpolates is evaluated
separately.
"""
return expr._ufl_is_terminal_ or isinstance(expr, Interpolate)

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 pattern repeats through other files. I don't agree with the name. In which sense are terminals "modifiable"?

operator is linear in it, instead of recording the derivative as an
action to be assembled separately. This composes to higher
derivatives and keeps the result an ordinary form, which a form
compiler that evaluates the operator cell-locally needs.

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.

Is this needed to enable derivative(interpolate(u, V1)*dx, u)? Should this be the default?



def apply_derivatives(expression):
def apply_derivatives(expression, differentiate_through_operators: bool = False):

@pbrubeck pbrubeck Nov 3, 2026 •

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.

I don't understand. Is False going to be ignoring what's inside a BaseFormOperator? Why is it the default? I think preserve_types in #451 might be a related mechanism.

if isinstance(do, Zero):
return Zero(g.ufl_shape)
return apply_grads(do)
self.pending_operations += (o,)

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 pending_operations nonsense is removed in #544

@schnellerhase

Copy link
Copy Markdown
Contributor Author

Bug fixes have been integrated into #554.

Closing in favor of #554.

@schnellerhase
schnellerhase deleted the schnellerhase/interpolate branch November 19, 2026 10:16
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