How to extract vetices of a entity?


I want to iterate the values of MeshFunction and find interesting entities. Specific questions are in the comments of the code.

import meshio
from mshr import *
from fenics import *

mesh = UnitCubeMesh(2,2,2)
boundary = MeshFunction('size_t' ,mesh , 2)
class BoundaryDown(SubDomain):
    def inside(self,x,on_boundary):
        return on_boundary and near(x[1], 0)

down = BoundaryDown()
down.mark(boundary, 1)

n = 0
# I can iterate the values of MeshFunction. 
# If I am interested in the value, I will get the entity.
MeshEntity(mesh, 2, n)
# Also, I can get the midpoint of this entity.
MeshEntity(mesh, 2, n).midpoint()
# But I can not find a function which return the vertices of the entity.

After I studied FEniCS for nearly a month, I can answer the question by myself.

# return an array which records the indices of 0-dimension entities of testEntity.
testEntity = MeshEntity(mesh, 2, n)
indices = testEntity.entities(0)
# return a vertex by index
vertex = Vertex(mesh, indices[0])
# get the coordinate of this vertex
vertex.x(0) # x axis
vertex.x(1) # y axis
vertex.x(2) # z axis
# another way to get the coordinate

…this also works: