CEE363c Lecture 9 1
CEE363c Lecture 9: More shallow water
equation discretizations
Hirt anaysis for the theta method
In one dimension and in the absence of depth variation, the one-dimensional Saint-Venant
equations are given by
∂u ∂u ∂H
+u = −g ,
∂t ∂x ∂x
∂H ∂
+ (Hu) = 0 .
∂t ∂x
If we let u = u + u′ and assume that u′ << u, substitution yields
∂u ∂u′ ∂u ∂u′ ∂u ∂u′ ∂h
+ +u +u + u′ + u′ = −g ,
∂t ∂t ∂x ∂x ∂x ∂x ∂x
∂h ∂ ∂ ∂u ∂u′
+ (hu) + (hu′ ) + d +d = 0.
∂t ∂x ∂x ∂x ∂x
Linearization can be achived by assuming that u = 0 and that products of small quantities
can be ignored, such that if h′ u << 1 and u′ u′ << 1, we have the linearized form of the
Saint-Venant equations
∂u ∂h
+g = 0, (1)
∂t ∂x
∂h ∂u
+d = 0, (2)
∂t ∂x
where we have neglected the primes on u′ . Applying the theta-method to the continuity
equation (2) gives
∆t h n+1 i
hn+1
i − hn
i = −d θ u i+1/2 − u n+1
i−1/2 + (1 − θ) u n
i+1/2 − u n
i−1/2 . (3)
∆x
Using Taylor series, we have
n+1/2 ∆t ∆t2
hn+1
i = hi + (ht )n+1/2
i + (htt )n+1/2
i + O ∆t3 ,
2 8
n+1/2 ∆t ∆t2
hni = hi − (ht )n+1/2
i + (htt )n+1/2
i + O ∆t3
,
2 8
so that
hn+1
i − hni = ∆t (ht )n+1/2
i + O ∆t3 .
CEE363c Lecture 9 2
Using Taylor series, the spatially-discretized terms are given by
∆x ∆x2
un+1 n+1
i±1/2 = ui ± (ux )n+1
i + (uxx )n+1
i ± O ∆x3 ,
2 8
n+1/2 ∆t ∆t2
= ui + (ut )n+1/2
i + (u tt )n+1/2
i + O ∆t 3
2 8
∆x n+1/2 ∆t n+1/2 2
± (ux )i + (uxt )i + O ∆t
2 2
∆x2 h i
+ (uxx )n+1/2
i + O (∆t) ± O ∆x3
8
n+1/2 ∆t ∆t2
= ui + (ut )n+1/2
i + (u tt )n+1/2
i + O ∆t 3
2 8
∆x ∆x∆t
± (ux )n+1/2
i ± (uxt )n+1/2
i + O ∆x∆t2
2 4
∆x2
+ (uxx )n+1/2
i + O ∆x2 ∆t ± O ∆x3 .
8
Neglecting the truncation errors, the discrete derivative is then given by
n+1/2
n+1 n+1 ∆t
θ ui+1/2 − ui−1/2 = θ∆x ux + uxt + O ∆x3 .
2 i
By the same argument, it is easy to show that
n+1/2
∆t
(1 − θ) uni+1/2 − uni−1/2 = ∆x (1 − θ) ux − uxt + O ∆x3 .
2 i
Substitution into the discrete equation (3) gives
" n+1/2
n+1/2 3
∆t ∆t
∆t (ht )i + O ∆t = −d ∆xθ ux + uxt + O ∆x3
∆x 2 i
n+1/2 #
∆t
+∆x (1 − θ) ux − uxt + O ∆x3 .
2 i
n+1/2 ∆t n+1/2
= −d∆t (ux )i + (2θ − 1) (uxt )i + O ∆x2 ,
2
which yields the modified form of the depth-averaged continuity equation evaluated at (i, n+
1/2) as
∂h ∂u 1 ∂2u
+d = −d∆t θ − + O ∆t2 , ∆x2 . (4)
∂t ∂x 2 ∂x∂t
From the momentum equation, we have
∂u ∂h
+g = 0,
∂t ∂x
∂ ∂u ∂2h
+ g 2 = 0,
∂x ∂t ∂x
∂2u ∂2h
= −g 2 ,
∂x∂t ∂x
CEE363c Lecture 9 3
which can be substituted into equation (4) to yield
∂h ∂u 1 ∂2h 2 2
+d = gd∆t θ − + O ∆t , ∆x . (5)
∂t ∂x 2 ∂x2
From this equation we can see that the equation has interesting stability properties based
on the value of θ:
θ = 0 Forward Euler, which is unstable (FTCS).
θ < 1/2: Negative diffusion and the scheme is unstable.
θ = 1/2: No diffusion and stable (Crank-Nicolson).
θ > 1/2: Positive diffusion and stable with first-order time accuracy.
θ = 1: Backward Euler, which is stable (BTCS).
This stability character can be plotted if we analyze the model ODE
Du
= λu ,
Dt
which, after employing the theta method, yields
un+1 = un + λhθun+1 + λh (1 − θ) un ,
(1 − λhθ) un+1 = [1 + λh (1 − θ)] un ,
un+1 1 + λh (1 − θ)
Gn = n = .
u 1 − λhθ
The stability boundaries for different values of θ are plotted in Figure 1.
When θ > 0.5, the method is formally first-order accurate in time and damped, so that all
wave motions are damped in time. We can obtain an analytical solution for the modified
equivalent partial differential equation by assuming the solutions of the form
h(x, t) = b
h(t) exp(ikx) , (6)
u(x, t) = u
b(t) exp(ikx) . (7)
Assuming that the momentum equation is solved exactly, and that the theta method results
in the modified equivalent pde given in equation (5), substitution of (6) and (7) results in
Db
u
+ ikgb
h = 0, (8)
Dt
Db
h
u = −c2 k 2 ∆t(θ − 1/2)b
+ ikdb h. (9)
Dt
Differentiating (9) in time gives
d2b
h Db
u 2 2 Db
h
+ ikd = −c k ∆t(θ − 1/2) . (10)
dt2 Dt Dt
CEE363c Lecture 9 4
3
θ = 1/2
θ = 3/4
2 θ = 1/4
1 θ=1
Im(λ h)
0
θ=0
−1
−2
−3
−3 −2 −1 0 1 2 3
Re(λ h)
Figure 1: Stability boundaries for the theta method. The arrows imply the side of the
countour that is stable.
The time derivative of u
b is given by equation (8) as
Db
u
= −ikgb
h,
Dt
which is substituted into equation (10) to obtain an equation for b
h as a second-order damped
harmonic oscillator
d2b
h Dbh
+ c 2 2
k ∆t(θ − 1/2) + c2 k 2 b
h = 0,
dt2 Dt
d2b
h Dbh
+ ω 2
∆t(θ − 1/2) + ω 2b h = 0, (11)
dt2 Dt
where c2 = gd is the shallow-water wave speed and ω = ck is the wave frequency. Suppose
we would like to compute the oscillations of a standing wave with an initial free-surface
distribution given by
h(x, t = 0) = a cos(kx) ,
where k = π/L, as shown in Figure 2. Using this initial condition, bh(t = 0) = a, and the
solution to (11) is given by
b
h(t) = a cos(ωt) exp −ω 2 ∆t(θ − 1/2)t ,
CEE363c Lecture 9 5
so that the solution to the modified equivalent pde which includes the effects of the theta
method is given by
h(x, t) = a cos(kx) cos(ωt) exp −ω 2 ∆t(θ − 1/2)t . (12)
This solution is compared to the result of using the θ method as described in Lecture 8 in
Figure 3 and shows how the θ method increasingly damps the solution as θ approaches 1.
These results were obtained with a Courant number of C = c∆t/∆x = 1 and with 50 grid
cells in a domain with L = 1000 m, d = 10 m, and g = 10 m2 s−1 . The analytical results are
virtually indistinguishable from the numerical results when C = 1, but when C = 5, there is
a clear difference, particularly for θ = 1.0, which results because, in addition to increasing
the decay rate, the numerical error also results in a phase lag. As suggested by the analysis
in Lecture 8, the stability bounds do not specify a maximum value of θ, although values of
θ > 1 are extremely damped, as shown in Figure 5, which shows how the analytical result
(refeq:ah) still holds when θ = 10 but fails when θ = 0.45, since the numerical solution is
unstable.
Figure 2: Schematic of the initial condition for the free-surface seiche.
CEE363c Lecture 9 6
θ = 0.5
1
θ = 0.55
0.8
0.6 θ = 0.75
0.4
θ=1
0.2
h(x=0)/h0
−0.2
−0.4
−0.6
−0.8
−1
0 1 2 3 4 5 6 7 8
t/T0
Figure 3: Comparison of a solution of the shallow water equations using the theta method
(solid line −) to the analytical solution at x = 0 (dotted line · · ·) with the initial condition
given in Figure 2 with a Courant number of 1. The dashed line corresponds to the expo-
nentially decaying function exp[−ω 2 ∆t(θ − 1/2)t], while h0 = a is the initial amplitude, and
T0 = 2π/ω is the period.
CEE363c Lecture 9 7
θ = 0.5
1
0.8 θ = 0.55
0.6
0.4 θ = 0.75
0.2
θ=1
h(x=0)/h0
−0.2
−0.4
−0.6
−0.8
−1
0 1 2 3 4 5 6 7 8
t/T0
Figure 4: Same as Figure 3 except with a Courant number of C = 5.
1
θ = 0.45
0.8
0.6
0.4
θ = 10
0.2
h(x=0)/h0
−0.2
−0.4
−0.6
−0.8
−1
0 0.5 1 1.5 2 2.5 3
t/T0
Figure 5: Same as Figure 3 except with different values of θ.
CEE363c Lecture 9 8
Discretization using leapfrog
The disadvantage to using the theta method is that it requires a matrix inversion (for the
two-dimensional problem) which can be expensive when the Courant number c∆t/∆x is not
necessarily large for accuracy reasons. In this case, which results when accuracy may be
desired for the short timescales associated with fast waves, or when an undamped solution is
desired, then it is advantageous to employ the non-dissipative leapfrog method. Beginning
with the linearized form of the Saint-Venant equations
∂u ∂h
+g = 0, (13)
∂t ∂x
∂h ∂u
+d = 0, (14)
∂t ∂x
a finite-difference approximation to these equations is given by
n+1/2 n−1/2
ui+1/2 − ui+1/2 hni+1 − hni
+g = 0, (15)
∆t ∆x
n+1/2 n+1/2
hn+1
i − hni ui+1/2 − ui−1/2
+d = 0, (16)
∆t ∆x
where now u and h are staggered in both space and time, as shown in Figure 6. Taking
Taylor series to expand the terms in the continuity equation gives
n+1/2∆t ∆t2 ∆t3
hn+1
i = hi (ht )n+1/2
+ i + (h tt )n+1/2
i + (httt )n+1/2
i + O ∆t4
,
2 8 24
n+1/2 ∆t ∆t2 ∆t3
hni = hi − (ht )n+1/2
i + (h )
tt i
n+1/2
− (httt )n+1/2
i + O ∆t4 ,
2 8 24
n+1/2 n+1/2 ∆x ∆x 2
∆x3
ui±1/2 = ui ± (ux )n+1/2
i + (u xx )n+1/2
i ± (u xxx )n+1/2
i + O ∆x 4
.
2 8 24
Substitution into (16) gives
∆t2 ∆x2
(ht )n+1/2
i + n+1/2
(httt )i + O ∆t 3 n+1/2
= −d (ux )i + (uxxx )n+1/2
+ O ∆x 3
.
24 24
1 2
(ht )n+1/2
i + d (u )n+1/2
x i = − ∆t (h )n+1/2
ttt i + d∆x 2
(u xxx )n+1/2
24
+O ∆t3 , ∆x3 .
To convert the third-order time derivative to a spatial derivative, we begin with the continuity
equation and differentiate in the usual way
ht = −dux ,
htt = −duxt ,
= gdhxx , (17)
CEE363c Lecture 9 9
Figure 6: The spatially and temporally staggered grid layout for the leapfrog discretization
of the shallow water equations.
where uxt = −ghxx from the momentum equation. Differentiating again with respect to
time, we have
httt = gdhxxt ,
= gd(−dux )xx ,
= −gd2 uxxx ,
so that the modified equivalente pde becomes, after dropping the sub- and superscripts,
1
ht + dux = − −gd2 ∆t2 uxxx + d∆x2 uxxx + O ∆x3 , ∆t3 ,
24
d∆x2 gd∆t2 3 3
= − 1− u xxx + O ∆x , ∆t ,
24 ∆x2
∂h ∂u d∆x2 ∂ 3u
+d = − 1 − C2 + O ∆x 3
, ∆t3
,
∂t ∂x 24 ∂x3
CEE363c Lecture 9 10
√
where the Courant number is C = c∆t/∆x and c = gd. This equation shows the following
behavior for the leapfrog method based on the Courant number:
C > 1 Positive dispersion; scheme is unstable.
C = 1 No dispersion; scheme is stable and O (∆t3 ).
C < 1 Negative dispersion; scheme is stable and O (∆t2 ).
When the nonlinear equations are discretized, spatial and temporal interpolations must
be performed to extract the flux-face heights in the nonlinear depth-averaged continuity
equation. As an example, consider the same discretization of
n+1/2
∂h ∂
+ (Hu) = 0,
∂t ∂x i
n+1/2 n+1/2 n+1/2 n+1/2
hn+1
i − hni Hi+1/2 ui+1/2 − Hi−1/2 ui−1/2
+ = 0.
∆t ∆x
Because h is stored at time steps n, the most accurate method to discretize this equation
would be to incorporate a time- and space- interpolation of the form (assuming d is constant)
n+1/2 1 n
Hi+1/2 = d + hi + hni+1 + hn+1
i + hn+1
i+1 .
4
However, this would lead to a nonlinear system of equations for hn+1
i . Evaluation of the
flux-face height using lagging would make for a much more practical solution, such that
n+1/2 1 n
Hi+1/2 = d + hi + hni+1 .
2
The more common method of employing leapfrog for the nonlinear equations is to stagger
the variables space but not in time on the same grid that the theta method is employed,
such that
un+1 n−1
i+1/2 − ui+1/2 uni+3/2 − uni−3/2
hni − hni−1
+ uni+1/2 +g = 0,
2∆t 2∆x ∆x
n
hn+1
i − hin−1 Hi+1/2 uni+1/2 − Hi−1/2
n
uni−1/2
+ = 0,
2∆t ∆x
where now the flux-face heights can be evaluated at time step n without incurring a loss of
temporal accuracy. They are approximated as averages on either side of the faces with
n 1 n
Hi±1/2 =d+ hi + hni±1 .
2