SF2521NPDE hmwk1-2
SF2521NPDE hmwk1-2
Topics: Stability of numerical schemes; Conservation form; Relation between non-linear and
linearized problems; The Shallow- water equations; The Lax-Friedrichs Scheme; Solution by
characteristics; Boundary conditions.
Purpose: (1) Understand how inhomogeneous term in a numerical scheme affect the solutions.
(2) Get acquainted with elementary properties of and solution schemes for initial-boundary value
problems for hyperbolic systems.
Instructions: Write a short report with the plots and answers to the questions posed. Make
sure the plots are annotated and there is explanation for what they illustrate. Consult the
canvas course page for further details about writing a report.
1. [1/2 point] Let Q(t) be an approximation to an exact solution of a differential equation, q(t),
such that Q(t + ∆t) = SQ(t), q(t + ∆t) = Rq(t), and Q(0) = q(0). Then after n−time steps
n
!
X
n n n−k k−1
Q(t + ∆t) − q(t + ∆t) = (S − R )q(0) = S (S − R)R q(0),
k=1
where accuracy of the discretization is represented by ∥Sq − Rq∥ ≤ C1 ∆tp+1 for q being
a smooth solution and for n∆t ≤ T . Here, p + 1 represents the order of accuracy of the
discretization, the well-posedness is represented by ∥q(t + ∆t)∥ ≤ C2 ∥q(0)∥ and stability of
the approximation is represented by ∥Q(t + ∆t)∥ ≤ C3 ∥q(0)∥. Determine the bound on the
error.
2. [1/2 point] Let xi = 21 xi−1/2 + xi+1/2 be the cell center of a one-dimensional finite volume
discretization. Show that the cell average, Q, is a second order approximation to the exact
solution, q, at the cell midpoint. That is, show
where Z xi+1/2
1
Qi (t) = q(x, t) dx
∆x xi−1/2
(a) For the above system, show that we can assign one boundary condition at x = 0 and
two boundary conditions at x = 1.
(b) Compute the characteristic variables, z, for the above system in terms of the primitive
variables, q.
(c) Determine boundary conditions that can be assigned to the characteristic variables, z,
that will be equivalent to assigning Dirichlet boundary conditions q1 (1, t) = 1, q2 (1, t) =
sin 2t and q3 (0, t) = cos 2t.
4. Given the equation
u2
ut + = 0, x ∈ [−1, 1]. (1)
2 x
We will consider two different initial conditions:
1
u(x, 0) =1 − sin(πx) (2)
( 2
0, −1 ≤ x < 0
u(x, 0) = . (3)
1, 0≤x≤1
For the sine initial condition, we use periodic boundary conditions. For the piecewise
constant initial condition, we implement the exact boundary condition.
(a) [2 points] Behavour of solutions:
i. Given a general initial condition, u(x, 0) = v(x), determine the implicit solution
for Burgers equation (1).
ii. Prove that the solution obtained in Exercise (i) satisfies equation (1).
iii. Compute the maximum and minimum values of the two initial conditions ((2) and
(3)). Use the result to plot the time evolution of the characteristics for these values
for 0 ≤ t ≤ 1.5.
iv. Compute the time t = t∗ at which the characteristics first intersect, if they inter-
sect.
(b) [1 point] For the solution to equation (1) using initial condition (2), a reference solution
will be needed to assess the quality of the initial approximation. To construct this
reference solution, a nonlinear implicit solver (e.g. a root finding method such as
Newton-Raphson) is used. Construct a reference solution for Burgers equation using
an inbuilt nonlinear implicit solver and graph the solution up to t = t∗ .
(c) [8 points] To construct an approximation to equation (1), a finite volume scheme will
be implemented. The general one-dimensional finite volume scheme can be written as
∆t b
Qn+1
i = Qni − Fi+1/2 − Fbi−1/2 , i = 1, . . . , N,
∆x
where Fbi+1/2 is the numerical flux. In this homework, the Lax-Friedrichs flux:
LxF 1
Fbi+1/2 = f (Qni+1 ) + f (Qni ) − αi+1/2
LxF
(Qi+1 − Qi )
2
LF
with αi+1/2 = maxQi ,Qi+1 |f ′ (Q)| and the Lax-Wendroff flux:
LW 1 1 n n ∆t LW 1
Fi+1/2 =
b f (Qi+1 ) + f (Qi ) − α (Qi+1 − Qi )
2 2∆x i+1/2
LW 1 = f ′ Qi +Qi+1 will be used.
with αi+1/2 2
i. Consider initial condition (3). Take a series of meshes consisting of N = 20, 40, 80, 160
elements and let ∆t = λ∆x.
α) Determine λ using the Lax-Friedrichs Flux and compare that to the value of
λ when using the Lax-Wendroff flux. Discuss the motivation for choosing the
value of λ.
Page 2
β) Make a table displaying the {ℓ1 , ℓ2 , ℓ∞ }−errors and corresponding orders of
accuracy for the two schemes using the series of meshes. Make log-log plots
of N vs {ℓ1 , ℓ2 , ℓ∞ }−error. What do the slopes of the plots indicate? Note
that
N
1 X
∥u−uh ∥ℓ1 = |u(xj , t)−uh (xj , t)|, ∥u−uh ∥ℓ∞ = max |u(xj , t)−uh (xj , t)|.
N xj
j=1
ii. Take N = 160 elements and consider both initial conditions ((2) and (3)):
α) Plot the cell average, Qni , and exact solution as well as the errors for the two-
initial conditions for 0 ≤ t ≤ 1.1. State your observations on the evolution
of the cell average and errors for the different initial conditions and different
fluxes.
β) At every time-step, calculate the discrete ℓ1 −errors. Construct a plot of time
versus the ℓ1 −errors for 0 ≤ t ≤ 1.1. State your observations on the evolution
of the ℓ1 − errors for the different initial conditions and different fluxes.
Total: 15
Page 3
F1/2 F3/2 F5/2 FN −5/2 FN −3/2 FN −1/2 FN +12
q0 q1 q2 ··· qN −2 qN −1 qN qN +1
Page 4
– Initially, plotting and printing allows you to inspect the approximation, fluxes, and other
ingredients at each time step; turn off the plotting and printing when the code works.
– To avoid having to repeat computations, make sure you are saving your data to a file. Later
on you may need to read in your data and construct an interpolant. This will allow you
to do a pointwise comparison of solutions (in time and space) from different grids and with
different parameter settings, e.g. for showing convergence in L2 −norm and showing several
solutions in one plot.
– Many editors have debugging options – use them; once your code is working reasonably well
you can profile your code to see which part of your code is taking the most computational
time and check that there is a way to make your code faster.
– Note that the most common bugs in coding, aside from sign errors, are from incorrect bound-
ary conditions or not satisfying the cfl condition.
– Do not use ”l” for an index or variable name, it looks too similar to ”1”.
• Order to check your code (for a linear equations – non-linear equations are a bit more complicated):
– For systems, check that you have the correct eigenvalue decomposition.
– First check your code is working for smooth solutions and periodic boundary conditions.
– You can then check your code is working for smooth solutions and, if applicable, (i) Dirichlet,
(ii) Neumann, (iii) Robin boundary conditions.
– Check how your code performs for non-smooth solutions and periodic boundary conditions.
Note that you will not see the expected convergence rates due to the non-smooth parts.
However, you should still be able to produce reasonable approximations.
– You can then check that the other boundary conditions are working.
• Calculating the order of accuracy requires two levels of resolution (and to check that the approxi-
mation is indeed converging asymptotically requires more).
References
[1] Leveque R.J., Finite-Volume Methods for Hyperbolic Problems, Cambridge University
Press, 2002.
[2] Gustafsson B., Kreiss H.-O., Time-Dependent Problems and Difference Methods (2nd ed.),
John Wiley & Sons, 2013.
[3] Kreiss H.-O., Lorenz J., Initial-Boundary Value Problems and the Navier-Stokes Equa-
tions, SIAM Society for Industrial and Applied Mathematics.
Page 5