0% found this document useful (0 votes)
114 views5 pages

SF2521NPDE hmwk1-2

This homework assignment involves numerical solutions to partial differential equations using finite volume methods. Students are asked to: 1) Analyze the stability and accuracy of numerical schemes for differential equations. 2) Implement finite volume schemes like Lax-Friedrichs and Lax-Wendroff to solve the Burgers' equation with different initial conditions. 3) Compare the errors and convergence of the schemes using various mesh sizes. 4) Observe the evolution of cell averages and errors over time for different initial conditions and fluxes. The homework provides suggestions for structuring code to solve a general conservation law using interchangeable functions for the initial condition, boundary condition, and flux.

Uploaded by

BlooD LOVER
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views5 pages

SF2521NPDE hmwk1-2

This homework assignment involves numerical solutions to partial differential equations using finite volume methods. Students are asked to: 1) Analyze the stability and accuracy of numerical schemes for differential equations. 2) Implement finite volume schemes like Lax-Friedrichs and Lax-Wendroff to solve the Burgers' equation with different initial conditions. 3) Compare the errors and convergence of the schemes using various mesh sizes. 4) Observe the evolution of cell averages and errors over time for different initial conditions and fluxes. The homework provides suggestions for structuring code to solve a general conservation law using interchangeable functions for the initial condition, boundary condition, and flux.

Uploaded by

BlooD LOVER
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SF2521: Numerical Solution to Partial Differential Equations Homework 1

Spring 2023 Due: 17 February 2023

*For this homework only, assignments will be accepted until 20/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

q(xi , t) − Qi (t) = O(∆x2 ),

where Z xi+1/2
1
Qi (t) = q(x, t) dx
∆x xi−1/2

is the cell average.

3. [3 points] Consider the system of equations:


 
−5/3 −1 −5/3
qt + +1/3 1 +7/3 qx = 0,
−1/3 1 −1/3

(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

x1/2 x3/2 x3/2 xN −5/2 xN −3/2 xN −1/2 xN +1/2


| {z }
∆x

Suggestions for program structure


The homework assignments in this course requires coding of finite volume schemes for several different
initial-boundary value problems as well as several different models. The schemes are mostly explicit and
suggestions for the program structure are below. You can, of course, write your code in the manner that
you find practical.
A suggested program structure: Since this course is mostly working with equations that can be
written in the form:
qt + f (q)x = 0,
a generalized code can be written using interchangable functions for the initial condition, boundary
condition, and flux function. For example, most finite volume schemes 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. Then the pseudo-code is:


Mesh: Define the mesh, time step, as well as any other global parameters.
IC: Define the initial condition. That is, the state variables, q, for a system of s equations is an N × s
array, i.e., Q(0 : N + 1, 1 : s), where Q(0, 1 : s) and Q(N + 1, 1 : s) define the array for the ghost
cells.
RT
0
dt: During the time evolution:
BC: Define ghost cells 0 and N + 1 by using the boundary conditions; and augment Q by rows
for the ghost cells 0 and N + 1.
F:
b ∗ Compute the numerical fluxes Fbi+1/2 , i = 0, 1, . . . , N . This may entail much more
computation than evaluating the flux function f which defines the differential equation.
For Lax-Friedrichs scheme it is not much more, i.e., f (q) is a function that you define
that is then put into the function that calculates the numerical flux.
∗ Compute the flux differences, Fbi+1/2 − Fbi−1/2 , i = 1, . . . , N .
Qn+1 Update the cells 1, . . . , N at the new time and set t = t + ∆t.
– Repeat the previous steps until the final time is reached.
Plots: Write a separate routine that calculates the errors as well as order of accuracy, makes the necessary
plots, and outputs the errors.
Further suggestions:
• To debug:
– First check that you obtain the expected order of accuracy for the initial condition.
– Evolve the approximation in time by only one time-step, ∆t, and check that this order of
accuracy is maintained. Also check that there are no non-physical oscillations propagating
into the domain from the boundaries. After correcting any mishaps, run your code for a
longer time and check that the code still works.

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

You might also like