Thank you for your help, your code fixed the error, however I now get a different
error Cell In[1], line 31
29 # Interpolate 2D->3D
30 u0 = fem.Function(V0, dtype=xtype)
---> 31 u0.interpolate(u1, nmm_interpolation_data=fem.create_nonmatching_meshes_interpolation_data(
32 u0.function_space.mesh._cpp_object,
33 u0.function_space.element,
34 u1.function_space.mesh._cpp_object, 0))
35 u0.x.scatter_forward()
AttributeError: 'dolfinx.cpp.mesh.Mesh_float64' object has no attribute '_cpp_object'
I have found a couple of forum posts about not having a _ccp_object
they are quite and are different from the error I am currently having (forum 1 and forum 2).
Do you know how to fix this error?
Also, here is my new code
from dolfinx.mesh import create_unit_square, create_unit_cube, CellType
from basix.ufl import element
from dolfinx import fem
from mpi4py import MPI
import numpy as np
xtype = np.float64
cell_type0 = CellType.hexahedron
cell_type1 = CellType.triangle
mesh0 = create_unit_cube(MPI.COMM_WORLD, 5, 6, 7, cell_type=cell_type0, dtype=xtype)
mesh1 = create_unit_square(MPI.COMM_WORLD, 5, 4, cell_type=cell_type1, dtype=xtype)
def f(x):
return np.vstack((7 * x[1], 3 * x[0]))
el0 = element("Lagrange", mesh0.topology.cell_name(), 1, shape=(3,))
V0 = fem.functionspace(mesh0, el0)
el1 = element("Lagrange", mesh1.topology.cell_name(), 1, shape=(2,))
V1 = fem.functionspace(mesh1, el1)
# Interpolate on 2D mesh
u1 = fem.Function(V1, dtype=xtype)
u1.interpolate(f)
u1.x.scatter_forward()
# Interpolate 2D->3D
u0 = fem.Function(V0, dtype=xtype)
u0.interpolate(u1, nmm_interpolation_data=fem.create_nonmatching_meshes_interpolation_data(
u0.function_space.mesh._cpp_object,
u0.function_space.element,
u1.function_space.mesh._cpp_object, 0))
u0.x.scatter_forward()