# Annotate mapping from function on submesh to function on parentmesh

Hello,

I learned to map a function defined on a submesh by `MeshView()` to another function defined on the parentmesh from MeshView submesh vertex map to parent mesh, however, assign the vertex value accoding to the index mapping is apprently not annotated. Below is MWE that I tried. I would like to know how could I make this kind of mapping work for dolfin-adjoint. Many thanks!

``````from dolfin import *
from dolfin_adjoint import *

parentmesh = UnitSquareMesh(10, 10)

class Block(SubDomain):
def inside(self, x, on_boundary):
return between(x[0],(0.4,0.6))

subdomains = MeshFunction("size_t", parentmesh, parentmesh.topology().dim())
subdomains.set_all(0)
Block().mark(subdomains,1)
submesh  = Mesh(MeshView.create(subdomains, 1))

A     = FunctionSpace(parentmesh, "DG", 0)
A_sub = FunctionSpace(submesh, "DG", 0)

x     = interpolate(Constant(0.0), A)
x_sub = interpolate(Constant(1.0), A_sub)

sub_to_parent = submesh.topology().mapping()[parentmesh.id()].cell_map()
values = x.vector().get_local()
#print(len(sub_to_parent))
for cell in cells(submesh):
values[sub_to_parent[cell.index()]] = x_sub.vector()[cell.index()]
x.vector().set_local(values)
plot(x)

m = Control(x_sub)
dx = Measure('dx', domain = parentmesh, subdomain_data = subdomains)
J = assemble(x*dx(1))
grad_vec = compute_gradient(J, m)
print(grad_vec.vector().get_local())
``````

This is currently not supported, see: Is there any function similar to FunctionAssigner that works with different meshes?

Hi Dokken,

thanks a lot for your information! Seems the way with `A.ident_zeros()` to solve the problem on the full mesh is the only workaround at the moment.