我寫了poisson eq。用譜方法求解。然而,得到的結果與週期性邊界條件差分法的結果並不一致。 我想我錯誤地使用了FFTW。 你能告訴我下面哪段代碼包含錯誤? 謝謝。poisson eq。用譜法
program main
implicit none
include 'fftw3.f'
integer(8) :: plan
integer, parameter :: j_max = 100, k_max = 100, m_max = j_max/2 + 1, n_max = k_max
integer :: j, k, m, n, mm, nn
real(8) :: v(1:j_max, 1:k_max), f(1:j_max, 1:k_max)
real(8) :: x_max, y_max, dx, dy, x, y, t_max, pi
complex(8), parameter :: im = (0.d0, 1.d0)
complex(8) :: vk(1:m_max, 1:n_max), fk(1:m_max, 1:n_max)
pi = 4.d0*atan(1.d0)
x_max = 2.d0*pi
y_max = 2.d0*pi
dx = x_max/j_max
dy = y_max/k_max
!*-- Initial Condition ---
do j = 1, j_max
x = dx*j
do k = 1, k_max
y = dy*k
f(j, k) = dexp(-(x - x_max/2)**2 -(y - y_max/2)**2)
enddo
enddo
!*-- FFT forward ---
call dfftw_plan_dft_r2c_2d(plan, j_max, k_max, v, vk, FFTW_ESTIMATE)
call dfftw_execute(plan)
call dfftw_plan_dft_r2c_2d(plan, j_max, k_max, f, fk, FFTW_ESTIMATE)
call dfftw_execute(plan)
do m = 1, m_max
do n = 1, n_max
if(m <= m_max/2 + 1) then
mm = m - 1
else
mm = m - 1 - m_max
endif
if(n <= n_max/2 + 1) then
nn = n - 1
else
nn = n - 1 - n_max
endif
if(mm == 0 .and. nn == 0) then
else
vk(m, n) = fk(m, n)/(mm**2 + nn**2)
endif
enddo
enddo
!*-- FFT backward ---
call dfftw_plan_dft_c2r_2d(plan, j_max, k_max, vk, v, FFTW_ESTIMATE)
call dfftw_execute(plan)
!*-- normalization ---
v = v/j_max/k_max
call dfftw_destroy_plan(plan)
end program main
可能是哪種語言? Fortran語言? –