Load mesh in DOLFINx using the C++ API

How can I load a gmsh-generated mesh into DOLFINx in C++? Happy to convert the mesh file if it makes it easier.

In C++ the mesh would have to be in XDMF-format.
I would either use the Python interface of dolfinx to convert it, or use meshio.

Thanks! Do you have a short code snippet/example that shows how to load it in XDMF in C++?

The only thing I have at hand is:

allthough it should be easier as one can use
https://docs.fenicsproject.org/dolfinx/v0.7.3/cpp/io.html#_CPPv4NK7dolfinx2io8XDMFFile9read_meshERKN3fem17CoordinateElementIdEEN4mesh9GhostModeENSt6stringENSt6stringE

1 Like

Ok, seems to work with:

io::XDMFFile file(comm, filename, "r");

auto cel = fem::CoordinateElement<double>(mesh::CellType::triangle, 1, basix::element::lagrange_variant::unset);
auto mesh = std::make_shared<mesh::Mesh<double>>(file.read_mesh(cel, mesh::GhostMode::shared_facet, "mesh"));

Thanks!