Error with msh file

Hi all,

For context, I am converting a .key file to a .msh file. However, I’m having trouble reading the msh file, and I suspect there is an error somewhere in the formatting. The error occurs for a very simple mesh, with 4 quarilateral elements, entities and nodes labelled as shown.


The .msh file is saved as “simple_mesh.msh” and is

$MeshFormat
4.1 0 8
$EndMeshFormat
$Entities
4 4 1 0
1 0.0 0.0 0 0
2 15.0 0.0 0 0
3 15.0 50.0 0 0
4 0.0 50.0 0 0
1 0.0 0.0 0 15.0 0.0 0 0 2 1 -2
2 15.0 0.0 0 15.0 50.0 0 0 2 2 -3
3 0.0 50.0 0 15.0 50.0 0 0 2 3 -4
4 0.0 0.0 0 0.0 50.0 0 0 2 4 -1
1 0.0 0.0 0 15.0 50.0 0 1 1 4 1 2 3 4
$EndEntities
$Nodes
9 9 1 9
0 1 0 1
1
0.0 0.0 0
0 2 0 1
3
15.0 0.0 0
0 3 0 1
9
15.0 50.0 0
0 4 0 1
7
0.0 50.0 0
1 1 0 1
2
7.5 0 0
1 2 0 1
4
15.0 25 0
1 3 0 1
8
7.5 50 0
1 4 0 1
6
0 25 0
2 1 0 1
5
7.5 25 0
$EndNodes
$Elements
1 4 1 4
2 1 2 4
1 1 2 5 6
2 2 3 4 5
3 5 4 9 8
4 6 5 8 7
$EndElements

Then I run

from dolfinx import io
from mpi4py import MPI
domain, cell_markers, facet_markers = io.gmshio.read_from_msh("simple_mesh.msh", MPI.COMM_WORLD, 0, gdim=2)

and get the error

Info    : Reading 'simple_mesh.msh'...
Info    : 9 entities
Info    : 9 nodes
Info    : 4 elements
Info    : Done reading 'simple_mesh.msh'
Invalid rank, error stack:
internal_Issend(61644): MPI_Issend(buf=0x559a5a6173f1, count=1, MPI_BYTE, 1, 1, comm=0x84000005, request=0x559a5a6198e4) failed
internal_Issend(61605): Invalid rank has value 1 but must be nonnegative and less than 1
Abort(674890502) on node 0 (rank 0 in comm 416): application called MPI_Abort(comm=0x84000005, 674890502) - process 0

Does anyone have any idea how to fix it? I’m hoping its just a mistake in the format but I can’t see where it is.
Many thanks in advance,
Katie

Are you sure the mesh is defined as you wished? Open gmsh and have a look at the result as followed:

1 Like

Hi chenyongxin,

Thanks for your reply! I managed to fix it by opening gmsh as you said. It was fixed by changing

$Elements
1 4 1 4
2 1 2 4
1 1 2 5 6
2 2 3 4 5
3 5 4 9 8
4 6 5 8 7
$EndElements

to

1 4 1 4
2 1 3 4
1 1 2 5 6
2 2 3 4 5
3 5 4 9 8
4 6 5 8 7

Turns out 2 corresponds to a mesh of simplices, and 3 corresponds to a mesh of quads, so I was giving it the wrong type of element.

Many thanks for your help!
Katie