Mapping from mesh.coordinates() to u.vector()

Hello there,

Given some index i that I use to get the position on a mesh: x = mesh.coordinates()[i],
is there a way to find out the index j (indices for non-scalar functions) such that u.vector()[j] = u(x)?

from dolfin import *

f    = Expression('sin(x[0])*cos(x[1])', degree=2)
mesh = UnitSquareMesh(10, 10)
V    = FunctionSpace(mesh, 'CG', 1)
u    = interpolate(f, V)
i    = 21
x    = mesh.coordinates()[i]

# j = some_mapping(i)
# print(u(x) == u.vector()[j]) # check if mapping works

You can use the vertex_to_dof_map function, as used here: Bitbucket

1 Like

Awesome! Thank you very much!