Derivatives of vectors and matrices with respect to the mesh

In the context of parametric optimization, I’m interested in seeing how a stiffness matrix is affected by changes in the mesh geometry. I accomplish this using ufl.derivative:

spatialCoordinate = ufl.SpatialCoordinate(meshComponent.domain)
dX = fem.Function(meshComponent.meshFunctionSpace)
dX.vector.array = meshDeformation
stiffnessDerivativeForm = dolfinx.fem.form(ufl.derivative(stiffnessForm, spatialCoordinate, dX))
dK = dolfinx.fem.petsc.assemble_matrix(stiffnessDerivativeForm)

However, changing the mesh will not only change the integration domain but also change the interpolation points in the space where the solution lives (e.g. high-order Lagrange). Is this change is automatically propagated through chain rule by ufl.derivative?

If you update the mesh geometry with the perturbed coordinates (resulting from an update using for instance the shape derivative) this will be reflected in interpolation points, assembly etc, as we do not pre-compute interpolation points, jacobians etc in physical space.
We compute them on the reference element and push them forward to physical space when required.

1 Like