Transcript MA375
MA/CS471
Lecture 6
Fall 2003
Prof. Tim Warburton
[email protected]
1
Today
Today we are going to derive one of the simplest possible
partial differential equations:
u
u
a
0
t
x
We will then motivate a simple numerical scheme for solving
this equation.. (btw I was going to talk about a finite difference
scheme, but instead I will discuss a finite volume scheme).
2
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.
3
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
d
x, t dx u b, t b, t u a, t a, t
dt a
Explain on board
4
• In detail:
b
d
x, t dx u b, t b, t u a, t a, t
dt 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
5
Use the Fundamental Theorem of Calculus
• Look carefully at the right hand side:
b
d
x, t dx u b, t b, t u a, t a, t
dt a
• Clearly we may rewrite this as:
d
x, t dx u x, t x, t dx
dt a
x
a
b
b
• From which we may deduce:
a t x, t x u x, t x, t dx 0
b
6
Finally…
• Assuming that the integrand of:
a t x, t x u x, t x, t dx 0
b
is continuous and noting that this relation
holds for all choices of a,b then we may
deduce:
x, t u x, t x , t 0
t
x
• In short hand:
u
0
t
x
7
Advection Equation
• Let’s choose a simple, constant, fluid velocity
u x, t u
• Then the pde reduces to the advection equation:
u
0
t
x
• This is a pretty easy equation to solve . Consider
the change of variables:
t t
x x ut
8
• 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
9
Solution and Interpretation
• So we know: 0
t
• Which we can instantly solve: x, t 0 x
0 x ut
where: 0 x : x, 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
10
Space Time Diagram
• Let’s track the information:
t
1
Slope =
u
• The dashed lines are x ut const which are known as
characteristics of the equation.
x
• 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
11
Recall
• Assuming that the integrand of:
a t x, t x u x, t x, t dx 0
b
is continuous and noting that this relation holds for all
choices of a,b then we may deduce:
x, t u x, t x , t 0
t
x
• Well – this does not hold if the density is discontinuous
and the integral equation is the appropriate
representation: d b
x, t dx u b, t b, t u a, t a, t
dt
a
12
Building a Finite Volume Solver
1) Let’s consider the advection equation:
b
d
x, t dx u b, 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
x1
dx
xN
3) In each section we will approximate the density by a
constant value
i
i 1,..., N 1
13
Piecewise Constant Approximation
x1
xN
In the n’th section the density will be approximated by the
constant:
n
14
• Choosing a = xi, b=xi+1,
b
d
x, t dx u b, t u a, t
dt a
• Is approximated (to first order in time) by:
in1 in dx u x , t u x , t
i 1
i
dt
where the time axis has been divided into sections of
length dt and the i’th cell xaverage at time n*dt is
i 1
1
represented by
in
x, t ndt dx
dx xi
• Outstanding question: Now we have to figure out how to
evaluate the density at the interval end points given the
cell averages.
15
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 xi1 , t u xi , t u in u in1
16
Basic Upwind Finite Volume Method
n1
i
in dx
dt
u in u in1
simplify
in1 1 u
dt n dt n
i u i 1
dx
dx
u
dt
dx
in1 1 in in1
Note: we must supply a value for the left most average at each time step:
0n
17
Homework
• Advance notice of homework to come.
• After finishing the card playing homework
start on the following homework.
• The first version of the code should be written
and debugged in serial..
• Due: 09/24/03
18
Homework
Q1) Solve the pde
2
0
t
x
( x, t 0) e
Q2) Solve the pde
analytically.
Q3) Solve the pde
analytically
analytically on the domain
x2
, [0, )
2
x 2t
t
x
( x, t 0) e
x2
3
t
x
( x, t 0) e
x2
and explain what happens to the density along the characteristics.
19
PTO
Homework cont
Q4) Implement the finite volume approximation of: t 3 x 0
( x, t 0) e
x2
Geometry:
By:
N i
i 1
x1 4, xN 4, xi
x
1
xN
N 1
N 1
Scheme:
in1 1 in in1
dt
3
dx
Initial Condition :
xi xi 1
,t 0
2
Boundary Condition :
0
i
0
0
0
20
Homework cont
Q4 cont)
a) For N=10,40,160,320,640,1280 run to t=100, with:
dx = (8/(N-1))
dt = dx/6
b) 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.
c) Comment on the curves.
d) NOTE: For the purposes of this test we define error as:
x x
error n max in i i 1 , ndt
1i N
2
21