Finite differences 1
Finite differences
Finite differences 2
Introduction1 j-1 j j+12 N N+1
<------------------------------- L ---------------------------------->
Taylor series expansion:
2 31
2 31
1 1' '' ( ) ''' ( ) ....
2! 3!1 1
' '' ( ) ''' ( ) ....2! 3!
j j j j j
j j j j j
x x x
x x x
1,........, 1j jx x j N
x
Finite differences 3
Finite differences approximations
11 1
1 1 2'' ''' ( ) ..2! 3!
' .j jj j jwhere E x xE
x
forward approximation
=Consistent if , ,…. are bounded
12 2
1 1 2'' ''' ( ) ..2! 3!
' .j jj j jwhere E x xE
x
backward approximationadding both
1 1 1 2''' ( ) ..3!
' .2
j jj jwhere E xE
x
==
=
centered differences
"j '''
j
Finite differences 4
Finite differences approximations (2)
Also
1 1 2 2 44 1' ( )
3 2 3 4j j j j
j O xx x
===
1 1 22
2'' ( )
( )j j j
j O xx
===
fourth order approximation to the first derivative
Second order approximation to the second derivative
Finite differences 5
The linear advection equation00
xU
t00
xU
t
+ initial and boundary conditionsAnalytical solution
)()(),( tTxXtx Substituting we get 0
0 1UC
dt
dT
Tdx
dX
X
U
TUdt
dT
Xdx
dX
0
Eigenvalue problems for the operators
tU
x
eTT
eXX0
0
0
dt
dand
dx
d
With periodic B.C. λ can only have certain (imaginary) valueswhere k is the wavenumber
ik
The general solution is a linear combination of several wavenumbers
Finite differences 6
The linear advection equation (2)
The solution is then:
)(),( 0)(
0)(
0000 tUxfeeTXtx tUxtUx
Propagatingwith speed U0
For a single wave of wavenumber k, the frequency is ω=kU0
No dispersion
Energy conservation
L
dxtE0
2
2
1)(
022 0
20
0
20
L
L Udx
x
U
t
E
If periodic B.C.
Finite differences 7
Space discretization
xxjj
j
211
dt
d
xU
tjjjj
211
0
xikjettTry j )()( ; substituting
0)sin(
0
xk
xkikU
dt
d
whose solution is ikcte 0 with )()sin(
0 kfxk
xkUc
U0
c
kΔx
The phase speed c depends on k; dispersion
kΔx= π ---> λ=2Δx ==> c=0
centered second-order approximation
Finite differences 8
Group velocity
dk
dcg
)cos()(
)(
0*
00
xkUdk
kcdc
Udk
kUdc
g
gContinuous equation
Discretized equation
=-U0 for kΔx=π
Approximating the space operator introduces dispersion
Finite differences 9
Time discretization
tn
t
nj
njj
1
xtU
xU
t
nj
njn
jn
j
nj
nj
nj
nj
2211
0111
0
1
Try xikjetnin
j e 0 Substituting we get
)sin(0 xkix
tUtie
α (Courant-Friedrich-Levy number)
\--v--/
ω=a+ib
If b>0, φjn increases exponentially with time (unstable)
If b<0, φjn decreases exponentially with time (damped)
If b=0, φjn maintains its amplitude with time (neutral)
Also another dispersion is introduced, as we have approximated the operator ∂/ ∂t
first-order forward approx.
Finite differences 10
Three time level scheme (leapfrog))( 11
11
jn
jnn
jn
j)( 11
11
jn
jnn
jn
j
This scheme is centered (second order accurate) in both space and time
Try a solution of the form
xikjnk
nj e 0
exponentialIf |λk| > 1 solution unstableif |λk| = 1 solution neutralif |λk| < 1 solution damped
Substituting
)sin(0122 xkpwhereip kk
21 pipk 11
11
2
2
pip
pip
k
k Δx--->0Δt --->0
physical mode
computational mode
Finite differences 11
Stability analysisEnergy method
define ;2
1)(
0
2L
dxtE
L
LUdx
x
U
t
E
00
202
0 0]22Periodic boundaryconditionsDiscretized analog : En
N
j
nj
n xE1
2)(2
1 φn N+1≡ φn
1
If En=const, stable t
Finite differences 12
Example of the energy method
xU
t
jnn
jn
jn
j
10
1upwind if U0>0downwind if U0<0
xj-1 j
x
tUj
nnj
nj
nj
nj
nj
01
1221 ;))(()()(
21
21
2221 ))(1(})(){()()( j
nnj
nj
nj
nj
nj
j
0
1
21
1 )()1(
N
jj
nj
nnn xEE
En+1=En ifα=0 ==> U0=0 no motionα=1 Δt= Δx/U0
if En+1 > En -------> unstable
En+1 < Enα > 0 ==> U0 > 0 (upwind)α < 1 U0 Δt/ Δx < 1 (CFL condition) damped
Finite differences 13
Von Neumann methodConsider a single wave jikxn
kknj ectx ),(
if |λk| < 1 the scheme is damping for this wavenumber kif |λk| = 1 k the scheme is neutralif |λk| > 1 for some value of k, the scheme is unstable
alternatively jikxtniknj eectx ),(
if Im(ω) > 0 scheme unstableif Im(ω) = 0 scheme neutralif Im(ω) < 0 scheme damping
Vf= ω/k vg=∂ω/∂k
Finite differences 14
Matrix methodLet
nn A 1for a two-time-level scheme
A is called the amplification matrix
kVAnd call the eigenvectors of kkk VVAA
Expanding the initial condition 0 In terms of these eigenvectors
k
kkV00and applying n times the amplification matrix
k
kn
kkn V0
exponential
therefore 1 kn anyif
Finite differences 15
Stability of some schemes• Forward in time, centered in space (FTCS) scheme
• Upwind or downwind
xU
t
nj
nj
nj
nj
211
0
1
using Von Neumann, we find
kxki kk 1)sin(1 scheme unstable
xU
t
nj
nj
nj
nj
10
1upwind if U0 > 0downwind if U0 < 0
Using Von Neumann:
))cos(1()1(21;)1(1
0
2
xke kxik
k
α(α-1) > 0 ------> unstableα < 0 downwindα > 1 CFL limit
-1/4 < α(α-1) < 0==> 0 ≤ α ≤ 1 -------------> stable damped scheme
Finite differences 16
Stability of some schemes (cont)
• Leapfrog
xU
t
nj
nj
nj
nj
2211
0
11
Using von Neumann we find |α|≤1 as stability condition
Finite differences 17
• Lax Wendroff
Stability of some schemes (cont)
From 2
22)(
!2
1),(),(
tt
tttxttx
(Taylor in t)
2
220
20 )(
!2
1),(),(
xUt
xtUtxttx
)2(2
)(2 11
2
111 n
jnj
nj
nj
nj
nj
nj
)(
)(2/)(2/1
2/12/1
2/12/1
2/12/1
1
11
nj
nj
nj
nj
nj
nj
nj
nj
nj
Equivalent to
Applying Von Neumann we can find that |α| ≤1 -----> stable
j j+1/2 j+1
x
Finite differences 18
Stability of some schemes (cont)• Implicit centered scheme
• Krank-Nicholson
xU
t
tj
tj
nj
nj
22
21
21
0
11where
2
112
nnt
using von Neumann
1)sin(1
)sin(12
xki
xki Always neutral
)tan(0 t
t
U
c
Dispersion worsethan leapfrog
xU
t
tj
tj
nj
nj
2
2/12/1
110
1
2
12/1
nnt
where
1)sin(
21
)sin(2
12
xki
xki Always neutral
)2/tan(
2/
0 t
t
U
c
Dispersionbetter thanimplicit.No computationalmode
Finite differences 19
“Intuitive” look at stabilityIf the information for the future time step “comes from” insidethe interval used for the computation of the space derivative,the scheme is stableOtherwise it is unstable
x--> point where the informationcomes from (xj-U0Δt)
j-1 j j+1
x
U0Δt
Interval used for thecomputation of ∂φ/∂x
Downwind scheme
j-1 j j+1
xox ----> α < 1o ----> α > 1
Upwind scheme
CFL number ==> fractionof Δx traveled in Δt secondsLeapfrog
xo
Implicitj-1 j j+1
Finite differences 20
Dispersion and group velocity
ωΔt
π/2 π
U0
vg
vf
Leapfrog
K-N
Implicit
Finite differences 21
Effect of dispersionIn
itial
Lea
pfro
gim
plic
it
Finite differences 22
Two-dimensional advection equation000
yV
xU
t
Using von Neumann, assuming a solution of the form )(0 lykxinn e
we obtain
y
ylV
x
xkUt
)sin()sin( 00
using )sin,cos(),( 00 RRVUV
we obtain, for |λ| to be ≤1 the condition
2R
st
where Δs= Δx= Δy
This is more restrictive than in one dimension by a factor 2