# FEniCS: extracting points from a cell

I'd like to loop over all edges of a simplex (in a mesh). To this end: How can I extract the the points from a cell?

This is for the eval method of a C++ definition of an Expression, i.e.,

void eval(Array<double>& v,
const Array<double>& x,
const ufc::cell& c
) const
{
Cell cell(*mesh, c.index);
// do something with cell?
}


You can always use an iterator to access the entities connected to a cell, like the edges in your case. Just as you suggest, you first need to create a dolfin::Cell from the ufc::cell. Then do something like this:

void eval(Array<double>& v,
const Array<double>& x,
const ufc::cell& c) const
{
Cell cell(*mesh, c.index);
for (EdgeIterator edge(cell); !edge.end(); ++edge)
{
// Do something with edge
}
}


For speed, and maybe easier access, you could directly access the edges (entities of dimension 1 as follows):

const unsigned int* edge_indices = cell.entities(1);
Edge e0(mesh, edge_indices[0]);
Edge e1(mesh, edge_indices[1]);
Edge e2(mesh, edge_indices[2]);


In a similar way, you can access the vertices of the edges (by calling cell.entities(0) or ei.entities(0)).

Note that for this to work, you need to instantiate the edges of the mesh (they will be created automatically by the iterators). You can do this by

mesh.init(1);


This should do. Here, I assume that mesh is your mesh, Q is the function space and that you use the dolfin interface in python.

for (i, cell) in enumerate(cells(mesh)):
print "Global dofs associated with cell %d: " % i
print Q.dofmap().cell_dofs(i)
print "The Dof coordinates:"
print Q.dofmap().tabulate_coordinates(cell)

• This is actually in Python, but I guess to define a custom expression on that level, I need to provide the C++ code. I modified the question accordingly. – Nico Schlömer May 8 '13 at 18:11