Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Master in Applied and Computational Mathematics Year 2022/2023

Computational Techniques for Differential Equations


Assignment 4

The wave equation

In one spatial dimension, the wave equation has the general form

∂2u 2
2∂ u
= a
∂t2 ∂x2
where, for simplicity, we will assume that a is constant. Observe that it is possible to rewrite
the wave equation as a system of coupled first-order PDE
∂r ∂s


 = a



 ∂t ∂x
∂s ∂r

= a


 ∂t ∂x
 ∂u =


s

∂t
where
∂u ∂u
r=a and s= .
∂x ∂t

The first two equations can be symbolically written in conservative form as

∂U ∂F (U )
+ = 0, (1)
∂t ∂x
where
" # " #
r 0 −a
U= and F (U ) = U.
s −a 0

The Lax-Friedrichs Scheme

We can apply the Lax-Friedrichs scheme to the solution of the wave equation through the
first-order system (1) and easily obtain
1 n ν
rjn+1 = n
(rj+1 + rj−1 ) + (snj+1 − snj−1 ),
2 2
1 n ν n
sn+1 = (s n
+ sj−1 ) + (rj+1 n
− rj−1 ).
j
2 j+1 2
where ν = ak/h. Once the value of sn+1
j has been calculated, the value for un+1
j can be com-
puted according to
un+1
j = unj + ksnj .

1
Master in Applied and Computational Mathematics Year 2022/2023

The Leapfrog Scheme

We can adapt the Leapfrog scheme to equations (1) for the solution of the wave equation in
one dimension, centring variables on appropriate half-mesh points
∂u n unj+1 − unj

n
rj+ 1 := a ≈ a , (2)
2 ∂x j+ 1 h
2
n+ 1
n+ 1 ∂u 2 un+1
j − unj
sj 2 := ≈ , (3)
∂t j k

and then considering the Leapfrog representation of equations (1)

n+1 n n+ 1 n+ 12
1 + ν(sj+1 − sj
2
rj+ 1 = rj+ ), (4)
2 2
n+ 12 n− 12 n n
sj = rj + ν(rj+ 1 − r ). (5)
2
j− 12

As in the previous scheme, the new value for the wave variable u is finally computed after
the integration in time of s. Here however, to preserve the second-order accuracy in time it is
necessary to average the time derivative s between n and n + 1 to obtain
k k n+ 1
un+1
j = unj + (sn+1
j + snj ) = unj + sj 2 + O(k 2 ).
2 2

A simple substitution of (2) and (3) into (4) and (5) shows how the Leapfrog representation
of the wave equation is nothing but its second-order differencing

un+1 − 2unj + un−1


 n
uj+1 − 2unj + unj−1

j j 2
=a
k2 h2
so that the solution at the new time-level is

un+1
j = ν 2 unj+1 + 2(1 − ν 2 )unj + ν 2 unj−1 − ujn−1 .

Note that by doing this, the Leapfrog scheme has been effectively recast into a “one-level”
scheme.

The Lax-Wendroff Scheme

We can start with the time evolution of the variable r to obtain


 
n+1/2 n+1/2
rjn+1 = rjn + ν sj+1/2 − sj−1/2

where the terms in the spatial derivatives are computed as


n+1/2 1 n
sj+1/2 = (s + snj ) + ν(rj+1
n
− rjn ),
2 j+1
n+1/2 1 n
sj−1/2 = (s + snj−1 ) + ν(rjr − rj−1
n
).
2 j

2
Master in Applied and Computational Mathematics Year 2022/2023

It is convenient to combine these equations into two “one-level” evolution equations

ν ν2 n
rjn+1 = rjn + (snj+1 − snj−1 ) + (rj+1 − 2rjn + rj+1
n
),
2 2
ν n ν2
sn+1
j = snj + (rj+1 n
− rj−1 ) + (snj+1 − 2snj + snj+1 ).
2 2
Again, to preserve the second-order accuracy in time it is necessary to average the time deriva-
tive s between n and n + 1 to obtain
k
un+1
j = unj + (sn+1 + snj ).
2 j

Question 1

(a) Which is the expected rate of convergence of each of the methods described above?
Hint: obtain the local truncation error.

(b) Calculate the corresponding stability conditions (or, at least, justify them).
Hint: use Von-Neumann analysis (or some of the arguments discussed in class)

Boundary conditions

Unavoidable and common to all the numerical schemes discussed so far is the problem of
treating the solution on the boundaries of the spatial grid as the time evolution proceeds.
Some boundary conditions of general interest are:

ˆ Dirichlet-type boundary conditions: values of the relevant quantity are imposed


at the boundaries of the numerical grid. These values can be either functions of time
or be held constant. Within this type, periodic boundary conditions are often used. As
discussed in class, this is
un+1
0 = un+1
m+1 .

ˆ Neumann-type boundary conditions: values of the derivatives of the relevant quan-


tity are imposed at the boundaries of the numerical grid. As for Dirichlet, these values
can be either functions of time or be held constant. Within this type, reflecting bound-
ary conditions
ux = 0

mimic the presence of a reflecting boundary, i.e., of a boundary with zero transmission
coefficient. Observe that this condition enforced at x0 leads to
u1 − u−1
= 0 =⇒ u1 = u−1 .
2h

3
Master in Applied and Computational Mathematics Year 2022/2023

ˆ Sommerfeld boundary conditions (or radiative boundary conditions): this is the


most natural boundary conditions for the evolution of a wave equation. Consider a
scalar wave outgoing in the positive x-direction which is described by the advection
equation
∂u ∂u
+a = 0.
∂t ∂x
A finite-difference, first-order accurate representation of equation which is centered in
both time (at n + 21 ) and in space (at j + 12 ) is given by

1 h n+1 i a h n+1 i
(uj+1 + un+1
j ) − (un
j+1 + un
j ) = − (uj+1 + un
j+1 ) − (un+1
j + un
j )
2k 2h
and which leads to

un+1 n+1
j+1 (1 + ν) = −uj (1 − ν) + unj+1 (1 − ν) + unj (1 + ν).

This can be written as

un+1 n n+1
j+1 = uj − uj Q + unj+1 Q, (6)

(1 − ν)
where Q = . This equation will provide first-order accurate and stable bound-
(1 + ν)
ary conditions. Note, however, that this is a discrete representation of a physical condi-
tion which would transmit the wave without reflection. In practice, however, a certain
amount of reflection is always produced (the transmission coefficient is never exactly
one); the residual wave is then transmitted back in the numerical box. A few reflections
are usually sufficient to reduce the wave content to values below the machine accuracy.
Similarly, a scalar wave outgoing in the negative x-direction (or ingoing in the positive
one) described by ut − aux = 0, leads to

un+1
j = unj+1 − un+1 n
j+1 Q + uj Q, (7)

where Q is the same quantity as for the out-going wave. If we use equations (6) and (7)
to evolve the solution at time-step n + 1 at the boundary of our spatial grid, we are
guaranteed that our profile will be completely transported away, whatever integration
scheme we are adopting (Leapfrog, Lax-Wendroff, etc).

Question 2

Consider the 1D wave equation

utt = uxx , −1 < x < 1 t > 0, (8)


2
with the initial conditions u(x, 0) = e−200x and ut (x, 0) = 0.

4
Master in Applied and Computational Mathematics Year 2022/2023

(a) Implement each of the numerical schemes above to solve the PDE problem (8) with ho-
mogeneous Dirichlet boundary conditions. Integrate until T = 4 and use, for instance,
the command waterfall in MATLAB. You should obtain a graph similar to Figure 1.
Run experiments to prove convergence at the expected rate.

Figure 1: Numerical solution of the PDE problem (8)

(b) Choose the Leapgrog scheme to solve the PDE problem (8) with boundary conditions:

ˆ u(−1, t) = 0 and ux (1, t) = 0.


ˆ Periodic.
ˆ Sommerfeld at x = 0 and ux (1, t) = 0.

(c) The initial condition ut (x, 0) = −ux (x, 0) corresponds to a left-moving Gaussian pulse
which can be approximated by
2
u(x, −k) = e−200(x−k) .

Implement this case with u(−1, t) = 0 and ux (1, t) = 0.

In all them, integrate until T = 4 and use the command waterfall as in Figure 1.

You might also like