Skip to content

Interpolate nonmatching mesh

Mikael Mortensen edited this page Jun 21, 2013 · 16 revisions

The dolfin project or interpolate functions can not handle interpolation or projection from a FunctionSpace in one mesh to a FunctionSpace on a different mesh, at least not in parallel. Using the interpolate_nonmatching_mesh function this is now possible.

mesh1 = UnitSquareMesh(16, 16)
V1 = FunctionSpace(mesh1, 'CG', 2)
u1 = interpolate(Expression("sin(pi*x[0])*cos(pi*x[1])"), V1)
# Create a new _different_ mesh and FunctionSpace
mesh2 = UnitSquareMesh(10, 10)
x = mesh2.coordinates()
x[:, :] = x[:, :] * 0.5 + 0.25
V2 = FunctionSpace(mesh2, 'CG', 1)
u2 = interpolate_nonmatching_mesh(u1, V2)

The reular dolfin interpolate routine can handle this same interpolation problem on one processor. However, with this routine here it works in parallel as well. A ParaView plot of both u1 and u2 is shown below, where the colorscale has been reversed for the smaller mesh:

Interpolate nonmatching mesh

Interpolation from the small mesh onto the larger can be handled by dolfin's interpolate by setting parameters['allow_extrapolation'] = True. However, this will then extrapolate the solution from inside the small domain to the outside. Using interpolate_nonmatching_mesh the solution is simply set to zero outside the domain we are interpolating from:

u3 = interpolate_nonmatching_mesh(u2, V1)

leads to

Interpolate nonmatching mesh 2