Load Marked mesh in cpp for parallel running

I am trying to load a mesh along with a mesh function and boundary function in cpp. The old approach of using

auto mesh = std::make_shared<Mesh>("./startfiles/mesh.xml");
auto mf = std::make_shared<MeshFunction<std::size_t>>(mesh,"./startfiles/mf.xml");
auto bf = std::make_shared<MeshFunction<std::size_t>>(mesh,"./startfiles/bf.xml");

no longer works in parallel, and I am trying to transition away from using xml mesh files and start using meshio. However, I have so far not had any luck importing .h5 or .xdmf mesh function files in cpp in parallel. Does anyone have a simple example of how to do this?

Apologies if I have missed an obvious solution that someone has already given, I have not managed find an answer in


so far, or in the standard fenics demo’s.

You should be able to translate the example used here Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio directly to C++.

from dolfin import * 
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
mvc = MeshValueCollection("size_t", mesh, 2) 
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)

There are no functions used to load the mesh or mesh-function here that are python specific. They are just bindings to c++ functions.

1 Like

That’s the answer :slight_smile: For completeness, some c++ code is below,

auto mesh = std::make_shared<Mesh>();
XDMFFile initialmeshfile(MPI_COMM_WORLD, "./startfiles/mesh.xdmf");

MeshValueCollection<std::size_t> mf_mvc(mesh, 3);
XDMFFile initialmffile(MPI_COMM_WORLD, "./startfiles/mf.xdmf");
initialmffile.read(mf_mvc, "name_to_read");
auto mf = std::make_shared<MeshFunction<std::size_t>>(mesh, mf_mvc);