I am running a script to convert a .msh file to a .xdmf file, using the following part of the script:
if __name__ == "__main__":
path_msh = Path("../meshes/patient9.msh")
msh = meshio.read(path_msh)
mesh_interior = create_mesh(msh, "tetra")
mesh_facets = create_mesh(msh, "triangle")
# store intermediate meshes in XDMF format
path_tmp_tets = path_msh.with_name(path_msh.stem + "_tets.xdmf")
path_tmp_tri = path_msh.with_name(path_msh.stem + "_tri.xdmf")
meshio.write(path_tmp_tets, mesh_interior, file_format="xdmf")
meshio.write(path_tmp_tri, mesh_facets, file_format="xdmf")
# read back in with dolfinx to obtain the mesh in the correct format
with io.XDMFFile(MPI.COMM_WORLD, path_tmp_tets, "r") as xdmf:
mesh = xdmf.read_mesh(name="Grid")
However, my script runs indefinitely en gets stuck at the mesh = xdmf.read_mesh(name=“Grid”) line: it prints test1 but not test2. do you have any idea why this happens?
The mesh is created with GMSH. by importing as an stl file adding a volume as an physical entity, and the adding a volume mesh an exporting it as an msh file. I do now think of the fact that I exported it as a version 2 ASCII instead of the a version 4 ASCII, could that have anything to do with it?
Info : Reading '../meshes/patient9cgs.msh'...
Info : 37093 nodes
Info : 213865 elements
Info : Done reading '../meshes/patient9cgs.msh'
Traceback (most recent call last):
File "/home3/s3234266/nsx/examples/scripts/readmsh.py", line 4, in <module>
mesh, cell_markers, facet_markers = gmshio.read_from_msh("../meshes/patient9cgs.msh", MPI.COMM_WORLD, gdim=3)
File "/home3/s3234266/spack/var/spack/environments/fenicsx/.spack-env/view/lib/python3.10/site-packages/dolfinx/io/gmshio.py", line 311, in read_from_msh
msh = model_to_mesh(gmsh.model, comm, rank, gdim=gdim, partitioner=partitioner)
File "/home3/s3234266/spack/var/spack/environments/fenicsx/.spack-env/view/lib/python3.10/site-packages/dolfinx/io/gmshio.py", line 221, in model_to_mesh
cell_id = cell_information[perm_sort[-1]]["id"]
IndexError: index -1 is out of bounds for axis 0 with size 0
I managed to get rid of the indexerror above by adding a volume and a surface as a physical entity. However, when running the original code I still get the problem that it gets stuck at the mesh = xdmf.read_mesh(name=“Grid”) line…
I’ve provided the .msh file that I now use to run the code: