Gmshio.model_to_mesh 1D mesh error

Hi,
i’ve encountered an error when tried to create 1d mesh with gmesh.occ and transform with gmshio.model_to_mesh. The problem is not preveilant when using gmesh.geo. Any suggestions why there is the difference between .occ and .geo result when using gmshio.model_to_mesh?

The error:

229 perm_sort = np.argsort(cell_dimensions)
    231 # Broadcast cell type data and geometric dimension
--> 232 cell_id = cell_information[perm_sort[-1]]["id"]
    233 tdim = cell_information[perm_sort[-1]]["dim"]
    234 num_nodes = cell_information[perm_sort[-1]]["num_nodes"]

IndexError: index -1 is out of bounds for axis 0 with size 

gmesh code:

gmsh.initialize()
gmsh.model.add("1d")
p1 = gmsh.model.occ.addPoint(1, 1, 0)
p2 = gmsh.model.occ.addPoint(2, 1, 0)
l1 = gmsh.model.occ.addLine(p1, p2)
gmsh.model.addPhysicalGroup(1, [l1], 101)
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(1)
    
gdim = 2
gmsh_model_rank = 0
mesh_comm = MPI.COMM_WORLD
    
mesh1, cell_tags1, facet_tags1 = gmshio.model_to_mesh(gmsh.model, mesh_comm, gmsh_model_rank, gdim=gdim)

dolfinx → 0.7.1

You should never call

after adding physical groups, as it removes them. I.e. restructuring the code as

import dolfinx
from mpi4py import MPI
import gmsh


gmsh.initialize()
gmsh.model.add("1d")
p1 = gmsh.model.occ.addPoint(1, 1, 0)
p2 = gmsh.model.occ.addPoint(2, 1, 0)
l1 = gmsh.model.occ.addLine(p1, p2)
gmsh.model.occ.synchronize()

gmsh.model.addPhysicalGroup(1, [l1], 101)
gmsh.model.mesh.generate(1)

gdim = 2
gmsh_model_rank = 0
mesh_comm = MPI.COMM_WORLD

mesh1, cell_tags1, facet_tags1 = dolfinx.io.gmshio.model_to_mesh(
    gmsh.model, mesh_comm, gmsh_model_rank, gdim=gdim)

runs with no error

thanks for the answer. Now code works fine