On 01/04/2014 18:37, Maximilian Albert wrote:
I saw a proposal a while ago about advanced HDF5File functionality
(e.g. using 'HDF5FunctionHandle'); see this thread: [1]. However, this
doesn't seem implemented yet. Is it still on the agenda, or was it
superseded by something else? In the meantime, what are the
recommended alternatives?
No, that was never carried forward - seemed a little too complex.
Currently I can do something like the following (where 'u' denotes a
dolfin.Function):
==>
f = df.HDF5File('data.h5', 'w')
f.write(u, 'my_function', 0.0) #
f.write(u, 'my_function', 1e-9) # data at 1 nanosecond
f.write(u, 'my_function', 2e-9) # data at 2 nanoseconds
# ... etc. ...
f.close()
<==
This creates a toplevel group in the .h5 file called '/my_function'
containing a bunch of arrays named 'vector', 'vector_1', 'vector_2',
etc., which contain the data for the individual timesteps. In
addition, the timesteps themselves (here: [0, 1e-9, 2e-9]) are saved
in an attribute named 'series' of the toplevel group. This is all
nice, but the function "f.read(...)" doesn't seem to support
timesteps. So how do I read the data e.g. at time t=2e-9 back?
I believe you can do this:-
f = df.HDF5File('data.h5','r')
# u must alread exist and be on the correct FunctionSpace
u = Function(Q)
f.read(u, 'my_function/vector_2')
though perhaps not the most elegant. Suggestions for improvement are
welcome
- provided that they make the interface simple and intuitive :-).
There is another issue with the attribute "series", which is that it
will be limited in size, so you will probably find it cannot take more
than ~8k timesteps.
This should be fixed (e.g. by storing timestamps as attributes of
individual vectors).
Alternatively, I saw that there is a class in dolfin called
'TimeSeriesHDF5' (although it appears to be intended for more
low-level use). This also allows me to store the function vector at
different timesteps :
==>
ts = df.TimeSeriesHDF5('timeseries.h5')
ts.store(u.vector(), 0)
ts.store(u.vector(), 1e-9)
ts.store(u.vector(), 2e-9)
<==
This example creates a toplevel group called '/Vector' containing
multiple arrays named '0', '1', '2', etc. which store the timeseries
data (and the timesteps themselves are again stored in a 'series'
attribute of that toplevel group). Using "ts.retrieve()" this allows
me to read back data at specific timesteps, but it has the drawback
that I need to set up the dolfin.Functions manually before retrieving
the data. More severely, I can't see a way of storing *multiple*
function vectors in the same .h5 file (which is a showstopper for me).
Also, there is no tie-up with the dofmap, so you can't easily restore
the function, e.g. on a different number of cores.
_______________________________________________
fenics mailing list
[email protected]
http://fenicsproject.org/mailman/listinfo/fenics