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

How to get facet with specific index

+2 votes

How can I get a mesh facet with a given index? Essentially, I'd like to replace the for loop through the facet iterator in the following code with something less wasteful:

mesh = Mesh('mymesh.xml')
mesh.init()
bbox = mesh.bounding_box_tree()
(idx, distance) = bbox.compute_closest_entitity(Point(1, 1, 1))

#  Now it gets ugly:
it = facets(mesh)
for i in xrange(idx):
   next(it)
my_facet = next(it)

Is there a way to do something like

my_facet = mesh.get_facet(idx)

instead?

asked Mar 6, 2014 by Nikolaus Rath FEniCS User (2,100 points)

1 Answer

+3 votes
 
Best answer

Hi, there is

my_facet = Facet(mesh, facet_index)
answered Mar 6, 2014 by MiroK FEniCS Expert (80,920 points)
selected Mar 6, 2014 by Nikolaus Rath
...