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

How to refine just the boundaries of a mesh?

+1 vote

I would like to refine a mesh along its boundary. I will refer to the method suggested by hernan_mella on the following link.

https://fenicsproject.org/qa/9760/what-is-the-best-approach-to-mesh-refinement-on-boundary

I make one adjustment to the Border class. I only care about points close to the boundary.

class Border(SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary

After running this code the refinement is spread all over the mesh. Why don't I get more vertices just along the boundary?

asked Feb 28, 2017 by aldenpack FEniCS User (1,450 points)

1 Answer

+1 vote
 
Best answer

It should be noted that dolfin as yet has no support for non-conforming meshes and hanging nodes. You refine cells of a mesh. You can provide a CellFunction which marks which cells should be refined. Consider the following to refine the cells adjacent to the exterior boundary:

from dolfin import *

mesh = UnitSquareMesh(1, 1)

for j in range(4):
  mesh.init(1, 2) # Initialise facet to cell connectivity
  markers = CellFunction('bool', mesh, False)

  for c in cells(mesh):
    for f in facets(c):
      if f.exterior():
        markers[c] = True
        break

  mesh = refine(mesh, markers)

  plot(mesh)
interactive()
answered Feb 28, 2017 by nate FEniCS Expert (17,050 points)
selected May 9, 2017 by aldenpack
...