Upload
guest56708a
View
32.641
Download
11
Embed Size (px)
DESCRIPTION
Finite difference methods with introduction to Burgers Equation
Citation preview
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
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
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
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 )(
fauuct
ud
)(
fauuct
ud
)(2
2
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
t
TTtxT
t
nj
nj
nj
2
11
2
2 2),(
x
TTTtxT
x
nj
nj
nj
nj
)2( 1121 n
jnj
nj
nj
nj
nj TTT
x
ttSTT
njnj TtxT ),(Let
FTCS method for the heat equationFTCS method for the heat equation
Initial conditions
Plot
FTCS
01.0t
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
2
12
x
t
)2(2
2 11211 n
jnj
nj
nj
nj
nj TTT
x
ttSTT
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 )
Plasma ApplicationModeling POSTECH
Lax methodLax methodSimple modification to the CTCS method
In the differenced time derivative,
)2(2
2)( 1121
11
1211 n
jnj
nj
nj
nj
nj
nj TTT
x
ttSTTT
t
TTT
t
TT nj
nj
nj
nj
nj
2
)]([
2
)( 11
112
1111
Replacement by average value from surrounding grid points
The resulting difference equation is
Courant condition for Lax method
4
12
x
t( Second-order accuracy in both time and space )
Plasma ApplicationModeling POSTECH
Crank Nicolson Algorithm ( Implicit Method )Crank Nicolson Algorithm ( Implicit Method )
BTCS ( Backward time, centered space ) method for heat equation
)2( 111
2
nj
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 equation
taking 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
Crank Nicolson AlgorithmCrank Nicolson Algorithm
Initial conditions
Plot
Crank-Nicolson scheme
)/sin(),(22 / LxetxT Lt
Exact solution
Plasma ApplicationModeling POSTECH
Crank Nicolson AlgorithmCrank Nicolson Algorithm
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
y
tTTT
x
ttSTT
Courant condition for this scheme
22
22
2
1
yx
yxt
( Other schemes such as CTCS and Lax can be easily extended to multiple dimensions. )
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
vz
yxvyxzyxzyxz
txxtxz
txztyztyz
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
y
tczzz
x
tczzz
CTCS method for the wave equation :
) ( 2
12
22
yxfortc
Courant condition :
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
y
czzz
x
ca
Since initial velocity and value,
0
01
00
jk
jkjk
z
zv
Plasma ApplicationModeling POSTECH
Wave equation with nonuniform wave speedWave equation with nonuniform wave speed
Plasma ApplicationModeling POSTECH
Wave equation with nonuniform wave speedWave equation with nonuniform wave speed
2D Poisson’s equation2D Poisson’s equation
),(),()( 2
2
2
2
yxyxyx
Poisson’s equation
Direct Solution for Poisson’s equation
jkjkjkjkkjjkkj
yx
2
11
2
11 22
Centered-difference the spatial derivatives
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
2
111211222
221 n
jknjk
njk
nkj
njk
nkjjk
njk
njk yxyx
yx
)(1
)(1
2
111211222
22njk
njk
nkj
nkjjk yxyx
yx
),(),(),,(t
),(),( 22 yxyxtyxyxyx
) 2
1 (
22
22
yx
yxt
FTCS
(Maximum time step satisfying Courant condition)
Jacobi methodJacobi method
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
yx
yx
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)
Simultaneous OverRelaxation (SOR)Simultaneous OverRelaxation (SOR)
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 ),(),(
x
txT
t
txT
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
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
txnx
txn
t
txn
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
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-Wendorf
Enter 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),(),(
x
txu
t
txu
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-Wendorf
Enter 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
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 grid
Enter 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
y
yx
x
yx