pdemathematica-090326234843-phpapp02

28
How to solve PDEs usi ng MATHEMATIA and MATLAB Plasma Application Modeling POSTECH G. Y. Park, S. H. Lee and J.K. Lee Department of Electronic and Electrical Engineering, POSTECH 2006. 5. 17

Upload: designamrita

Post on 19-Nov-2014

113 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: pdemathematica-090326234843-phpapp02

How to solve PDEs using MATHEMATIA and MATLAB

Plasma ApplicationModeling POSTECH

G. Y. Park, S. H. Lee and J.K. LeeDepartment of Electronic and Electrical Engineering,

POSTECH

2006. 5. 17

Page 2: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

ContentsContents• Solving PDEs using MATHEMATICA

- FTCS method

- Lax method

- Crank Nicolson method

- Jacobi’s method

- Simultaneous-over-relaxation (SOR) method

• Solving PDEs using MATLAB

- Examples of PDEs

Page 3: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

ReferencesReferences

• Textbook

- ‘Numerical and Analytical Methods for Scientists and Engineers Using Mathematica’, Daniel Dubin, Wiley, 2003

- ‘Applied numerical methods in C’, S. Nakamura

Page 4: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

PDE (Partial Differential Equation)PDE (Partial Differential Equation) PDEs are used as mathematical models for phenomena in

all branches of engineering and science.

- Three Types of PDEs:

1) Elliptic: Steady heat transfer, flow and diffusion

2) Parabolic: Transient heat transfer, flow and diffusion

3) Hyperbolic: Transient wave equation

fauuc )(

fauuctud )(

fauuctud

)(2

2

Page 5: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

FTCS method for the heat equationFTCS method for the heat equation

FTCS ( Forward Euler in Time and Central difference in Space )

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

),(),(),(

21

2

2

ydiffusivitthermaltTtLTtTtT

txStxTx

txTt

Heat equation in a slab

),(1

tTT

txTt

nj

nj

nj

211

2

2 2),(

xTTT

txTx

nj

nj

nj

nj

)2( 1121 n

jnj

nj

nj

nj

nj TTT

xttSTT

njnj TtxT ),(Let

Page 6: pdemathematica-090326234843-phpapp02

FTCS method for the heat equationFTCS method for the heat equation

Initial conditions

Plot

FTCS

01.0t

Page 7: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Stability of FTCS and CTCSStability of FTCS and CTCSFTCS is first-order accuracy in time and second-order accuracy in space.So small time steps are required to achieve reasonable accuracy.

05.0t Courant condition for FTCS

21

2 xt

)2(22 11211 n

jnj

nj

nj

nj

nj TTT

xttSTT

CTCS method for heat equation(Both the time and space derivatives are center-differenced.)

However, CTCS method is unstable for any time step size.

( unstable )

Page 8: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Lax methodLax methodSimple modification to the CTCS method

In the differenced time derivative,

)2(22)( 1121

11

1211 n

jnj

nj

nj

nj

nj

nj TTT

xttSTTT

tTTT

tTT n

jnj

nj

nj

nj

2)]([

2)( 1

11

121111

Replacement by average value from surrounding grid points

The resulting difference equation is

Courant condition for Lax method

41

2 xt

( Second-order accuracy in both time and space )

Page 9: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Crank Nicolson Algorithm ( Implicit Method )Crank Nicolson Algorithm ( Implicit Method )

BTCS ( Backward time, centered space ) method for heat equation

)2( 111

2nj

nj

njx

tnj

nj

nj TTTtSTT

( This is stable for any choice of time steps, however it is first-order accurate in time. )

Crank-Nicolson scheme for heat equationtaking the average between time steps n-1 and n,

)22(

)(1

111

111

1211

2

nj

nj

nj

nj

nj

njx

t

nj

nj

nj

nj

TTTTTT

SStTT

( This is stable for any choice of time steps and second-order accurate in time. )

a set of coupled linear equations for njT

Page 10: pdemathematica-090326234843-phpapp02

Crank Nicolson AlgorithmCrank Nicolson Algorithm

Initial conditions

Plot

Crank-Nicolson scheme

)/sin(),(22 / LxetxT Lt

Exact solution

Page 11: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Crank Nicolson AlgorithmCrank Nicolson Algorithm

Page 12: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Multiple Spatial DimensionsMultiple Spatial Dimensions

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

2

2

2

tyxStyxTyx

tyxTt

FTCS for 2D heat equation

)2()2( 1121121 n

jknjk

njk

nkj

njk

nkj

njk

njk

njk TTT

ytTTT

xttSTT

Courant condition for this scheme

22

22

21

yxyxt

( Other schemes such as CTCS and Lax can be easily extended to multiple dimensions. )

Page 13: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Wave equation with nonuniform wave speedWave equation with nonuniform wave speed

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

2

2

22

2

2

tyxzyx

yxctyxzt

2D wave equation

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

00

00

vzyxvyxzyxzyxz

txxtxztxztyztyz

2sin)1(),0,(,0),1,(),,1(),,0(

Initial condition :

Boundary condition :

])5.0(5)5.0(2exp[7.01),( 22101 yxyxcWave speed :

)2()2(2 112

22

112

2211 n

jknjk

njk

jknkj

njk

nkj

jknjk

njk

njk TTz

ytc

zzzxtc

zzz

CTCS method for the wave equation :

) ( 21

2

22

yxfortcCourant condition :

Page 14: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Wave equation with nonuniform wave speedWave equation with nonuniform wave speed

Since evaluation of the nth timestep refers back to the n-2nd step, for the first step, a trick is employed.

jkt

jkjkjk atvzz 2001 2

)2()2( 112

20

100

12

2njk

njk

njk

jkkjjkkj

jkjk TTz

yc

zzzxc

a

Since initial velocity and value,

0

01

00

jk

jkjk

z

zv

Page 15: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Wave equation with nonuniform wave speedWave equation with nonuniform wave speed

Page 16: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Wave equation with nonuniform wave speedWave equation with nonuniform wave speed

Page 17: pdemathematica-090326234843-phpapp02

2D Poisson’s equation2D Poisson’s equation

),(),()( 2

2

2

2 yxyxyx

Poisson’s equation

Direct Solution for Poisson’s equation

jkjkjkjkkjjkkj

yx

2

112

11 22

Centered-difference the spatial derivatives

Page 18: pdemathematica-090326234843-phpapp02

Jacobi’s method ( Relaxation method )Jacobi’s method ( Relaxation method )Direct solution can be difficult to program efficiently.

Relaxation methods are relatively simple to code, however, they are not as fast as the direct methods.

Idea : I. Poisson’s equation can be thought of as the equilibrium solution to

the heat equation with source.II. Starting with any initial condition, the heat equation solution will

eventually relax to a solution of Poisson’s equation.

)2(1)2(1

21

11211222

221 n

jknjk

njk

nkj

njk

nkjjk

njk

njk yxyx

yx

)(1)(121

11211222

22njk

njk

nkj

nkjjk yxyx

yx

),(),(),,(t

),(),( 22 yxyxtyxyxyx

) 21 ( 22

22

yxyxt

FTCS

(Maximum time step satisfying Courant condition)

Page 19: pdemathematica-090326234843-phpapp02

Jacobi methodJacobi method

Page 20: pdemathematica-090326234843-phpapp02

Plasma ApplicationModeling POSTECH

Simultaneous OverRelaxation (SOR)Simultaneous OverRelaxation (SOR)The convergence of the Jacobi method is quite slow.

Furthermore, the larger the system, the slower the convergence.

Simultaneous OverRelaxation (SOR) :

the Jacobi method is modified in two ways,

)(1)(1

2)1(

1112

1112

22

221

njk

njk

nkj

nkjjk

njk

njk

yx

yxyx

1. Improved values are used as soon as they become available.

2. Relaxation parameter ω tries to overshoot for going to the final result. ( 1<ω<2)

Page 21: pdemathematica-090326234843-phpapp02

Simultaneous OverRelaxation (SOR)Simultaneous OverRelaxation (SOR)

Page 22: pdemathematica-090326234843-phpapp02

O.V. Manuilenko

MATLAB The Language of Technical Computing

Plasma ApplicationModeling GroupPOSTECH

MATLAB PDE

Run: dftcs.m >> dftcs

dftcs - Program to solve the diffusion equation using the Forward Time Centered Space scheme.

Enter time step: 0.0001Enter the number of grid points: 51Solution is expected to be stable

2

2 ),(),(xtxT

ttxT

Page 23: pdemathematica-090326234843-phpapp02

O.V. Manuilenko

MATLAB The Language of Technical Computing

Plasma ApplicationModeling GroupPOSTECH

MATLAB PDE

Run: dftcs.m >> dftcs

dftcs - Program to solve the diffusion equation using the Forward Time Centered Space scheme.Enter time step: 0.00015Enter the number of grid points: 61WARNING: Solution is expected to be unstable

Page 24: pdemathematica-090326234843-phpapp02

O.V. Manuilenko

MATLAB The Language of Technical Computing

Plasma ApplicationModeling GroupPOSTECH

MATLAB PDE

Run: neutrn.m >> neutrn Program to solve the neutron diffusion equation using the FTCS.Enter time step: 0.0005Enter the number of grid points: 61Enter system length: 2 => System length is subcriticalSolution is expected to be stableEnter number of time steps: 12000

),(),(),(2

2

txnxtxn

ttxn

Page 25: pdemathematica-090326234843-phpapp02

O.V. Manuilenko

MATLAB The Language of Technical Computing

Plasma ApplicationModeling GroupPOSTECH

MATLAB PDE

Run: neutrn.m >> neutrn Program to solve the neutron diffusion equation using the FTCS.Enter time step: 0.0005Enter the number of grid points: 61Enter system length: 4 => System length is supercriticalSolution is expected to be stableEnter number of time steps: 12000

Page 26: pdemathematica-090326234843-phpapp02

O.V. Manuilenko

MATLAB The Language of Technical Computing

Plasma ApplicationModeling GroupPOSTECH

MATLAB PDE

Run: advect.m >> advect

advect - Program to solve the advection equation using the various hyperbolic PDE schemes: FTCS, Lax, Lax-WendorfEnter number of grid points: 50Time for wave to move one grid spacing is 0.02Enter time step: 0.002Wave circles system in 500 stepsEnter number of steps: 500

FTCS FTCS

0),(),(

xtxu

ttxu

Page 27: pdemathematica-090326234843-phpapp02

O.V. Manuilenko

MATLAB The Language of Technical Computing

Plasma ApplicationModeling GroupPOSTECH

MATLAB PDE

Run: advect.m >> advect

advect - Program to solve the advection equation using the various hyperbolic PDE schemes: FTCS, Lax, Lax-WendorfEnter number of grid points: 50Time for wave to move one grid spacing is 0.02Enter time step: 0.02Wave circles system in 50 stepsEnter number of steps: 50

Lax Lax

Page 28: pdemathematica-090326234843-phpapp02

O.V. Manuilenko

MATLAB The Language of Technical Computing

Plasma ApplicationModeling GroupPOSTECH

MATLAB PDE

Run: relax.m >> relax

relax - Program to solve the Laplace equation using Jacobi, Gauss-Seidel and SOR methods on a square gridEnter number of grid points on a side: 50Theoretical optimum omega = 1.88184 Enter desired omega: 1.8Potential at y=L equals 1 Potential is zero on all other boundariesDesired fractional change = 0.0001

0),(),(2

2

2

2

yyx

xyx