picklinge GridFunction Error

Hi everyone,

im trying to pickle and unpickle GridFunctions in a time dependent problem, in order to restart a computation from the pickled data. However, on writing the data from an unpickled GridFunction into the GridFunction used in the computation

v1 = GridFunction(V)
unpickler = pickle.Unpickler(open("1.dat","rb"))
up1, = unpickler.load()

v1.vec.data = up1.data

I get the following an error:

netgen.libngpy._meshing.NgException: Archive error: Polymorphic type ngcomp::S_GridFunction<double> not registered for archive

I have attached an MWE and I on the master branch commit ee5d90c06.

Can anyone help me with this?

Best wishes,
Henry

Attachment: test_pickle.py

Hi Henry,

you have to use

v1.vec.data = up1.vec.data

since you can not write a GridFunction on a Basevector.

If I want to save some data for longer times, I usually save the raw data of the vector (just the values in a list and some information the reconstruct the FESpace). There have been quite a lot changes in the pickling interface which caused me some troubles in the past when loading with a newer NGSolve.

Best,
Christoph

Hi Christoph,

thanks for the quick reply! Sorry I missed that!

Best wishes,
Henry

On a related Note:

I also need to pickle BitArrays. I have implemented this netgen/libsrc/core/python_ngcore_export.cpp , but would it be possible to get this into the source code? What would be the best way to do this?

Best wishes,
Henry