Local Mesh Refinement

Hi guys,

So I’m trying to locally refine a 2D mesh in the neighborhood of an interior point. The only method I’ve seen thus far is to apply the ‘refine’ method iteratively and thus create successively finer meshes.

If I need a mesh which is very fine in the neighborhood of some point, the above approach is not only ham-fisted, it may simply be too computationally expensive.

Is there a better way?

You can generate your mesh using gmsh. In gmsh you start with points, then lines, then surfaces (for 2D). When you define a point, you write something like;

lc = 1e-2
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)

where lc is characteristic length of that point. You should define a small lc for the point you define, which is near the refinement region.

For more information, play with this tutorial.

1 Like

Hi @zaccandels,

you can also pass a MeshFunction to refine which indicates whether a given cell should be refined or not. This then needs to local refinement and you just need to write some code for a heuristic that refines close to your interior point.

Here is an example of what this could like, but I decided to refine all triangles that interest the vertical lines x = 2.5 and x = 3.5.

refine_cell = MeshFunction("bool", mesh, mesh.topology().dim())
for c in cells(mesh):
  vertices_x = sorted(c.get_vertex_coordinates()[::2])
  if (vertices_x[0] < 2.5 < vertices_x[1]) or (vertices_x[0] < 3.5 < vertices_x[1]):
    refine_cell[c] = True
  else:
    refine_cell[c] = False
mesh = refine(mesh, refine_cell)
1 Like