How to save workspace variables in FEniCS
I would like to save the workspace variables in FEniCS - the reason is because it takes a really long time to get to the beginning of the time loop. So i would like to save all the workspace variables just before the time loop, then load the workspace variables later in a different script to just run the time loop and not have to wait for the assembly of the bilinear forms all over again.
This is very easy to do in MATLAB - I'm looking for the equivalent of save file.mat and load file.mat.
I tried doing this in Spyder, but Spyder does not save the bilinear or the linear forms (because they are never explicitly stored in the variable explorer).
Hope to hear from someone soon. Thank you,
Not sure if this will help: When I tried finding something similar in Python to saving .mat workspace data in MATLAB, the best I found was pickle, https://docs.python.org/3/library/pickle.html , or object serialization. I've had mixed luck with being able to pickle complicated Python objects, and I don't yet know how pickle friendly fenics is. Also I haven't pickled anything in parallel.
Edit: Perhaps a better answer: I implemented checkpoint/restarting in my own code entirely using HDF5. I'd be surprised if you're trying to save something that can't be written/read to/from HDF5.
I think you want to use HDF5 to save your tensors, as they save in parallel :
Note that you probably do not want to store the sparse assembled matrix -- the assembly of bilinear forms is rather fast -- but saving the mesh and any projected or interpolated expressions will save time.