Interpolation Data Has Wrong Shape/Size

Then try using the following:

from dolfinx.mesh import create_unit_square, create_unit_cube, CellType
from basix.ufl import element
from dolfinx import fem

from mpi4py import MPI
import numpy as np

xtype = np.float64
cell_type0 = CellType.hexahedron
cell_type1 = CellType.triangle

mesh0 = create_unit_cube(MPI.COMM_WORLD, 5, 6, 7, cell_type=cell_type0, dtype=xtype)
mesh1 = create_unit_square(MPI.COMM_WORLD, 5, 4, cell_type=cell_type1, dtype=xtype)


def f(x):
    return np.vstack((7 * x[1], 3 * x[0]))


el0 = element("Lagrange", mesh0.topology.cell_name(), 1, shape=(3,))
V0 = fem.functionspace(mesh0, el0)
el1 = element("Lagrange", mesh1.topology.cell_name(), 1, shape=(2,))
V1 = fem.functionspace(mesh1, el1)

# Interpolate on 2D mesh
u1 = fem.Function(V1, dtype=xtype)
u1.interpolate(f)
u1.x.scatter_forward()

# Interpolate 2D->3D
u0 = fem.Function(V0, dtype=xtype)
u0.interpolate(
    u1,
    nmm_interpolation_data=fem.create_nonmatching_meshes_interpolation_data(
        u0.function_space.mesh,
        u0.function_space.element,
        u1.function_space.mesh,
        padding=1.0e-6,
    ),
)
u0.x.scatter_forward()
1 Like