Converting mesh from XML format to hd5 format

I am converting the mesh from xml format to hd5 format using HDF5File. Below is the code that I am using

xml_file = 'geometry_2d.xml'
mesh = Mesh(xml_file)
out = HDF5File(mesh.mpi_comm(), 'geometry_2d.h5', 'w')
out.write(mesh, 'mesh')

When I run the code on the cluster, I get errors related to hdf5 and the error is

HDF5-DIAG: Error detected in HDF5 (1.10.4) MPI-process 0:
  #000: H5S.c line 489 in H5Sclose(): not a dataspace
    major: Invalid arguments to routine
    minor: Inappropriate type

Has anyone else faced the similar issue? does the HDF5File use h5py to convert XML mesh to h5 format? Thank you.

I would recommend storing data with XDMFFile, as it is more widely used, and has visualization support in Paraview. In particular, you can use meshio to convert your meshes (there are many posts regarding usage of meshio on this forum).

1 Like

Currently, I am converting xml file to h5 file and stores both mesh and facet in it as follow:

mesh = Mesh(xml_file)
out = HDF5File(mesh.mpi_comm(), 'filename.h5', 'w')
out.write(mesh, 'mesh')
f = MeshFunction('size_t', mesh, r_xml_file)
out.write(f,'facet')

And then I read the mesh as follow:

mesh = Mesh()
h5 = HDF5File(mesh.mpi_comm(), 'filename.h5', 'r')
h5.read(mesh, 'mesh', False)
surfaces = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
h5.read(surfaces, 'facet')

Can I export and import mesh, surfaces separately with meshio? Thank you.

As I said previously, there are plenty of examples of usecases of meshio on the forum, for instance:

Note that most of these problems reads the meshes from msh. However, a similar procedure can be done with xml meshes.