Refine mesh on gmsh with Python Api

Dear all,

I am creating a crack inside of a rectangular domain, could anyone tell me how to refine the area along the crack?

width = 1
length = 1
h = 1e-3  # crack_thickness

rec1 = gmsh.model.occ.addRectangle(0, 0, 0, width, length)
rec2 = gmsh.model.occ.addRectangle(0, (width-h)/2, 0, width/2, (width+h)/2)
domain = gmsh.model.occ.cut([(2, rec1)], [(2,rec2)])
gmsh.model.occ.synchronize()

Thanks you

Use Gmsh fields, see for instance Electromagnetics example — FEniCSx tutorial

1 Like

Hi dokken,

could I ask one more question?

mesh_comm = MPI.COMM_WORLD
if mesh_comm.rank == model_rank:

Why we need to include the above code in the tutorial?

Kindly
Qiong

Gmsh doesn’t use mpi parallelism. Thus if you disregard it, N copies of the mesh generation will run on N processes with mpirun -n N python3 …

Got you. I looked thought the tutorial, and I could not find the relevant explanation about the option (such as “IField, Lcmin” etc). Do you know where I can find the detailed illustration?

    gmsh.model.mesh.field.add("Threshold", 2)
    gmsh.model.mesh.field.setNumber(2, "IField", 1)
    gmsh.model.mesh.field.setNumber(2, "LcMin", r / 3)
    gmsh.model.mesh.field.setNumber(2, "LcMax", 6 * r)
    gmsh.model.mesh.field.setNumber(2, "DistMin", 4 * r)
    gmsh.model.mesh.field.setNumber(2, "DistMax", 10 * r)

See the gmsh documentation: Gmsh 4.12.0 (development version)

1 Like