Interpolation between different meshes in 0.7.1

Hey there,

I just shifted from dolfinx 0.6.0 to the new version 0.7.1 and found some behavior I could not explain myself. In version 0.6.0 I could interpolate between meshes (as in the following MWE)

from mpi4py import MPI
import dolfinx as dfx
import numpy as np

print("dolfinx version:", dfx.__version__)
mesh1 = dfx.mesh.create_unit_interval(MPI.COMM_SELF, 10)
V1 = dfx.fem.FunctionSpace(mesh1, ("CG", 1))
mesh2 = dfx.mesh.create_interval(MPI.COMM_WORLD, 5, (0.0, 0.5))
V2 = dfx.fem.FunctionSpace(mesh2, ("CG", 1))

func1 = dfx.fem.Function(V1)
func1.x.array[:] = np.arange(len(V1.tabulate_dof_coordinates()))

print("func1.x.array", func1.x.array)

func2 = dfx.fem.Function(V2)
func2.interpolate(func1)

print("func2.x.array", func2.x.array)

and get

dolfinx version: 0.6.0
func1.x.array [ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]
func2.x.array [0. 1. 2. 3. 4. 5.]

Now, in the new version, running the same code as above, I get

dolfinx version: 0.7.1
func1.x.array [ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind and https://petsc.org/release/faq/
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run 
[0]PETSC ERROR: to get more information on the crash.
[0]PETSC ERROR: Run with -malloc_debug to check if memory corruption is causing the crash.
Abort(59) on node 0 (rank 0 in comm 0): application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0

Did something change in the interpolation interface from 0.6 to 0.7? I tried looking up the “User facing changes” of v0.7.0 and found #2414, but I’m not sure what I can do to get my code running again. Specifically, I used the installation via conda for both versions.
Thanks a lot :slight_smile:

As indicated by the changes in the referenced PR, you should supply the interpolation data, i.e.

from mpi4py import MPI
import dolfinx as dfx
import numpy as np

print("dolfinx version:", dfx.__version__)
mesh1 = dfx.mesh.create_unit_interval(MPI.COMM_SELF, 10)
V1 = dfx.fem.FunctionSpace(mesh1, ("CG", 1))
mesh2 = dfx.mesh.create_interval(MPI.COMM_WORLD, 5, (0.0, 0.5))
V2 = dfx.fem.FunctionSpace(mesh2, ("CG", 1))

func1 = dfx.fem.Function(V1)
func1.x.array[:] = np.arange(len(V1.tabulate_dof_coordinates()))

print("func1.x.array", func1.x.array)

func2 = dfx.fem.Function(V2)
interpolation_data = dfx.fem.create_nonmatching_meshes_interpolation_data(
        func2.function_space.mesh._cpp_object,
        func2.function_space.element,
        func1.function_space.mesh._cpp_object)
func2.interpolate(func1, nmm_interpolation_data=interpolation_data)

print("func2.x.array", func2.x.array)
1 Like