You are on page 1of 10

Lecture Notes 3

Finite Volume Discretization of the Heat Equation


We consider nite volume discretizations of the one-dimensional variable coecient heat
equation, with Neumann boundary conditions
u
t

x
(k(x)
x
u) = S(t, x), 0 < x < 1, t > 0, (1)
u(0, x) = f(x), 0 < x < 1,
u
x
(t, 0) = u
x
(t, 1) = 0, t 0.
The coecient k(x) is strictly positive.
1 Semi-discrete approximation
By semi-discretization we mean discretization only in space, not in time. This approach is also
called method of lines.
Discretization
We discretize space into N equal size grid cells (bins) of size h = 1/N, and dene x
j
= h/2 +jh,
so that x
j
is the center of cell j, see gure. The edges of cell j are then x
j1/2
and x
j+1/2
.
x
0
x
1
x
N1
h
Unknowns
In a nite volume method the unknowns approximate the
average of the solution over a grid cell. More precisely, we
let q
j
(t) be the approximation
q
j
(t) u
j
(t) :=
1
h
_
x
j+1/2
x
j1/2
u(t, x)dx.
Note the contrast with nite dierence methods, where
pointwise values are approximated, and nite element
methods, where basis function coecients are approxi-
mated.
1 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
Exact update formula
We derive an exact update formula for u
j
(t), the exact local averages. Integrating (1) over cell
j and dividing by h we get
1
h
_
x
j+1/2
x
j1/2
u
t
(t, x)dx =
1
h
_
x
j+1/2
x
j1/2

x
(k(x)
x
u)dx +
1
h
_
x
j+1/2
x
j1/2
S(t, x)dx
=
k(x
j+1/2
)u
x
(t, x
j+1/2
) k(x
j1/2
)u
x
(t, x
j1/2
)
h
+
1
h
_
x
j+1/2
x
j1/2
S(t, x)dx.
Upon dening the ux
F
j
(t) = F(t, x
j
) = k(x
j
)u
x
(t, x
j
),
and the local average of the source
S
j
(t) =
1
h
_
x
j+1/2
x
j1/2
S(t, x)dx,
we get the exact update formula
du
j
(t)
dt
=
F
j+1/2
(t) F
j1/2
(t)
h
+S
j
(t).
The uxes F
j+1/2
and F
j1/2
then represents
how much heat ows out through the left and
right boundary of the cell.
Note, this is an instance the conservation law in integral form,
d
dt
_
V
udV +
_
S

F ndS =
_
V
SdV,
where we have picked V as the interval [x
j1/2
, x
j+1/2
], and scaled by |V | = h.
Approximation of the ux
To use the exact update formula as the basis for a numerical scheme we must approximate the
uxes F
j1/2
. Since the value in the midpoint of the cell is a second order approximation of the
average, we have for smooth u,
F
j1/2
(t) = k(x
j1/2
)u
x
(t, x
j1/2
) = k(x
j1/2
)
u(t, x
j
) u(t, x
j1
)
h
+O(h
2
)
= k(x
j1/2
)
u
j
(t) u
j1
(t)
h
+O(h
2
).
We therefore use
F
j1/2
(t)

F
j1/2
(t) = k(x
j1/2
)
q
j
(t) q
j1
(t)
h
.
as approximation. This leads to the numerical scheme for inner points 1 j N 2,
dq
j
(t)
dt
=

F
j+1/2
(t)

F
j1/2
(t)
h
+S
j
(t) (2)
=
k(x
j+1/2
)(q
j+1
(t) q
j
(t)) k(x
j1/2
)(q
j
(t) q
j1
(t))
h
2
+S
j
(t).
2 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
Hence, with k
j
:= k(x
j
),
dq
j
dt
=
k
j+1/2
q
j+1
(k
j+1/2
+k
j1/2
)q
j
+k
j1/2
q
j1
h
2
+S
j
, (3)
for j = 1, . . . , N 2. This is a second order approximation.
Boundary conditions
To complete the scheme (3) we need update formulae also
for the boundary points j = 0 and j = N 1. These
must be derived by taking the boundary conditions into
account. We introduce the ghost cells j = 1 and j = N
which are located just outside the domain. The boundary
conditions are used to ll these cells with values q
1
and
q
N
, based on the values q
j
in the interior cells. The same
update formula (3) as before can then be used also for
j = 0 and j = N 1.
Let us consider our boundary condition u
x
= 0 at x = 0. (We can also think of this as a
"no ux" condition, F = 0.) We formally extend the denition of the solution u for x < 0, i.e.
outside the domain, and, as before, approximate
0 = u
x
(t, 0) =
u(t, x
0
) u(t, x
1
)
h
+O(h
2
)
=
u
0
(t) u
1
(t)
h
+O(h
2
) u
1
(t) = u
0
(t) +O(h
3
).
Replacing u
j
by our approximation q
j
and dropping the O(h
2
) term we get an expression for q
1
in terms of q
0
as the boundary rule
q
1
(t) = q
0
(t).
We now insert this into the update formula (3) for j = 0,
dq
0
dt
=
k
1/2
q
1
(k
1/2
+k
1/2
)q
0
+k
1/2
q
1
h
2
+S
0
= k
1/2
q
1
q
0
h
2
+S
0
. (4)
In exactly the same way we obtain for j = N 1 that q
N
(t) = q
N1
(t) and therefore
dq
N1
dt
= k
N3/2
q
N2
q
N1
h
2
+S
N1
. (5)
Remark 1 Dirichlet boundary conditions u(t, 0) = u(t, 1) = 0 can be approximated to second
order in two ways.
First, one can use a shifted grid, x
j
= jh so that x
0
and x
N
, the centers of cells 0 and N,
are precisely on the boundary. Then one does not need ghost cells; one just sets q
0
= q
N
= 0.
Note that the number of unknows are now only N 1, so A R
(N1)(N1)
etc.
Second, one can take the average of two cells to approximate the value in between,
0 = u(t, 0) =
u(t, x
0
) +u(t, x
1
)
2
+O(h
2
) =
u
0
(t) +u
1
(t)
2
+O(h
2
),
leading to the approximations
q
1
= q
0
, q
N
= q
N1
.
3 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
Matrix form
We put all the formulae (3), (4), (5) together and write them in matrix form. Introduce
q =
_
_
_
q
0
.
.
.
q
N1
_
_
_
, S =
_
_
_
S
0
.
.
.
S
N1
_
_
_
, q, S R
and
A =
1
h
2
_
_
_
_
_
_
_
k
1/2
k
1/2
k
1/2
(k
1/2
+k
3/2
) k
3/2
.
.
.
.
.
.
.
.
.
k
N5/2
(k
N5/2
+k
N3/2
) k
N3/2
k
N3/2
k
N3/2
_
_
_
_
_
_
_
R
NN
. (6)
Then we get the linear ODE system
dq(t)
dt
= Aq(t) + S(t). (7)
Hence, in this semi-discretization the time-dependent PDE has been approximated by a system
of ODEs, where the matrix A is a discrete approximation of the second order dierential operator

x
k(x)
x
, including its boundary conditions.
1.1 Brief outline of extensions to 2D
The same strategy can be used in 2D. We give a cursory description of the main steps here. To
simplify things we consider the constant coecient problem,
u
t
u = S(t, x, y), 0 < x < 1, 0 < y < 1, t > 0,
u(0, x, y) = f(x, y), 0 < x < 1, 0 < y < 1,
u
x
(t, 0, y) = u
x
(t, 2, y) = u
y
(t, x, 0) = u
y
(t, x, 2) = 0, 0 < x < 1, 0 < y < 1, t 0.
Discretization
We discretize the domain [0, 1]
2
into N N equal size grid cells of size h h, where h = 1/N.
We dene x
j
= h/2 +jh and y
k
= h/2 +kh and denote the cell with center (x
j
, y
k
) by I
jk
.
4 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
x
0
x
1
x
N1
y
0
y
1
y
N1
I
jk
Unknowns
The unknowns are now q
jk
(t), which are approximations of the average of the solution over the
grid cell I
jk
,
q
jk
(t) u
jk
(t) :=
1
h
2
_
I
jk
u(t, x, y)dxdy.
Exact update formula
The update formula is again an instance of the conservation law in integral form where we pick
the volume V as I
jk
and scale by |I
jk
| = h
2
,
d
dt
1
h
2
_
I
jk
udxdy +
1
h
2
_
I
jk

F ndS =
1
h
2
_
I
jk
Sdxdy,
where F = u. Upon dening
S
jk
(t) :=
1
h
2
_
I
jk
S(t, x, y)dxdy,
this can be written as
du
jk
(t)
dt
=
1
h
2
_
I
jk

F ndS +S
jk
(t).
Let F = (f
1
, f
2
) and dene the average ux through each side of the cell,
F
j,k1/2
(t) :=
1
h
_
x
j+1/2
x
j1/2
f
2
(t, x, y
k1/2
)dx, F
j1/2,k
(t) :=
1
h
_
y
k+1/2
y
k1/2
f
1
(t, x
j1/2
, y)dy,
we get the exact formula
du
jk
dt
=
1
h
(F
j+1/2,k
F
j1/2,k
+F
j,k+1/2
F
j,k1/2
) +S
jk
. (8)
5 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
Again, the uxes F
j,k1/2
and F
j1/2,k
represent the
heat ux (upto sign) out through the four sides of the
cell.
Approximation of the ux
We use the same type of approximation as in 1D for
F = u. We get for instance
F
j,k1/2
=
1
h
_
x
j+1/2
x
j1/2
u
y
(t, x, y
k1/2
)dx =
1
h
_
x
j+1/2
x
j1/2
u(t, x, y
k
) u(t, x, y
k1
)
h
dx +O(h
2
)
=
1
h
2
_
x
j+1/2
x
j1/2
u(t, x, y
k
)dx +
1
h
2
_
x
j+1/2
x
j1/2
u(t, x, y
k1
)dx +O(h
2
)
=
1
h
3
_
I
jk
u(t, x, y)dxdy +
1
h
3
_
I
j,k1
u(t, x, y)dxdy +O(h
2
)
=
u
jk
+u
j,k1
h
+O(h
2
).
Replacing u
jk
by q
jk
, dropping O(h
2
) and inserting in the exact formula (8) we get the ve-point
formula,
dq
jk
dt
=
1
h
2
(q
j+1,k
+q
j1,k
+q
j,k+1
+q
j,k1
4q
jk
) +S
jk
.
Boundary conditions is done as in 1D. The matrix form is more complicated and the subject of
Homework 1.
2 Properties of the semi-discrete approximation
2.1 Conservation
When S = 0 in (1) we have seen that the solution has the conservation property
_
1
0
u(t, x)dx = constant =
_
1
0
f(x)dx.
In fact this holds for all conservation laws with "no-ux" boundary conditions F = 0, which is
easily seen from the integral form of the PDE. An analogue of this holds also for the semi-discrete
approximation. More precisely, let us dene
Q(t) =
N1

j=0
q
j
(t)h.
Then
Q(t) = constant. (9)
Moreover, if we start the approximation with exact values, q
j
(0) = u
j
(0), then it follows that
Q(t) is exactly the integral of the solution u for all time,
Q(t) = constant = Q(0) =
N1

j=0
u
j
(0)h =
N1

j=0
1
h
_
x
j+1/2
x
j1/2
u(0, x)hdx =
_
1
0
u(0, x)dx =
_
1
0
u(t, x)dx.
We prove the exact discrete conservation (9) in two ways.
6 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
Recall from (2) that when S = 0,
dq
j
(t)
dt
=

F
j+1/2
(t)

F
j1/2
(t)
h
. (10)
Then
dQ
dt
=
N1

j=0
dq
j
dt
h =
N1

j=0

F
j1/2
(t)

F
j+1/2
=

F
1/2


F
N1/2
= 0,
where we used the boundary conditions (4) and (5) which implies that

F
1/2
= k
1/2
q
0
q
1
h
= 0,

F
N1/2
= k
N1/2
q
N
q
N1
h
= 0.
Note that this discrete conservation property is true for any discretization of the type (10)
if

F
1/2
=

F
N1/2
, regardless of how the uxes

F
j1/2
are computed.
Recall from (7) that when S = 0,
dq(t)
dt
= Aq(t).
Moreover,
Q(t) = 1
T
qh, 1 =
_
_
_
_
_
1
1
.
.
.
1
_
_
_
_
_
R
N
.
Then
dQ(t)
dt
= 1
T
dq(t)
dt
h = 1
T
Aq(t)h = 0,
since 1
T
Aq(t) = (A1)
T
q(t) by the symmetry of A and A1 are the row sums of A which
are zero, by (6).
2.2 Maximum principle
We have seen before that in the continuous case that when S = 0 in (1), the maximum value of
the solution u(t, x) in [0, T] [0, 1] is either attained on the boundary x {0, 1} or for the initial
data at t = 0 (regardless of boundary conditions). The corresponding result in the semi-discrete
case says that
q

= max
j0,...,N1
sup
0t<T
|q
j
(t)|
is attained either for j = 0, j = N 1 or for the initial data t = 0. This is easily shown by
contradiction. Suppose the maximum is attained at t = t

> 0 and that it is strictly larger than


q
0
(t

) and q
N1
(t

). Then, there must be an interior index j

[1, N 2] such that


q
j

1
(t

) < q
j
(t

), q
j
(t

) q
j

+1
(t

).
Therefore
dq
j
(t

)
dt
= k
j

+1/2
(q
j

+1
q
j
)
. .
0
k
j

1/2
(q
j
q
j

1
)
. .
>0
< 0.
Hence, there is an such that q
j
(t) > q
j
(t

) for all t (t

, t

), which contradicts the


assumption that q
j
(t

) is a maximum.
Furthermore, as in the continuous case local spatial maximum (minimum) of q
j
in the interior
cannot increase (decrease) in time.
7 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
Forward Euler Im
Re
1
1
D
Backward Euler Im
Re
1
1
D
Figure 1. Stability regions D for the Forward and Backward Euler methods.
3 Fully discrete approximation
The semi-discrete approximation leads to a system of ODEs.
dq(t)
dt
= Aq(t) + S(t). (11)
This can be solved by standard numerical methods for ODEs with a time step t, e.g. the
Forward Euler method
u
n+1
= u
n
+ tf(t
n
, u
n
), t
n
= nt.
Applied to (11) this would give the fully discrete scheme for (1),
q
n+1
= q
n
+ t[Aq
n
+ S(t
n
)], q
n
q(t
n
).
As for any ODE method we must verify its absolute stability: that for our choice of step size t
t
k
D, k,
where D is the stability region of the ODE solver and {
k
} are the eigenvalues of A. For parabolic
problems the real part of the eigenvalues are negative, and the size of them in general grow as
1/h
2
. This is a major diculty. It means that when the stability region D is bounded, as in
explicit methods, we get a time step restriction of the type
t Ch
2
.
This is a severe restriction, which is seldom warranted from an accuracy point of view. It leads
to unnecessarily expensive methods.
Example 1 In the constant coecient case k(x) 1 the eigenvalues of A are precisely

k
=
4
h
2
sin
2
_
kh
2
_
, k = 0, . . . , N 1.
This gives the stability condition t h
2
/2 for Forward Euler.
8 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
The underlying reason for the severe time-step restriction is the fact that parabolic problems
include processes on all time-scales: high frequencies decay fast, low frequencies slowly. Their
semi-discretization have time-scales spread out all over the interval [1/h
2
, 0], which means
that the ODEs are sti. The consequence is that implicit methods should be used for parabolic
problems. Implicit methods typically have unbounded stability domains D and have no stability
restriction on the time-step they are unconditionally stable. Of course, implicit methods are
more expensive per time-step than explicit methods, since a system of equations must be solved,
but this is outweighed by the fact that much longer time-steps can be taken. Moreover, w hen
the coecients do not vary with time, matrices etc. can be constructed once, and re-factored
only as changes of time-step make it necessary.
The "-method" is a class of ODE methods dened as
u
n+1
= u
n
+ t
_
f(t
n+1
, u
n+1
) + (1 )f(t
n
, u
n
)

, 0 1.
This includes some common methods:
= 0 Forward Euler (explicit, 1st order),
= 1/2 CrankNicolson (implicit, 2nd order),
= 1 Backward Euler (implicit, 1st order),
Applied to (11) we have
q
n+1
= q
n
+ tA[q
n+1
+ (1 )q
n
] + t [S(t
n+1
) + (1 )S(t
n
)]
. .
S
n

, (12)
or
(1 tA)q
n+1
= (1 + (1 )tA)q
n
+ tS
n

.
For the constant coecient problem k 1 one can show the time-step restriction
t h
2
_
1
2(12)
, < 1/2,
, 1/2 1, (unconditionally stable).
Remark 2 The Crank-Nicolson scheme is second order accurate but gives slowly decaying os-
cillations for large eigenvalues. It is unsuitable for parabolic problems with rapidly decaying
transients. The = 1 scheme damps all components, and should be used in the initial steps.
Remark 3 The most used family of time-stepping schemes for parabolic problems are the Back-
ward Dierentiation Formulas (BDF), of order 1 through 5 which are A()-stable. They are
multistep methods generalizing Backward Euler to higher order. For instance, the second order
BDF method is
u
n+1
=
4
3
u
n

1
3
u
n1
+
2
3
tf(t
n+1
, u
n+1
).
BDF methods are also known as Gears methods and available in Matlab as ODE15S.
3.1 Fully discrete conservation
For the -method we also have discrete conservation when S 0. Let
Q
n

N1

j=0
q
n
j
h = 1
T
q
n
h.
9 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg
Then upon multiplying by 1 from the left in (12) we get
Q
n+1
= 1
T
q
n+1
h = 1
T
q
n
h+t1
T
A[q
n+1
+(1)q
n
]h = Q
n
+t(A1)
T
[q
n+1
+(1)q
n
]h = Q
n
,
since as before A1 = 0. In particular, if initial data is exact, q
0
j
= u
j
(0), then
Q
n
=
_
1
0
u(t
n
, x)dx,
for all n 0. The same is true for the second order BDF method if the initialization of the rst
step Q
1
is conservative so that Q
1
= Q
0
. Then
q
n+1
=
4
3
q
n

1
3
q
n1
+
2
3
tAq
n+1
implies
Q
n+1
= 1
T
q
n+1
h =
4
3
1
T
q
n
h
1
3
1
T
q
n1
h +
2
3
1
T
tAq
n+1
h =
4
3
Q
n

1
3
Q
n1
.
With the stipulated initial data this dierence equation has the solution Q
n
= Q
0
for all n 0.
4 Acknowledgement
Part of these notes are based on earlier notes by Prof. Jesper Oppelstrup.
10 (10)
DN2255 Numerical Solutions of Dierential Equations Spring 2012
Olof Runborg

You might also like