HDF5File and PETSc object in wrong state

Issue #171 resolved
Simone Pezzuto created an issue
from dolfin import *
mesh = UnitSquareMesh(4, 4)

V = FunctionSpace(mesh, "CG", 1)
u = interpolate(Constant(1.0), V)

osol = HDF5File("solution.h5", "w")
osol.write(u, "solution_000")

u_read = Function(V)
osol.read(u_read, "solution_000")
#u_read.vector().apply("insert") # <- uncomment to avoid the error
u.assign(u_read)

info("%f" % assemble(u*dx))
info("%f" % assemble(u_read*dx))

On the other hand, dumping the function into an XML file yields the correct behaviour. By comparing HDF5File.cpp and XMLFunctionData.cpp it seems that a

  // Finalise vector
  vector.apply("insert");

is missing.

Comments (6)

  1. Chris Richardson

    It's possibly caused by not closing the HDF5 file between writing and reading. Have you tried:

    del osol
    osol = HDF5File("solution.h5", "r")
    

    between writing and reading?

  2. Simone Pezzuto reporter

    @chris_richardson it doesn't help. The reading process is fine, but when you try to use the vector, PETSc says that the object is in the wrong state (error code: 73). Which makes sense since Vec is not finalised.

  3. Log in to comment