How to read a mesh from mesh.h5?

I usually read meshes from mesh.msh, but now have a mesh.h5 file. What commands to use to read it in fenics? I tried

f = HDF5File(MPI.comm_world, ‘mesh.h5’, ‘r’)
mesh = Mesh()
f.read(mesh, ‘mesh’)

AttributeError: ‘dolfin.cpp.mesh.Mesh’ object has no attribute ‘_cpp_object’

1 Like

Same problem here. What is the correct syntax for saving and loading results with HDF5File? Here is a minimal example:

from dolfin import UnitSquareMesh, Mesh, HDF5File

mesh = UnitSquareMesh(10,10)

f = HDF5File(mesh.mpi_comm(), 'psi.h5','w')
f.write(mesh,'mesh')
f.close()

mesh = Mesh()
f    = HDF5File(mesh.mpi_comm(), 'psi.h5','r')
f.read(mesh, 'mesh')

where the last line throws the aforementioned error:

AttributeError: 'dolfin.cpp.mesh.Mesh' object has no attribute '_cpp_object'

My version of dolfin is

In : df.__version__
Out: '2019.2.0.dev0'

See:
https://bitbucket.org/fenics-project/dolfin/src/8060a84e8ada0df018772497534092727b06bd56/python/test/unit/io/test_HDF5.py?at=master#lines-210:213

from dolfin import UnitSquareMesh, Mesh, HDF5File

new_mesh = UnitSquareMesh(10,10)

f = HDF5File(new_mesh.mpi_comm(), 'psi.h5','w')
f.write(new_mesh,'mesh')
f.close()

mesh2 = Mesh()
f    = HDF5File(mesh2.mpi_comm(), 'psi.h5','r')
f.read(mesh2, 'mesh', False)

The signature of HDF5File read mesh is found at: Bitbucket

1 Like

Thank you! We were confused by the old documentation, which indicates the syntax

  • read(mesh, name)
    Read Mesh from file