This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Reading hdf5 file with FEniCS 2016.2

+1 vote

Hello,

I just tried to run this old code after installing FEniCS 2016.2 and I get an error at the f.read line.

mesh = Mesh()
f = HDF5File(mpi_comm_world(), meshname+"hdf5", 'r')
f.read(mesh, meshname, False)

The error is :

Error:   Unable to convert string to cell type.
*** Reason:  Unknown cell type ("").
*** Where:   This error was encountered inside CellType.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2016.2.0
*** Git changeset:  0f003bc07ee5fd583fb956245016d5972b80fea1

Many thanks in advance !

Claire

asked Feb 15, 2017 by Claire L FEniCS User (2,120 points)

1 Answer

+1 vote
 
Best answer

Let's say you have an xml mesh in the current directory, write 'h5' file as follows:

import dolfin as df

mesh = df.Mesh(xml_mesh_name)
mesh_file = df.HDF5File(df.mpi_comm_world(), h5_file_name, 'w')
mesh_file.write(mesh, '/mesh')

# maybe you have defined a mesh-function (boundaries, domains ec.)
# in the xml_mesh aswell, in this case use the following two lines

domains = df.MeshFunction("size_t", mesh, 3, mesh.domains())
mesh_file.write(domains, "/domains")

read in parallel:

mesh = df.Mesh()
hdf5 = df.HDF5File(df.mpi_comm_world(), h5_file_name, 'r')
hdf5.read(mesh, '/mesh', False)

# in case mesh-functions are available ...

domains = df.CellFunction("size_t", mesh)
hdf5.read(domains, "/domains")
answered Feb 21, 2017 by RR FEniCS User (3,330 points)
selected Apr 30, 2017 by Claire L

this works for all my meshes in FEniCS 2016.2. Maybe there is another version of HDF5 files implemented now?

...