Conservation Laws and Finite-Volume Methods

Conservation Laws and Finite-Volume Methods
Knut–Andreas Lie
Dept. of Informatics, University of Oslo
INF2340 / Spring 2005 – p. 1
Conservation Laws
A fundamental modelling principle for physical systems is the
conservation of a given quantity Q:
change of Q
volume Ω
!
=
flux F over the
boundary of Ω
!
Examples of conserved quantities:
• mass
• momentum
• energy
Conservation laws are basic building blocks when studying the
behaviour of fluids.
INF2340 / Spring 2005 – p. 2
A Motiviation Example: Pipe Flow
ρ(x,t)
h(x)
x
• Consider a one-dimensional pipe parametrised with the
variable x
• At every point x, the pipe has a cross-section h(x)
• The pipe is filled with a fluid of density ρ(x, t) (which is
constant in the cross-sectional direction).
INF2340 / Spring 2005 – p. 3
Pipe Flow: Derivation of Conservation Law
a
b
• Let us now consider a section of the pipe x ∈ [a, b]
• Assume that the fluid flows with a velocity u(x, t) (which we
for the moment assume is positive so that all fluid flows in
the positive x-direction)
• Assume that no fluid is created or destroyed at any point
inside the section
INF2340 / Spring 2005 – p. 4
Derivation of Conservation Law, cont’d
a
b
Conservation law:
time rate of change of fluid
inside the section[a, b]
!
=
flow into the pipe
at x = a
!
−
flow out of the pipe
at x = b
Mathematically, an equation on integral form:
d
dt
Z
a
b
ρ(x, t)h(x) dx = ρ(a, t)u(a, t)h(a) − ρ(b, t)u(b, t)h(b)
INF2340 / Spring 2005 – p. 5
!
Derivation of Conservation Law, cont’d
Let us rewrite the conservation law:
Z b
d
ρ(x, t)h(x) dx = ρ(a, t)u(a, t)h(a) − ρ(b, t)u(b, t)h(b)
dt a
Z b
∂ =−
ρ(x, t)u(x, t)h(x) dx
a ∂x
Now, since the section [a, b] does not move in time:
Z b
∂
∂ ρ(x, t)h(x) +
ρ(x, t)u(x, t)h(x) dx = 0
∂t
∂x
a
If the equation holds for all a, b and the integrand is continuous,
then:
∂
∂
ρh +
ρuh = 0
∂t
∂x
INF2340 / Spring 2005 – p. 6
Closure of the Model
Our model so far:
∂
∂
ρh +
ρuh = 0
∂t
∂x
To close the model, we must specify
• the velocity: u(x, t) = f x, t, ρ ,
• the initial data: ρ(x, 0) = ρ0 (x)
• and some boundary data, e.g, a given value at the inflow
and outflow boundaries
ρ(x1 , t) = ρ1 (t),
ρ(x2 , t) = ρ2 (t)
or a given inflow value and free outflow
ρ(x1 , t) = ρ1 (t),
∂x ρ(x2 , t) = 0
INF2340 / Spring 2005 – p. 7
Example: Advection Equation
In the case where h(x) ≡ 1 and u(x, t) does not depend on the
unknown ρ, the conservation law reduces to the linear advection
equation
∂ρ ∂ρu
+
= 0,
ρ(x, 0) = ρ0 (x)
∂t
∂x
This equation is hyperbolic and describes the passive advection
of a quantity ρ within a given velocity field u.
Let us now consider a particularly simple example, for which
u(x, t) ≡ c > 0, i.e.,
∂ρ
∂ρ
+c
= 0,
∂t
∂x
ρ(x, 0) = ρ0 (x)
INF2340 / Spring 2005 – p. 8
Solving the Advection Equation
To solve the advection equation, we perform a change of
variables
τ = t,
ξ = x − ct
Using the chain rule:
∂τ ∂
∂ξ ∂
∂
∂
∂
=
+
=
−c
∂t
∂t ∂τ
∂t ∂ξ
∂τ
∂ξ
∂τ ∂
∂ξ ∂
∂
∂
=
+
=
∂x
∂x ∂τ
∂x ∂ξ
∂ξ
Hence:
∂ρ
∂ρ ∂ρ
∂ρ ∂ρ
∂ρ
+c
+c
=
−c
=
0=
∂t
∂x
∂τ
∂ξ
∂ξ
∂τ
INF2340 / Spring 2005 – p. 9
Solving the Advection Equation, cont’d
This is easy to solve:
∂ρ
=0
∂τ
=⇒
ρ = ρ(ξ)
From the initial condition:
ρ(x, t) = ρ(ξ) = ρ(ξ, τ = 0)
= ρ0 (ξ) = ρ0 (x − ct)
In other words, the profile of the solution is shifted in the positive
x-direction with time, but the shape does not change
The lines x − ct = constant are called the characteristics of the
equation. If we know the solution ρ(x, t) at one point on a
characteristic, we also know it at all other points on the same
characteristic.
INF2340 / Spring 2005 – p. 10
What About Discontinuous Data?
Well, the integral equation is still valid:
d
dt
Z
a
b
ρ(x, t)h(x) dx = ρ(a, t)u(a, t)h(a) − ρ(b, t)u(b, t)h(b)
However, we cannot derive a PDE as above. Instead we define
a so-called weak solution that satisfies
Z ∞Z ∞
∂φ
∂φ
ρh +
ρuh dxdt = 0,
∂x
0
−∞ ∂t
for a sufficiently smooth function φ(x, t)
INF2340 / Spring 2005 – p. 11
Example: Burgers’ Equation
Assume now that the velocity u = 12 ρ. This gives Burgers’
equation
∂ρ
∂ 1 2
+
ρ =0
∂t
∂x 2
Burgers’ equation is a simple nonlinear equation is often used
as a model for the momentum equations in fluid mechanics
INF2340 / Spring 2005 – p. 12
The Method of Characteristics
In order to use our previous method of characteristics, we
rewrite the equation as
∂ρ
∂ρ
+ρ
=0
∂t
∂x
Now we can introduce a change of variables as above
τ = t,
ξ = x − ρt
which gives
∂ρ
= 0,
∂τ
ρ(ξ) = ρ0 (ξ)
INF2340 / Spring 2005 – p. 13
The Method of Characteristics, cont’d
Problem: the characteristics depend on the solution
−→ triple-valued solutions reminiscent of ‘breaking waves’.
This is clearly not mathematically valid
INF2340 / Spring 2005 – p. 14
Burgers Equation: Correct Solution
The correct solution forms a discontinuity (a so-called shock)
where the characteristics meet
INF2340 / Spring 2005 – p. 15
Shocks and Other Discontinuities
Observation: The method of characteristics failed to give
mathematically feasible solutions.
Solution: use our definition of weak solutions
Z ∞Z ∞
∂φ
∂φ
ρ+
f (ρ) dxdt = 0,
∂t
∂x
0
−∞
Introduce shock waves that are propagating discontinuities that
satisfies
f (ρL ) − f (ρR )
dx
=
dt
ρL − ρ R
where ρL and ρR are the left and right values, respectively.
INF2340 / Spring 2005 – p. 16
The Method of Characteristics, revisited
Consider now initial data of the
form
(
0, x < 0
ρ0 (x) =
1, x > 0
How do we fill the missing part?
Use a piecewise linear wave?
Generally: several weak solutions are possible!
We need extra conditions to determine correct solution (e.g., by
incorporating viscosity, which has been neglected in the model,
and study the vanishing viscosity limit).
INF2340 / Spring 2005 – p. 17
Example: A Traffic Model
xL
xR
• Density of cars:
ρ
• Velocity of each car:
u(ρ) = ρm − ρ
• Conservation of ’mass’:
ρ(t + ∆t) − ρ(t) (xL − xR ) = ∆t ρL u(ρL ) − ρr uR (ρR )
• In the limit, xR → xL , ∆t → 0
ρt + f (ρ)x = 0,
f (ρ) = ρu(ρ) = ρ(ρm − ρ)
INF2340 / Spring 2005 – p. 18
The Traffic Light Turns Red
Tetthet ved tid 0.0
Tetthet ved tid 20.0
1
1
0.5
0.5
0
−5
2
0
0
5
10
−5
2
0
0
−2
−2
−4
−4
−6
−6
−8
−8
−10
−10
−12
−12
−14
−14
−16
−5
0
5
10
−16
−5
0
5
10
0
5
10
INF2340 / Spring 2005 – p. 19
The Traffic Light Turns Green
Tetthet ved tid 0.0
Tetthet ved tid 10.0
1
1
0.5
0.5
0
−10
2
0
−8
−6
−4
−2
0
2
4
6
8
10
−10
2
0
0
−2
−2
−4
−4
−6
−6
−8
−8
−10
−10
−8
−6
−4
−2
0
2
4
6
8
10
−10
−10
−8
−6
−4
−2
0
2
4
6
8
10
−8
−6
−4
−2
0
2
4
6
8
10
INF2340 / Spring 2005 – p. 20
A Local Congestion in the Traffic
Tetthet ved tid 0.0
Tetthet ved tid 20.0
1
1
0.5
0.5
0
−20
2
0
−15
−10
−5
0
5
10
15
20
25
30
35
−20
2
0
0
−2
−2
−4
−4
−6
−6
−8
−8
−10
−10
−12
−12
−14
−14
−16
−20
−15
−10
−5
0
5
10
15
20
25
30
35
−16
−20
−15
−10
−5
0
5
10
15
20
25
30
35
−15
−10
−5
0
5
10
15
20
25
30
35
INF2340 / Spring 2005 – p. 21
Linear Systems of Conservation Laws
Consider the linear system
Ut + AUx = 0,
U (x, 0) = U0 (x)
Hyperbolicity means that A is diagonalisable with real
eigenvalues λi :
A = RΛR−1 ,
Λ = diag(λ1 , . . . , λm )
where each column ri of R is a right eigenvector of A
Now, premultiply the conservation law by R−1 and define
V = R−1 U . Then
∂t V + Λ∂x V = 0
Thus, we have a set of scalar equations ∂t vi + λi ∂x vi = 0
INF2340 / Spring 2005 – p. 22
Linear Systems of Conservation Laws, cont’d
Each scalar equation is solved by
vi (x, t) = vi0 (x − λi t)
Now the solution is given as a superposition of m simple waves
U (x, t) =
m
X
vi0 (x − λi t)ri
i=0
Nonlinear systems:
Qt + F (Q)x = 0
We can rewrite
Qt + A(Q)Qx = 0,
A(Q) =
dF
dQ
Although we cannot repeat the analysis from the linear case, we observe that
eigenvalues and eigenvectors must have some importance for the local solution.
INF2340 / Spring 2005 – p. 23
The Shallow Water Model
The model is a nonlinear system of conservation laws:
"
" #
"
#
#
hu
0
h
+
=
.
1
2
2
hu + 2 gh
0
hu
t
x
Here h is water depth, g is acceleration of gravity, and (u, v) the
water velocity.
As opposed to our previous wave model (the linear wave
equation), this model accounts for water height and allows for
bores, hydraulic jumps, ’breaking waves’, etc.
( Modelling passive advection of pollution particles: qt + (qu)x = 0 )
INF2340 / Spring 2005 – p. 24
The Euler Equations for Gas Dynamics
This is the canonical example of a conservation law. Here in two
spatial dimensions:





ρ
ρu
ρv
E






 +


t
ρu
ρu2 + p
ρuv
u(E + p)






 +


x
ρv
ρuv
ρv 2 + p
v(E + p)



 = 0.

y
Here ρ denotes density, u and v velocity in x- and y - directions, p
pressure, and E is the total energy (kinetic plus internal energy)
given by
E = ρ(u2 + v 2 )/2 + p/(γ − 1)
We will return to the Euler and the shallow-water equations later
INF2340 / Spring 2005 – p. 25
Finite-Volume Methods
Previously we have used finite-differences to make pointwise
approximations to PDEs.
We now take another approach. Let us revisit the linear
advection equation:
d
dt
Z
b
ρ(x, t) dx = cρ(a, t) − cρ(b, t)
a
Let us now divide the section [a, b] into grid-cells [xi−1/2 , xi+1/2 ]
such that xM −1/2 = a and xN +1/2 = b for some integers N, M .
Now define the cell-averages
1
ρi (t) =
xi+1/2 − xi−1/2
Z
xi+1/2
ρ(x, t) dx
xi−1/2
INF2340 / Spring 2005 – p. 26
Finite-Volume Methods, cont’d
By imposing the conservation law on each grid-cell, we obtain
d
ρi (t)∆xi = cρ(xi−1/2 , t) − cρ(xi+1/2 , t)
dt
The grid-cells [xi−1/2 , xi+1/2 ] are referred to as finite volumes;
hence the name of the method.
Two points remain:
• How do we solve the ODEs for the cell-averages ρi (t)?
• And given cell-averages ρi : how do we evaluate the
point-values ρ(xi±1/2 ) at the cell-edges?
INF2340 / Spring 2005 – p. 27
Finite-Volume Methodscont’d
The first question has a simple answer: we use a standard ODE
solver, e.g., forward Euler:
n
(ρn+1
−
ρ
i)
i
= cρ(xi−1/2 , n∆t) − cρ(xi+1/2 , n∆t)
ri
where ri = ∆t/∆xi
The second question is a bit more complicated and consists of
two parts:
• reconstruction of point-values from cell-averages
• and evaluation of edge-fluxes
INF2340 / Spring 2005 – p. 28
Finite-Volume Methods: Reconstruction
In the finite-volume method, our discrete quantities are the
cell-averages ρi defined over the grid-cells [xi−1/2 , xi+1/2 ].
To define point-values, we must assume a functional form for the
unknown solution ρ(x, t).
Obvious idea: use a piecewise polynomial inside each finite
volume.
Simplest solution: piecewise constant,
ρ(x, t) = ρi (t), for x ∈ [xi−1/2 , xi+1/2 ]
More advanced methods: higher-order reconstruction based
upon piecwise polynomial (or rational function) interpolation of
cell-averages.
INF2340 / Spring 2005 – p. 29
Finite-Volume Methods: Flux-Evaluation
Problem: our piecewise constant approximation gives two candidate
values for ρ(xi+1/2 ):
• ρ(x−
i+1/2 ) obtained from the grid-cell [xi−1/2 , xi+1/2 ] to the left of
the cell edge
• ρ(x+
i+1/2 ) obtained from the grid-cell [xi+1/2 , xi+3/2 ] to the right of
the cell edge
Question: which one should we choose?
Answer: this depends upon the equation, and different choices gives
different numerical methods!
Here: since c > 0, the solution shifts from left to right as time
increases. Hence, we should use the upwind value ρ(x−
i+1/2 ) = ρi
INF2340 / Spring 2005 – p. 30
Our First Finite-Volume Method ...
Summing up, we have obtained:
ρn+1
i
=
ρni
−
cri ρni
−
ρni−1
This is called the first-order upwind method and is stable under the
CLF conditions
∆t
≤ 1.
c max ri = c max
i
i
∆xi
If c < 0, we can derive an analogous method
ρn+1
i
=
ρni
−
cri ρni+1
−
ρni
Linear systems: upwind in each characteristic component vi
INF2340 / Spring 2005 – p. 31
A Conservative Method
Since conservation was the fundamental modelling principle, our
numerical methods should obey the same principle
To see that the method is conservative: summing over all i gives
a telescoping sum for the fluxes:
N
X
i=M
ρn+1
∆xi
i
=
N
X
ρni ∆xi
i=M
n
− c∆t ρN − ρnM ],
where ρM = ρ(a) and ρN = ρ(b)
INF2340 / Spring 2005 – p. 32
Generalisation to Nonlinear Equations
Let us now consider a general nonlinear equation
ρt + f (ρ)x = ρt + f 0 (ρ)ρx = 0
The finite-volume scheme then reads
n
−
ρ
(ρn+1
i)
i
= f ρ(xi−1/2 , n∆t) − f ρ(xi+1/2 , n∆t)
ri
Point-values at cell edges from piecewise constant reconstruction −→
two candidate values:
ρ(xi+1/2 , n∆t ) = ρni
or
ρ(xi+1/2 , n∆t) = ρni+1
In other words, the scheme reads:
n
−
ρ
(ρn+1
n
n
n n
i)
i
= F ρi−1 , ρi − F ρi , ρi+1
ri
INF2340 / Spring 2005 – p. 33
Generalisation to Nonlinear Equation, cont’d
Repeating the argument from the linear case:
F (ρni , ρni+1 ) =

n

f
(ρ

i ),

f 0 (ρ) > 0 ∀ρ,
f (ρni+1 ), f 0 (ρ) < 0 ∀ρ,



??
otherwise
Generally: must solve local (Riemann) problems of the form
ρt + f (ρ)x = 0,

ρ ,
x < 0,
i
ρ(x, 0) =
ρi+1 , x > 0
This has a similarity solution ρ(x, t) = v(x/t). If we know v(ζ), then
F (ρi , ρi+1 ) = f v(0) −→ Godunov schemes, which are
generalisations of the upwind scheme for nonlinear equations
INF2340 / Spring 2005 – p. 34
Another Approach
Rather than using the Godunov flux, we can try the simple choice
F (ρni , ρni+1 )
This gives a centred scheme
=
1
2
f
ρni
+f
ρni+1
− ρni )
(ρn+1
n
n
i
= f ρi−1 − f ρi+1
ri
which is notoriously unstable.
Remedy: stabilize by adding artificial diffusion, (∆x2 /∆t)∂x2 ρ,
discretized by standard finite-differences −→ the centred
Lax–Friedrichs scheme
ρn+1
i
h
i
1 n
ρi+1 + ρni−1 + 12 ri f ρni+1 − f ρni−1 .
=
2
INF2340 / Spring 2005 – p. 35
Higher Order
The upwind and the Lax–Friedrichs schemes are first order.
To obtain higher order, we can solve the ODEs
d
ρi (t)∆xi = f ρ(xi−1/2 , t) − f ρ(xi+1/2 , t)
dt
by the modfied Euler method
n
−
ρ
)
(ρn+1
i
i
= f ρ xi−1/2 , (n + 12 )∆t − f ρ xi+1/2 , (n + 12 )∆t
ri
1
The point-values ρ xi±1/2 , (n + 2 )∆t can be obtained from the
Lax–Friedrichs scheme on a grid with half the grid size −→ the
second-order Lax–Wendroff’s method
n+1/2
ρi+1/2
ρn+1
i
n
n
=
+
−
f (ρi+1 ) − f (ρi ) ,
n+1/2
n+1/2 = ρi − ri f (ρi+1/2 ) − f (ρi−1/2 ) .
1
2
ρni
ρni+1
1
2 ri
INF2340 / Spring 2005 – p. 36
Numerical Examples
Consider a linear advection equation with periodic boundaries
ut + ux = 0,
u(x, 0) = u0 (x),
u(0, t) = u(1, t).
As initial data u0 (x) we choose a combination of a smooth squared
cosine wave and a double step function.
upwind
Lax–Friedrichs
Lax–Wendroff
1
1
1
0.8
0.8
0.8
0.6
0.6
0.6
0.4
0.4
0.4
0.2
0.2
0.2
0
0
0
−0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
−0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
−0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
INF2340 / Spring 2005 – p. 37
1
Numerical Examples, cont’d
Consider a Burgers’ equation with periodic boundaries
ut + ux = 0,
u(x, 0) = u0 (x),
u(0, t) = u(1.5, t).
As initial data u0 (x) we choose a combination of a smooth squared
cosine wave and a double step function.
upwind
Lax–Friedrichs
Lax–Wendroff
1
1
1
0.8
0.8
0.8
0.6
0.6
0.6
0.4
0.4
0.4
0.2
0.2
0.2
0
0
0
0
0.5
1
1.5
0
0.5
1
1.5
0
0.5
1
1.5
INF2340 / Spring 2005 – p. 38
Finite Volumes vs. Finite Differences
Observation: for the linear advection equation, the upwind
method can be obtained directly in a finite-difference setting with
forward differences in time and backward differences in space.
Similarly for other methods and other equations.
Question: so, what is the difference?
Short answer: the interpretations are different!
Longer answer: the generalisations to higher-order,
higher-dimesions, complex grids, etc are different...
Moreover, to add to the confusion: it is customary conservative finite-difference methods
for finite-volume methods
INF2340 / Spring 2005 – p. 39
Two Spatial Dimensions
The Lax–Friedrichs scheme on a Cartesian grid
ρn+1
ij
1 n
= ρi+1,j + ρni−1,j + ρni,j+1 + ρni,j−1
4
i 1 h
i
1 h
− r f ρni+1,j − f ρni−1,j − r g ρni,j+1 − g ρni,j−1
2
2
The extensions for the upwind scheme and Lax–Wendroff are
similar.
Using the finite-volume approach, the extension to more
complex grids are rather straightforward. This is one major
advantage of finite volumes versus finite differences.
INF2340 / Spring 2005 – p. 40
High-Resolution Schemes
The schemes we have introduced so far suffer from the following
drawbacks:
• they have low (formal) spatial accuracy (order one or two)
• first-order schemes smear discontinuitites
• second-order schemes create spurious oscillations
Remedy: Introduction of modern high-resolution schemes
A high-resolution scheme delivers high-order
resolution in smooth parts and avoids the creation of
spurious oscillations near discontinuities
Today there are a lot of high-resolution schemes available: flux-limiter
schemes, slope-limiter schemes, wave-propagation, (W)ENO
schemes, discontinuous Galerkin,... However, these schemes are
outside the scope of this course.
INF2340 / Spring 2005 – p. 41