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