Solving Poisson's Equation using the FFT

0 downloads 0 Views 123KB Size Report
Nov 5, 2004 - The Fast Fourier Transform can be used to solve elliptic partial differential equations in multiple ... The solution is given by the inverse transform.
Chapter 6

Partial Differential Equations

Lecture 2

Solving Poisson’s Equation using the FFT The Fast Fourier Transform can be used to solve elliptic partial differential equations in multiple dimensions. The basic idea is very simple. Consider the one-dimensional equation d2 φ = ρ(x) . dx2 Express f and ρ in terms of their Fourier transforms: 1 f (x) = √ 2π

Z

1 ρ(x) = √ 2π

g(k)eikx dk ,

Z

σ(k)eikx dk .

The equation is diagonalized in k-space −k 2 g(k) = σ(k)



g(k) = −

Z

σ(k) ikx e dk . k2

σ(k) . k2

The solution is given by the inverse transform 1 f (x) = − √ 2π

We need to impose appropriate boundary conditions, and also specify how to treat the singularity at k = 0 in the integral. Boundary conditions and types of transforms The boundary conditions determine the appropriate type of Fourier transform to solve the problem. Some problems, like conduction of heat through a rod which Fourier studied, require a sine transform. Others require a cosine or exponential transform. PHY 410-505 Computational Physics I

1

Friday, November 5, 2004

Chapter 6

Partial Differential Equations

Lecture 2

Consider a domain 0 ≤ x ≤ L in one dimension. Choose a lattice of N equally spaced points xn = nL/N, n = 0, . . . , N − 1. The complex Fourier transform coefficients of f (x) are N −1 1 X kn gk = √ W fn , N n=0

The inverse transform

W = e2iπ/N .

N −1 1 X −nk W gk , fn = √ N k=0

will be periodic in xn with period L. This complex Fourier transform is therefore appropriate for problems which satisfy periodic boundary conditions. If the problem involves Dirichlet boundary conditions, for example, f (0) = f (L) = 0, then it would be appropriate to use a sine Fourier transform r N −1   2 X πnk fn = sin gk . N N k=1

If the problem involves Neumann boundary conditions it is appropriate to use is the cosine Fourier transform. One discrete version on N + 1 points given in Numerical Recipes is 1 [g0 + (−1)n gN ] + fn = √ 2N

r

  N −1 2 X πnk cos gk . N N k=1

Note that the cosine and sine transforms are not just the real and imaginary parts of the complex exponential transform. This is because the sine, cosine, and exponential functions separately form complete sets, albeit with different boundary conditions. The basic phase factor for the sine and cosine transforms is π/N compared with 2π/N for the exponential: PHY 410-505 Computational Physics I

2

Friday, November 5, 2004

Chapter 6

Partial Differential Equations

Lecture 2

the sine and cosine transforms require twice as many lattice points because they are real, compared with the exponential transform which is complex. Fast Sine and Cosine transforms can be defined similarly to the FFT of Chapter 5. Details and programs are given in Section 12.3 of Numerical Recipes. Poisson’s equation in two dimensions Let’s consider the discrete form of Poisson’s equation  2  ∂ ∂2 1 [φj+1,k + φj−1,k + φj,k+1 + φj,k−1 − 4φj,k ] = −ρj,k + φ(x, y) ' ∂x2 ∂y 2 h2 on an N × N grid of points in the region 0 ≤ x, y ≤ 1 with a given charge density, say a single point charge located at the center of the square. For simplicity, we will impose periodic boundary conditions so that the exponential FFT can be used to obtain the solution. The discrete Fourier transform is a linear operation, so we can apply it separately in the x and y directions, and it does not matter in which order the transforms are done. The two-dimensional Fourier coefficients are given by N −1 N −1 1 X X mj+nk ˜ φm,n = W φj,k , N j=0 k=0

ρ˜m,n

N −1 N −1 1 X X mj+nk W ρj,k . = N j=0 k=0

The inverse transforms are φj,k PHY 410-505 Computational Physics I

N −1 N −1 1 X X −jm−kn ˜ = W φm,n , N m=0 n=0

3

Friday, November 5, 2004

Chapter 6

Partial Differential Equations ρj,k

Lecture 2

N −1 N −1 1 X X −jm−kn = W ρ˜m,n . N m=0 n=0

Plugging these expressions into the discretized equation and equating coefficients of W −mj−nk gives  1  m −m n −n W + W + W + W − 4 φ˜m,n = −˜ ρm,n , 2 h which is easily solved for φ˜m,n =

h2 ρ˜m,n . 4 − W m − W −m − W n − W −n

The inverse Fourier transform then gives the potential. PoissonFFT.cpp #include #include #include #include #include #include



1 2 3 4 5 6

#include "Vector.hpp"

8

int main() {

10

std::cout