Dolfin-convert, meshio invalid lateral/need mesh format 2

Hey there,

I’ve created a mesh with the gmsh api. When I’m trying to convert the .msh to .xml (with dolfin-convert and meshio) or .xmdf with meshio, then I get the following errors:

dolfin-convert error:
ValueError: invalid literal for int() with base 10: '112 55296\n'

meshio error:
AssertionError: Need mesh format 2

Those errors only appear if I use the API, maybe some gmsh users know this problem?
My script for generating the mesh with gmsh is the following:

import gmsh

gmsh.initialize()
gmsh.open("porous_structure_gmsh.geo")

entities = gmsh.model.getEntities(3)
entities2 = gmsh.model.getEntities(2)

domainId = [entity[1] for entity in entities]
noslipId = [entity[1] for entity in entities2 if gmsh.model.getType(entity[0], entity[1]) == 'Sphere']

# Nodes = gmsh.model.mesh.getNodes(-1,-1,True)
# Elements = gmsh.model.mesh.getElements(3,-1)
gmsh.model.addPhysicalGroup(3, domainId,0)
gmsh.model.addPhysicalGroup(2, noslipId, 1)
gmsh.model.setPhysicalName(3,0,"0")
gmsh.model.setPhysicalName(2,1,"NoSlipBoundary")

gmsh.model.mesh.generate(3)
gmsh.model.mesh.refine()
gmsh.model.mesh.refine()

gmsh.write("test.msh")
gmsh.finalize()

If I open the .msh in gmsh everything seems right, even the physical groups work perfectly

Here are all necessary files to reproduce the error (geo file, gmsh meshing script as above and of course the mesh which I’m not able to convert)

Thanks in advance and kind regards
Max

3 Likes

Hello,

you must certainly be using Gmsh version 4.0 which has been released quite recently and introduces a new msh format. dolfin-convert needs the previous msh format to work. meshio may probably have included the new msh format, check the latest meshio version to know.

To force the previous msh format in Gmsh there may be some option using the API but I don’t know it since I am not using the API. For command line from a geo file use:
gmsh -3 your_geo_file.geo -format msh2

3 Likes

Hey Jeremy,

thank you for this important information.I use the API to mark an important and geometrical complex boundary properly. However, I don’t know beforehand how this boundary will look like, but I can determine it, since it’s the only part with it’s entity being a 2D sphere.

Anyways, if other people want to use this, Jeremy was totally right and the python script needs one small modification

import gmsh
import sys

gmsh.initialize(sys.argv)

By doing so, one can execute the python script like this:
python script.py -format msh2

Hello max,

you can set gmsh to write *.msh files in the legacy format:

import gmsh
gmsh.initialize()
gmsh.option.setNumber(“Mesh.MshFileVersion”,2.2)

1 Like

And on the command line this is done with the -format flag:

gmsh -2 -format msh2 file.geo

(For meshing a 2d file)