I have a surface mesh in 3D and I want to define a vertex_normals matrix that represents the average of the normal vectors (properly aligned) of all the cells that intersect with each vertex. My approach is not very fast and I wonder if there's a better (or preexisting) way to do it.
My approach has been the following:
- make a list (vertex_neighbours) of all the the cells that contain each vertex.
- make a list (normal_faces) of the normal vector to each cell (cross product of vertex coordinates, not sure if fenics has this functionality already).
- combine both lists to generate the desired vertex_normals:
vertex_normals = [np.sum(normal_faces[vertex_neighbours[vertex]])/
len(vertex_neighbours[vertex]) for vertex in xrange(num_vertices)]
This is unfortunately not very fast for large meshes, and so far I haven't been able to figure out a way to vectorize it.