Anda di halaman 1dari 26

LECTURE 3

Elliptic PDEs and Solvers

Aim of Lecture
This week we will discuss

Overview of Finite Difference Method for


Elliptic PDEs
Taylor series
Forward, Backward, Central Differences
Boundary conditions

Using EXCEL to solve PDEs


Jacobi
Gauss-Seidel

Taylor Series
Consider the function u expanded about the point i,j.
u h 2
ui 1, j ui , j h
x 2
u h 2
ui 1, j ui , j h
x 2
u k 2
ui , j 1 ui , j k

y 2

2u
3

O
(
h
) .... (1)
2
x
2u
3

O
h
(
) .... ( 2)
2
x
2u
3
(
) .... (3)

O
k
2
y

j +1

u k 2 2u
3
ui , j 1 ui , j k

O
(
k
) .... ( 4)
2
y 2 y

i-1

j
h

i k
j-1

i+1
3

Finite Difference Equations


Consider the function u expanded about the point x.
u h 2 2u
3

(
) .... (1)
ui 1, j ui , j h
O
h
2
x 2 x
ui 1, j ui , j
u

O(h)
x i , j
h

Forward Difference

u h 2 2u
3
ui 1, j ui , j h

O
h
(
) .... (2)
2
x 2 x
Backward Difference
ui , j ui 1, j
u

O ( h)
x i , j
h

NOTE: Order of Truncation Error

Taylor Series
Central difference approximations obtained by:
j +1
ui 1, j
ui 1, j

u h 2
ui , j h
x 2
u h 2
ui , j h
x 2

2u
3

O
h
(
) .... (1)
2
x
2u
3

O
h
(
) .... ( 2)
2
x

ui 1, j ui 1, j
u

O(h 2 )
2h
x i , j

j
i-1

i+1

j-1

Central Difference

ui 1, j 2ui , j ui 1, j
2u
2

O
(
h
)
2
2
x i , j
h

Similar approximation for y.


5

Finite Difference Method


Method based on truncated Taylor series

ui 1, j ui , j
u

h
x i , j
ui , j ui 1, j
u

h
x i , j
ui 1, j ui 1, j
u

2h
x i , j
ui 1, j 2ui , j ui 1, j
2u

2
h2
x i , j

- Forward difference

j+1
ui,j
j

j -1
i -1
- Backward difference

i+1

- Central difference

- Central difference

Above approximations can be substituted for differentials in the PDE.


6

Laplace Equation - FDM


Consider the Laplace equation.
j+1

u u

0
2
2
x
y
2

ui,j
j
j -1

ui 1, j 2ui , j ui 1, j
h

ui , j 1 2ui , j ui , j 1
k

Difference formula for each node:

ui , j

i -1

i+1

k 2 ui 1, j ui 1, j h 2 ui , j 1 ui , j 1
2(h 2 k 2 )

When h = k we have:

ui , j

ui 1, j ui 1, j ui , j 1 ui , j 1
4
7

Poisson Equation - FDM


Consider the Poisson equation.

2u 2u
g 0

2
2
y
x
ui 1, j 2ui , j ui 1, j
h

ui , j 1 2ui , j ui , j 1
k

j+1

ui,j
j
j -1

g 0

i -1

i+1

Difference formula for each node:

ui , j

k 2 ui 1, j ui 1, j h 2 ui , j 1 ui , j 1 h 2 k 2 g
2(h 2 k 2 )

When h = k we have:

ui , j

ui 1, j ui 1, j ui , j 1 ui , j 1
4

h2 g

4
8

Including Boundary Conditions


Two types of boundary
conditions
Dirichlet u = a
Neumann u
y

Boundary conditions must


be included into the
discretised equations

u=a
j+1
ui,j
j
j -1

i -1

i+1

y
j

ui,j

j -1
j-2

i -1

i+1
9

Dirichlet Boundary Conditions


Dirichlet Boundary Conditions: e.g. u = 2
ui , j

ui,j+1 = 2

k 2 ui 1, j ui 1, j h 2 ui , j 1 ui , j 1 h 2 k 2 g

j+1

2(h 2 k 2 )

ui,j

j -1

i -1

i+1

Include boundary value directly


ui , j

k 2 ui 1, j ui 1, j h 2 2 ui , j 1 h 2 k 2 g
2(h 2 k 2 )

10

u=0

(1,1)

2u 0

u=0

u=1

j=1

(0,1)

Consider the following square domain


and its representation using a Finite
Difference Grid.

Example

i=1

(0,0)

u=0

(1,0)

Need to solve for internal


nodal values

Finite difference approximation


k 2 ui 1, j ui 1, j h 2 ui , j 1 ui , j 1
ui , j
2(h 2 k 2 )

11

Example
4

Taking h = k = 1/3 we have:

ui , j 1 ui 1, j 4ui , j ui 1, j ui , j 1 0

4 1 1 0 u2, 2 0
1 4
0 1 u3, 2 1


4 1 u2,3 0
1 0

u
0
1
1
4

3,3 1

j=1

Can show that

i=1

u2, 2 0.125
u 0.375
3, 2

u2,3 0.125

u
0
.
375

3,3

12

Neumann Boundary Conditions


Either use backward/forward difference
ui , j ui , j 1
u

O(k )
y i , j
k
so that

ui , j k ui , j 1

ui,j

j -1
j-2

i -1

Or use central difference (need to introduce artificial


nodes outside the boundary, but note error)
j
ui , j 1 ui , j 1
u

O(k 2 )
j -1
y i , j
2k
so that

ui , j 1 2k ui , j 1

i+1

ui,j

j-2

u
Alternatively, for derivatives in x direction, if
a
x
then
ui 1, j 2ah ui 1, j

i -1

i+1
13

Consider the following square domain and


its representation using a Finite Difference
Grid.
(1,1)

u
2
x

u0
2

u=1

j=1

u=1

(0,1)

Example

i=1

x h 0.5

Y
(0,0)

u=1

(1,0)

y k 0.5

ui , j

k 2 ui 1, j ui 1, j h 2 ui , j 1 ui , j 1
2(h 2 k 2 )

14

Example
Taking h = k = 1/2 we have:

So that

4
1
(u3, 2 u1, 2 u2,3 u2,1 )
4
1
(u4, 2 u2, 2 u3,3 u3,1 )
4

u2, 2
u 3, 2

j=1

ui , j

ui 1, j ui 1, j ui , j 1 ui , j 1

i=1

Artificial Node

Dirichlet boundary conditions give u1, 2 u2,3 u2,1 u3,3 u3,1 1


Using central difference approximation u4, 2 2 u2, 2
1
u2, 2 (u3, 2 3)
4
1
u3, 2 (2u2, 2 4)
4

u2, 2

8
1.143
7

u3, 2

11
1.571
7
15

EXCEL FOR SOLVING FINITE


DIFFERENCE EQUATIONS

16

USING EXCEL
Ideal for solving Finite Difference Equations

i-1

j +1
j
j-1

i+1

17

Setting Parameters
Write Parameter in Name Box:

Name Box

Formula Box

18

IF command in Excel
Using the IF Command
IF(CONDITION, THEN DO THIS, ELSE DO THIS)

19

Setting up FD Grid in EXCEL


Consider Tutorial 3, Question 2

Boundary conditions (grey)

Unknowns (white)

x values (peach)

20

Input FD Formula
Formula for D16

Formula for D9
Previous Iteration

Latest Iteration
21

Iteration in Excel
The Function key (F9) updates all values (1
Iteration)
Use the FLAG Parameter
FLAG = 0 (sets all cell values back to 0)
FLAG = 1 (Starts Iterations)

Keep pressing F9 to increment iteration count.


EXCEL updates cells in Columns.
Can program both Jacobi and Gauss-Seidel.

22

Iteration in Excel
Consider two iterations (Press F9 twice)

First Iteration

Second Iteration
23

Iteration in Excel
Continue Iterating (Pressing F9) until convergence

Solution converged to 4
decimal places

24

Gauss Seidel in Excel


Even easier than Jacobi (dont require the old values of the
previous iteration)
Each cell just uses most up-to-date values
Dont even know/care which order the cells are calculated in
Consider Tutorial 3, Question 1

25

Using Excel summary/list of tasks


Set up the parameters of the problem such as FLAG, h, k, g
NB when solving a Laplace equation it is better to set up Excel to
solve Poisson and then just set g = 0

Set up the domain (size, x/y values)


Fill in the known (Dirichlet) boundary values
Work out the general FD formula and copy it across all
cells with unknown values
Work out FD formulas for all unknown (Neumann)
boundary values and copy to relevant cells next week
There should be no cells inside the domain that reference
cells outside the domain (apart from parameters like g or h)
Double click each boundary cell to check

26

Anda mungkin juga menyukai