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

Vertex on Mesh Boundary

+4 votes

I need to know the vertices on mesh physical boundary.

I know I could define a function to check the coordinators of each vertex. But my mesh boundary is not fixed, and I need to rewrite the function each time.

I am wondering whether there is a simply way to check whether a vertex is on the mesh physical boundary.

I also find "DirichletBC" object has a "markers()" function, which returns the boundary markers. But the return value is a swig object and I can not see the value in python.

asked Mar 18, 2014 by vincehouhou FEniCS Novice (540 points)

2 Answers

+3 votes

First find facets that are on the boundary (i.e., facets that are connected to only one cell), then iterate over the vertices of facets that are on the boundary.

answered Mar 18, 2014 by Garth N. Wells FEniCS Expert (35,930 points)
+3 votes

You can find the vertices on the boundary like this:

from dolfin import *
mesh = UnitSquareMesh(4, 4)

# Mark a CG1 Function with ones on the boundary
V = FunctionSpace(mesh, 'CG', 1)
bc = DirichletBC(V, 1, DomainBoundary())
u = Function(V)
bc.apply(u.vector())

# Get vertices sitting on boundary
d2v = dof_to_vertex_map(V)
vertices_on_boundary = d2v[u.vector() == 1.0]

# Mark VertexFunction to check
vf = VertexFunction('size_t', mesh, 0)
vf.array()[vertices_on_boundary] = 1.

plot(vf)
interactive()

The DirichletBC.markers() returns a vector (numpy array in python) of the facets on that boundary, at least for development version.

answered Mar 18, 2014 by mikael-mortensen FEniCS Expert (29,340 points)

My FEniCS doesn't have this function "dof_to_vertex_map". I need a more recent version of FEniCS?

You probably need dolfin-1.3.0. Older versions have the function as part of the dofmap, try:

d = V.dofmap()
d2v = d.dof_to_vertex_map(mesh)
...