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