Lecture 2 - Rutgers University

Download Report

Transcript Lecture 2 - Rutgers University

Introduction to Numerical Methods I
1
Finite difference approximation to derivatives
2
Consider a smooth function g(x). Taylor’s theorem reads:
x k ( k )
g ( x0  x)  g ( x0 )  
g ( x0 )
k!
k
In particular:
g ( x0  x )  g ( x0 )  xg(1) ( x0 )  O ( x 2 )
(1)
g ( x0  x )  g ( x0 )  xg(1) ( x0 )  O ( x 2 )
( 2)
g ( x0  x )  g ( x0 )
Eq.(1)  g ( x0 ) 
 O ( x )
x
(1)
(3)
g ( x0 )  g ( x0  x )
Eq.( 2)  g ( x0 ) 
 O ( x ) (4)
x
g ( x0  x )  g ( x0  x )
(1)
Eqs.(3)  ( 4)  g ( x0 ) 
 O ( x 2 )
2x
3
(1)
Short course on: Numerical methods for hyperbolic equations and applications-Trento, Italia-June 7th to 18th, 2004
Finite difference approximation of PDEs: FTCS
PDE : La ( q)  qt  qx  0 x  [0, L] t  (0, T ]
IC :
q( x,0)  q0 ( x )
Discretise the x-t domain into a finite number of M+1 points, I=0,…,M
( xi , t n ) with xi  ix; t n  nt; i, n  0;
Mesh :
x  L / M ; t : time step
qin  q( xi , t n )
4
Now approximate partial derivatives.
Use finite differences:
qin 1  qin
qt 
 O ( t ) : forward in time (FT)
t
qin1  qin1
qx 
 O ( x 2 ) : centred in space (CS)
2x
Then the PDE is replaced by a finite difference approximate operator:
n 1
n
n
n
q

q
q

q
i
La(qin )  i
  i 1 i 1  0
t
2x
n
n



t
q

q


numerical scheme
n 1
n
i 1
i 1 

 qi  qi  

 x  2x 
5
Introduce the dimensionless number:
  t 
c

 x 
The Courant-Friedrichs-Lewy number
or CFL number, or Courant number
Note that c is a dimensionless quantity, it is the ratio of two velocities:
 t

speed of PDE
c


x
x / t
speed of mesh
Finally, the FTCS scheme reads:
n 1
i
q
1
 q  c( qin1  qin1 )
2
n
i
Stencil
This formula allows us to calculate explicitly the evolution in time of discrete
approximate values of the solution at every point, except for i=0 and i=M.
6
Convergence
Our ultimate goal is to construct schemes that converge, that is schemes
that approach the true solution of the PDE when the mesh size tends to zero.
Lax’s Equivalence theorem says that:
the only schemes that are CONVERGENT are those that
are CONSISTENT and STABLE
We must therefore work on CONSISTENCY AND STABILITY.
7
Local truncation error
Consider a particular scheme: FTCS.
The numerical analogue of the PDE is the approximate operator:
n 1
n
n
n
q

q
q

q
i
La ( qin )  i
  i 1 i 1  0
t
2x
We define the local truncation error:
ET  La (q(ix, nt ))
q(ix, (n  1)t )  q(ix, nt )
q((i  1)x, nt )  q((i  1)x, nt )
ET 

t
2x
8
Assuming the solution is sufficiently smooth we Taylor expand and obtain:
n
1
1

n
LTE  ( qt  qx )i   tqtt  x 2 qxxx  O( x 3 )  O ( t 2 )
6
2
i
Noting that:
( qt  qx )in  0 
n
1
1

LTE   tqtt  x 2 qxxx  O ( x 3 )  O( t 2 )
6
2
i
LTE  O(t )  O(x 2 )
The FTCS is a first-order scheme
In general, if the local truncation error of a scheme is of the form:
LTE  O( t k )  O( x l )
Then the scheme is said to be k-th order accurate in time and l-th order accurate in space.
9
Consistency
A numerical scheme is said to be consistent with the PDE being discretized
if the local truncation error tends to zero as the mesh size tends to zero.
LTE  0 as
t  0 and x  0
For example, for the FTCS scheme we have
LTE  O(t )  O(x 2 )
Therefore FTCS is consistent wit the PDE
10
Stability of a numerical method.
If a method is consistent with the PDE, then all we need to bother is stability.
One view of stability is that of unbounded growth of errors as the numerical
scheme evolves the solution in time.
Another view of stability is that of controlling spurious oscillations
Stability in the sense on unbounded growth can be analysed by a variety of methods
A popular method is the von Neumann method
One performs a Fourier decomposition of the error. It is sufficient to consider a
single component.
11
Stability analysis of the FTCS
qin  An e Ii : trial solution
1
n 1
n
n
n
q

q

c
(
q

q
i
i 1
i 1 ) 
 1 ; i : spacial index i
2
I 
 : frequency angle


1
A e  A e  c An e I ( i 1)  An e I ( i 1) 
2
1
1
I
 I
A  1 c e  e
 1  c2 I sin   
2
2
A  1  Ic sin  
n 1 Ii
n

Ii

A  1  c 2 sin 2   1
2
Thus FTCS is unstable under all circumstances: UNCONDITIONALLY
UNSTABLE (useless).
12
Godunov’s first-order upwind scheme
• Approximate derivatives in qt  qx  0 ,   0
by
then
qin1  qin
qt 
t
qin  qin1
, qx 
x
n 1
n
n
n

q

q
q

q
n
i
i
i
i 1 
  0
La ( qi ) 
  
t
 x 
• The scheme reads
Illustrate the
stencil
qin1  qin  c(qin  qin1 )
13
Local truncation error:
The finite difference operator is:
 qin  qin1 
qin 1  qin

La ( q ) 
 
0


t
x


n
i
Substitution of the exact solution into the approximate opetaror gives:
LTE 
q(ix, ( n  1)t )  q(ix, nt )
q(ix, nt )  q((i  1)x, nt )

t
x
Assuming sufficient smoothness and Taylor expanding:
n
1
1

LTE  ( qt  qx )in   tqtt  x 2 qxxx  O( x 3 )  O ( t 2 )
6
2
i
n
1
1

LTE   tqtt  xqxx  O ( x 2 )  O ( t 2 )
2
2
i
The scheme is first-order accurate in space and time
14
Stability analysis
A  (1  c) 2  2c(1  c) cos  c 2
2
and the stability condition
0  c 1
A  1 becomes
2
The CFL condition of Courant condition
Given wave speed  and mesh spacing x the time
step t is determined from the stability condition
t

x
0
1 0 
 1  t 
x
x / t

x
Set : t  Ccfl
with 0  Ccfl  1 
Ccfl 
t
x

: the CFL number of the computatio n.
15
The stencil (upwind)
t
x
n+1
dx / dt    0
o
dx / dt  x / t
t
n

o
xi1
xp
cx
True domain
of dependency
o
xi
x
Numerical domain of dependency
The exact solution q ( xi , t n ) is the value on the characteristic
dx

dt
at ( xi , t n 1 )
that is : q ( xi , t n 1 )  q ( x p , t n )
where x p is the foot of the characteristic at time t  t n
16
• For appropriate choices of x , t the point x p lies
between xi 1 and xi
• Assume a linear interpolation between xi 1 and xi
n
n
n  x  xi 1 
~
 , x  xi 1 , xi 
q ( x)  qi 1  ( qi  qi 1 )
 x 
• Evaluation of
q~( x ) at
x  x p  (i  c )x
gives
q~( x p )  qin  c(qin  qin1 )
which is the Godunov scheme
17
The “downwind” scheme
• Approximate derivatives in qt  qx  0 ,   0
by
then
qin 1  qin
qt 
t
qin1  qin
, qx 
x
n 1
n
n
n

q

q
q

q
n
i
i
i 1
i 
  0
La ( qi ) 
  
t
 x 
• The scheme reads
qin 1  qin  c( qin1  qin )
Exercise: derive the local truncation error. Is the scheme consistent ?
Exercise: show that this scheme is unconditionally unstable.
18
General Form of the First-Order Upwind Scheme
• For
 0
• For both
the upwind scheme is qin1  qin  c(qin1  qin )
 0
and
 0
define:
1
  max(  ,0)  (   )  0
2
1

  min(  ,0)  (   )  0
2
t
t


c 
, c 
x
x

• The scheme reads:
qin1  qin  c  (qin  qin1 )  c  (qin1  qin )
Exercise: show that the upwind scheme for negative speed is conditionally stable
19
Fully discrete and semi-discrete schemes
qt  qx  0 ,   0
n 1
n
n
n

q

q
q

q
n
i
i
i 1
i 
  0
La ( qi ) 
  
t
 x 
Fully discrete
If the time derivative is left in its continuous form
 qin1  qin 
d

q   
dt
 x 
Semi-discrete
The method of lines
20
Explicit scheme and implicit schemes
qt  qx  0 ,   0
 qin1  qin 
qin 1  qin
  0 
  
t
 x 
qin 1  qin  c( qin1  qin )
Explicit
 qin11  qin 1 
qin1  qin
  0 
  
t
x


qin 1  qin  c( qin11  qin 1 )
Implicit
Exercise: construct the fully discrete implicit version of FTCS
21
Monotone Schemes
q
n 1
i
 H (q ,....q ,...., q )
n
i s
n
i
n
ir
A monotone scheme satisfies:

H  0 for all k
n
qk
Monotone schemes for the linear advection equation with constant
speed of propagation are those whose coefficients are non-negative.
Example: The Godunov upwind scheme.
qin 1  qin  c( qin  qin1 )
H  cq  (1  c)q
n
i 1
n
i
22
More Schemes
The Lax-Friedrichs scheme (LF)
n 1
i
q
1
1
n
 (1  c)qi1  (1  c)qin1
2
2
• Conditionally stable c  1
• Monotone
• Modified equation has  LF  x (1  c 2 )
2c
LF may also be seen as the FTCS scheme (unstable) with
1 n
replaced by
(q  q n )
2
i 1
q
n
i
i 1
Note the shape of the stencil.
23
The Godunov Centred Scheme
n 1
i
q
1
1
n
2
n
 c(1  2c)qi1  (1  2c )qi  c(1  2c)qin1
2
2
• Conditionally stable
1
0 c 
2
2
• Monotone for
1
1
c
2
2
2
• Oscillatory for
0 c 
Stencil
1
!!
2
This is an interesting example of a first-order scheme that is NOT MONOTONE.
24
The Lax-Wendroff Scheme (LW)
q
n 1
i
1
1
n
2
n
 c(1  c)q i1  (1  c )q i  c(1  c)q in1
2
2
• Conditionally stable
Stencil
0  c 1
• Non-monotone (verify by inspection)
25
The FORCE scheme
n 1
i
q
1
1
1
2 n
2
n
 (1  c) qi 1  (1  c )qi  (1  c)2 qin1
4
2
4
stencil
• Conditionally stable: c  1
• Monotone
 1 c2  1
1
   LF
• Modified equation:  force  x
4
 c  2
26
© Toro 2004