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

How to get the tetrahedrons list for a mesh and facets and node for all tetrahedron

0 votes

take this example please

from dolfin import *
omega = BoxMesh(-1, -1, -1, 1, 1, 1, 20, 20, 20)

this is $\Omega$. The question is how to get the elements (tetrahedrons), facets (triangles) and nodes (points) for this domain, and how to iterate over that objects. additionally how to get these objects as a list of indexes over the points list.

I want to get this (numpy or list) arrays

>>>elements[1]
[1,4,3,5]
>>>facets[5]
[3,2,9]
>>>node[23]
[2.9, 3.0, 9.0]

thaks!

asked Nov 22, 2013 by ljofre FEniCS Novice (720 points)
edited Nov 23, 2013 by ljofre

1 Answer

+2 votes
from dolfin import *
omega = BoxMesh(-1, -1, -1, 1, 1, 1, 20, 20, 20)
omega.init()
tet_inds = [cell.index() for cell in cells(omega)]
facet_inds = [facet.index() for facet in facets(omega)]
point_inds = [vert.index() for vert in vertices(omega)]
answered Nov 22, 2013 by johanhake FEniCS Expert (22,480 points)

Thanks my dear friend:
I have only a question ¿what is the function of omega.init()?

It computes the connectives between the different mesh entities. In this case it is actually not necessary as the relevant connectives are initiated by the iterators.

>>> omega.init()
>>> tet_inds = [cell.index() for cell in cells(omega)]
>>> facet_inds = [facet.index() for facet in facets(omega)]
>>> point_inds = [vert.index() for vert in vertices(omega)]
>>> tet_inds
[0, 1, 2, 3, 4, 5, 6, 7]
>>> facet_inds
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

that is not the same, with this I have the object index, but not the object index over the mesh points, an example.

>>>elements[1]
[1,4,3,5]
>>> facets[5]
[3,2,9]
>>> node[23]
[2.9, 3.0, 9.0]
...