dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #17081
Re: [Question #95085]: Mesh traversal
Question #95085 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/95085
Status: Open => Answered
Anders Logg proposed the following answer:
On Thu, Dec 24, 2009 at 03:52:33PM -0000, dbeacham wrote:
> New question #95085 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/95085
>
> Is there an easy way to systematically traverse a given mesh in either python or cpp?
>
> ie I want to create a spline represenation of the boundary, but cannot find an easy way to calculate the index of the adjacent/connected vertices/edges/cells within the mesh. Currently I have to create my own connectivity structure using cells(mesh), but was wondering if getting adjacency/connectivity information between and within dimensions could be more easily achieved?
>
> Thanks, David.
You can get all adjacency information you need by iterators. For a
tetrahedral mesh, there are 4 different kinds of entities (vertices,
edges, faces, cells) and you can get all 16 combinations of
connectivities between the entities.
Say you want to iterate over all neighboring vertices of all vertices
of all edges on all cells. Then just do
for cell in cells(mesh):
for edge in edges(cell):
for vertex0 in vertices(edge):
for vertex1 in vertices(vertex0):
...
You can do the same in C++ (which will be much faster) using
CellIterator, EdgeIterator, VertexIterator.
You can also get the array of indices for the neighboring entities by
using the num_entities and entities member functions. For example
cell.num_entities(0)
returns the number of vertices of a cell and
cell.entities(0)
returns the array of indices for those vertices.
Note that the num_entities and entities functions require explicit
initialization of entities (which the iterators do automatically), so
to get connectivity between edges and faces, you would need to do
mesh.init(1, 2)
--
Anders
--
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.