Create nonmatching meshes interpolation data gives cryptic error. Whats wrong?

Hello together,

I’ve got a short but for me cryptic error while trying to use create_nonmatching_meshes_interpolation_data function in DOLFINx version 0.7.3. I want to do interpolation of functions defined on different vector-spaces and meshes. I’ve search all related topics

I tried to validate the following test:


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

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 (7 * x[1], 3 * x[0], x[2] + 0.4)

el0 = element("Lagrange", mesh0.basix_cell(), 1, shape=(3, ))
V0 = FunctionSpace(mesh0, el0)
el1 = element("Lagrange", mesh1.basix_cell(), 1, shape=(3, ))
V1 = FunctionSpace(mesh1, el1)

# Interpolate on 3D mesh
u0 = Function(V0, dtype=xtype)
u0.interpolate(f)
u0.x.scatter_forward()

# Interpolate 3D->2D
u1 = Function(V1, dtype=xtype)
u1.interpolate(u0, nmm_interpolation_data=create_nonmatching_meshes_interpolation_data(
    u1.function_space.mesh._cpp_object,
    u1.function_space.element,
    u0.function_space.mesh._cpp_object))
u1.x.scatter_forward()

But it gives me the error message:

Traceback (most recent call last):
  File "~/02z_test_dolfinx.py", line 31, in <module>
    u1.interpolate(u0, nmm_interpolation_data=create_nonmatching_meshes_interpolation_data(
TypeError: create_nonmatching_meshes_interpolation_data(): incompatible function arguments. The following argument types are supported:
    1. (mesh0: dolfinx.cpp.mesh.Mesh_float32, element0: dolfinx.cpp.fem.FiniteElement_float32, mesh1: dolfinx.cpp.mesh.Mesh_float32, padding: float) -> Tuple[List[int], List[int], List[float], List[int]]
    2. (geometry0: dolfinx.cpp.mesh.Geometry_float32, element0: dolfinx.cpp.fem.FiniteElement_float32, mesh1: dolfinx.cpp.mesh.Mesh_float32, cells: numpy.ndarray[numpy.int32], padding: float) -> Tuple[List[int], List[int], List[float], List[int]]
    3. (mesh0: dolfinx.cpp.mesh.Mesh_float64, element0: dolfinx.cpp.fem.FiniteElement_float64, mesh1: dolfinx.cpp.mesh.Mesh_float64, padding: float) -> Tuple[List[int], List[int], List[float], List[int]]
    4. (geometry0: dolfinx.cpp.mesh.Geometry_float64, element0: dolfinx.cpp.fem.FiniteElement_float64, mesh1: dolfinx.cpp.mesh.Mesh_float64, cells: numpy.ndarray[numpy.int32], padding: float) -> Tuple[List[int], List[int], List[float], List[int]]

Invoked with: <dolfinx.cpp.mesh.Mesh_float64 object at 0x7f8d60bee3e0>, <dolfinx.cpp.fem.FiniteElement_float64 object at 0x7f8d607a91b0>, <dolfinx.cpp.mesh.Mesh_float64 object at 0x7f8d604b8590>

The “Invoked with” line says that I’m in the Input-case 3, so why does this give me an error? Thanks for any help in advance,
Best

I don’t think that you are in case 3: you are missing the padding: float argument.

You’re right, the padding input is missing and with

create_nonmatching_meshes_interpolation_data(
    u1.function_space.mesh._cpp_object,
    u1.function_space.element,
    u0.function_space.mesh._cpp_object, 0)

everthing works fine. What does the padding mean? My guess is, that going from a domain to a larger domain one needs to clarify how you extend the function.

But nevertheless, the code was copied from the test_interpolation.py code from Github. Shouldn’t there be the padding as well?

See Speed up non-matching interpolation data and add extrapolation parameter by jorgensd · Pull Request #2858 · FEniCS/dolfinx · GitHub for the PR that introduced this change.

For the test, you most probably found a link in this forum, and that link points to an older version of the test, before the extra input argument was added. If you look at the file as it is now dolfinx/python/test/unit/fem/test_interpolation.py at a9c5de0b370502baa111357a9063dcc2f83a1e15 · FEniCS/dolfinx · GitHub you’ll see that the argument is indeed there.

2 Likes