I'm trying to write a function to an hdf5 file viz Johan's example in:
here
When I try this in 1.4.0 I still get garbled data if I run the first program with more than one core.
With the first with one core, I can run the second, reading program with as many cores as I want.
(Code copied from above link)
from dolfin import *
import cPickle
mesh = UnitSquareMesh(12,12)
V = FunctionSpace(mesh, "CG", 1)
e = Expression("x[0]*(t*0.1+1)", t=0., degree=1)
u = project(e, V)
f = HDF5File(mesh.mpi_comm(), "u.h5", "w")
f.write(u, "/initial")
times = []
t = 0; dt=0.5
while t < 5:
t += dt
e.t = t
u.interpolate(e)
times.append(t)
f.write(u.vector(), "/values_{}".format(len(times)))
cPickle.dump(times, open("times.cpickle", "w"))
Then when I load the values I do something like:
from dolfin import *
import cPickle
mesh = UnitSquareMesh(12,12)
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
times = cPickle.load(open("times.cpickle"))
f = HDF5File(mesh.mpi_comm(), "u.h5", "r")
f.read(u, "/initial")
plot(u, title="u_{}".format(0))
for ind, t in enumerate(times):
f.read(u.vector(), "/values_{}".format(ind+1), True)
plot(u, title="u_{}".format(t))