33
1 EEE 431 Computational Methods in Electrodynamics Lecture 4 By Dr. Rasime Uyguroglu [email protected] u.tr

1 EEE 431 Computational Methods in Electrodynamics Lecture 4 By Dr. Rasime Uyguroglu [email protected]

Embed Size (px)

Citation preview

1

EEE 431Computational Methods in

Electrodynamics

Lecture 4By

Dr. Rasime [email protected]

2

FINITE DIFFERENCE METHODS

3

Introduction

In general real life EM problems cannot be solved by using the analytical methods, because:

The PDE is not linear, The solution region is complex, The boundary conditions are of mixed types, The boundary conditions are time dependent, The medium is inhomogeneous or anisotropic.

4

Introduction

For such complicated problems numerical methods must be employed.

Finite Difference Method (FDM) is one of the available numerical methods which can easily be applied to solve PDE’s with such complexity.

FDM, is easy to understand and apply.

5

Introduction

FD techniques are based upon approximations of differential equations by finite difference equations.

Finite difference approximations: have algebraic forms, Relate the value of the dependent variable

at a point in the solution region to the values at some neighboring points.

6

Introduction

Steps of finite difference solution: Divide the solution region into a grid of

nodes, Approximate the given differential

equation by finite difference equivalent, Solve the differential equations subject

to the boundary conditions and/or initial conditions.

7

Introduction

Rectangular Grid Pattern

8

Finite Difference Schemes

The derivative of a given function f(x) can be approximated as:

0 0 0

0 0 0

0 0 0

( ) ( ) ( )(1)

( ) ( ) ( )(2)

( ) ( ) ( )(3)

2

df x f x x f xForward Difference Formula

dx xdf x f x f x x

Backword Difference Formuladx x

df x f x x f x xCentral Difference Formula

dx x

9

Finite Difference Schemes

0x x

f(x)

x

A

P B

0x x 0x

10

Finite Difference Schemes

Estimate of second derivative of f(x) at P:

0 0

2

2

0 0 0 0

0 0 02

( ) ( )2 2

1 ( ) ( ) ( ) ( )

( ) 2 ( ) ( )(4)

( )

x xf x f x

f x xx x

f x x f x f x f x x

x x x

f x x f x f x x

x

11

Finite Difference Schemes

Or, by using Taylor Series:

2 3320 0 0

0 0 2 3

2 3320 0 0

0 0 2 3

( ) ( ) ( )1 ( )( ) ( ) ( ) ... (5)

2! 3!

( ) ( ) ( )1 ( )( ) ( ) ( ) ... (6)

2! 3!

f x f x f xxf x x f x x x

x x x

f x f x f xxf x x f x x x

x x x

12

Finite Difference Schemes

Adding these equations:

Assuming that higher order terms are neglected:

22 40

0 0 0 2

( )( ) ( ) 2 ( ) ( ) ( )

f xf x x f x x f x x O x

x

20 0 0

2 2

( ) 2 ( ) ( )

( )

f f x x f x f x x

x x

13

Finite Difference Schemes

is the error introduced by truncating the series.

It represents the terms that are not greater than .

4( )O x

4( )x

14

Finite Difference Schemes

Subtracting Eq.6 from Eq. 5 and neglecting terms of the order

Error is second order. Eq. 3- Eq.4 are second order, Eq.1 and

Eq. 2 are first order.

3( )x

0 0 0( ) ( ) ( )

2

f x f x x f x x

x x

15

Finite Difference Schemes

As long as the derivatives of f are well behaved and the step size is not too large, the central difference should be the most accurate of the other two. i.e. Backward and forward difference approximations.

16

Finite Difference Schemes

The error in central difference decreases quadratically as the step size decreases, whereas the decrease is only linear for the other two formula.

In general, CDF is to be preferred. Situations where the data is not available on both sides of the point where the numerical derivative is to be calculated are exceptions.

17

Finite Difference Schemes

To apply the difference method to find the solution of a function the solution region is divided into rectangles:

( , )x t

18

Let the coordinates (x, t) of a typical grid point or a node be:

The value of at a point:

Finite Difference Schemes

, 0,1,2,...

, 0,1,2,...

x i x i

t j t j

( , ) ( , )i j i x j t

19

Finite Difference Schemes

Using this notation, the central difference approximations of at (i, j) are: First derivative:

( , )

( , )

( 1, ) ( 1, )

2

( , 1) ( , 1)

2

i j

i j

i j i j

x x

i j i j

t t

20

Finite Difference Schemes

Second derivative:

2

2 2( , )

2

2 2( , )

( 1, ) 2 ( , ) ( 1, )

( )

( , 1) 2 ( , ) ( , 1)

( )

i j

i j

i j i j i j

x x

i j i j i j

t t

21

Finite Difference Schemes

One dimensional example: Solve

Subject to the boundary conditions:

Assume

2

24 0 , 0 1.0

ff x

x

(0) 0

(1) 1

f

f

0.5x

22

Finite Difference Schemes

Solution: Discretization of the equation:

2

2

( 1) 2 ( ) ( 1)4 ( ) 0

( )

(2) 2 (1) (0)4 (1) 0

(0.5)

f i f i f if i

x

f f ff

23

Finite Difference Schemes

Since there is one unknown, one equation is enough to find this unknown.

(1) (0) (2)

(1) 1

f f f

f

24

Finite Difference Schemes

If 0.25x

2

2

2

(2) 2 (1) (0)4 (1) 0

(0.25)

(3) 2 (2) (1)4 (2) 0

(0.25)

(4) 2 (3) (2)4 (3) 0

(0.25)

f f ff

f f ff

f f ff

25

Finite Difference Schemes

f(1), f(2) and f(3) are unknowns. Therefore, three equations are written to find three unknowns.

26

Finite Difference Schemes

For we have (N-1) unknowns and we need (N-1) equations to solve.

The equation of the i th node is:

1 N x

2

( 1) 2 ( ) ( 1)4 ( ) 0

( )

f i f i f if i

x

27

Finite Differencing of Parabolic PDE’s

Consider the diffusion equation:

Where k is a constant. Discretized equation:

2

2kt x

2

( , 1) ( , ) ( 1, ) 2 ( , ) ( 1, )

( )

i j i j i j i j i jk

t x

28

Finite Difference Schemes

Where

Forward difference for t and central difference for x is used.

Let:

, 0,1,2,...,

, 0,1,2,...,

x i x i n

t j t j n

2( )

trk x

29

Finite Difference Schemes

We can write:

This equation can be calculated in terms of boundary and initial conditions.

This explicit formula can be used to find

explicitly in terms of .

( , 1) ( 1, ) (1 2 ) ( , ) ( 1, )i j r i j r i j r i j

( , )x t t ( , )x t

30

Stability

Stability is important for the numerical solutions.

A stable solution is only possible when (1-2r) is nonnegative. Or:

Choose r=1/2. Then our equation becomes:

10

2r

1( , 1) ( 1, ) ( 1, )

2i j i j i j

31

Stability

Stability increases by applying an implicit formula. The formula is simple to apply but it is computationally slow. Crank and Nicholson’s formula:

2

2

( , 1) ( , ) 1 ( 1, ) 2 ( , ) ( 1, ){2 ( )

( 1, 1) 2 ( , 1) ( 1, 1)}

( )

i j i j i j i j i jk

t x

i j i j i j

x

32

Example (Cont.)

Rewrite:

Three known values on the left hand side and three unknown values on the right hand side.

( 1, 1) 2(1 ) ( , 1) ( 1, 1)

( 1, ) 2(1 ) ( , ) ( 1, )

r i j r i j r i j

r i j r i j r i j

33

The formula is valid for all finite values of r, chose r=1:

Example (cont.)

( 1, 1) 4 ( , 1) ( 1, 1) ( 1, ) ( 1, )i j i j i j i j i j