MeshFunction vertex mapping/coordinates

Hi,

How do I get a mapping that relates the output of a mesh function (defined over vertices) to the mesh coordinates (need to identify the coordinates of each vertex in the mesh function array)?

Below is the code I am working with - I think I need a mapping to reorder vertex_func.array() so that it matches the coords array. If this is not possible, how can I obtain the coordinates (or vertex indices) that correspond to the values in the vertex_array?

from dolfin import *
import numpy as np

n = 30

mesh = UnitCubeMesh.create(n,n,n,CellType.Type.hexahedron)
coords = mesh.coordinates()


class ss(SubDomain):
    def inside(self,x,on_boundary):
        return near(x[0],0.5) 

mesh.init(3,3)
mesh.init(2,2)

vertex_func = MeshFunction('size_t', mesh,0)
vertex_func.set_all(0)

vertex_func0 = ss()
vertex_func0.mark(vertex_func,1)

vertex_array = vertex_func.array()

ordered_vertex_array = vertex_array[SOME_MAPPING]             
##ORDER OF coords == ordered_vertex_array

##OR 

vertex_idx_array = SOME_FUNCTION
idx_ordered_vertex_array = vertex_array[vertex_idx_array] #reorders array in order of vertex index

Many thanks,
D

Hi D,

Could you give a bit more background on what you are exactly trying to do? The meshfunction you have defined is used as a marker for marking subdomain ss. The coordinate array of the vertices in this subdomain may be retrieved as follows:

idx = []
for vertex in vertices(mesh):
    if vertex_func[vertex]:
        idx.append(vertex.index())
print('idx: ', idx)

ss_coord_array = mesh.coordinates()[idx]
print('coord_array: ', ss_coord_array)

Thanks,

Rudy.