# Parallelized Interpolation from mesh to submesh

I am following the interpolation process from mesh to submesh as listed at https://github.com/FEniCS/dolfinx/blob/e4439ccca81b976d11c6f606d9c612afcf010a31/python/test/unit/fem/test_interpolation.py#L790. However, the speed of execution is slow. Is there a way to speed up the interpolation?

Are you using the main branch? If so, have a look at:

it fixes a regression that I introduced when making the interpolation more stable.

If you interpolation is from a mesh to a sub mesh and between the same space, there are much faster ways of doing the interpolation than using this operator.

If you provide an example with a built in mesh I can sketch out what I would do

1 Like

No, am using conda version 0.7.1. If by builtin mesh you mean mesh created using dolfinx then yeah.

``````import dolfinx
import numpy as np

from dolfinx.fem import (Expression, Function, FunctionSpace, assemble_scalar,
create_nonmatching_meshes_interpolation_data, form)
from dolfinx.geometry import bb_tree, compute_collisions_points
from dolfinx.mesh import (CellType, create_mesh, create_rectangle,
create_unit_cube, create_unit_square,
locate_entities, locate_entities_boundary, meshtags)
from mpi4py import MPI

xtype = np.float64

mesh1 = dolfinx.mesh.create_rectangle(comm=MPI.COMM_WORLD,
points=((0.0, 0.0), (1.0, 1.0 )), n=(2, 2),

def submesh_marker(x):
return x <= 0.5

submesh_entities = dolfinx.mesh.locate_entities(mesh1, mesh1.topology.dim, marker = lambda x: submesh_marker(x))
mesh2 = dolfinx.mesh.create_submesh(mesh1, mesh1.topology.dim, submesh_entities)

# Test interpolation from mesh1 to mesh2

u1 = Function(FunctionSpace(mesh1, ("CG", 1)), name="u1", dtype=xtype)
u2 = Function(FunctionSpace(mesh2, ("CG", 1)), name="u2", dtype=xtype)

def f_test1(x):
return 1.0 - x * x

u1.interpolate(f_test1)
u1.x.scatter_forward()

u1_2_u2_nmm_data = \
create_nonmatching_meshes_interpolation_data(
u2.function_space.mesh._cpp_object,
u2.function_space.element,
u1.function_space.mesh._cpp_object)

u2.interpolate(u1, nmm_interpolation_data=u1_2_u2_nmm_data)
u2.x.scatter_forward()
``````