33
Scientific Computing Partial Differential Equations Poisson Equation

Scientific Computing Partial Differential Equations Poisson Equation

Embed Size (px)

Citation preview

Page 1: Scientific Computing Partial Differential Equations Poisson Equation

Scientific Computing

Partial Differential EquationsPoisson Equation

Page 2: Scientific Computing Partial Differential Equations Poisson Equation

Partial Differential Equations

• Our study of PDE’s has focused on linear, second-order equations

• The following general form of such PDE’s can be classified by B2 - 4AC (Variables – x and y/t)

A2u

x 2 B2u

xyC

2u

y 2 D 0

Page 3: Scientific Computing Partial Differential Equations Poisson Equation

Partial Differential Equations

B2-4AC Category Example

< 0 Elliptic Laplace equation (steady state with 2 spatial dimensions)

= 0 Parabolic Heat conduction equation (time variablewith one spatial dimension)

>0 Hyperbolic Wave equation (time-variable with onespatial dimension)

2

2

22

2 1

t

y

cx

y

2

2

2

20

T

x

T

y

t

T

x

T

2

2

Page 4: Scientific Computing Partial Differential Equations Poisson Equation

Multi-dimensional Heat Equation

• Consider an object in which the temperature is a function of more than just the x-direction. Then the heat conduction equation can be written:– 2-D:

– 3-D:

tyyxx uuu )(2

tzzyyxx uuuu )(2

Page 5: Scientific Computing Partial Differential Equations Poisson Equation

2-D Steady State

• The Steady State solution for the Heat Equation requires that the temperature reaches an equilibrium distribution, that is we have

• Then,

• This is called Laplace’s Equation or the Potential Equation.

uxx uyy 0

ut 0

Page 6: Scientific Computing Partial Differential Equations Poisson Equation

The Laplace Equation

• Models a variety of problems involving the potential of an unknown variable u(x,y)

• The solution of this equation is used in thermodynamics (steady state of heat flow), fluid flow (finding potential function), and other problems where we are calculating the potential of some quantity.

uxx uyy 0

Page 7: Scientific Computing Partial Differential Equations Poisson Equation

The Poisson Equation

• Models a variety of problems involving the potential of an unknown variable u(x,y) where the right side of the equality is non-zero.

• For example, in calculations involving an Electric Field.

uxx uyy f (x,y)

Page 8: Scientific Computing Partial Differential Equations Poisson Equation

Electric Potential

• The electric field is related to the charge density bythe divergence relationship: (Gauss’s Law)• The electric field is related to the electric potential by a gradient relationship• Therefore the potential is related to the charge densityby Poisson's equation• In a charge-free region of space, this becomes Laplace's equationNote: is called the Laplacian operator = sum of 2nd

partials

E V

oE 0

E electric field

chargedensity

0 permittivity

oV 2V 0

2V 0

2

Page 9: Scientific Computing Partial Differential Equations Poisson Equation

Poisson’s equation: Example

• Show that the 2D potential

distribution satisfies the Poisson’s equation

Let’s evaluate the Laplacian operator:

Thus,

V 4 0

(x 2 y 2)

2V

x 2 2

4 0

2 0

;2V

y 2 2

4 0

2 0

2V 0

2V (2V

x 2 2V

y 2 ) 0

Page 10: Scientific Computing Partial Differential Equations Poisson Equation

Poisson vs Potential

• Laplace’s Equation or Potential Equation:

• Poisson Equation:

uxx uyy 0

uxx uyy f (x,y)

Page 11: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• Both the Laplace and Poisson Equations involve calculating the Laplacian Operator.

• We will approximate this sum of derivatives based on a grid in x and y and centered finite differences:

)()(2

2

22

2

21

22

nx

u

x

u

x

uu

Page 12: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• Here h = Δx and

k = Δy

(i,j)

(i+1,j)(i-1,j)

(i,j+1)

(i,j-1)

2u

x 2 ui1, j 2ui, j ui 1, j

h2

2u

y 2 ui, j1 2ui, j ui, j 1

k 2

Page 13: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• Thus, for the Poisson Equation

• For the Potential (Laplace) equation we have

ui1, j 2ui, j ui 1, j

h2 ui, j1 2ui, j ui, j 1

k 2 f (x i,y j )

ui1, j 2ui, j ui 1, j

h2 ui, j1 2ui, j ui, j 1

k 2 0

Page 14: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• The equation

is valid at all interior points of the grid. What about the boundary?

ui1, j 2ui, j ui 1, j

h2 ui, j1 2ui, j ui, j 1

k 2 f (x i,y j )

Page 15: Scientific Computing Partial Differential Equations Poisson Equation

Boundary Conditions

• Simplest boundary conditions specify value of u(x,y) on each of the fours sides of the region (grid) 0 ≤ x ≤ 1, 0 ≤ y ≤ 1

)(),1(

(y)),0(

)()1,(

)()0,(

1

0

1

0

ygyu

gyu

xfxu

xfxu

Page 16: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• If we assume h = k, we get for the Poisson Equation (putting lower i, j terms first)

• For the Potential (Laplace) equation we have

04 ,1,1,,1,1 jijijijiji uuuuu

),(4 2,1,1,,1,1 jijijijijiji yxfhuuuuu

Page 17: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• If we negate the Poisson equation and re-write we get:

• Consider the interior node equations for j=1:

),(4 21,1,,1,,1 jijijijijiji yxfhuuuuu

),(4:)1,1(

),(4:)1,2(

),(4:)1,3(

),(4:)1,2(

),(4:)1,1(

122

1,0,12,11,11,2

122

0,22,21,11,21,3

132

0,32,31,41,31,2

122

0,22,21,31,21,1

112

1,00,12,11,21,1

yxfhuuuuun

yxfhuuuuun

yxfhuuuuu

yxfhuuuuu

yxfhuuuuu

nnnnnn

nnnnnn

Page 18: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• If we let

• Then, we can write the equations on the previous slide as where

tnnnnn

tnnnnn

ffffffF

uuuuuuu

],,,,,,,,[

],,,,,,,,[

1,11,12,12,11,11,1

1,11,12,12,11,11,1

B − I[ ] u = −h2F(:,1) +b1

1,0,1

0,2

0,2

1,00,1

1,

1

1

1

1

,

41

141

141

14

nn

n

uu

u

u

uu

bIB

Page 19: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• Now, consider the interior node equations for j=2: ),(4 2

23,1,2,12,2,1 yxfhuuuuu iiiiii

),(4:)2,1(

),(4:)2,2(

),(4:)2,3(

),(4:)2,2(

),(4:)2,1(

212

2,3,12,12,21,1

222

3,22,12,22,31,2

232

3,32,42,32,21,3

222

3,22,32,22,11,2

212

2,03,12,22,11,1

yxfhuuuuun

yxfhuuuuun

yxfhuuuuu

yxfhuuuuu

yxfhuuuuu

nnnnnn

nnnnnn

Page 20: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• If we let

• Then, we can write the equations on the previous slide as

tnnnnn

tnnnnn

ffffffF

uuuuuuu

],,,,,,,,[

],,,,,,,,[

1,11,12,12,11,11,1

1,11,12,12,11,11,1

−I B − I[ ] u = −h2F(:,2) +b2

2,

2,0

2

0

0

,

1

1

1

1

41

141

141

14

nu

u

bIandB

Page 21: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• Similarly, for j=3,4,…,n-2 we can write the equations as

where

−I B − I[ ] u = −h2F(:, j) +b j

jn

j

j

u

u

bIandB

,

,0

0

0

,

1

1

1

1

41

141

141

14

Page 22: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• Now, consider the interior node equations for j=n-1: ),(4 1

2,2,1,11,1,1 nininininini yxfhuuuuu

),(4:)1,1(

),(4:)1,2(

),(4:)1,3(

),(4:)1,2(

),(4:)1,1(

112

1,,11,11,22,1

122

,21,11,21,32,2

132

,31,41,31,22,3

122

,21,31,21,12,2

112

1,0,11,21,12,1

nnnnnnnnnnnn

nnnnnnnnnnnn

nnnnnn

nnnnnn

nnnnnn

yxfhuuuuunn

yxfhuuuuunn

yxfhuuuuun

yxfhuuuuun

yxfhuuuuun

Page 23: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• If we let

• Then, we can write the equations on the previous slide as

tnnnnn

tnnnnn

ffffffF

uuuuuuu

],,,,,,,,[

],,,,,,,,[

1,11,12,12,11,11,1

1,11,12,12,11,11,1

−I B[ ] u = −h2F(:,2) +bn−1

1,,1

,2

,2

1,0,1

1,

1

1

1

1

,

41

141

141

14

nnnn

nn

n

nn

n

uu

u

u

uu

bIB

Page 24: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• If we let

• Then, we can write the entire (grid interior) system of equations as:

tnnnnn

tnnnnn

ffffffF

uuuuuuu

],,,,,,,,[

],,,,,,,,[

1,11,12,12,11,11,1

1,11,12,12,11,11,1

bFhAu 2

Page 25: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

BI

IBI

IBI

IBI

IB

A

41

141

141

14

B

bFhAu 2

1

2

2

1

n

n

b

b

b

b

b

1,0,1

0,2

0,2

1,00,1

1

nn

n

uu

u

u

uu

b

1,,1

,2

,2

1,0,1

1

nnnn

nn

n

nn

n

uu

u

u

uu

b )2,,2(

0

0

,

,0

nj

u

u

b

jn

j

j

Page 26: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• The matrix A is sparse, block-tridiagonal (for the way we set up the vector for u), symmetric, and positive definite (xt A x > 0 for all x).

• Also, A is a (n-1)2 x (n-1)2 matrix.

BI

IBI

IBI

IBI

IB

A

Page 27: Scientific Computing Partial Differential Equations Poisson Equation

Solution Method

• Since A is positive definite, the eigenvalues of A will be positive, so A is invertible. The solution exists as

• Now, this solution is not ideal, as it is computationally expensive to find the inverse of A.

• We could instead use Gaussian Elimination or LU factorization to solve for u, but this is not optimal, as A has a lot of zeroes, so we are wasting operations.

)( 21 bFhAu

Page 28: Scientific Computing Partial Differential Equations Poisson Equation

Iterative Solution Method

• It turns out (no proof) that our iterative methods from earlier in the course work well for this system.

• Review: The iterative methods we looked at to solve Ax=B were: – Jacobi Method– Gauss-Seidel Method– SOR (Successive Over-Relaxation)

Page 29: Scientific Computing Partial Differential Equations Poisson Equation

Jacobi Iterative Formula

• Jacobi Iteration: D=diagonal of A. x(k+1) = D-1(B + (D-A) x(k)) Element-wise, this is

n

jij

kjiji

ii

ki xaB

ax

,1

)()1( )(1

Page 30: Scientific Computing Partial Differential Equations Poisson Equation

Jacobi Iterative Formula

• In our case the x vector is

and xik+1 corresponds to solving for the diagonal terms in

Ax=B, thus in our case of the Jacobi equation becomes

• Now, after adding back the terms from the vector b, we get

tnnnnn uuuuuuu ],,,,,,,,[ 1,11,12,12,11,11,1

ui, j(k+1) =

1

4(−h2 f i, j +bi, j − sum(−1⋅ offdiagonal um,n )

)(4

11,1,,1,1,

2)1(,

kji

kji

kji

kjiji

kji uuuufhu

bFhAu 2

Page 31: Scientific Computing Partial Differential Equations Poisson Equation

Jacobi Iterative Formula

• So, we initialize ui,j0 on the boundary of the grid, and

set the interior values to some start values, say uij= 1, then use the Jacobi iteration formula

repeatedly to converge to the solution, keeping tabs on the error in our approximation.

)(4

11,1,,1,1,

2)1(,

kji

kji

kji

kjiji

kji uuuufhu

Page 32: Scientific Computing Partial Differential Equations Poisson Equation

Matlab Implementationfunction [x y u] = explicitPoisson(f, f0, f1, g0, g1, n)%Explicit solution of wave equation% Constants and vectors h = 1/n; x = 0:h:n*h; y = 0:h:n*h; % Initial guess at u is u=1 for all x,y u = ones(n+1,n+1); % Boundary conditions u(1:n+1, 1) = f0(x); u(1:n+1, n+1) = f1(x); u(1, 1:n+1) = g0(y); u(n+1, 1:n+1) = g1(y); % unew = next iterate, err will measure the error from % one iteration to next unew = u; err= unew-u;

Page 33: Scientific Computing Partial Differential Equations Poisson Equation

Matlab Implementation% Iterative procedure epsilon = 1e-4; % tolerance for convergence imax = 1000; % maximum number of iterations allowed k = 1; % initial index value for iteration % Calculation loop while k<= imax for i = 2:n for j = 2:n unew(i,j)=(-h^2*f(i,j) + u(i-1,j)+u(i+1,j) +u(i,j-1)+u(i,j+1))/4.0; err(i,j) = abs(unew(i,j)-u(i,j)); end; end; u = unew; k = k + 1; errmax = max(max(err));

if errmax < epsilon u = u'; mesh(x,y,u); fprintf('Convergence for %i iterations.\n',k); return; end; end;end