Complex vector operations, absolute value & phase

Hi!

I am working with complex vectors.
Is there any fast way to get the element wise absolute value and phase of the vector entries?
Getting the real and imaginary values with vector.real and vector.imag is helpful but I could not find such functions for the absolute or phase.

Thank You

You can use numpy for that. You can get a view of the vector as a numpy array by

vec.FV().NumPy()

Best
Christopher

Hi Christopher.

Thank you. Using numpy for complex vector operations is useful.
But is there a way to convert numpy vectors back into a GridFunction so I can plot results onto the mesh?

Best regards,
Nils

You can assign to that vector as well:

npvec = gf.vec.FV().NumPy()
npvec[:] = some_array

Best
Christopher