Gmshio.model_to_mesh - error

Hi,
i am buzzled with an error that i get when trying to transform gmsh mesh to dolfinx with gmshio.model_to_mesh.
The error i get is:

--->  meshD = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank)
-->   cell_id = cell_information[perm_sort[-1]]["id"]
IndexError: index -1 is out of bounds for axis 0 with size 0

The minimal reproducible example for my problem:

def create_mesh_with_gmsh():
    gmsh.initialize()
    gmsh.model.add("two_squares")

    # Omega1
    Omega1 = gmsh.model.occ.addRectangle(-0.5, -0.5, 0, 1, 1)
    gmsh.model.occ.synchronize()

    # Omega2
    sOmega2 = gmsh.model.occ.addRectangle(0.5, -0.5, 0, 1, 1)
    gmsh.model.occ.synchronize()

    # elem size
    gmsh.option.setNumber("Mesh.ElementOrder", 1)
    gmsh.option.setNumber("Mesh.CharacteristicLengthMin", 0.05)
    gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 0.05)

    # Gen 2D mesh
    gmsh.model.mesh.generate(2)

    # Convert Gmsh --> dolfinx mesh
    gdim = 2
    gmsh_model_rank = 0
    mesh_comm = MPI.COMM_WORLD
    meshD = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank)

    # gmsh.write("test_mesh.msh")

    gmsh.finalize()

    return meshD

meshD = create_mesh_with_gmsh()

Mesh saved and inspected in the gmsh gui looks ok.

Dolfinx version: 0.6.0
python-gmsh version: 4.11.1

You need to tag your volume (and potential surfaces) with physical markers, as explained in:

ok, i added physical tags for the surfaces:

    gmsh.model.addPhysicalGroup(2, [Omega1], 1)
    gmsh.model.addPhysicalGroup(2, [Omega2], 2)

but this produced an error:

---> 247 meshD = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank)
---> gmsh_cell_perm = cell_perm_array(_cpp.mesh.to_type(str(ufl_domain.ufl_cell())), num_nodes)
    249 cells = cells[:, gmsh_cell_perm]
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. dolfinx.cpp.fem.CoordinateElement(celltype: dolfinx.cpp.mesh.CellType, degree: int)
    2. dolfinx.cpp.fem.CoordinateElement(celltype: dolfinx.cpp.mesh.CellType, degree: int, variant: basix::element::lagrange_variant)

Invoked with: , 1, 

I would suggesting looking at this thread, as the error message is the same Error after gmshio.model_to_mesh - #4 by conpierce8

1 Like