Inverse FFT to CoefficientFunction

Hello.
I am solving a problem where I have used FEM and then FFT to separate the modes. I want to calculate the energy flux now and for this purpose, I want to convert an array which I got after IFFT to a CoefficientFunction. How can it be done?

1 Like

The array contains nodal values or what data?
for nodal data you can set it as the coefficients of a H1 order 1 GridFunction:

func = GridFunction(H1(mesh, order=1))
func.vec.FV().NumPy()[:] = numpy_values

Hello Christopher,
My code is doing a calculation for FEM, and then I am using the points as below

X1 = np.arange(-90,90,1/ks)
Y1 = np.linspace(-140,0,len(X1))
X,Y = np.meshgrid(X1,Y1)
points = [mesh(i,j) for i,j in zip(X.ravel(),Y.ravel())]
u = np.array([gfu(p) for p in points]).reshape((len(Y1)),len(X1))) # u being calculated from FEA
dx = X1[1]-X1[0]
u_fft = np.fft.fft(u,axis=1)
k = np.fft.fftfreq(u_fft.shape[1],d=dx)*2*np.pi

For this you can use VoxelCoefficient
usage should be described in

help(VoxelCoefficient)

best