FFT solve Poisson, why amplitude not match

236 Views Asked by At

I'm testing the FFT method, use a Poission equation

$\Delta u = -16\pi\sin(4\pi x)$

The analytical solution should be

$u = \sin(4\pi x)$

My result is more or less similarly, however the amplitude is not correct. What's then the correction?

FFT solve Poisson Plot

import matplotlib.pyplot as plt
import numpy as np

rows = 1
cols = 2
plt.clf()
plt.gcf().set_size_inches(cols*4.5,rows*4.5+0.2)
plt.minorticks_on()

N = 100
xmin = 0; xmax = 2
Lx = xmax - xmin
dx = Lx/(N-1)

#x=np.arange(xmin,xmax,dx,dtype='complex_')
#print(x)
x=np.linspace(xmin,xmax,N,dtype='complex_')

'''
Poission Equation   : u" = -16*pi*sin(4*pi*x)
Analytical Solution : u  = sin(4*pi*x)
'''

def rhs(x):
    return -16.0*np.pi*np.sin(4.0*np.pi*x)

ana = np.sin(4.0*np.pi*x)

#omega = 2*np.pi*np.array([i/(dx*Lx) for i in range(0,N)])
omega = 2*np.pi*np.fft.fftfreq(N, d=dx)

fhat = np.fft.fft(rhs(x))

uhat=np.zeros(len(x),dtype='complex_')
for i in range(len(x)):
    if (omega[i]==0):
        uhat[i]=0
    else:
        uhat[i]= -fhat[i]/omega[i]**2

u = np.real(np.fft.ifft(uhat))

print('plotting')
plt.title('fft poission 1d')

plt.subplot(rows,cols,1,title=r'Poisson Eq.: $\Delta u = -16\pi\sin(4\pi x)$')
plt.plot(x,u.real,'r--',label='FFT result')
plt.xlabel('x')
plt.legend()

plt.subplot(rows,cols,2,title='u')
plt.plot(x,ana,label=r'Ana = $\sin(4\pi x)$')
plt.plot(x,u.real,'r--',label='FFT result')
plt.xlabel('x')
plt.legend()

plt.tight_layout()
plt.savefig( 'fft_poission1d.png', format = 'png')
plt.show()
1

There are 1 best solutions below

0
On

Young man, you made a simple mistake. If

$u = \sin(4\pi x)$

The right Poisson equation is

$\Delta u = -16\pi^2\sin(4\pi x)$