Is it possible to save and read GridFunction or CoefficientFunction object?

Hi all,

I am working with large data that I must read from a .msh file and then a .out file line by line (which makes it super slow) every time. Then I construct that in ngsolve as some piecewise GridFunction. I am looking to speed up and also simplify this process. Do we have any data format that can store a GridFunction or a CoefficientFunction object?

Thanks in advance!

For a GridFunction, say gfu, you can export the set of values to a numpy file.

Something like
np.save("output", gfu.vec.FV().NumPy()[:]),
which can then be loaded in with
gfu.vec.FV().NumPy()[:] = np.load("output.npy")

1 Like

If you don’t need long term storage you can also pickle functions. This might not work across different ngsolve versions

1 Like