HDF5File.read
does not do enough error checking. Consider the following code, which writes a mixed function and tries to read in a scalar function:
from dolfin import *
mesh = UnitSquareMesh(2, 2)
Ve = FiniteElement("CG", triangle, 1)
Ze = MixedElement([Ve, Ve, Ve])
V = FunctionSpace(mesh, Ve) # scalar function space
Z = FunctionSpace(mesh, Ze) # mixed function space
# write a mixed function to HDF5
d = interpolate(Constant((1, 2, 3)), Z)
h5w = HDF5File(mpi_comm_world(), "bug.h5", "w")
h5w.write(d, "/solution")
del h5w
# read in a scalar function from HDF5
u = Function(V) # wrong space, should be Z!
h5r = HDF5File(mpi_comm_world(), "bug.h5", "r")
h5r.read(d, "/solution")
print "d.vector(): ", list(d.vector())
It prints [1.0, 2.0, 3.0, ...]
instead of raising an exception.
Yes. Consider also #820.