# Numerical Methods for Partial

Differential Equations
CAAM 452
Spring 2005
Lecture 9

Instructor: Tim Warburton
CAAM 452 Spring 2005
Today
• Introduction to a very basic finite volume method

CAAM 452 Spring 2005
Mass Conservation
• For the following we are going to consider a 1-dimensional
domain which we parameterize with the variable x.

• Now imagine that this line is a figurative representation of
a pipe which contains fluid.

• At every point on the line the fluid has a density measured
in mass per meter ( with units kgm
-1
)

• We define a new function which is a
non-negative, real valued function defined on the space-time
domain.
x
: [0, ) µ × ÷ ·
CAAM 452 Spring 2005
Derivation of Mass Conservation Law
• Next we consider an arbitrary section of the pipe, say [a,b]

• We now assume that the fluid is not created or destroyed at any point
inside the section and is traveling with velocity u (which is a function of
space and time). For the moment we will assume that u is positive (i.e.
the fluid is flowing in the direction of positive x)

• This allows us to state the following:
– The time rate of change of the total fluid inside the section [a,b]
changes only due to the flux of fluid into and out of the pipe at the
ends x=a and x=b.

• A simple formula relating these two quantities is:

( ) ( ) ( ) ( ) ( )
, , , , ,
b
a
d
x t dx u b t b t u a t a t
dt
µ µ µ = ÷ +
}
CAAM 452 Spring 2005
• In detail:

( ) ( ) ( ) ( ) ( )
, , , , ,
b
a
u b
d
x t u a t b t t dx
d
t
t
a µ µ µ + ÷ =
}
The time rate of
change of total
mass in the
section of pipe
[a,b]
The flux out of
the section at
the right end of
the section of
pipe per unit
time
The flux into the
section at the
left end of the
section of pipe
per unit time
CAAM 452 Spring 2005
Use the Fundamental Theorem of
Calculus
• Look carefully at the right hand side:

• Clearly we may rewrite this as:

• From which we may deduce:
( ) ( ) ( ) ( ) ( )
, , , , ,
b
a
d
x t dx u b t b t u a t a t
dt
µ µ µ = ÷ +
}
( ) ( ) ( ) ( )
, , ,
b b
a a
d
x t dx u x t x t dx
dt x
µ µ
c
= ÷
c
} }
( ) ( ) ( ) ( )
, , , 0
b
a
x t u x t x t dx
t x
µ µ
c c
+ =
c c
}
CAAM 452 Spring 2005
Finally…
• Assuming that the integrand of:

is continuous and noting that this relation holds for
all choices of a,b then we may deduce:

• In short hand:
( ) ( ) ( ) ( )
, , , 0
b
a
x t u x t x t dx
t x
µ µ
c c
+ =
c c
}
( ) ( ) ( ) ( )
, , , 0 x t u x t x t
t x
µ µ
c c
+ =
c c
( )
0
u
t x
µ
µ
c
c
+ =
c c
CAAM 452 Spring 2005
• Let’s choose a simple, constant, fluid velocity

• Then the pde reduces to the advection equation:

• This is a pretty easy equation to solve . Consider
the change of variables:
( )
, u x t u =
0 u
t x
µ µ c c
+ =
c c
t t
x x ut
=
= ÷
CAAM 452 Spring 2005
• Note that the units of each variable are
consistent.

• Basic calculus:

• From which we obtain:
t t
x x ut
=
= ÷
t x
u
t t t t x t x
t x
x x t x x x
c c c c c c c
= + = ÷
c c c c c c c
c c c c c c
= + =
c c c c c c
0 u
t x
u u
t x x
t
µ µ
µ µ µ
µ
c c
= +
c c
c c c
| | | |
= ÷ +
| |
c c c
\ . \ .
c
=
c
CAAM 452 Spring 2005
Solution and Interpretation
• So we know:

• Which we can instantly solve:

where:

• So an interesting property of the advection
equation is the way that the profile of the
solution does not change shape but it does shift
in the positive x direction with constant velocity
0
t
µ c
=
c
( ) ( )
( )
0
0
, x t x
x ut
µ µ
µ
=
= ÷
( ) ( )
0
: , 0 x x t µ µ = =
CAAM 452 Spring 2005
Space Time Diagram
• Let’s track the information:

• The dashed lines are which are known as
characteristics of the equation.

• If we choose a point on one of these dashed lines and track
back down to t=0 and we will find the value of the density which
applies at all points on the dashed line
x
t
Slope =
1
u
x ut const ÷ =
CAAM 452 Spring 2005
Recall
• Assuming that the integrand of:

is continuous and noting that this relation holds for all
choices of a,b then we may deduce:

• Well – this does not hold if the density is discontinuous
and the integral equation is the appropriate representation:
( ) ( ) ( ) ( )
, , , 0
b
a
x t u x t x t dx
t x
µ µ
c c
+ =
c c
}
( ) ( ) ( ) ( )
, , , 0 x t u x t x t
t x
µ µ
c c
+ =
c c
( ) ( ) ( ) ( ) ( )
, , , , ,
b
a
d
x t dx u b t b t u a t a t
dt
µ µ µ = ÷ +
}
CAAM 452 Spring 2005
1) Let’s consider the advection equation:

2) Next we take a finite portion of the real line from
x
1
to x
N
divided into N-1 equal length sections

3) In each section we will approximate the density by a
constant value
Building a Finite Volume Solver
( ) ( ) ( )
, , ,
b
a
d
x t dx u b t u a t
dt
µ µ µ = ÷ +
}
x
1
x
N

1,..., 1
i
i N µ = ÷
dx
CAAM 452 Spring 2005
In the n’th section the density will be approximated by the
constant:
Piecewise Constant Approximation
x
1
x
N
n
µ
µ
CAAM 452 Spring 2005
• Choosing a = x
i
, b=x
i+1
,

• Is approximated (to first order in time) by:

where the time axis has been divided into sections of length
dt and the i’th cell average at time n*dt is represented by

• Outstanding question: Now we have to figure out how to
evaluate the density at the interval end points given the cell
averages.

( ) ( ) ( )
, , ,
b
a
d
x t dx u b t u a t
dt
µ µ µ = ÷ +
}
( )
( ) ( )
1
1
, ,
n n
i i
i i
dx
u x t u x t
dt
µ µ
µ µ
+
+
÷
= ÷ +
( )
1
,
i
i
x
n
i
x
x t ndt dx µ µ
+
~ =
}
CAAM 452 Spring 2005
Upwind Treatment for Flux Terms

• Recall that the solution shifts from left to right
as time increases.

• Idea: use the upwind values
t
Slope =
1
u
( ) ( )
1 1
, ,
n n
i i i i
u x t u x t u u µ µ µ µ
+ ÷
÷ + ~ ÷ +
CAAM 452 Spring 2005
Basic Upwind Finite Volume Method
1
1
1
n n n
i i i
dt dt
u u
dx dx
µ µ µ
+
÷
| | | |
= ÷ +
| |
\ . \ .
( )
1
1
n n
i i
n n
i i
dx
u u
dt
µ µ
µ µ
+
÷
÷
= ÷ +
simplify
dt
u
dx
ì =
( ) ( )
1
1
1
n n n
i i i
µ ì µ ì µ
+
÷
= ÷ +
Note we must supply a value for the left most average at each time step:
0
n
µ
CAAM 452 Spring 2005
Basic Upwind Finite Volume Method
( )
1
1
n n
i i
n n
i i
dx
u u
dt
µ µ
µ µ
+
÷
÷
= ÷ +
Approximate time derivative and look for
solution
dt
u
dx
ì =
( ) ( )
1
1
1
n n n
i i i
µ ì µ ì µ
+
÷
= ÷ +
Note we must supply a value for the left most average at each time step:
0
n
µ
Recall
( ) ( ) ( )
1
, ,
i i i
d
q dx uq x t uq x t
dt
+
= ÷ +
Approximate fluxes with upwind flux
( )
1 i i i
d
q dx uq uq
dt
÷
~ ÷ +
n n
i i
q µ ~
CAAM 452 Spring 2005
Convergence
• We have constructed a physically reasonable numerical scheme to

• However, we need to do some extra analysis to determine how
good at approximating the true PDE the discrete scheme is.

• Let us suppose that the i’th subinterval cell average of the actual
solution to the PDE at time T=n*dt is denoted by
( ) ( )
( ) ( ) ( ) ( )
1 1
1
1
1
1 1
, ,
where q satisfies:
, , ,
i i
i i
i
i
x x
n
i
i i
x x
x
i i i
x
q q x ndt q x ndt
x x dx
d d
q x t dx dxq uq x t uq x t
dt dt
+ +
+
+
+
= =
÷
= = ÷ +
} }
}
CAAM 452 Spring 2005
Error Equation
• The goal is to estimate the difference of the exact solution
and the numerically obtained solution at some time
T=n*dt.

• So we are interested in the error:

• For the given finite volume scheme dt and dx will be
related in a fixed manner (i.e. dt = Cdx for some C,
independent of dx).

• Suppose we let and then

the scheme is said to be of order s.
, n
n n n
i i i
T
E q
dt
µ = ÷ =
0 dt ÷
( )
n s
E O dt =
CAAM 452 Spring 2005
Norms and Definitions
• We define the discrete p-norms:

• We say that the scheme is convergent at time T in
the norm ||.|| if:

• It is said to be accurate of order s if:
1/ p
i
p
i
p
i
E dx E
=+·
=÷·
| |
=
|
\ .
¿
{ }
0
lim 0
n
dt
ndt T
E
÷
=
=
( )
as 0
n s
E O dt dt = ÷
CAAM 452 Spring 2005
Local Truncation Error
• Suppose at the beginning of a time step we actually have the exact
solution -- one question we can ask is how large is the error
committed in the evaluation of the approximate solution at the end
of the time step.

• i.e. choose

• Then

i
,t
n
with Taylor series:

( )
1
1
1 1
1
1
:
n n
i i
n n n
i i i
n n n
i i i
q
dt dt
u q u q
dx dx
R q
dt
µ
µ
µ
+
÷
+ +
=
| | | |
= ÷ +
| |
\ . \ .
= ÷
1
1
,
n n
i i
q q
+
÷
____ ____
2 2
3
1
2
____ ____
2 2
1 3
2
( )
2
( )
2
n n
i i
n n
i i
q dx q
q q dx O dx
x x
q dt q
q q dt O dt
t t
÷
+
| |
c c
| |
|
= ÷ + +
|
|
c c
\ .
|
\ .
| |
c c
| |
|
= + + +
|
|
c c
\ .
|
\ .
CAAM 452 Spring 2005
Estimating Truncation Error
• Inserting the formulas for the expanded q’s:
1
1
____
____
2 2
3
2
____
____
2 2
3
2
1
: 1
1
1
( )
2
( )
2
n n n n
i i i i
n
i
n
i
n
i
dt dt
R u q u q q
dt dx dx
dt
u q
dx
dt q dx q
u q dx O dx
dt dx x x
q dt q
q dt O dt
t t
+
÷
| |
| | | |
= ÷ + ÷
| |
|
\ . \ .
\ .
| |
÷
|
\ .
¦ ¹
| | c c ¦ ¦ | | | |
= + ÷ + +
´ `
| | |
c c
\ . \ .
\ .
¦ ¦
¹ )
¦ ¹
| | c c ¦ ¦ | |
÷ + + +
´ `
| |
c c
\ .
\ .
¦
¹
| |
|
|
|
|
|
|
|
|
|
|
|
|
¦ |
)
\ .
CAAM 452 Spring 2005
____
____
2 2
3
2
____
____
2 2
3
2
1
1
: ( )
2
( )
2
n
i
n n
i i
n
i
dt
u q
dx
dt q dx q
R u q dx O dx
dt dx x x
q dt q
q dt O dt
t t
| |
|
| |
|
÷
|
|
\ .
|
¦ ¹
|
| | c c ¦ ¦ | | | |
|
= + ÷ + +
´ `
| | |
| c c
\ . \ .
\ .
¦ ¦
¹ ) |
|
¦ ¹
|
| | c c ¦ ¦ | |
÷ + + +
|
´ `
| |
c c
\ .
\ . |
¦ ¦ |
¹ )
\ .
Estimating Truncation Error
• Removing canceling terms:
CAAM 452 Spring 2005
Estimating Truncation Error
• Simplifying:
____
____
2 2
3
2
____
____
2 2
3
2
( )
2
1
:
( )
2
n
i
dt q dx q
u dx O dx
dx x x
R
dt
q dt q
dt O dt
t t
| |
¦ ¹
| | c c ¦ ¦ | | | | |
+ ÷ + +
´ `
| | |
|
c c
\ . \ .
\ .
¦ ¦
|
¹ )
=
|
¦ ¹
|
| | c c ¦ ¦ | |
|
÷ + + +
´ `
| |
| c c
\ .
\ .
¦ ¦ |
¹ )
\ .
( )
____ ____
____ ____
2 2
2 2
2 2
:
( ) ( )
2 2
n
i
q q
u
t x
R
dt q dx q
O dt u O dx
t x
| |
¦ ¹
c c ¦ ¦ | | | |
|
÷ +
´ `
| |
|
c c
\ . \ .
¦ ¦
| ¹ )
=
|
¦ ¹
|
| | | | c c ¦ ¦
÷ + ÷ + |
´ `
| |
c c
\ . \ . |
¦ ¦
¹ )
\ .
CAAM 452 Spring 2005
Final Form
• Using the definition of q
____
2
2
2
: 1 ( )
2
n
i
udx udt q
R O dx
dx x
| |
c
| |
|
= ÷ +
|
|
c
\ .
|
\ .
Using that:
____ ____
2 2
2
2 2
q q
u
t x
c c
=
c c
( )
____ ____
____ ____
2 2
2 2
2 2
:
( ) ( )
2 2
n
i
q q
u
t x
R
dt q dx q
O dt u O dx
t x
| |
¦ ¹
c c ¦ ¦ | | | |
|
÷ +
´ `
| |
|
c c
\ . \ .
¦ ¦
| ¹ )
=
|
¦ ¹
|
| | | | c c ¦ ¦
÷ + ÷ + |
´ `
| |
c c
\ . \ . |
¦ ¦
¹ )
\ .
( )
____ ____
2 2
2 2
2 2
: ( ) ( )
2 2
n
i
dt q dx q
R O dt u O dx
t x
| |
| | | | c c
|
= ÷ + + +
| |
|
c c
\ . \ .
|
\ .
CAAM 452 Spring 2005
Interpretation of Consistency
So the truncation error is O(dx) under the assumption that
dt/dx is a constant..

This essentially implies that the numerical solution diverges
from the actual solution by an error of O(dx) every time step.

If we assume that the solution q is smooth enough then the
truncation error converges to zero with decreasing dx. This
property is known as consistency.
____
2
2
2
: 1 ( )
2
n
i
udx udt q
R O dx
dx x
| |
c
| |
|
= ÷ +
|
|
c
\ .
|
\ .
CAAM 452 Spring 2005
Error Equation
• We define the error variable:

• We next define the numerical iterator N:

• Then:

• So the new error consists of the action of the numerical
scheme on the previous error and the error commited in the
approximation of the derivatives.
n n n
i i i
q E µ = +
1 n n
N µ µ
+
=
( )
( ) ( ) ( )
( ) ( )
{ }
1 1
1
n n n n
n n n n n
n n n n
E N q E q
N q E N q N q q
N q E N q dtR
+ +
+
= + ÷
= + ÷ + ÷
= + ÷ +
CAAM 452 Spring 2005
Abstract Scheme
• Without considering the specific construction of the scheme
suppose that the numerical N operator satisfies:

• i.e. N is a contraction operator in some norm then…
( ) ( )
N P N Q P Q ÷ s ÷
CAAM 452 Spring 2005
Estimating Error in Terms of Initial Error
and Cumulative Truncation Error
( ) ( ) { }
( ) ( )
{ }
1
1
1
1
1 1
1 0
1
triangle inequality
contraction property of
.....

n n n n n
n n n n n
n n n n n
n n n
n n n
m n
n m
m
E N q E N q dtR
E N q E N q dt R
E q E q dt R N
E E dt R
E dt R dt R
E E dt R
+
+
+
+
÷ ÷
=
+
=
= + ÷ +
+
s + ÷ +
+
s + ÷ +
+
s +
s + +
s
+
s +
¿
by induction
CAAM 452 Spring 2005
Error at a Time T (independent of
dx,dt)

• If the method is consistent (and the actual solution
is smooth enough) then:

• As dx -> 0 the initial error ->0 and consequently
the numerical error at time T tends to zero with
decreasing dx (and dt).
( )
1 0
1
1 0
1,..
max
m n
n m
m
n m
m n
E E dt R
E E T R
=
+
=
+
=
s +
¹
s +
¿
( )
1 0

n
E E T O dx
+
s +
CAAM 452 Spring 2005
Specific Case: Stability and Consistency
for the Upwind Finite Volume Scheme

• We already proved that the upwind FV scheme is
consistent.

• We still need to prove stability of.

( ) ( )
1
1
1
n n n
i i i
µ ì µ ì µ
+
÷
= ÷ +
CAAM 452 Spring 2005
Stability in the Discrete 1-norm
( ) ( )
( ) ( )
( )
1
1
1
1 1
1
1
1
1
1
1 1
1
1 1
1
0
1
0
1
1
1 triangle inequality
1 assuming 0 1
n n n
i i i
N
n n
i
i
N
n n
i i
i
N N
n n
i i
i i
N
n n
i
i
n n
dx
dx
dx dx
dx dx
dx
µ ì µ ì µ
µ µ
ì µ ì µ
ì µ ì µ ì
ì µ µ
ì µ µ
+
÷
÷
+ +
=
÷
÷
=
÷ ÷
÷
= =
÷
=
= ÷ +
¹
=
= ÷ +
s ÷ + s s
s +
s +
¿
¿
¿ ¿
¿
So here’s the interesting story. In the case of a zero boundary
condition then we automatically observe that the operator is a
contraction operator.
CAAM 452 Spring 2005
Boundary Condition
• Suppose are two numerical solutions with

• Then:

• i.e. if we are spot on with the left boundary
condition the N iterator is indeed a contraction.
, µ o
0 0
n n
µ o =
1 1
0 0
1 1
1
n n n n n n
n n
dx µ o ì µ o µ o
µ o
+ +
÷ s ÷ + ÷
s ÷
CAAM 452 Spring 2005
Relaxation on Stability Condition
• Previous contraction condition on the numerical
iterator N

• A less stringent condition is:

• Where alpha is a constant independent of dt as dt-
>0
( ) ( )
N P N Q P Q ÷ s ÷
( ) ( ) ( )
1 N P N Q dt P Q o ÷ s + ÷
CAAM 452 Spring 2005
Relaxation on Stability Condition
• In this case the stability analysis yields:
( ) ( ) { }
( )
( ) ( )
{ }
( ) ( )
( )
( )
1
1
1
1 1
1
1 0
1
0
1,..
1
1 1
.....
1 1
max Ndt=T
n n n n n
n n n n n
n n n
n n n
m n
n n m
n m
m
T m
m n
E N q E N q dtR
E q E q dt R
E dt E dt R
dt dt E dt R dt R
E dt E dt dt R
e E T R
o
o
o o
o o
+
+
+
÷ ÷
=
+ ÷
+
=
=
= + ÷ +
¹
s + ÷ +
+
s + +
s + + + +
s
+
s + + +
s +
¿
CAAM 452 Spring 2005
Interpretation

• Relaxing the stability yields a possible exponential
growth – but this growth is independent of T so if
we reduce dt (and dx) then the error will decay to
zero for fixed T.

( )
( )
1 0
1,..
max , Ndt=T
n T m
m n
E e E T R
o +
=
s +
CAAM 452 Spring 2005
Homework 2
• Due on Friday

• Recall report presentation policy

• Time will be given in class on Wednesday to go
over questions.
CAAM 452 Spring 2005
Homework 2
Q1) Solve the pde analytically on the domain

Q2) Solve the pde
analytically.

Q3) Solve the pde
analytically

and explain what happens to the density along the
characteristics.
2
2 0
( , 0)
x
t x
x t e
µ µ
µ
÷
c c
+ =
c c
= =
( )
, [0, ) ÷· · × ·
2
2 2
( , 0)
x
x t
t x
x t e
µ µ
µ
÷
c c
+ = ÷
c c
= =
2
3
( , 0)
x
t x
x t e
µ µ
µ
µ
÷
c c
+ = ÷
c c
= =
PTO
CAAM 452 Spring 2005
Homework 2 cont
Q4) Implement the numerical approximation of:

By:
2
3 0
( , 0)
x
t x
x t e
µ µ
µ
÷
c c
+ =
c c
= =
( ) ( )
1 1
1
1
0
1
0
0
Geometry:
1
4, 4,
1 1
Scheme:
1
3
Initial Condition :
, 0
2
Boundary Condition :
0
N i N
n n n
i i i
i i
i
N i i
x x x x x
N N
dt
dx
x x
t
µ ì µ ì µ
ì
µ µ
µ
+
÷
+
÷ ÷
| | | |
= ÷ = = +
| |
÷ ÷
\ . \ .
= ÷ +
=
| | +
| |
= =
|
|
\ .
\ .
=
CAAM 452 Spring 2005
Homework 2 cont
Q4 cont)

For N=10,40,160,320,640,1280 run to t=100, with:
dx = (8/(N-1))
dt = dx/6

On the same graph, plot t on the horizontal axis and error
on the vertical axis. The graph should consist of a sequence
of 6 curves – one for each choice of dx.

Comment on the curves.

NOTE: For the purposes of this test we define error as:

1
1
max ,
2
n n
i i
i
i N
x x
error ndt µ µ
+
s s
| |
+
| |
= ÷
| |
\ .
\ .
CAAM 452 Spring 2005
Lecture 5
• We will define stability for a numerical scheme and
investigate stability for the upwind scheme.

• We will compare this scheme with a finite difference
scheme.

• We will consider alternative ways to approximate
the flux functions.

CAAM 452 Spring 2005
Homework 2
correction
Q4) Implement the numerical approximation of:

By:
2
3 0
( , 0)
x
t x
x t e
µ µ
µ
÷
c c
+ =
c c
= =
( ) ( )
1 1
1
1
0
1
0
0
Geometry:
1
4, 4,
1 1
Scheme:
1
3
Initial Condition :
, 0
2
Boundary Condition :
0
N i N
n n n
i i i
i i
i
N i i
x x x x x
N N
dt
dx
x x
t
µ ì µ ì µ
ì
µ µ
µ
+
÷
+
÷ ÷
| | | |
= ÷ = = +
| |
÷ ÷
\ . \ .
= ÷ +
=
| | +
| |
= =
|
|
\ .
\ .
=
CAAM 452 Spring 2005
Homework 2 cont
Q4 cont)

For N=10,40,160,320,640,1280 run to t=10, with:
dx = (8/(N-1))
dt = dx/6

Use

On the same graph, plot t on the horizontal axis and error on the vertical
axis. The graph should consist of a sequence of 6 curves – one for each
choice of dx.

Comment on the curves.

NOTE: For the purposes of this test we define error as:

1
1
max ,
2
n n
i i
i
i N
x x
error ndt µ µ
+
s s
| |
+
| |
= ÷
| |
\ .
\ .
1
0 0 1
1
n n n
N
dt dt
u u
dx dx
µ µ µ
+
÷
| | | |
= ÷ +
| |
\ . \ .

Today
• Introduction to a very basic finite volume method

CAAM 452 Spring 2005

Mass Conservation
• For the following we are going to consider a 1-dimensional domain which we parameterize with the variable x.

x • Now imagine that this line is a figurative representation of a pipe which contains fluid. • At every point on the line the fluid has a density measured in mass per meter ( with units kgm-1 ) • We define a new function  :   [0, ) which is a non-negative, real valued function defined on the space-time domain. CAAM 452 Spring 2005

Derivation of Mass Conservation Law
• Next we consider an arbitrary section of the pipe, say [a,b] • We now assume that the fluid is not created or destroyed at any point inside the section and is traveling with velocity u (which is a function of space and time). For the moment we will assume that u is positive (i.e. the fluid is flowing in the direction of positive x) • This allows us to state the following: – The time rate of change of the total fluid inside the section [a,b] changes only due to the flux of fluid into and out of the pipe at the ends x=a and x=b. • A simple formula relating these two quantities is:

d    x, t  dx  u b, t   b, t   u  a, t    a, t  dt a
CAAM 452 Spring 2005

b

t    a.b] The flux out of the section at the right end of the section of pipe per unit time The flux into the section at the left end of the section of pipe per unit time CAAM 452 Spring 2005 .• In detail: d    x. t   u  a. t  dx  u  b. t    b. t  dt a b The time rate of change of total mass in the section of pipe [a.

t  dx     u  x. t    x.Use the Fundamental Theorem of Calculus • Look carefully at the right hand side: d    x. t    a. t   x  u  x. t    x. t  dx  u b. t  dt a b • Clearly we may rewrite this as: b b d    x. t  dx dt  x a a • From which we may deduce: b    t   x. t   u  a. t   dx  0 a CAAM 452 Spring 2005 . t   b.

t   dx  0 a b is continuous and noting that this relation holds for all choices of a.b then we may deduce:     x. t    x. t    0 t x • In short hand:    u    0 t x CAAM 452 Spring 2005 . t    x. t   x  u  x. t    u  x.Finally… • Assuming that the integrand of:    t   x.

t   u • Then the pde reduces to the advection equation:   u 0 t x • This is a pretty easy equation to solve . constant. Consider the change of variables: t  t x  x  ut CAAM 452 Spring 2005 .Advection Equation • Let’s choose a simple. fluid velocity u  x.

• Note that the units of each variable are consistent. t  t x  x  ut • Basic calculus:  t  x       u t t t t x t x  t  x      x x t x x x • From which we obtain: 0   u t x         u u   x   t  x    t CAAM 452 Spring 2005 .

t  0  • So an interesting property of the advection equation is the way that the profile of the solution does not change shape but it does shift in the positive x direction with constant velocity CAAM 452 Spring 2005 . t   0  x   0  x  ut  where: 0  x  :   x.Solution and Interpretation • So we know:   0 t • Which we can instantly solve:   x.

Space Time Diagram • Let’s track the information: t 1 Slope = u x • The dashed lines are x  ut  const which are known as characteristics of the equation. • If we choose a point on one of these dashed lines and track back down to t=0 and we will find the value of the density which applies at all points on the dashed line CAAM 452 Spring 2005 .

b then we may deduce:     x. t   b. t   dx  0  t x a is continuous and noting that this relation holds for all choices of a. t    a.Recall • Assuming that the integrand of: b     x. t    u  x. t   u  a. t    x. t    x. t    u  x. t    0 t x • Well – this does not hold if the density is discontinuous and the integral equation is the appropriate representation: d    x. t  dt a CAAM 452 Spring 2005 b . t  dx  u b.

N  1 CAAM 452 Spring 2005 . t  dx  u   b.Building a Finite Volume Solver 1) Let’s consider the advection equation: d    x. t   u   a.. t  dt a 2) Next we take a finite portion of the real line from x1 to xN divided into N-1 equal length sections b x1 dx xN 3) In each section we will approximate the density by a constant value i  i  1....

Piecewise Constant Approximation  x1 xN In the n’th section the density will be approximated by the constant: n  CAAM 452 Spring 2005 .

t  dx  u  b. b=xi+1. t  dt a b • Is approximated (to first order in time) by: in1  in  dx  dt where the time axis has been divided into sections of length dt and the i’th cell average at time n*dt is represented by  u   xi1 . t  ndt  dx xi • Outstanding question: Now we have to figure out how to evaluate the density at the interval end points given the cell averages. t   u   xi . CAAM 452 Spring 2005 . t  in  xi 1    x. t   u   a. d    x.• Choosing a = xi.

t   u   xi . t   u in  u in 1  CAAM 452 Spring 2005 .Upwind Treatment for Flux Terms t 1 Slope = u • Recall that the solution shifts from left to right as time increases. • Idea: use the upwind values u   xi 1 .

Basic Upwind Finite Volume Method  n1 i  in  dx dt  u in  u in 1  simplify  n 1 i dt  n  dt  n   1  u  i   u  i 1 dx    dx   u dt dx in1  1    in     in 1  Note we must supply a value for the left most average at each time step:  n 0 CAAM 452 Spring 2005 .

t  dt Approximate fluxes with upwind flux d  qi dx   uqi  uqi1 dt  n1 i  in  dx dt Approximate time derivative and look for solution in  qin  u in  u in 1   u dt dx in1  1    in     in 1  0n Note we must supply a value for the left most average at each time step: CAAM 452 Spring 2005 . t   uq  xi .Recall Basic Upwind Finite Volume Method d  qi dx   uq  xi1 .

t dx   dxqi   uq  xi 1 . we need to do some extra analysis to determine how good at approximating the true PDE the discrete scheme is. ndt   xi 1 x q  x. • Let us suppose that the i’th subinterval cell average of the actual solution to the PDE at time T=n*dt is denoted by qin  1 xi 1  xi xi 1  q  x. t  dt CAAM 452 Spring 2005 .Convergence • We have constructed a physically reasonable numerical scheme to approximate the advection equation. • However. ndt  dx i xi 1 where q satisfies: d dt xi 1  xi d q  x. t   uq  xi .

CAAM 452 Spring 2005 . • So we are interested in the error: E  q  n i n i n i T . independent of dx). • Suppose we let dt  0 and E n  O  dt s  then the scheme is said to be of order s. dt = Cdx for some C.e.n dt • For the given finite volume scheme dt and dx will be related in a fixed manner (i.Error Equation • The goal is to estimate the difference of the exact solution and the numerically obtained solution at some time T=n*dt.

|| if: n • It is said to be accurate of order s if:  dt 0 ndt T lim E  0  E n  O  dt s  as dt  0 CAAM 452 Spring 2005 .Norms and Definitions • We define the discrete p-norms: E p  p   dx  Ei   i  i  1/ p • We say that the scheme is convergent at time T in the norm ||.

one question we can ask is how large is the error committed in the evaluation of the approximate solution at the end of the time step.Local Truncation Error • Suppose at the beginning of a time step we actually have the exact solution -. choose • Then • We expand  dt  n  dt  n   1  u  qi   u  qi1  dx   dx  1 n1 n Ri :  i  qin1  dt qin 1 .tn with Taylor series:   ____  2  q  dx   q  n n qi 1  qi  dx    O (dx 3 ) 2   x  2  x     ____ ____ 2  2   q  dt   q  qin 1  qin  dt    O (dt 3 ) 2   t  2  t   ____ 2 CAAM 452 Spring 2005 . n n i  qi n 1 i • i. qin1 about xi.e.

Estimating Truncation Error • Inserting the formulas for the expanded q’s: Rin :  1   dt  n  dt  n 1  u  qi   u  qi 1  qin1   dt   dx   dx         1  dt u  q n    i   dx     ____ ____    2 2 1   dt    q  dx   q      u  qin  dx    O (dx 3 )    2 dt   dx    x  2  x         ____ ____  2 2   n   q  dt   q  3    qi  dt     t 2  O (dt )   t  2           CAAM 452 Spring 2005 .

Estimating Truncation Error • Removing canceling terms:      1  dt u  q n    i   dx     ____ ____    2 2 1   dt    q  dx   q  Rin :    u  qin  dx    O (dx 3 )    2 dt   dx    x  2  x         ____ ____  2 2   n   q  dt   q  3    qi  dt     t 2  O(dt )   t  2           CAAM 452 Spring 2005 .

Estimating Truncation Error • Simplifying:  ____ ____   2 2    dt u  dx  q  dx   q  O(dx3 )       x 2    dx      x  2     1   Rin :   ____ ____ dt     2 2 q  dt   q      dt     O(dt 3 )     t 2      t  2          ____   ____      q  u  q           t   x         n Ri :   ____ ____     dt   2 q  dx   2 q  2 2      2  O(dt )   u   2  O(dx )   2  x    2  t      CAAM 452 Spring 2005 .

Final Form ____   ____ • Using the definition  q of q q      u            t   x         n Ri :   ____ ____     dt   2 q  dx   2 q       2  O(dt 2 )   u   2  O(dx 2 )   2  x    2  t      ____ ____     2q    2q  dt dx Rin :    2  O(dt 2 )   u   2  O(dx 2 )   2  t   2  x      ____ ____ 2 2 Using that:  q 2  q u 2 t x 2  ____  udx  udt    2 q  n Ri : 1  O(dx 2 )   2  dx   x 2    CAAM 452 Spring 2005 .

This property is known as consistency. This essentially implies that the numerical solution diverges from the actual solution by an error of O(dx) every time step. CAAM 452 Spring 2005 . If we assume that the solution q is smooth enough then the truncation error converges to zero with decreasing dx.Interpretation of Consistency  ____  udx  udt    2 q  n Ri : 1  O(dx 2 )   2  dx   x 2      So the truncation error is O(dx) under the assumption that dt/dx is a constant..

CAAM 452 Spring 2005 .Error Equation • We define the error variable: in  qin  Ein  n1  N  n • We next define the numerical iterator N: • Then: E n 1  N q  E n n q  N q  E   N q   N q   q   N  q  E   N  q   dtR n n 1 n n n n n n n n 1 • So the new error consists of the action of the numerical scheme on the previous error and the error commited in the approximation of the derivatives.

e. N is a contraction operator in some norm then… CAAM 452 Spring 2005 .Abstract Scheme • Without considering the specific construction of the scheme suppose that the numerical N operator satisfies: N  P   N Q   P  Q • i.

...Estimating Error in Terms of Initial Error and Cumulative Truncation Error E n1  N  q n  E n   N  q n   dtR n  E n1  N  q n  E n   N  q n   dt R n  E n1  q n  E n  q n  dt R n  E n1  E n  dt R n  E n1  dt R n 1  dt R n  .  E n 1   triangle inequality contraction property of N    E  dt  R m 0 m 1 mn by induction CAAM 452 Spring 2005 ..

CAAM 452 Spring 2005 .n E n1  E 0  T max R m   • If the method is consistent (and the actual solution is smooth enough) then: E n1  E 0  T O  dx  • As dx -> 0 the initial error ->0 and consequently the numerical error at time T tends to zero with decreasing dx (and dt)...dt) E n 1  E  dt  R m 0 m 1 mn  m 1.Error at a Time T (independent of dx.

Specific Case: Stability and Consistency for the Upwind Finite Volume Scheme • We already proved that the upwind FV scheme is consistent. • We still need to prove stability of. in1  1    in     in 1  CAAM 452 Spring 2005 .

Stability in the Discrete 1-norm in1  1    in     in1   n 1 1  dx in1 i 1 N 1  dx 1    in     in 1  i 1 N 1 i 1 N 1 i 1 n i N 1 triangle inequality  dx 1      dx  in 1 assuming 0    1   dx   dx in n 0 i 1 N 1  dx  0n   n 1 So here’s the interesting story. In the case of a zero boundary condition then we automatically observe that the operator is a contraction operator. CAAM 452 Spring 2005 .

if we are spot on with the left boundary condition the N iterator is indeed a contraction. are two numerical solutions with  n1   n1 1  dx 0n   0n   n   n   n  n 1 1 n 0 • Then: • i. CAAM 452 Spring 2005 .e.Boundary Condition • Suppose   n 0  .

Relaxation on Stability Condition • Previous contraction condition on the numerical iterator N N  P   N Q   P  Q • A less stringent condition is: N  P   N  Q   1   dt  P  Q • Where alpha is a constant independent of dt as dt>0 CAAM 452 Spring 2005 .

 E n 1      1   dt   eT n 1 E  dt  1   dt  0 m 1 m 1.Relaxation on Stability Condition • In this case the stability analysis yields: E n1  N  q n  E n   N  q n   dtR n  E n1  q n  E n  q n  dt R n  E n1  1   dt  E n  dt R n  1   dt  1   dt  E n1  dt R n1  dt R n  ..n mn nm Rm  E 0  T max R m   Ndt=T CAAM 452 Spring 2005 ......

Interpretation E n1  eT E 0  T max R m m 1.. Ndt=T • Relaxing the stability yields a possible exponential growth – but this growth is independent of T so if we reduce dt (and dx) then the error will decay to zero for fixed T..n    . CAAM 452 Spring 2005 .

CAAM 452 Spring 2005 .Homework 2 • Due on Friday • Recall report presentation policy • Time will be given in class on Wednesday to go over questions.

CAAM 452 Spring 2005 PTO . t  0)  e  x2 and explain what happens to the density along the characteristics.  x2  . t  0)  e  x2 Q3) Solve the pde analytically   3   t x  ( x.Homework 2 Q1) Solve the pde   2 0 t x analytically on the domain  ( x.    [0. t  0)  e Q2) Solve the pde analytically. )   2  x  2t t x  ( x.

xi   x1     xN  N 1   N 1  Scheme: in1  1    in     in 1  dt  3 dx Initial Condition :   xi  xi 1       . t  0)  e Geometry: By:  x2  N i   i 1  x1  4.t  0   2   Boundary Condition : 0 i 00  0 CAAM 452 Spring 2005 . xN  4.Homework 2 cont Q4) Implement the numerical approximation of:   3 0 t x  ( x.

NOTE: For the purposes of this test we define error as:  x x  error n  max  in    i i 1 .Homework 2 cont Q4 cont) For N=10.160. with: dx = (8/(N-1)) dt = dx/6 On the same graph. plot t on the horizontal axis and error on the vertical axis.1280 run to t=100.320. The graph should consist of a sequence of 6 curves – one for each choice of dx.40. ndt   1i  N  2   CAAM 452 Spring 2005 . Comment on the curves.640.

CAAM 452 Spring 2005 . • We will compare this scheme with a finite difference scheme.Lecture 5 • We will define stability for a numerical scheme and investigate stability for the upwind scheme. • We will consider alternative ways to approximate the flux functions.

xN  4. t  0)  e  N i   i 1  x1  4.t  0   2   Boundary Condition : 0 i 00  0 CAAM 452 Spring 2005 .Homework 2 correctionapproximation of: Q4) Implement the numerical Geometry: By:   3 0 t x  ( x. xi   x1     xN  N 1   N 1  Scheme:  x2 in1  1    in     in 1  dt  3 dx Initial Condition :   xi  xi 1       .

40. NOTE: For the purposes of thistest we define error as: x x  error n  max  in    i i 1 . ndt   1i  N  2   CAAM 452 Spring 2005 . plot t on the horizontal axis and error on the vertical axis.320.640.Homework 2 cont Q4 cont) For N=10. Comment on the curves. The graph should consist of a sequence of 6 curves – one for each choice of dx.1280 run to t=10. with: dx = (8/(N-1)) dt = dx/6 Use 0n1  1  u   dt  n  dt  n  0   u   N 1 dx   dx  On the same graph.160.