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

How do I check if a Facet is part of the boundary?

+1 vote

I would like to define a function that's zero everywhere except on the boundary of my mesh. How do I do this? What I have so far is:

mesh = Mesh('mesh.xml')
bmesh = BoundaryMesh(mesh, 'exterior')
my_function = FacetFunction('int', mesh)
my_function.set_all(0)
for facet in facets(mesh):
    if facet in bmesh: # What's the proper check here?
        my_function[facet] = 42

Not surprisingly, the "facet in bmesh" expression doesn't work. But what do I have to use instead?

asked Jan 30, 2014 by Nikolaus Rath FEniCS User (2,100 points)

2 Answers

+2 votes
 
Best answer

Found the answer in question 927: the function that I need is facet.exterior().

Still, if someone can tell me the route I should have followed to get this from the documentation, please go ahead. I certainly feel a bit lost..

answered Jan 30, 2014 by Nikolaus Rath FEniCS User (2,100 points)
selected Jan 30, 2014 by johanhake
0 votes

The following might be faster than the solution from the first answer:

mapping = bmesh.entity_map(2)
boundary_facets = [ Facet(mesh, mapping[cell.index()])
                    for cell in cells(bmesh) ]
for facet in boundary_facets:
    my_function[facet] = 1
answered Jan 30, 2014 by Nikolaus Rath FEniCS User (2,100 points)
...