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

Slides:



Advertisements
Similar presentations
Lecture on Numerical Analysis Dr.-Ing. Michael Dumbser
Advertisements

Solving Systems of Equations using Substitution
Prof. Muhammad Saeed ( Ordinary Differential Equations )
Ordinary Differential Equations
Derivation of the third-order
Chapter 6 Differential Equations
Solving Quadratic Equations by Completing the Square
Solving Linear Systems by Graphing
X-and Y-intercepts. Standard Form (of a linear equation) ax + by = c, where a, b, and c are integers.
2.3 slope and 2.4 writing linear equation
MATLAB EXAMPLES Initial-value problems
TNPL JoongJin-Cho Runge-kutta’s method of order 4.
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L8&9 KFUPM.
Eng Ship Structures 1 Hull Girder Response Analysis
National Technical University of Athens Diploma Thesis «Computational Simulation of the road behaviour of a vehicle by use of a non- linear six-degree.
Numeriska beräkningar i Naturvetenskap och Teknik 1. Numerical differentiation and quadrature Discrete differentiation and integration Trapezoidal and.
Solving Equations = 4x – 5(6x – 10) -132 = 4x – 30x = -26x = -26x 7 = x.
Ordinary Differential Equations
ECE490O: Special Topics in EM-Plasma Simulations JK LEE (Spring, 2006)
18 September 2007 KKKQ 3013 PENGIRAAN BERANGKA Week 11 – Ordinary Differential Equations 18 September am – 9.00 am.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 32 Ordinary Differential Equations.
11 September 2007 KKKQ 3013 PENGIRAAN BERANGKA Week 10 – Ordinary Differential Equations 11 September am – 9.00 am.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 31 Ordinary Differential Equations.
A spring with a mass of 6 kg has damping constant 33 and spring constant 234. Find the damping constant that would produce critical damping
Differential Equations and Boundary Value Problems
Introduction 1. MSc (1994): Punjab University Specialization: Applied Mathematics 2. MS /M.Phil (2006): COMSATS, Islamabad Specialization: Applied Mathematics.
Numerical Solution of Ordinary Differential Equation
Introduction to Differential Equations
EE3561_Unit 8Al-Dhaifallah14351 EE 3561 : Computational Methods Unit 8 Solution of Ordinary Differential Equations Lesson 3: Midpoint and Heun’s Predictor.
Fin500J Topic 6Fall 2010 Olin Business School 1 Fin500J: Mathematical Foundations in Finance Topic 6: Ordinary Differential Equations Philip H. Dybvig.
Computational Method in Chemical Engineering (TKK-2109)
DOUBLE PENDULUM By: Rosa Nguyen EPS 109 – Fall 2011.
5/30/ Runge 4 th Order Method Chemical Engineering Majors Authors: Autar Kaw, Charlie Barker
11/17/ Shooting Method Major: All Engineering Majors Authors: Autar Kaw, Charlie Barker
1/16/ Runge 4 th Order Method Civil Engineering Majors Authors: Autar Kaw, Charlie Barker
1/19/ Runge 4 th Order Method Major: All Engineering Majors Authors: Autar Kaw, Charlie Barker
Partial Derivatives Example: Find If solution: Partial Derivatives Example: Find If solution: gradient grad(u) = gradient.
Differential Equations Linear Equations with Variable Coefficients.
Today’s class Ordinary Differential Equations Runge-Kutta Methods
Ordinary Differential Equations
2/28/ Runge 4 th Order Method Computer Engineering Majors Authors: Autar Kaw, Charlie Barker
Section 1.1 Basic Definitions and Terminology. DIFFERENTIAL EQUATIONS Definition: A differential equation (DE) is an equation containing the derivatives.
Homepage : Boundary Value Problems of Ordinary Differential Equations & Scharfetter-Gummel method (Computational E&M: 490D) Sung.
MATH II – QUADRATICS to solve quadratic equations. MATH III – MATH II –
Introduction to Differential Equations
7.4 Consistent and Inconsistent Systems
Introduction to Differential Equations
Civil Engineering Majors Authors: Autar Kaw, Charlie Barker
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L4&5.
Solving Linear Systems Algebraically
Civil Engineering Majors Authors: Autar Kaw, Charlie Barker
Industrial Engineering Majors Authors: Autar Kaw, Charlie Barker
Rigid Body Dynamics (unconstrained)
Solving Systems of Equation by Substitution
Numerical Analysis Lecture 37.
Numerical Analysis Lecture 38.
Solving Equations 3x+7 –7 13 –7 =.
Numerical solution of first-order ordinary differential equations
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L6.
Systems of Equations Solve by Graphing.
Electrical Engineering Majors Authors: Autar Kaw, Charlie Barker
Warm Up Check to see if the point is a solution for the
Numerical Computation and Optimization
6th Lecture : Numerical Methods
Chemical Engineering Majors Authors: Autar Kaw, Charlie Barker
Solving a System of Linear Equations
MATH 2140 Numerical Methods
CISE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L1 KFUPM.
Numerical solution of first-order ordinary differential equations 1. First order Runge-Kutta method (Euler’s method) Let’s start with the Taylor series.
CISE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM Read , 26-2, 27-1 CISE301_Topic8L6 KFUPM.
Presentation transcript:

Computational Eng./Sci.

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

ECE490O: ODE JK LEE (Spring, 2006)

Gonsalves ’ lecture notes (Fall 2005)

Plasma Application Modeling Group POSTECH Programs of Initial Value Problem & Shooting Method for BVP ODE Sung Jin Kim and Jae Koo Lee

Gonsalves ’ lecture notes (Fall 2005)

Plasma Application Modeling, POSTECH Initial Value Problems of Ordinary Differential Equations Program 9-1 Second-order Runge-kutta Method, y(0)=1, y’(0)=0 Changing 2 nd order ODE to 1 st order ODE, (1) (2) y(0)=1 z(0)=0

Plasma Application Modeling, POSTECH Second-Order Runge-Kutta Method By 2 nd order RK Method

Plasma Application Modeling, POSTECH Program 9-1 /* CSL/c9-1.c Second Order Runge-Kutta Scheme (Solving the problem II of Example 9.6) */ #include #include #include /* 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 e e e e e e e e e e e e e e e e e e e e e e-04 result

Plasma Application Modeling, POSTECH Various Numerical Methods h=0.1 h=0.01 h=0.001 Exact Solution:

Plasma Application Modeling Group POSTECH Error Estimation Fourth order Runge-Kutta Error estimation

Plasma Application Modeling, POSTECH Program 9-2 Fourth-order Runge-Kutta Scheme A first order Ordinary differential equation y(0)=1 Fourth-order RK Method

Plasma Application Modeling, POSTECH Program 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 4 th order RK method at program 9-2 4th order RK CSL/C9-2 Fourth-Order Runge-Kutta Scheme Interval of t for printing ? 1 Number of steps in one printing interval? 10 Maximum t? 5 h= t y e e e e e e e Maximum t limit exceeded Interval of t for printing ? 1 Number of steps in one printing interval? 100 Maximum t? 5 h= t y e e e e e e

Plasma Application Modeling, POSTECH Program th order RK Method for a Set of ODEs A second order Ordinary differential equation y 1 (0)=1,y 1 (0)=1, y 1 ’(0)=0 * The 4 th 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; }

Plasma Application Modeling, POSTECH Results of Program 9-3 CSL/C9-3 Fourth-Order Runge-Kutta Scheme for a Set of Equations Interval of t for printing ? 1 Number of steps in one print interval ? 10 Maximum t to stop calculations ? 5.0 h= 0.1 t y(1), y(2), e e e e e e e e e e e e e e-01 Type 1 to continue, or 0 to stop. 1 Interval of t for printing ? 1 Number of steps in one print interval ? 100 Maximum t to stop calculations ? 5.0 h= 0.01 t y(1), y(2), e e e e e e e e e e e e-01 Type 1 to continue, or 0 to stop. 1 Interval of t for printing ? 1 Number of steps in one print interval ? 1 Maximum t to stop calculations ? 5.0 h= 1 t y(1), y(2), e e e e e e e e e e e e-01 Type 1 to continue, or 0 to stop.

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

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

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

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

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

Plasma Application Modeling, POSTECH 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 –lm where, a is a changeable execution sentence.

Homepage : Boundary Value Problems of Ordinary Differential Equations & Scharfetter-Gummel method Sung Soo Yang and Jae Koo Lee P lasma A pplication M odeling

Plasma Application POSTECH Boundary value problems Type of ProblemsAdvantagesDisadvantages Shooting methodAn 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 1) : Neumann type boundary condition 1) : Mixed type boundary condition

Plasma Application POSTECH Solve difference equation, With the boundary conditions,   x = 012 i = Especially for i = 1, known y(0)=1 Program 10-1

Plasma Application POSTECH For i = 10, Summarizing the difference equations obtained, we write Tridiagonal matrix Program 10-1

Plasma Application POSTECH Solution Algorithm for Tridiagonal Equations (1) R2R2 R3R3 Based on Gauss elimination

Plasma Application POSTECH Solution Algorithm for Tridiagonal Equations (2)

Plasma Application 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 Calculate the following equation in decreasing order of i Solution Algorithm for Tridiagonal Equations (3)

Plasma Application POSTECH /* CSL/c10-1.c Linear Boundary Value Problem */ #include /* 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

Plasma Application 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 e e e e e e e e e e e-02

Plasma Application POSTECH Program 10-3 An eigenvalue problem of ordinary differential equation We assume a b   i-1ii+1

Plasma Application POSTECH Program 10-3 (Inverse Power method) Step1 :for all i andare set to an arbitrary initial guess. Step2 : is solved by the tridiagonal solution for Step3 : The next estimate for is calculated by the equation: Step4 : is solved by the tridiagonal solution for 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. Criterion for convergence

Plasma Application POSTECH Program 10-3 main() { while (TRUE) { k = 0; n = 10; ei = 1.5; it = 30; ep = ; 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 1 Step 6 Step 3 Step 2,4

Plasma Application 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 e e e e-02 Eigenvalue = Eigenfunction i f(i) e e e e e e e e e e Type 1 to continue, or0 to stop. Program 10-3

Plasma Application POSTECH Scharfetter-Gummel method 2D discretized continuity eqn. integrated by the alternative direction implicit (ADI) method Tridiagonal matrix Scharfetter-Gummel method

Plasma Application POSTECH Scharfetter-Gummel method   Flux is constant between half grid points and calculated at the grid point Flux is a linear combination of and Analytic integration between i and i+1 leads to

Plasma Application POSTECH Scharfetter-Gummel method where, The main advantage of SG scheme is that is provides numerically stable estimates of the particle flux under all conditions (Big potential difference)(small potential difference)

Plasma Application POSTECH Scharfetter-Gummel method In case of Drift flux

Plasma Application POSTECH Scharfetter-Gummel method In case of Diffusion flux

Plasma Application Modeling, POSTECH Shooting 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 1) : Neumann type boundary condition 1) : Mixed type boundary condition Second-order Boundary-Value Problem y(a)=A and y(b)=B

Plasma Application Modeling, POSTECH Computational 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.

Plasma Application Modeling, POSTECH Shooting Method for Boundary Value Problem ODEs Rewrite the second-order ODE as two first-order ODEs: We should assume a initial value of z(a). z(a) is determined for which y(b)=B by secant method.

Plasma Application Modeling, POSTECH Example of Shooting Method Ex) T(0)=0 and T(1.0)=100 Sol) Rewrite the second-order ODE as two first-order ODEs: T(0)=0.0 S(0)=T’(0) By modified Euler method Let  x=0.25, S(0.0) (1) =50, S(0.0) (2) =100

Plasma Application Modeling, POSTECH Solution by the Shooting Method

Plasma Application Modeling, POSTECH Errors in the Solution by the Shooting Method

Plasma Application Modeling, POSTECH Equilibrium Method y(a)=A and y(b)=B Ex) T(0)=0 and T(1.0)=100 Let  x=0.25, T a =0,  =2.0 x=0.25 : x=0.50 : x=0.75 : T1T2T3T1T2T =