gmshio.read_from_msh/MPI_Issend fails: Invalid rank (DOLFINx v0.9.0)

Say that I want to build a circular plane using Gmsh (v4.13.1), store the geometry and then import it in FEniCSx (DOLFINx v0.9.0). I have created the following script.

import gmsh
from mpi4py import MPI
from dolfinx import io

if __name__ == '__main__':
    gmsh.initialize()

    # Add a circular plane
    c = factory.addCircle(3, 0, 0, 1)
    cl = factory.addCurveLoop([c])
    ps = factory.addPlaneSurface([cl])
    gmsh.model.occ.synchronize()

    pg = gmsh.model.addPhysicalGroup(2, [ps])  # Comment
    gmsh.model.setPhysicalName(2, pg, 'Circle')  # Comment

    gmsh.model.mesh.generate(3)

    filename = 'test.msh'
    gmsh.write(filename)

    gmsh.finalize()

    # Test reading for FEniCSx
    io.gmshio.read_from_msh(filename, MPI.COMM_WORLD)  # FAILS if the circle is added :(

However, I get the following error:

Invalid rank, error stack:
internal_Issend(61644): MPI_Issend(buf=0x58841a1f9741, count=1, MPI_BYTE, 1, 1, comm=0x84000005, request=0x58841a212424) failed
internal_Issend(61605): Invalid rank has value 1 but must be nonnegative and less than 1
Abort(943325958) on node 0 (rank 0 in comm 416): application called MPI_Abort(comm=0x84000005, 943325958) - process 0

What should I do? Thanks in advance

I’m not at a computer, so I cannot test this.
However, my best guess is that this is not the right physical group.

You can check if gmsh.model.getEntities(2) returns the same entity as ps is.

Secondly,

Is not the right syntax, as I would assume that you want a 2D grid (not a flat manifold in 3D), and then you should add the keyword arg gdim=2.

1 Like

Excuse me, I forgot four lines that add a 3D box and create a physical group for it:

import gmsh
from mpi4py import MPI
from dolfinx import io

if __name__ == '__main__':
    gmsh.initialize()

    # Add a box
    factory = gmsh.model.occ
    b = factory.addBox(0, 0, 0, 1, 1, .5)
    factory.synchronize()

    pg = gmsh.model.addPhysicalGroup(3, [b])
    gmsh.model.setPhysicalName(3, pg, 'Box')

    # Add a circular plane
    d = factory.addDisk(3, 0, 0, 1, 1)
    print(c, cl, ps)  # For debugging
    factory.synchronize()

    pg = gmsh.model.addPhysicalGroup(2, [d])
    gmsh.model.setPhysicalName(2, pg, 'Circle')

    gmsh.model.mesh.generate(3)
    print(pg)  # For debugging
    print(gmsh.model.getEntities(2))  # For debugging
    print(gmsh.model.getEntities(3))  # For debugging

    filename = 'test.msh'
    gmsh.write(filename)

    gmsh.finalize()

    # Test reading for FEniCSx
    io.gmshio.read_from_msh(filename, MPI.COMM_WORLD)  # FAILS if the circle is added :(
    print('FEniCSx reading OK')

print(c, cl, ps) gives 13 7 7. The other three print commands give:

1
[(2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6), (2, 7)]
[(3, 1)]

This is as expected. However, the ‘Invalid rank’ error appears when using the function read_from_msh. What could I do?