This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to list pairs of vertices for each edge in mesh?

0 votes

I need to list all pairs of vertices corresponding to the edges in my mesh. How can this be done?

For example if vertices 1 and 2 are connected by an edge; my list should contain the pair (1,2).

I am using Fenics 1.3 and the C++ interface.

asked Sep 30, 2014 by BB FEniCS Novice (710 points)

1 Answer

+1 vote
 
Best answer

Something like this (in serial):

std::vector<std::pair<std::size_t, std::size_t> > edge_pairs;

for (EdgeIterator e(mesh); !e.end(); ++e)
{
   std::size_t v0 = e->entities(0)[0];
   std::size_t v1 = e->entities(0)[1];
   edge_pairs.push_back(std::make_pair<std::size_t, std::size_t>(v0, v1));
}

you also need to make sure the topology is initialised

mesh.init(1, 0);
answered Sep 30, 2014 by chris_richardson FEniCS Expert (31,740 points)
selected Sep 30, 2014 by BB
...