meshio icon indicating copy to clipboard operation
meshio copied to clipboard

failure parsing .msh files generated by gmsh version 4.1.3

Open gertjanvanzwieten opened this issue 5 years ago • 7 comments

Gmsh version 4.1.3 generates .msh files that cannot currently be read by meshio: it fails in _read_entities of gmsh/_gmsh41.py after incorrectly reading only 3 out of 6 bounding box items for an entity of dimension 0 (line 114).

The error, however, appears to be in the _readers dictionary of gmsh/main.py, which directs mesh format "4" to _gmsh41 rather than _gmsh40. Changing this manually does indeed solve the issue.

The 'dotless' major versions appear to play a role in a fallback strategy of read_buffer for situations where the actual version is not recognized. However, this backfires in the situation that gmsh itself omits the minor version.

To reproduce the issue, below a minimal .msh file as generated by gmsh 4.1.3:

$MeshFormat
4 0 8
$EndMeshFormat
$PhysicalNames
1
2 1 "domain"
$EndPhysicalNames
$Entities
3 3 1 0
1 0 0 0 0 0 0 0 
2 1 0 0 1 0 0 0 
3 0 1 0 0 1 0 0 
4 0 0 0 1 0 0 0 2 1 -2 
5 0 0 0 1 1 0 0 2 2 -3 
6 0 0 0 0 1 0 0 2 3 -1 
8 0 0 0 1 1 0 1 1 3 4 5 6 
$EndEntities
$Nodes
4 3
1 0 0 1
1 0 0 0
2 0 0 1
2 1 0 0
3 0 0 1
3 0 1 0
8 2 0 0
$EndNodes
$Elements
1 1
8 2 2 1
1 1 2 3 
$EndElements

gertjanvanzwieten avatar May 05 '20 12:05 gertjanvanzwieten

That's a bug indeed, but mind you not many people take interest in this particular version of gmsh. It uses an "intermediate" format that was fixed on version after. You might want to upgrade.

nschloe avatar May 05 '20 12:05 nschloe

Indeed, on another platform with a newer gmsh version things work fine. Note however that 4.1.3 is the version in Debian stable (https://packages.debian.org/buster/gmsh) so this issue may affect a larger number than you are aware of.

gertjanvanzwieten avatar May 05 '20 14:05 gertjanvanzwieten

I knew the moment the format came out this was going to be trouble. I wish they'd just stick to a standard. Anyway, you're the first to have noticed, so I think it's not awfully bad. :smiley_cat:

If you think it's worth fixing, meshio is very open to PRs.

nschloe avatar May 05 '20 14:05 nschloe

Indeed I guess it isn't. But good to know you welcome PRs, I might give that a go. Thanks!

gertjanvanzwieten avatar May 05 '20 14:05 gertjanvanzwieten

One more question about this. In the comments of gmsh/main.py it states that some mesh files have their version specified as version "4" when it really is "4.1". Is this correct? In the case of this issue version "4" should be "4.0", but if other mesh files indeed list version "4" for format "4.1" then the issue is clearly not fixable (barring messy introspection beyond the header).

gertjanvanzwieten avatar May 06 '20 08:05 gertjanvanzwieten

One more question about this. In the comments of gmsh/main.py it states that some mesh files have their version specified as version "4" when it really is "4.1". Is this correct?

Yes.

In the case of this issue version "4" should be "4.0",

You're out of luck then. I'd adapt my file to read 4.0 probably. Gmsh file formats are a mess. :frowning_face:

nschloe avatar May 06 '20 10:05 nschloe

Clear, so be it. Indeed they are.

gertjanvanzwieten avatar May 06 '20 16:05 gertjanvanzwieten