Using this non-matching meshes interpolation function seems to work.
Taken from GJK error in interpolation between non matching second ordered 3D meshes - #6 by chenyongxin
def nmm_interpolate(f_out: dolfinx.fem.Function, f_in: dolfinx.fem.Function):
"""Non Matching Mesh Interpolate: interpolate one function (f_in) from one mesh into
another function (f_out) with a mismatching mesh
args:
f_out: function to interpolate into
f_in: function to interpolate from
notes:
https://fenicsproject.discourse.group/t/gjk-error-in-interpolation-between-non-matching-second-ordered-3d-meshes/16086/6
"""
dim = f_out.function_space.mesh.topology.dim
index_map = f_out.function_space.mesh.topology.index_map(dim)
ncells = index_map.size_local + index_map.num_ghosts
cells = np.arange(ncells, dtype=np.int32)
interpolation_data = dolfinx.fem.create_interpolation_data(
f_out.function_space, f_in.function_space, cells, padding=1e-11
)
f_out.interpolate_nonmatching(f_in, cells, interpolation_data=interpolation_data)