Hi,
I need to interpolate a function defined on a submesh to the main mesh of higher dimension. I can make it work for nodal elements but I need to get it to work for functions defined on Nedelec space. I tried to use the functions introduced in release 0.9 but there seems to be an error I do not understand. I would appreciate if someone could fix the following MWE:
import dolfinx, ufl, gmsh, mpi4py
import numpy as np
from dolfinx.io import gmshio
def create_geometry():
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 0) # disable output messages
gmsh.clear()
gdim = 2
model_rank = 0
occ = gmsh.model.occ
gdim = 2
fov = occ.add_rectangle(0, 0, 0, 1, 1)
occ.synchronize()
# number all domains
all_doms = gmsh.model.getEntities(gdim)
for j, dom in enumerate(all_doms):
gmsh.model.addPhysicalGroup(dom[0], [dom[1]], j + 1) # create the main group/node
# number all boundaries
all_edges = gmsh.model.getEntities(gdim - 1)
for j, edge in enumerate(all_edges):
gmsh.model.addPhysicalGroup(edge[0], [edge[1]], edge[1]) # create the main group/node
# gmsh.model.mesh.setSize(gmsh.model.getEntities(), max_size)
gmsh.option.setNumber("Mesh.MeshSizeMax", 0.1)
gmsh.model.mesh.generate(gdim)
model_rank = 0
mesh, ct, ft = gmshio.model_to_mesh(gmsh.model, mpi4py.MPI.COMM_WORLD, model_rank, gdim)
return mesh, ct, ft
mesh, ct, ft = create_geometry()
# create submesh at x = 0
marker = lambda x: np.isclose(x[0], 0.0)
left_facets = dolfinx.mesh.locate_entities_boundary(mesh, mesh.topology.dim - 1, marker)
submesh, entity_map, vertex_map, node_map = dolfinx.mesh.create_submesh(mesh, 1, left_facets)
V_submesh = dolfinx.fem.functionspace(submesh, ("CG", 2, (2,))) # a vector function
uh_submesh = dolfinx.fem.Function(V_submesh)
V = dolfinx.fem.functionspace(mesh, ("N1curl", 2))
uh = dolfinx.fem.Function(V)
submesh_to_mesh_interp_data = dolfinx.fem.create_interpolation_data(V, V_submesh, ct.find(1)) # I only care about the boundary so take all cells for simplicity
# TOFIX:
uh.interpolate_nonmatching(uh_submesh, cells=None, interpolation_data=submesh_to_mesh_interp_data)