Hi,
[I hope the mailing list is the right place to ask about this. Let me
know if I should rather post this in the Q&A forum, but given that
development on this appears to be still in flux I didn't want to ask
about something where the solution is likely to change in the near
future.]
My question: I have a simulation with multiple dolfin Functions which
evolve over time, and I'd like to write these to a .h5 file so that I
can later retrieve the data for (some or all of) these functions at
specific timesteps. What is currently the "best practice" to achieve
this?
Below is a summary of my current understanding, and things that I have tried.
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?
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?
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).
Another option I was thinking of was to store the data by "manually"
indicating the timesteps in subgroup names, like this:
==>
f = df.HDF5File("data.h5", "w")
f.write(u, "/my_function/0/")
f.write(u, "/my_function/1e-9/")
f.write(u, "/my_function/2e-9/")
# [... etc. ...]
f.close()
<==
However, it seems that the HDF5File interface doesn't allow the
creation of subgroups of the toplevel group "/my_function", so this
approach doesn't currently work. Are there any intentions to support
this in the future?
Many thanks for reading through this long email and for any advice or
suggestions!
Best regards,
Max
[1] http://fenicsproject.org/pipermail/fenics/2013-October/000665.html
_______________________________________________
fenics mailing list
[email protected]
http://fenicsproject.org/mailman/listinfo/fenics