I now have a solution/workaround, simply saving the data from a fenics Vector as a numpy array.
I thought at first I would be able to solve the problem by saving data in FEniCS XML files, like this:
File('navier_stokes_cylinder/timepoint.xml.gz') << u_.vector()
This indeed works, and inspection of the XML file shows that it contains the right sort of information. However, I couldn't figure out any way to read the file back into a FEniCS Vector. In particular,
vector = Vector('navier_stokes_cylinder/timepoint.xml.gz')
just throws an exception. I tried several variations, but was unable to come up with anything that worked. Obviously I'm missing something here, since it seems unlikely that the developers created a way to save Vector's in XML files without providing any way to read those files, but I couldn't find it.
Eventually I wrote my own minimal TimeSeries class, which can be seen here. The next problem I ran into was copying numerical data into and out of Vectors. The data can be retrieved as a numpy array using u.vector().array()
. (Here u
is a Function
.) That was easy, It took me a good long while to figure out that if I had a numpy array data
, I could copy it back into a Function
using a slice assignment:
u.vector()[:] = data
Obviously there are all sorts of potential problems with the order of the elements, but I assumed that if I created a FunctionSpace
on exactly the same mesh in exactly the same way, the dofs would correspond, and that seems to work, or at least to give plausible results.
At any rate, here are my versions of the ft08 and ft09 demo problems from the tutorial.