You are on page 1of 44

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
Advection Equation
Lets 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
Lets 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) Lets 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 nth 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 ith 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
approximate the advection equation.

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 ith 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

We expand about x
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 qs:
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 heres 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

+

| | | |
= +
| |
\ . \ .

You might also like