# Projection of DG0 Function over Non-Matching Meshes

Hello, I am encountering some challenges in understanding the underlying mechanics of the interpolate method for DG0 functions defined on separate meshes. I employ the function create_nonmatching_meshes_interpolation_data in the following Minimal Working Example (MWE):

``````from mpi4py import MPI
import dolfinx as dfx
import numpy as np
from dolfinx.fem import create_nonmatching_meshes_interpolation_data

def non_matching_interpolation(old_function, new_function, tol=1e-6):
interpolation_data = create_nonmatching_meshes_interpolation_data(
new_function.function_space.mesh._cpp_object,
new_function.function_space.element,
old_function.function_space.mesh._cpp_object, tol)
new_function.interpolate(old_function, nmm_interpolation_data=interpolation_data)

mesh1 = dfx.mesh.create_unit_interval(MPI.COMM_SELF, 3)
V_CG_1 = dfx.fem.FunctionSpace(mesh1, ("CG", 1))
mesh2 = dfx.mesh.create_interval(MPI.COMM_WORLD, 4, (0.0, 1.))
V_CG_2 = dfx.fem.FunctionSpace(mesh2, ("CG", 1))

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

print("func1.x.array", func1.x.array)
func2 = dfx.fem.Function(V_CG_2)
non_matching_interpolation(func1, func2)
print("func2.x.array", func2.x.array)

V_DG_1 = dfx.fem.FunctionSpace(mesh1, ("DG", 0))
V_DG_2 = dfx.fem.FunctionSpace(mesh2, ("DG", 0))

func3 = dfx.fem.Function(V_DG_1)
func3.x.array[:] = [1,4,8]

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

func4 = dfx.fem.Function(V_DG_2)
non_matching_interpolation(func3, func4)
print("func4.x.array", func4.x.array)
``````

While the outcome for CG1 functions appears entirely intuitive to me, I would have expected somehow to observe a similar result in scenarios where a new DG0 element straddles two old DG0 elements that possess distinct values. Could anyone provide me with some insights on how the interpolate method functions and how one might achieve a more ‘continuous’ interpolation?
Many thanks,
Paul

I am not sure why you would expect anything else than what is shown when executing your code:

DG-0 means that each cell has a degree of freedom associated with its midpoint.

In the plot above we can see the initial mesh, with 3 elements, whose value is constant within each sub interval.
We also see the “new” mesh with 4 elements (denoted by the interval between the nodes).
As the degrees of freedom is associated with each midpoint, the old function is evaluated at these, giving rise to the plot below

which is logically in this way as the midpoint of the two cells in the middle both fall inside the “light-blue/green” area.

If you want something smoother, you can use an L2 projection as sketched out in L2 projection of fine mesh solution to a coarse mesh - #6 by dokken
However, you will encouter gibbs phenomenon, as discussed in
Projection and interpolation — FEniCS Tutorial @ Sorbonne

1 Like