54
Computational Eng./Sci. CES EE Phys/Chem/Bio Mech/Ch.Eng

Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Embed Size (px)

Citation preview

Page 1: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Computational Eng./Sci.

CES

EE Phys/Chem/Bio Mech/Ch.Eng

Page 2: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

ECE490O: Special Topics in EM-Plasma Simulations

JK LEE (Spring, 2006)

• ODE Solvers• PIC-MCC• PDE Solvers (FEM and FDM)• Linear & NL Eq. Solvers

Page 3: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

ECE490O: ODE

JK LEE (Spring, 2006)

Page 4: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Gonsalves’ lecture notes (Fall 2005)

Page 5: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &
Page 6: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling GroupPOSTECH

Programs of Initial Value Problem & Shooting Method for BVP ODE

Sung Jin Kim and Jae Koo Lee

Page 7: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Gonsalves’ lecture notes (Fall 2005)

Page 8: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &
Page 9: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &
Page 10: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &
Page 11: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

1

1

1 12

1 1 12

1

2 2 2

3 2

: ( , )

( ) :

. ( ) :

(1 )

.

(2 ) :

( , )

(3 ) :

( , )

( 2 , )

n n n

hn n n n

hn n n n n

n

k hn n

n n n

n

ODE IV y f y t

Euler Explicit y y h f

Modif Euler Implicit

y y f f

iter for NL

R K nd Order

y y f f y k t

R K rd k h f

k h f y t

k h f y k k t h

y

1

1 1 2 36 ( 4 )ny h k k k

Page 12: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

1

2

2 2 2

3 2 2

4 3

11 1 2 3 46

(4 ) : ( , )

( , )

( , )

2 2

k hn n

k hn n

n n

n n

R K th k h f y t

k h f y t

k h f y k t h

y y k k k k

12

12

1 1

12

1

: 2

:

n n n

n nn

n n n

Leaptrog y y h f

y y h fTwo step

y y h f

Page 13: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &
Page 14: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &
Page 15: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Initial Value Problems of Ordinary Differential Equations Initial Value Problems of Ordinary Differential Equations

Program 9-1 Second-order Runge-kutta Method

0)()()(2

2

tkytydt

dBty

dt

dM , y(0)=1, y’(0)=0

Changing 2nd order ODE to 1st order ODE,

)(),,()( tztzyftydt

d

0)()()( tkytBztzdt

dM

)()(),,()( tyM

ktz

M

Btzygtz

dt

d

(1)

(2)

y(0)=1

z(0)=0

Page 16: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Second-Order Runge-Kutta Method Second-Order Runge-Kutta Method

By 2nd order RK Method

nnn zhtzyhfk ),,(1

)(),,(1 nnnn yM

kz

M

Bhtzyhgl

)(),,( 1112 lzhtlzkyhfk nnn

)()(),,( 11112 ky

M

klz

M

Bhtlzkyhgl nnnn

211 2

1kkyy nn

211 2

1llzz nn

Page 17: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Program 9-1 Program 9-1

/* CSL/c9-1.c Second Order Runge-Kutta Scheme (Solving the problem II of Example 9.6) */ #include <stdio.h> #include <stdlib.h> #include <math.h> /* time : t y,z: y,y' kount: number of steps between two lines of printing k, m, b: k, M(mass), B(damping coefficient) in Example 9.6 int main() { int kount, n, kstep=0; float bm, k1, k2, km, l1, l2; static float time, k = 100.0, m = 0.5, b = 10.0, z = 0.0; static float y = 1.0, h = 0.001; printf( "CSL/C9-1 Second Order Runge-Kutta Scheme \n" ); printf( " t y z\n" ); printf( " %12.6f %12.5e %12.5e \n", time, y, z ); km = k/m; bm = b/m; for( n = 1; n <= 20; n++ ){ for( kount = 1; kount <= 50; kount++ ){ kstep=kstep+1; time = h*kstep ;

k1 = h*z; l1 = -h*(bm*z + km*y); k2 = h*(z + l1); l2 = -h*(bm*(z + l1) + km*(y + k1)); y = y + (k1 + k2)/2; z = z + (l1 + l2)/2; } printf( " %12.6f %12.5e %12.5e \n", time, y, z ); } exit(0); }

2nd order RK

CSL/C9-1 Second Order Runge-Kutta Scheme t y z 0.000000 1.00000e+00 0.00000e+00 0.100000 5.08312e-01 -6.19085e+00 0.200000 6.67480e-02 -2.46111e+00 0.300000 -4.22529e-02 -1.40603e-01 0.400000 -2.58300e-02 2.77157e-01 0.500000 -4.55050e-03 1.29208e-01 0.600000 1.68646e-03 1.38587e-02 0.700000 1.28624e-03 -1.19758e-02 0.800000 2.83107e-04 -6.63630e-03 0.900000 -6.15151e-05 -1.01755e-03 1.000000 -6.27664e-05 4.93549e-04

result

Page 18: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Various Numerical Methods

0.0 0.2 0.4 0.6 0.8 1.0-0.2

0.0

0.2

0.4

0.6

0.8

1.0

Y(m

)

time

Exact solution Modified Euler Second order RK Fourth orde Rk

0.0 0.2 0.4 0.6 0.8 1.0-0.2

0.0

0.2

0.4

0.6

0.8

1.0

Y(m

)

Time

Exact solution Euler Modified Euler Second order RK Fourth order Rk

0.0 0.2 0.4 0.6 0.8 1.0-0.2

0.0

0.2

0.4

0.6

0.8

1.0

Y(m

)

Time

Exact solution Euler Modified Second order RK Fourth order RK

h=0.1

h=0.01 h=0.001

Exact Solution:

,11 C22

C

tCtCey t 22

21 sincos

Page 19: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling GroupPOSTECH

Error Estimation

0.0 0.2 0.4 0.6 0.8 1.0-0.2

0.0

0.2

0.4

0.6

0.8

1.0

Y(m

)

time

Exact solution h=0.001 h=0.005 h=0.01 h=0.05 h=0.1

0.00 0.01 0.02 0.03 0.04 0.05

0.0000

0.0005

0.0010

0.0015

0.0020

0.0025

0.0030

Err

or

h

Euler Modified Euler Second order RK Fourth order RK

reference(h2)

reference(h3)

reference(h5)

Fourth order Runge-Kutta Error estimation

Page 20: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Program 9-2 Fourth-order Runge-Kutta SchemeProgram 9-2 Fourth-order Runge-Kutta Scheme

)(

)()('

22 tyt

tyty

A first order Ordinary differential equation

y(0)=1

),(1 nn tyhfk

2,

21

2

ht

kyhfk nn

2,

22

3

ht

kyhfk nn

htkyhfk nn ,34

Fourth-order RK Method

43211 226

1kkkkyy nn

Page 21: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Program 9-2 Fourth-order Runge-Kutta SchemeProgram 9-2 Fourth-order Runge-Kutta Scheme

do{ for( j = 1; j <= nstep_pr; j++ ){ t_old = t_new; t_new = t_new + h; yn = y; t_mid = t_old + hh; yn = y; k1 = h*fun( yn, t_old ); ya = yn + k1/2; k2 = h*fun( ya, t_mid ); ya = yn + k2/2; k3 = h*fun( ya, t_mid ); ya = yn + k3 ; k4 = h*fun( ya, t_new ); y = yn + (k1 + k2*2 + k3*2 + k4)/6;}

double fun(float y, float t) { float fun_v; fun_v = t*y +1; /* Definition of f(y,t) */ return( fun_v ); }

Main algorithm for 4th order RK method at program 9-2

4th order RK

CSL/C9-2 Fourth-Order Runge-Kutta Scheme Interval of t for printing ?1Number of steps in one printing interval?10Maximum t?5h=0.1 -------------------------------------- t y-------------------------------------- 0.00000 0.000000e+00 1.00000 1.410686e+00 2.00000 8.839368e+00 3.00000 1.125059e+02 4.00000 3.734231e+03 5.00000 3.357971e+05 6.00000 8.194354e+07 -------------------------------------- Maximum t limit exceeded

Interval of t for printing ?1Number of steps in one printing interval?100Maximum t?5h=0.01

-------------------------------------- t y-------------------------------------- 0.00000 0.000000e+00 1.00000 1.410686e+00 2.00000 8.839429e+00 3.00000 1.125148e+02 4.00000 3.735819e+03 5.00002 3.363115e+05 --------------------------------------

Page 22: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Program 9-3 4Program 9-3 4thth order RK Method for a Set of ODEs order RK Method for a Set of ODEs

0)()('' 11 tyty

A second order Ordinary differential equation

y1(0)=1, y1(0)=1, y1’(0)=0

)()( 21 tytydt

d )()( 12 tyty

dt

d

* The 4th order RK method for the set of two equations(Nakamura’s book p332)

do{ for( n = 1; n <= ns; n++ ){ t_old = t_new; /* Old time */ t_new = t_new + h; /* New time */ t_mid = t_old + hh; /* Midpoint time */ for( i = 1; i <= No_of_eqs; i++ ) ya[i] = y[i]; f( k1, ya, &t_old, &h ); for( i = 1; i <= No_of_eqs; i++ ) ya[i] = y[i] + k1[i]/2; f( k2, ya, &t_mid, &h ); for( i = 1; i <= No_of_eqs; i++ ) ya[i] = y[i] + k2[i]/2; f( k3, ya, &t_mid, &h ); for( i = 1; i <= No_of_eqs; i++ ) ya[i] = y[i] + k3[i]; f( k4, ya, &t_new, &h ); for( i = 1; i <= No_of_eqs; i++ ) y[i] = y[i] + (k1[i] + k2[i]*2 + k3[i]*2 + k4[i])/6; }

void f(float k[], float y[], float *t, float *h) { k[1] = y[2]**h; k[2] = -y[1]**h; /* More equations come here if the number of equations are greater.*/ return; }

Page 23: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Results of Program 9-3Results of Program 9-3

CSL/C9-3 Fourth-Order Runge-Kutta Scheme for a Set of Equations Interval of t for printing ? 1Number of steps in one print interval ? 10Maximum t to stop calculations ? 5.0 h= 0.1 t y(1), y(2), ..... 0.0000 1.00000e+00 0.00000e+00 1.0000 5.40303e-01 -8.41470e-01 2.0000 -4.16145e-01 -9.09298e-01 3.0000 -9.89992e-01 -1.41123e-01 4.0000 -6.53646e-01 7.56800e-01 5.0000 2.83658e-01 9.58925e-01 6.0000 9.60168e-01 2.79420e-01 Type 1 to continue, or 0 to stop. 1

Interval of t for printing ? 1Number of steps in one print interval ? 100Maximum t to stop calculations ? 5.0 h= 0.01 t y(1), y(2), ..... 0.0000 1.00000e+00 0.00000e+00 1.0000 5.40302e-01 -8.41471e-01 2.0000 -4.16147e-01 -9.09298e-01 3.0000 -9.89992e-01 -1.41120e-01 4.0000 -6.53644e-01 7.56802e-01 5.0000 2.83662e-01 9.58924e-01 Type 1 to continue, or 0 to stop. 1

Interval of t for printing ? 1Number of steps in one print interval ? 1Maximum t to stop calculations ? 5.0 h= 1 t y(1), y(2), ..... 0.0000 1.00000e+00 0.00000e+00 1.0000 5.41667e-01 -8.33333e-01 2.0000 -4.01042e-01 -9.02778e-01 3.0000 -9.69546e-01 -1.54803e-01 4.0000 -6.54173e-01 7.24103e-01 5.0000 2.49075e-01 9.37367e-01 Type 1 to continue, or 0 to stop.

Page 24: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

C   CSL/F9-1.FOR    SECOND ORDER RUNGE-KUTTA SCHEME

C                   (SOLVING THE PROBLEM II OF EXAMPL 9.6)       REAL M,K,K1,K2,L1,L2,KM

      PRINT *,'CSL/F9-1   SECOND ORDER RUNGE-KUTTA SCHEME'

      DATA T,   K,    M,   B,    Z,   Y,   H      %    /0.0,100.0, 0.5, 10.0, 0.0, 1.0, 0.001/

      PRINT *,'     T           Y             Z'       PRINT 1,T,Y,Z

1     FORMAT( F10.5,  1P2E13.5)       KM=K/M       BM=B/M

Page 25: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

DO 20 N=1,20         DO 10 KOUNT=1,50

            T=T+H             K1=H*Z

            L1=-H*(BM*Z + KM*Y)             K2=H*(Z+L1)

            L2=-H*(BM*(Z+L1) + KM*(Y+K1))             Y=Y+(K1+K2)/2             Z=Z+(L1+L2)/2

10      CONTINUE           PRINT 1,T,Y,Z

20    CONTINUE       STOP       END

Page 26: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

C-----CSL/F9-2.FOR   FOURTH-ORDER RUNGE-KUTTA SCHEME (FORTRAN)

      REAL K1,K2,K3,K4       PRINT *

      PRINT*,'CSL/F9-2.FOR  FOURTH-ORDER RUNGE KUTTA SCHEME (FORTRAN)'

1     PRINT *       PRINT *, 'INTERVAL OF T FOR PRINTING ?'

         READ *, XPR       PRINT *, 'NUMBER OF STEPS IN ONE PRINTING

INTERVAL ?'          READ *, I

      PRINT *,'MAXIMUM T ?'          READ *, XL

C  Setting the initial value of the solution       Y=1

Page 27: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

 H=XPR/I       PRINT *, 'H=', H

      XP=0       HH=H/2       PRINT *

      PRINT *,'-------------------- PRINT *,'       T                Y'       PRINT *,'----------------------

      PRINT 82, XP,Y 82    FORMAT( 1X,F10.6, 7X,1PE15.6)

30    DO 40 J=1,I          XB=XP

         XP=XP+H          YN=Y

         XM=XB+HH          K1=H*FUN(YN,XB)

         K2=H*FUN(YN+K1/2,XM)          K3=H*FUN(YN+K2/2,XM)          K4=H*FUN(YN+K3,XP)

         Y=YN + (K1+K2*2+K3*2+K4)/6 40    CONTINUE

Page 28: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

   IF (XP.LE.XL) GO TO 30       PRINT *,'------------------------

      PRINT *       PRINT *,' MAXIMUM X LIMIT IS EXCEEDED'

      PRINT * 200   PRINT*

      PRINT*,'TYPE 1 TO CONTINUE, 0 TO STOP.'       READ *,K

      IF(K.EQ.1) GOTO 1       PRINT*

      END       FUNCTION FUN(Y,X)       FUN = -Y/(X*X+Y*Y )

      RETURN       END

Page 29: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Executing Programs for the simulation class Executing Programs for the simulation class

An user ID will be made as team name at a PAM computer.

A password is the same as an user ID

You can execute your programs to connect your PC to pam computer by x-manager or telnet.

A C program is compiled by a gcc compiler at the linux PC.gcc –o a a.c –lmwhere, a is a changeable execution sentence.

Page 30: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Homepage : http://jkl.postech.ac.kr

Boundary Value Problems of Ordinary Differential Equations & Scharf

etter-Gummel method

Sung Soo Yang and Jae Koo Lee

Plasma Application Modeling

Page 31: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Boundary value problems

Type of Problems Advantages Disadvantages

Shooting method An existing program for initial value problems may be used

Trial-and-error basis. Application is limited to a narrow class of problems. Solution may become unstable.

Finite difference method using the tridiagonal solution

No instability problem. No trial and error.

Applicable to nonlinear problems with iteration.

Problem may have to be developed for each particular problem.

1) : Dirichlet type boundary condition

* Three types of boundary conditions

dt

adyay

)()(

0 01) : Neumann type boundary condition0 01) : Mixed type boundary condition0 0

Page 32: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

)2.0exp()()(2 xxyxy

)10()10(,1)0( yyy

Solve difference equation,

With the boundary conditions,

x = 0 1 2i = 0 1 2

9 109 10

11211 2

2)(

iiiiii yyy

h

yyyxy

)2.0exp()2(2 11 iyyyy iiii )2.0exp()()(2 xxyxy 1)0( yEspecially for i = 1, 2)2.0exp(25 21 yy

knowny(0)=1

)10()10( yy

Program 10-1

Page 33: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

For i = 10,

5.0

)9()10()10(

5.0

)5.9()10( yyyyyy

)10()10( yy

)2.0exp()()(2 xxyxy )2exp(5.05.42 109 yy

Summarizing the difference equations obtained, we write

)2.0exp(252 11 iiii xyyy

2)2.0exp(25 21 yy

)2exp(5.05.42 109 yy

)2exp(5.0

)32.0exp(

)22.0exp(

2)2.0exp(

5.42

252

252

25

10

3

2

1

y

y

y

y

Tridiagonal matrix

Program 10-1

Page 34: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Solution Algorithm for Tridiagonal Equations (1)

3

2

1

3

2

1

33

222

11

0

0

D

D

D

BA

CBA

CB

3

2

11

2

3

2

1

33

222

11

21

1

2

0

0

D

D

DB

A

BA

CBA

CB

AB

B

A

R2

3

2

12

3

2

1

33

222

122

0

0

D

D

DR

BA

CBA

CRA

3

122

12

3

2

1

33

2122

122

0

0

0

D

DRD

DR

BA

CCRB

CRA

2B2D

3

22

3

12

3

2

1

33

22

32

2

3

122

0

0

0

D

DB

ADR

BA

CB

AB

B

ACRA

R3

233

23

12

3

2

1

233

233

122

00

0

0

DRD

DR

DR

CRB

CRA

CRA

3B3D

Based on Gauss elimination

Page 35: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

3

23

12

3

2

1

3

233

122

00

0

0

D

DR

DR

B

CRA

CRA

3

33 B

D

2

33322

3

322332323 ,)(

B

ARCD

A

RDRCRA

)(1

3222

2 CDB

1

22211

2

211221212 ,)(

B

ARCD

A

RDRCRA

)(1

)(1

2111

2111

1 CDB

CDB

Solution Algorithm for Tridiagonal Equations (2)

Page 36: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

void trdg(float a[], float b[], float c[], float d[], int n) /* Tridiagonal solution */ { int i; float r; for ( i = 2; i <= n; i++ ) { r = a[i]/b[i - 1]; b[i] = b[i] - r*c[i - 1]; d[i] = d[i] - r*d[i - 1]; }

d[n] = d[n]/b[n];

for ( i = n - 1; i >= 1; i-- ) { d[i] = (d[i] - c[i]*d[i + 1])/b[i]; } return; }

Recurrently calculate the equations in increasing order of i until i=N is reached

Calculate the solution for the last unknown by

NNN BD

Calculate the following equation in decreasing order of i

iiiii BCD )( 1

Solution Algorithm for Tridiagonal Equations (3)

Page 37: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

/* CSL/c10-1.c Linear Boundary Value Problem */ #include <stdio.h> #include <stdlib.h> #include <math.h> /* a[i], b[i], c[i], d[i] : a(i), b(i), c(i), and d(i) n: number of grid points */ int main() { int i, n; float a[20], b[20], c[20], d[20], x; void trdg(float a[], float b[], float c[], float d[], int n); /* Tridiagonal solution */ printf( "\n\nCSL/C10-1 Linear Boundary Value Problem\n" ); n = 10; /* n: Number of grid points */

for( i = 1; i <= n; i++ ) { x = i; a[i] = -2; b[i] = 5; c[i] = -2; d[i] = exp( -0.2*x ); }

Program 10-1

)2.0exp(252 11 iiii xyyy

Page 38: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

d[1] = d[1] + 2; d[n] = d[n]*0.5; b[n] = 4.5; trdg( a, b, c, d, n ); d[0] = 1; /* Setting d[0] for printing purpose */ printf( "\n Grid point no. Solution\n" ); for ( i = 0; i <= n; i++ ) { printf( " %3.1d %12.5e \n", i, d[i] ); } exit(0); }

Program 10-1

CSL/C10-1 Linear Boundary Value Problem Grid point no. Solution 0 1.00000e+00 1 8.46449e-01 2 7.06756e-01 3 5.85282e-01 4 4.82043e-01 5 3.95162e-01 6 3.21921e-01 7 2.59044e-01 8 2.02390e-01 9 1.45983e-01 10 7.99187e-02

2)2.0exp(25 21 yy

)2exp(5.05.42 109 yy

Page 39: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Program 10-3

Hxxfxvxfxqxfdx

dxxp

dx

d

xm

m

0,)()()()()()(

1

An eigenvalue problem of ordinary differential equation

We assume

0,1)(,0)(,1)( mxvxqxp )()(2

2

xfxfdx

d

)1()1()(1

)()(1

t

iitt

iit

iit

ii fGfCfBfA a b

i-1 i i+1

211

11

2)()(

h

fff

hh

ff

h

ff

h

afbff iii

iiii

)1()1()(1

)()(1 2

ti

tti

ti

ti ffff

Page 40: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Program 10-3 (Inverse Power method)

Step1 : )0(if for all i and )0( are set to an arbitrary initial guess.

)0()0()1(1

)1()1(1 2 iiii ffff Step2 : is solved by the tridiagonal solution for )1(

if

Step3 : The next estimate for is calculated by the equation:

iiii

iiii

ffG

ffG

)1()1(

)1()0(

)0()1(

)1()1()2(1

)2()2(1 2 iiii ffff Step4 : is solved by the tridiagonal solution for )2(

if

Step5 : The operations similar to Step 3 and 4 are repeated as the iteration cycle t increases.

Step6 : The iteration is stopped when the convergence test is satisfied. 1/ )()1( tt Criterion for convergence

Page 41: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Program 10-3main(){ • • • • •while (TRUE){ k = 0; n = 10; ei = 1.5; it = 30; ep = 0.0001; for (i=1; i <= n; i++) { as[i] = -1.0; bs[i] = 2.0; cs[i] = -1.0; f[i] = 1.0; ds[i] = 1.0; } printf("\n It. No. Eigenvalue\n");

while (TRUE) { k = k+1; for (i=1; i<=n; i++) fb[i] = f[i]*ei; for (i=1; i<=n; i++) { a[i] = as[i]; b[i] = bs[i]; c[i] = cs[i]; d[i] = ds[i]*fb[i]; } trdg(a, b, c, d, n); sb = 0; s = 0; for (i=1; i <= n; i++) { f[i] = d[i]; s = s + f[i]*f[i]; sb = sb + f[i]*fb[i]; } eb = ei; ei = sb/s; printf("%3.1d %12.6e \n", k, ei); if (fabs(1.0-ei/eb) <= ep) break; if (k >it) { printf("Iteration limit exceeded.\n"); break; } }

Step 1Step 1

Step 6Step 6

Step 3Step 3

Step 2,4Step 2,4

Page 42: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

z = 0; for (i=1; i <= n; i++) if (fabs(z) <= fabs(f[i])) z = f[i]; for (i=1; i <= n; i++) f[i] = f[i]/z;

eigen = ei; printf("Eigenvalue = %g \n", eigen); printf("\n Eigenfunction\n"); printf("i f(i)\n"); for (i=1; i<=n; i++) printf("%3.1d %12.5e \n", i, f[i]); printf("------------------------------------\n");

printf("Type 1 to continue, or0 to stop. \n"); scanf("%d", &kstop); if (kstop != 1) exit (0);}}

It. No. Eigenvalue 1 8.196722e-02 2 8.102574e-02 3 8.101422e-02 4 8.101406e-02 Eigenvalue = 0.0810141

Eigenfunction i f(i) 1 2.84692e-01 2 5.46290e-01 3 7.63595e-01 4 9.19018e-01 5 1.00000e+00 6 1.00000e+00 7 9.19018e-01 8 7.63594e-01 9 5.46290e-01 10 2.84692e-01 ------------------------------------Type 1 to continue, or0 to stop.

Program 10-3

Page 43: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Scharfetter-Gummel method

St

n

Γ

• 2D discretized continuity eqn. integrated by the alternative direction implicit (ADI) method

yS

xt

nn kjiy

kjiyk

jijixjix

kjiji

5.0,,5.0,,,

*,5.0,

*,5.0,,

*,

2/

xS

yt

nn jixjixkji

kjiy

kjiyji

kji

*

,5.0,*

,5.0,,

15.0,,

15.0,,

*,

1,

2/

EΓ nqnD )sgn(

jijijijijijiji DnCnBnA ,*

,1,*,,

*,1,

',

11,

',

1,

',

11,

', ji

kjiji

kjiji

kjiji DnCnBnA

Tridiagonal matrix

jijixjix,i,j,jx,i nn ,1,,,5.0 Scharfetter-Gummel method

Page 44: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Scharfetter-Gummel method

ii

i

ii

iiiiii

Dnxx

zDn

Dnx

Ensign

21

2

1 )( Γ

21

21

i

i

iiii x

zDnDn

21

i 2

1

i

1in in 1in

Flux is constant between half grid points and calculated at the grid point

Flux is a linear combination of and

21

i

in 1in

21

21

21

2111

21

1

1

i

z

iiii

iiiie

Dnzx

Dnzx

Γ

ΓAnalytic integration between i and i+1 leads to

Page 45: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Scharfetter-Gummel method

121

21

1121

21

i

i

z

ii

z

iii

ie

DneDn

x

zΓ 1 iiii nn

21

21

1

21

i

i

z

zii

i ee

D

x

z

121

121

iz

ii

i

e

D

x

z

iii

i

ii

i

i

ix

D

signVV

D

signz

21

21

21

1

21

21

21

)()(

)(E

where,

The main advantage of SG scheme is that is provides numerically stable estimates of the particle flux under all conditions

12

1 i

z

(Big potential difference)

12

1 i

z

(small potential difference)

Page 46: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Scharfetter-Gummel method

2

12

11

21

21

21

12

1

21 1exp

exp

1exp

exp

ii

iiii

i

iii

i k

nkn

z

nznEEΓ

)exp(

)exp(

1exp

explimlim

21

21

1

21 k

k

k

nknii

ii

kik

21

21

21

21

1

)exp(1

)exp(lim

iiiii

ii

kn

k

knnEE

12

1 i

z

2

12

112

12

11

21 1exp

explimlim

iiiii

ii

kikn

k

nknEEΓ

In case of

Drift flux

Page 47: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling @ POSTECH

Scharfetter-Gummel method

i

iii

kiiii

kik x

Dk

k

nkn

k

nkn

21

1

021

21

1

021

0 1exp

explim

1exp

explimlim EΓ

12

1 i

zIn case of

1exp

explim

1

0

21

kdkd

nknkdkd

x

D ii

ki

i

)exp(

exp)1(lim 1

0

21

k

nkken

x

Dii

ki

i

i

iii x

nnD

1

21 Diffusion flux

Page 48: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Shooting Method for Boundary Value Problem ODEsShooting Method for Boundary Value Problem ODEs

Definition: a time stepping algorithm along with a root finding method for choosing the appropriate initial conditions which solve the boundary value problem.

1) : Dirichlet type boundary condition

* Three types of boundary conditions

dt

adyay

)()(

0 01) : Neumann type boundary condition0 01) : Mixed type boundary condition0 0

Second-order Boundary-Value Problem

),',,(''1 yyxfy y(a)=A and y(b)=B

Page 49: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Computational Algorithm of Shooting MethodComputational Algorithm of Shooting Method

Computational Algorithm

1. Solve the differential equation using a time-stepping scheme with the initial conditions y(a)=A and y’(a)=A’.

2. Evaluate the solution y(b) at x=b and compare this value with the target value of y(b)=B.

3. Adjust the value of A’ (either bigger or smaller) until a desired level of tolerance and accuracy is achieved. A bisection or secant method for determining values of A’, for instance, may be appropriate.

4. Once the specified accuracy has been achieved, the numerical solution is complete and is accurate to the level of the tolerance chosen and the discretization scheme used in the time-stepping.

Page 50: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Shooting Method for Boundary Value Problem ODEsShooting Method for Boundary Value Problem ODEs

Rewrite the second-order ODE as two first-order ODEs:

,)(' zty

),,,()(' zyxftz

Aay )(

?)(')( ayaz

We should assume a initial value of z(a).z(a) is determined for which y(b)=B by secant method.

Slope

BBAA

nnn

)()()1( )(

)'()'(

Slope

AA

BB

AA

BBnn

nn

nn

n

)1()(

)1()(

)()1(

)(

)'()'(

)(

)'()'(

)(

Page 51: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Example of Shooting Method Example of Shooting Method

Ex) ,0'' 2 TT T(0)=0 and T(1.0)=100

Sol) Rewrite the second-order ODE as two first-order ODEs:

,' ST

,' 2TS

T(0)=0.0

S(0)=T’(0)

By modified Euler method

iiP

i tSTT 1 iiPi TtSS 2

1

Piii

Ci SStTT 11 2

1 P

iiiCi TTtSS 1

21 2

1

Let x=0.25, S(0.0)(1)=50, S(0.0)(2)=100

Page 52: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Solution by the Shooting Method Solution by the Shooting Method

705078.10.500.100

253906.85507813.170

)0.0()0.0(

)0.1()0.1()1()2(

)1()2(

SS

TTSlope

648339.58

)0.1(0.100)0.0()0.0(

)2()2()3(

Slope

TSS

Page 53: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Errors in the Solution by the Shooting Method Errors in the Solution by the Shooting Method

Page 54: Computational Eng./Sci.. ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006) ODE Solvers PIC-MCC PDE Solvers (FEM and FDM) Linear &

Plasma ApplicationModeling, POSTECH

Equilibrium Method Equilibrium Method

),()(')(''1 xFyxQyxPy y(a)=A and y(b)=B

iiiiiii FxyPx

yQxyPx 2

12

1 212

21

Ex) ,'' 22aTTT T(0)=0 and T(1.0)=100

aiii TxTTxT 221

221 )2(

Let x=0.25, Ta=0, =2.0

025.2 11 iii TTT

x=0.25 :

x=0.50 :

x=0.75 :

,025.2 210 TTT

025.2 321 TTT

,025.2 432 TTT

00 T

0.1004 T

-2.25 1.0 0 1.0 -2.25 1.0 0 1.0 -2.25

T1

T2

T3

0 0-100

=