ColoState Notes on Finite Difference Methods MATH451

advertisement
ColoState
MATH451
Notes on Finite Difference Methods
for 1st and 2nd Order Hyperbolic Equations
Jiangguo (James) Liu
∗
May 4, 2016
This chapter discusses mainly the finite difference methods for 1st and 2nd order hyperbolic equations.
1
FDMs for 2nd Order Hyperbolic Equations
The wave equation is a typical 2nd order hyperbolic partial differential equation.
The “standard” (homogeneous) BIVP: on [0, L] for t ≥ 0

utt = c2 uxx



u(0, t) = u(L, t) = 0
u(x, 0) = f (x), x ∈ [0, L]



ut (x, 0) = g(x), x ∈ [0, L]
(1)
Spatial discretization h = L/(n + 1) (so that there are n interior nodes),
All nodes xi = ih, i ∈ {0, 1, 2, . . . , n + 1}
Temporal discretization k
Time moments tj = jk, k = 0, 1, 2, . . .
Applying the central finite differences and approximating the exact solution by the numerical
solution to obtain
utt (xi , tj ) ≈
ui,j−1 − 2ui,j + ui,j+1
vi,j−1 − 2vi,j + vi,j+1
≈
k2
k2
uxx (xi , tj ) ≈
ui−1,j − 2ui,j + ui+1,j
vi−1,j − 2vi,j + vi+1,j
≈
2
h
h2
and
Plugging into the PDE and dropping the error terms to obtain
vi−1,j − 2vi,j + vi+1,j
vi,j−1 − 2vi,j + vi,j+1
= c2
2
k
h2
(2)
Setting s = ck/h and rearranging the terms in the above scheme (equation) lead to
vi,j+1 = 2(1 − s2 )vi,j + s2 (vi−1,j + vi+1,j ) − vi,j−1 , i ∈ {1, 2, . . . , n},
∗
Department of Mathematics,
(liu@math.colostate.edu)
Colorado
State
University,
1
Fort
Collins,
j = 1, 2, . . . ,
CO
80523-1874,
(3)
USA
where the homogeneous boundary conditions
v0,j = vn+1,j = 0
are already used.
Note the two initial conditions.
At each time moment, the numerical solution values at the interior nodes could form a vector
as follows
vj = [v1,j , v2,j , . . . vn,j ]T .
Then the numerical scheme using the 5-point stencil or “spearhead” pitching or 2-step timemarching reads
vj+1 = Avj − vj−1 , j = 1, 2, . . . ,
(4)
where A is a tri-diagonal matrix

2(1 − s2 )
s2
0
2
2)
2

s
2(1
−
s
s

0
s2 2(1 − s2 )
A=


···
···
···
0
0
···
0
···
0
···
0
···
···
s2 2(1 − s2 )



.


(5)
Starter Solver for vi,1 : Note that vi−1,1 , vi,1 , vi+1,1 values are needed to compute vi,2 . There
are three options to get the vector v1 .
(1) Use f (x), g(x) directly. Note that by Taylor expansion, one has
u(xi , t1 ) = u(xi , t0 ) + kut (xi , t0 ) +
k2
utt (xi , τ1 ) = u(xi , t0 ) + kg(xi ) + O(k 2 ),
2
and hence
u(xi , t1 ) − u(xi , t0 )
= g(xi ) + O(k),
k
which provides an approximation with a local truncation error O(k). This is a mismatch with
the local truncation error O(k 2 ) for u(xi , tj ) for j ≥ 2. Anyway, one has a starter solver
vi,1 = vi,0 + kg(xi ).
(6)
(2) Use still f (x), g(x) and additionally f ′′ (x). Consider a higher order Taylor expansion
u(xi , t1 ) = u(xi , t0 ) + kut (xi , t0 ) +
k2
k3
utt (xi , t0 ) + uttt (xi , τ1 ).
2
6
Assuming the wave equation holds at t0 and f ′′ (xi ) is available, one has
utt (xi , t0 ) = c2 uxx (xi , 0) = c2 f ′′ (xi ).
Then one obtains a better starter solver
vi,1 = vi,0 + kg(xi ) +
2
c2 k 2 ′′
f (xi ).
2
(7)
(3) Use f (x), g(x) and the central finite difference for f ′′ (x). In practice, especially when
f ′′ (x) is not available, one could use the central finite difference to approximate f ′′ (xi ) and
obtain
f (xi−1 ) − 2f (xi ) + f (xi+1 )
f ′′ (xi ) ≈
,
h2
and hence
)
c2 k 2 (
u(xi , t1 ) = u(xi , t0 ) + kg(xi ) +
f
(x
)
−
2f
(x
)
+
f
(x
)
+ O(k 2 + h2 k).
i−1
i
i+1
2h2
Setting s = ck/h and dropping the error terms, one obtains a more practical starter solver
)
1 (
vi,1 = vi,0 + kg(xi ) + s2 f (xi−1 ) − 2f (xi ) + f (xi+1 ) ,
(8)
2
or
)
s2 (
vi,1 = (1 − s2 )f (xi ) +
f (xi−1 ) + f (xi+1 ) + kg(xi ).
(9)
2
Notice that the above scheme for the 1st order hyperbolic equation is an explicit scheme.
Theorem. It is necessary that s = ck/h ≤ 1 for the above explicit method for the wave
equation to be stable.
Error analysis for FDM for the wave equation Let ei,j = ui,j −vi,j , then vi,j = ui,j −ei,j .
Plugin to the numerical scheme, we obtain
...
Note that
ui,j−1 − 2ui,j + ui,j+1
k2
utttt (xi , τj ),
=
u
(x
,
t
)
+
tt
i
j
k2
12
ui−1,j − 2ui,j + ui+1,j
k2
uxxxx (ξi , tj ),
=
u
(x
,
t
)
+
xx
i
j
h2
12
and the PDE (wave equation) is satisfied at (xi , tj ), we obtain the following
Theorem. The explicit method for the wave equation has error
O(h2 + k 2 ).
Numerical Example
d’Alembert formula for the exact solution
∫
)
1(
1 x+ct
u(x, t) =
f (x + ct) + f (x − ct) +
g(y)dy.
2
2c x−ct
2
(10)
FDMs for 1st Order Hyperbolic Problems
The typical initial value problem (IVP) for a single 1st order hyperbolic equation reads
{
ut = cux x ∈ R, t > 0,
u(x, 0) = f (x),
where c is a (real) constant.
Later on, we shall see
3
x ∈ R.
(11)
(i) c is interpreted as the wave speed;
(ii) Some techniques are introduced to handle the infinity of R, since in general we cannot perform
computation on the whole real line;
(iii) A boundary condition is introduced based on the physics behind the partial differential equation.
A more eminent and interesting question is why we would solve such an equation numerically,
since the exact solution is readily available
u(x, t) = f (x + ct),
(12)
assuming f (·) is sufficiently smooth.
Let h, k be respectively the spatial and temporal step sizes. Denote xi = ih, tj = jk.
2.1
Explicit Lax-Wendroff Scheme
Establishing Explicit Scalar Lax-Wendroff Scheme
base point (x, t) in the temporal direction yields
u(x, t + k) = u(x, t) + kut +
Note that a Taylor expansion at the
k2
utt + O(k 3 ).
2
Note that ut = cux and accordingly utt = c2 uxx and so on so forth. We can rewrite the Taylor
expansion as
k 2 c2
u(x, t + k) = u(x, t) + kcux +
uxx + O(k 3 ).
2
Note the above spatial derivatives can be approximated by central finite differences:
u(x + h, t) − u(x − h, t)
u(x + h, t) − 2u(x, t) + u(x − h, t)
,
uxx (x, t) ≈
.
2h
h2
Now allowing a numerical solution to approximate the exact solution and dropping the truncation
error term(s), we obtain a numerical scheme
ux (x, t) ≈
vi+1,j − vi−1,j
c2 k 2 vi+1,j − 2vi,j + vi−1,j
+
.
2h
2
h2
This yields the so-called explicit Lax-Wendroff scheme
vi,j+1 = vi,j + ck
1
1
vi,j+1 = − s(1 − s)vi−1,j + (1 − s2 )vi,j + s(1 + s)vi+1,j ,
2
2
(13)
where s = ck/h.
If we follow the textbook to set s = ck/(2h), then the numerical scheme will be written as
vi,j+1 = (2s2 − s)vi−1,j + (1 − 4s2 )vi,j + (2s2 + s)vi+1,j .
Stability Analysis of Explicit Lax-Wendroff Scheme
Stability analysis of the explicit Lax-Wendroff scheme can be performed using the so-called
Fourier method and results in the so-called CourantFriedrichsLewy (CFL) condition
|c|k
≤ 1.
h
4
(14)
Download