Mesh refinements of a curved domain

I am trying to implement adaptivity for a simple eliptic problem posed on “pacman” domain. I defined the domain by

from dolfin import *
from fenics import *
from mshr import *
import matplotlib.pyplot as plt

# Define 2D geometry
square = Rectangle(Point(0.0, 0.0), Point(1.0,1.0)) 
circle = Circle(Point(0.0,0.0), 1)
domain = circle - square
# Generate and plot mesh
mesh2d = generate_mesh(domain, 2)
plot(mesh2d, "2D mesh")

and then I refine the mesh with

mesh2dref = adapt(mesh2d)#, cell_markers)
plot(mesh2dref, "2D mesh")

or with

cell_markers = MeshFunction("bool", mesh2d,mesh2d.topology().dim())
for cell in cells(mesh2d):
    cell_markers[cell] = True
mesh2dref = adapt(mesh2d)#, cell_markers)
plot(mesh2dref, "2D mesh")

I obtain this pictures

The refined mesh does not take into account the boundary of the original domain. I would like to ask if there is a way to obtain the right refinement for the initial domain.

Thank you!

  1. mshr is long deprecated, and should not be used.
  2. When the mesh is loaded into DOLFIN, you do not load the original geometric description of the boundaries, so it cannot use those to do refinements.

External software such as GMSH has some refinement functionality: