Mesh subdivision in Gmsh


I defined the mesh with Gmsh in this way:

from mpi4py import MPI
import gmsh

large_mesh_size = 2
corner1 = gmsh.model.occ.addPoint(0, 0, 0, large_mesh_size)
corner2 = gmsh.model.occ.addPoint(1, 0, 0, large_mesh_size)
corner3 = gmsh.model.occ.addPoint(0, 1, 0, large_mesh_size)

line1 = gmsh.model.occ.addLine(corner1, corner2)
line2 = gmsh.model.occ.addLine(corner2, corner3)
line3 = gmsh.model.occ.addLine(corner3, corner1)

loop = gmsh.model.occ.addCurveLoop([line1, line2, line3])

surface = gmsh.model.occ.addPlaneSurface([loop])


gmsh.model.addPhysicalGroup(2, [surface], 1)
gmsh.model.setPhysicalName(2, 1, “TriangleSurface”)

gmsh.option.setNumber(“Mesh.Algorithm”, 1)
gmsh.option.setNumber(“Mesh.Algorithm3D”, 1)
gmsh.option.setNumber(“Mesh.MeshSizeMin”, large_mesh_size)
gmsh.option.setNumber(“Mesh.MeshSizeMax”, large_mesh_size)


if MPI.COMM_WORLD.rank == 0:

I want to refine the mesh by connecting the midpoints of the edges of this mesh (creating new triangles by combining the midpoints of the triangle, 4 triangles in total, barycenteric subdivision). So, for example, I have 4 new triangles for one level.

I want to repeat the same process for each new triangle and make a subdivision at the level I want. I want to keep the coarser and finer meshes and extract information about which finer triangles belong to which coarser triangles. I tried many times for this, but I could not do it completely. I’m new to Fenicsx, I would be very happy if you could help me. I am usig Dolfinx 0.8.0 and new Fenicsx.

Thank you,

Hi @chan

First off, please use the three backticks (``` ___ code here _____ ```) for formatting code.

Gmsh has methods to recombine meshes (see Gmsh tutorial #11). Ultimately this task is really up to you to solve, but you will probably need script where you define a series of meshes. For each refined mesh, you can assign a physical group tag based on the cell locations from the previous mesh. I would suggest asking the gmsh community if you are running into specific issues with aspects of the software at gmsh / gmsh · GitLab .

Overall, this is more programming problem that you will need to solve. You have only provided a script that generates a mesh, which is far from the much more comprehensive and vaguely defined task you are asking someone else to solve for you. Otherwise, I would suggest talking to a colleague or an advisor about how to approach this programming problem.

1 Like