Initial support for interpolation - #63
Open
jorgensd wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature: Differentiable Function Interpolation Block
AI disclosure statement
This pull-request has been developed by me, with the help of Gemini (august 2026).
Description
This PR introduces the
InterpolationBlockand an overloadeddolfinx_adjoint.interpolatewrapper, enabling automatic differentiation throughdolfinx.fem.Function.interpolate. It supports bothPETSc.Matand nativedolfinx.la.MatrixCSRbackends while ensuring robust parallel execution and minimal memory overhead during optimization.Mathematical Formulation
Because function interpolation is a purely linear mapping between finite element spaces, the forward, adjoint, and Hessian operations are governed entirely by the interpolation matrix and its transpose.
1. Forward and Tangent Linear Model (TLM)$\Pi$ denote the interpolation matrix mapping from a source space $V$ to a target space $W$ . For an input coefficient vector $x \in V$ , the interpolated vector $y \in W$ is given by:
Let
Because the operator is linear, the Tangent Linear Model (the Jacobian action) applied to a perturbation$\delta x$ is simply the interpolation matrix itself:
2. Adjoint Model$y^* = \frac{\partial J}{\partial y}$ , the adjoint identity $\langle \Pi \delta x, y^* \rangle_W = \langle \delta x, \Pi^T y^* \rangle_V$ dictates that the sensitivity with respect to the input is the transpose of the interpolation matrix:
The adjoint of a linear operator propagates downstream sensitivities backwards. Given the sensitivity of a functional with respect to the output,
3. Hessian Vector Product$H_{yy} \delta y$ , the incoming Hessian sensitivity is $\delta y^* = H_{yy} \Pi \delta x$ . Our block completes the chain rule by applying the adjoint operator to this incoming sensitivity, yielding the full Hessian vector product for the control variable:
While the second derivative of the linear interpolation operator is zero, the chain rule dictates how downstream curvature is mapped backwards. Given a downstream Hessian vector product
Implementation Highlights
get_multclosure abstracts away the differences betweenPETScand nativedolfinx.la.MatrixCSRoperations._INTERPOLATION_MATRIX_CACHE). Additionally, persistent working C++ arrays (_row_vecand_col_vec) are cached on the matrix object, eliminating dynamic Python allocations during iterative line searches.