Process solution u (GridFunction) further with python

Hello,

i compute a solution for a 3D Magnetostatic problem using ngsolve.

u = GridFunction(fes)
...
u.vec.data = solver * f.vec

I’d like to compute the energy stored in the field. Therefore i need the solutionvector (in a flat manner) and the assembled load vector (in the same order).

At the moment i’m stuck how to transform the ngsolve vectors into scipy/numpy vectors. I can’t find any documentation. The method NumPy() doesn’t seem to exist for the u and f vector.

With best regards

u.vec.FV().NumPy()

it’s documented here:
https://ngsolve.org/docu/latest/how_to/howto_numpy.html

see also documentation->i-Tutorials for helpful documentation.

You could also use NGSolve’s InnerProduct:

InnerProduct (u.vec, f.vec)

Joachim