Gmsh causes python kernel to restart

Hello,
I tried using gmsh to generate a custom mesh as explained here. However, the the last line in the following MWE causes my python 3.10.5 (IPython 7.33.0) kernel to restart, instead of creating a mesh. Any help is appreciated.

from dolfinx import io, mesh, cpp
from mpi4py import MPI
import gmsh

gmsh.initialize()
gmsh.model.add('1d mesh')
lc = 0.1
gmsh.model.occ.addPoint(0, 0, 0, lc, 1)
gmsh.model.occ.addPoint(1, 0, 0, lc, 2)
gmsh.model.occ.addLine(1, 2, 3)
gmsh.model.occ.synchronize()
gmsh.model.addPhysicalGroup(1, [3], name='simulation_domain')
gmsh.model.mesh.generate(1)

geometry_data = io.extract_gmsh_geometry(gmsh.model)
topology_data = io.extract_gmsh_topology_and_markers(gmsh.model)
gmsh_cell_type = list(topology_data.keys())[0]
properties = gmsh.model.mesh.getElementProperties(gmsh_cell_type)

name, dim, order, num_nodes, local_coords, _ = properties
cells = topology_data[gmsh_cell_type]['topology']
cell_id, num_nodes = MPI.COMM_WORLD.bcast([gmsh_cell_type, num_nodes], root=0)
ufl_domain = io.ufl_mesh_from_gmsh(cell_id, 1)
gmsh_cell_perm = io.cell_perm_gmsh(cpp.mesh.to_type(str(ufl_domain.ufl_cell())), num_nodes)
cells = cells[:, gmsh_cell_perm] 
msh = mesh.create_mesh(MPI.COMM_WORLD, cells, geometry_data[:, :0], ufl_domain)

You surely do not want [:,:0], you should use [:,:1] if your mesh is a 1D mesh

3 Likes