Вы находитесь на странице: 1из 19

CEE262c Lecture 5 1

CEE262c Lecture 5: The advection-diffusion


equation
In Lecture 4 we showed that the FTCS scheme can be used in the presence of diffusion and
it will be stable as long as
C 2
Pe = < or C 2 < 2s < 1
s C
The addition of diffusion alters the character of the original PDE because it is no longer
purely hyperbolic. But that is the price of stability. While the addition of diffusion stabilizes
the scheme, it also adds another stability limitation. In the absence of advection, a forward
Euler discretization of the second-order central diffusion discretization is given by

2
= 2
t x
n+1
j j j1 2j + j+1
=
t x2
n+1
j = j + s (j1 2j + j+1 )

where s = t/x2 . This scheme is stable as long as 2s < 1, which, from a Hirt analysis, is
required in order to render the sign of the 4th-order derivative leading truncation error term
negative.

In most practical problems, the action of diffusion is usually confined to a relatively small
portion of the flow. Some examples are depicted in Figures 1, 2, and 3.

Figure 1: Propagation of a pollutant field.

Because the effects of diffusion are confined to very small regions of the flow, it is common
to add more grid points near boundaries or at fronts for improved resolution. This poses a
CEE262c Lecture 5 2

Figure 2: Viscous flow near boundaries.

Figure 3: Heat flux and conduction/turbulent diffusion into a lake.

very rigid stability limitation since, if s < 1/2, this implies

x2
t <
2
As an example, consider the flow in an estuary that is 10 m deep and the finest resolution
near the surface is z = 0.25 m. If we assume a near-surface, wind-induced turbulent
diffusion coefficient of = 0.01 m2 s1 , this implies

0.252
t < = 3.125 s
2 0.01
which is much less than the restriction imposed by advection, since if first-order upwinding
is used with forward Euler in time for advection, and if the vertical velocity is roughly
0.01 m s1 , then
z 0.25
t < = = 25 s
w 0.01
In order to remove the strict stability limitation associated with diffusion, the diffusion term
is often treated implicitly.
CEE262c Lecture 5 3

1 Implicit discretization of the diffusion term

If instead of using Forward Euler for the diffusion term, we employ Backward Euler, then
the diffusion equation is discretized as

2
= 2
t x
n+1
j jn
n+1
j 2n+1
j + n+1
j
=
t x2
Substitution of a Fourier mode nj = n exp(ikxj ) yields
 
n+1 n
exp(ikxj ) = 2
(exp(ikx) 2 + exp(ikx)) n+1 exp(ikxj )
t x
n+1 n = s (2 + exp(ikx) + exp(ikx)) n+1
n+1 n = 2s (1 cos(kx))) n+1
n+1 [1 + 2s(1 cos(kx))] = n
n+1 1
Gn = n =
1 + 2s(1 cos(kx))

Since 0 1 cos(kx) 2, then |Gn | < 1 for all s > 0, so the scheme is unconditionally
stable. The advantage of this implicit scheme is that it removes the stability limitation
associated with the diffusion operator. The disadvantage is that the problem becomes more
expensive to solve numerically. Consider the implicit discretization of the diffusion equation

n+1
j = nj + s n+1 n+1
j1 2j + nj

To solve for n+1


j we need to write this equation as

sn+1 n+1
j1 + (1 + 2s)j sn+1 n
j+1 = j
aj n+1 n+1
j1 + bj j + cj n+1 n
j+1 = j

where the coefficients are given by

aj = s bj = 1 + 2s cj = s

which defines a system of equations for n+1


j . Before we can solve this set of equations we need
to specify boundary conditions. We can specify one of the following boundary conditions

Dirichlet (specify a value): (x = 0) = b (t)

Neumann (specify a derivative): d/dx = gb (t)

Robin (mixed): a(x = 0) + bd/dx = c(t)


CEE262c Lecture 5 4

Figure 4: A finite difference grid with Dirichlet boundary conditions.

1.1 Dirichlet condition with a finite-difference grid

Dirichlet condition specifies a value:

n+1
1 = b (tn+1 )

Since n+1
1 is specified, this now alters the equation at j = 2. Writing the discretized equation
at j = 2 requires n+1
1 :

a2 n+1
1 + b2 n+1
2 + c2 n+1
3 = n2

Using the boundary condition, this is written as

a2 b (tn+1 ) + b2 n+1
2 + c2 n+1
3 = n2
b2 n+1
2 + c2 n+1
2 = n2 a2 b (tn+1 )

1.2 Neumann condition with a finite difference grid

Figure 5: A finite difference grid with Neumann boundary conditions.

Neumann condition specifies a derivative:


n+1 n+1
= 1 0
+ O (x) = g (tn+1 )
x x
n+1
0 = n+1
1 xg (tn+1 )

Writing the discretized equation at j = 1 requires n+1


0 :

a1 n+1
0 + b1 n+1
1 + c1 n+1
2 = n1
CEE262c Lecture 5 5

Using the boundary condition, this is written as


 
a1 n+1
1 xg (tn+1 ) + b1 n+1
1 + c1 n+1
2 = n1
(a1 + b1 )n+1
1 + c1 n+1
2 = n1 + a1 xg (tn+1 )

1.3 Dirichlet condition with a finite volume grid

Boundaries are now located half-way between points, as shown in Figure 6. Dirichlet condi-
tion specifies a value, which now must be interpolated:
1 n+1  
n+1 = + n+1
+ O x 2
= b (tn+1 )
1/2
2 0 1

which now gives n+1


0 in terms of n+1
1 as
n+1
0 = n+1
1 + 2b (t)
Writing the discretized equation at j = 1 requires n+1
0 :
a1 n+1
0 + b1 n+1
1 + c1 n+1
2 = n1
Using the boundary condition, this is written as

a1 1 + 2b (tn+1 ) + b1 n+1
1 + c1 n+1
2 = n1
(a1 + b1 )n+1
1 + c1 n+1
2 = n1 2a1 b (tn+1 )

Figure 6: A finite volume grid with Dirichlet or Neumann boundary conditions.

1.4 Neumann condition with a finite volume grid

Neumann condition specifies a derivative, which is given by:



n+1 n+1 
= 1 0
+ O x2 = g (tn+1 )
x 1/2
x
CEE262c Lecture 5 6

which now gives n+1


0 in terms of n+1
1 as

n+1
0 = n+1
1 xg (tn+1 )

Writing the discretized equation at j = 1 requires n+1


0 :

a1 n+1
0 + b1 n+1
1 + c1 n+1
2 = n1

Using the boundary condition, this is written as



a1 1 xg (tn+1 ) + b1 n+1
1 + c1 n+1
2 = n1
(a1 + b1 )n+1
1 + c1 n+1
2 = n1 + xa1 g (tn+1 )

1.5 Boundary Condition Summary at i = 1 (or 2) to obtain 0 (or

1 ):
Finite difference w/Dirichlet: b2 n+1
2 + c2 n+1
3 = n2 a2 b (tn+1 )

Finite difference w/Neumann: (a1 + b1 )n+1


1 + c1 n+1
2 = n1 + a1 xg (tn+1 )

Finite volume w/Dirichlet: (a1 + b1 )n+1


1 + c1 n+1
2 = n1 2a1 b (tn+1 )

Finite volume w/Neumann: (a1 + b1 )n+1


1 + c1 n+1
2 = n1 + xa1 g (tn+1 )

In general, the discrete implementation of a boundary condition reduces the equation at


i = 1 (or 2, for the dirichlet condition on a finite-difference grid) from

a1 n+1
0 + b1 n+1
1 + c1 n+1
2 = n1

to

b1 n+1
1 + c1 n+1
2 = n1 + b1

The same procedure is required for the dicretization at i = N , since

aN n+1 n+1
N 1 + bN N + cN n+1 n
N +1 = N

requires the ghost point N +1 . Using the appropriate boundary conditions, the equation at
i = N becomes

aN n+1 n+1
N 1 + bN N = nN + bN
CEE262c Lecture 5 7

2 The discrete diffusion equation in matrix-vector form

If we write the equations out for i = 1, . . . , N , we have


b1 n+1
1 + c1 n+1
2 = n1 + b1
a2 n+1
1 + b2 n+1
2 + c2 n+1
3 = n2
..
.
aN 1 n+1 n+1 n+1
N 2 + bN 1 N 1 + cN 1 N = N 1
n+1 n+1
aN N 1 + bN N

= nN + bN
which can be written in matrix-vector form as

b1 c1 n+1
1 n1 + b1
a1 b 1
c1
n+1
2

n2

... ... ... .. ..
. = .

aN 1 bN 1 cN 1 n+1
N 1
nN 1
aN 1 bN 1 n+1
N N + bN
This matrix is a tridiagonal matrix since it has zeros everywhere except along the three
diagonals. Instead of inverting the full matrix, which can be very expensive, we use sparse
matrix methods to invert matrices which have zeros in most of their elements. The simplest
and most common sparse matrix method is the tridiagonal solver.

By writing the problem in matrix-vector form we effectively write it as


M rn+1 = b rn+1 = M 1 b
where the inverse of the matrix M is not actually computed, but instead the solution is found
via the tridiagonal solver. If we had taken our original PDE and discretized it in space first,
we could have written it in the form
dr
= Dr
dt
where D is the diffusion matrix. We can then impose the backward Euler time differencing
scheme and write this as
rn+1 rn
= Drn+1
t
which can be rearranged to yield (I tD) rn+1 = rn so that the solution is given by
rn+1 = (I tD)1 rn
where I tD = M from the previous example.

We can also use this notation to discretize the problem in time with a different discretization
scheme, such as the second-order accurate Crank-Nicolson scheme, for which
rn+1 rn 1 
= Drn + Drn+1
t 2
CEE262c Lecture 5 8

which can be rearranged to yield


t n t n+1
rn+1 = rn + Dr + Dr
  2  2 
t t
I D rn+1 = I + D rn
2 2

the solution is then given by


 1  
n+1 t t
r = I D I+ D rn
2 2

Of course, this is mostly a convenient way of writing the method of solution. In practice, the
matrices are usually not constructed (if they are sparse) and the right hand side is usually
computed element by element rather than with a matrix-vector product.

3 Discretizations of the advection-diffusion equation

Given the 1-d advection-diffusion equation

2
+u = 2
t x x
we can employ the spatial discretization first to write the partial differential equation as
dr
= U r + Dr
dt
where U is the advection matrix (with opposite sign to that described in lecture 2), and D
is the diffusion matrix. This equation assumes that all appropriate boundary conditions are
imposed when constructing the matrices. We can discretize each term individually in time
with a different scheme based on the stability limitations of that scheme. For example, if
we would like to remove the stability limitation associated with the diffusion term, we can
discretize it implicitly with the backward Euler scheme and the advection term explicitly
with the forward Euler scheme:
Z tn+1 Z tn+1
dr
dt = (U r + Dr) dt
tn dt tn
rn+1 rn
= U rn + O (t) + Drn+1 + O (t)
t
The solution would then be given by

(I tD) rn+1 = (I + tU ) rn rn+1 = (I tD)1 (I + tU ) rn


CEE262c Lecture 5 9

As another example, using Crank-Nicolson for diffusion and forward Euler for advection we
would have
rn+1 rn 1  
= U rn + O (t) + D rn + rn+1 + O t2
 t
  2
t t
I D rn+1 = I + tU + D rn + O (t)
2 2

where now the method is first-order accurate due to the discretization of the advection term.
The solution can then be obtained with
 1  
n+1 t t
r = I D I + tU + D rn + O (t)
2 2

Second-order accuracy can be obtained by using the Adams-Bashforth method to approxi-


mate the advection term with
1  
U rn+1/2 = 3U rn U rn1 + O t2
2
so that the above method becomes
 1   
n+1 t 3t t n t n1 
r = I D I+ U+ D r Ur + O t2
2 2 2 2

4 Stability of the advection-diffusion equation

Discretizing the advection and diffusion terms with second-order central differences in space
gives
Dj u
+ (i+1 i1 ) = (i1 2i + i+1 ) ,
Dt 2x x2
CEE262c Lecture 5 10

Substitution of j = exp(ikxj ) into this discretization gives


j+1 j1 exp[ik(xj + x)] exp[ik(xj x)]
=
2x 2x
exp(ikx) exp(ikx)
= exp(ikxj )
2x
2i sin(kx)
= j
2x
i sin(kx)
= j
x
j1 2j + j+1 exp[ik(xj x)] 2 exp[ikxj ] + exp[ik(xj + x)]
2
=
x x2
exp(ikx) 2 + exp(ikx)
= exp(ikxj )
x2
2 cos(kx) 2
= j
x2
2[1 cos(kx)]
= j
x2
Substitution into the 1-d advection-diffusion equation yields
dj iu 2
= j sin(kx) j [1 cos(kx)]
dt x x2
1
= [j iC sin(kx) j 2s[1 cos(kx)]]
h
1
= (D hj + iA hj )
h
where
D h = 2s[1 cos(kx)]
A h = iC sin(kx) ,
and
ut
C = ,
x
t
s = .
x2

Stability will always be determined by the term in the equation that is discretized explicitly.
The amplification factors for each of the schemes in terms of D h and A h are given by

1. Advection: Forward Euler, Diffusion: Forward Euler


n+1
j nj = D hnj + iA hnj
n+1
j = (1 + D h + iA h) nj
Gn = 1 + D h + iA h
CEE262c Lecture 5 11

This is the most restrictive scheme, since both terms are evaluated explicitly. The
region of stability for this scheme is given by the circle of radius 1 centered about
D h = 1 and A h = 0 which requires

(D h + 1)2 + (A h)2 < 1

Substitution yields

[1 2s (1 cos(kx))]2 + C 2 sin2 (kx) < 1


1 4s(1 cos(kx)) + 4s2 (1 cos(kx))2 + C 2 (1 cos2 (kx)) < 1
4s(1 cos(kx)) + 4s2 (1 cos(kx))2 + C 2 (1 + cos(kx))(1 cos(kx)) < 0
4s + 4s2 (1 cos(kx)) + C 2 (1 + cos(kx)) < 0
4s + 4s2 + C 2 + (C 2 4s2 ) cos(kx) < 0
4s + 4s2 + C 2 < (4s2 C 2 ) cos(kx)

Three cases:

(a) cos(kx) = 0

4s + 4s2 + C 2 < 0
C 2 < 4s(1 s)

(b) cos(kx) = +1

4s + 4s2 + C 2 < 4s2 C 2


2C 2 < 4s
C 2 < 2s

(c) cos(kx) = 1

4s + 4s2 + C 2 < C 2 4s2


8s2 4s < 0
4s(2s 1) < 0
0 < 2s < 1 (since the s < 0 case is not possible)

From the last condition we know that s < 1/2, and when this is true 2s < 4s(1 s).
Therefore, we can neglect the first condition to yield the stability bounds shown in
Figure 7, i.e.

C 2 < 2s < 1
CEE262c Lecture 5 12

2. Advection: Forward Euler, Diffusion: Crank-Nicolson


1 
n+1
j n
j = D h n
j + D h n+1
j + iA hnj
  2
 
1 n+1 1
1 D h j = 1 + D h + iA h nj
2 2
1
1 + 2 D h + iA h
Gn =
1 12 D h
From Figure 7 we can see that the stability boundary is defined by the curve
A h2 < 2D h
and, because the diffusive term is handled implicitly, there is no bound on D h. Sub-
stitution yields
C 2 sin2 (kx) < 4s(1 cos(kx))
C 2 (1 cos2 (kx)) < 4s(1 cos(kx))
C 2 (1 + cos(kx))(1 cos(kx)) < 4s(1 cos(kx))
C 2 (1 + cos(kx)) < 4s
C 2 4s < C 2 cos(kx)
Three cases:
(a) cos(kx) = 0

C 2 4s < 0
C 2 < 4s

(b) cos(kx) = +1

C 2 4s < C 2
C 2 < 2s

(c) cos(kx) = 1

C 2 4s < C 2
s > 0
Since condition (b) is more restrictive than condition (a) for s > 0, the resulting
stability limit is
C 2 < 2s
and we have removed the limitation on s because of the implicit treatment of the
diffusion term.
CEE262c Lecture 5 13

3. Advection: Crank-Nicolson, Diffusion: Forward Euler


1 
n+1
j n
j = D h n
j + i A h n
j + i A h n+1
j
   2 
1 1
1 iA h n+1
j = 1 + D h + iA h nj
2 2
1
1 + D h + 2 iA h
Gn =
1 12 iA h
Since the advection term is treated implicitly there is no bound on A h, and the
scheme is therefore unconditionally stable for all C. For s 6= 0, the shaded region for
this scheme in Figure 7 implies
2 < D h < 0
2 < 2s(1 cos(kx)) < 0
1
0<s <
2
which is the limit for the diffusion term in the absence of advection.
4. Advection: Crank-Nicolson, Diffusion: Crank-Nicolson
1  1 
n+1
j nj = D hnj + D hn+1j + iA hnj + iA hn+1
j
  2
  2
1 1 1 1
1 D h iA h n+1
j = 1 + D h + iA h nj
2 2 2 2
1 1
1 + 2 D h + 2 iA h
Gn =
1 12 D h 21 iA h
The shaded region for this scheme implies that there is no stability limitation when
both terms are treated implicitly as long as D h < 0, which implies s > 0, i.e. the
diffusion coefficient must be positive.

The stability regions for each of these schemes is plotted in Figure 7.

5 Discretization of diffusion on a non-uniform grid

Most applications of diffusion involve a non-constant eddy-viscosity in the momentum equa-


tion. For environmental flows, this most commonly occurs in discretizations of vertical diffu-
sion in the horizontal momentum equation. Including only vertical diffusion in the linearized
horizontal momentum equation with a non-constant eddy-viscosity t , one obtains
 
u u 1 p
= t . (1)
t z z 0 x
CEE262c Lecture 5 14

Both explicit Explicit advection, Implicit diffusion


4

2 Ah2<2Dh
A h

Implicit advection,Explicit diffusion Both implicit


4

2
A h

4
4 2 0 2 4 4 2 0 2 4
D h D h

Figure 7: Stability regions for the four schemes discussed in the text.

The most convenient way to discretize this equation is with a non-uniform grid so that more
resolution can be employed to resolve the bottom boundary layer.

Discretizing equation (1) with the theta method in time gives (ignoring the pressure term
for convenience)
 n+1   n
un+1 un n u n u
= t + (1 ) t ,
t z z z z

where we have lagged the eddy-viscosity so that it can be evaluated at time step n. Now
discretizing the vertical derivatives on the non-uniform finite-volume grid depicted in Figure
8.
CEE262c Lecture 5 15

Figure 8: Detail of the non-uniform grid used to discretize the diffusion equation.

  "    #
u 1 u u
t = t t
z z k zk z k+1/2 z k+1/2
 
1 uk+1 uk uk uk1
= t,k+1/2 t,k1/2
zk zk+1/2 zk1/2
t,k+1/2 t,k1/2
= (uk+1 uk ) (uk uk1 )
zk zk+1/2 zk zk1/2
 
t,k1/2 1 t,k1/2 t,k+1/2 t,k+1/2
= uk1 + uk + uk+1
zk zk1/2 zk zk1/2 zk+1/2 zk zk+1/2
ak 1 ak+1
= uk1 (ak + ak+1 )uk + uk+1
zk zk zk
where
t,k1 +t,k
t,k1/2 2 t,k1 + t,k
ak = = zk1 +zk
=
zk1/2 zk1 + zk
2

Substitution into the equation (1) yields


ak n+1 1 ak+1 n+1
un+1
k = unk + t uk1 t (ak + ak+1 )un+1
k + t u
zk zk zk k+1
ak n 1 ak+1 n
+(1 )t uk1 (1 )t (ak + ak+1 )unk + (1 )t u
zk zk zk k+1

 
ak n+1 1 ak+1 n+1
t uk1 + 1 + t (ak + ak+1 ) un+1
k t u =
zk zk zk k+1
 
ak n 1 ak+1 n
(1 )t uk1 + 1 (1 )t (ak + ak+1 ) unk + (1 )t u
zk zk zk k+1
CEE262c Lecture 5 16

Figure 9: Detail of the non-uniform grid away from the wall.

This is a tridiagonal system of equations with nonconstant coefficients and can be written
as
MIn U n+1 = MEn U n ,
where MI and ME are the implicit and explicit diffusion operators, respectively. Note that
because the eddy-viscosity is lagged and evaluated at time step n, this discretization is
formally first-order accurate in time.

5.1 Bottom boundary condition on uk

At k = 1:
  "    #
u 1 u u
t = t t
z z 1 z1 z 3/2 z 1/2

At the lower wall k = 1/2, we apply a quadratic drag law of the form
 
u
t = CD |u1 |u1 . (2)
z 1/2

The drag coefficient is obtained by assuming a log-law velocity profile of the form
 
u z
u= ln ,
z0
CEE262c Lecture 5 17

which shows that, at z = z1 ,  


u z1
u1 = ln . (3)
z0
If we define the friction velocity as
b
(u )2 = = CD |u1 |u1 ,
0
where b is the bottom stress, then equation (3) can be used to show that
  2
1 z1
CD = ln .
z0
Substituting the quadratic drag law into the discrete vertical diffusion equation gives
 
u 1 t,3/2 CD |u1 |
t = (u2 u1 ) u1
z z 1 z1 z3/2 z1
1 1
= (a2 + CD |u1 |) u1 + a 2 u2
z1 z1

Figure 10: Depiction of zb = z1 for the bottom boundary condition.

5.2 Top boundary condition on uk .

At k = Nk :

     
u 1 t u
u
t = t

z z Nk zNk
z N +1/2 z
Nk 1/2
| {z k }
Stress-free
At the free-surface k = Nk + 1/2, we apply a no-stress condition such that
 
u
t =0
z Nk +1/2
CEE262c Lecture 5 18

Substituting,
 
u 1 t,Nk 1/2
t = (uNk uNk 1 )
z z 1 zNk zNk 1/2
1 1
= aNk 1 uNk 1 aN 1 uNk
zNk zNk k

6 Methods for the two-dimensional advection-diffusion

equation

The two-dimensional advection-diffusion equation in conservative form with turbulent diffu-


sion coefficient t , that may vary in space, is given by
   
u v
+ + = t + t .
t x y x x y y

The first step at tackling this equation is deciding on the time-advancement scheme, since
this will determine in a large part the computational complexity of the discretization (i.e. ex-
plicit=cheap/easy, implicit=expensive/complex). The following is a list of time-advancment
possiblities and their advantages and disadvantages:

1. Leapfrog for all terms


   
n+1 = n1 2t Anx (n ) + Any (n ) + 2t Dxn (n ) + Dyn (n ) ,

where
n
Anx () = (u ) ,
x
n
Any () = (v ) ,
y
 
n n
Dx () = t ,
x x
 

Dyn () = nt ,
y y

and the implies a spatial discretization. This scheme would behave well for the
hyperbolic term and is formally second-order accurate in time. However, it would be
unconditionally unstable for any spatial discretization of the diffusion term and would
require a filter to stabilize it.
CEE262c Lecture 5 19

2. Forward Euler for all terms


To counteract the stability problem associated with leapfrog, one might consider em-
ploying forward Euler for all terms in the equation to yield
   
n+1 = n t Anx (n ) + Any (n ) + t Dxn (n ) + Dyn (n ) .

This scheme is succeptible to a stability limitation but behaves well as long as the
aformentioned stability limitations associated with advection and diffusion are satisfied.
For example, if central differencing is employed in space for the advection terms then
enough diffusion must be added such that

Cx2 Cy2
+ < 2,
sx sy

and
1
sx + sy ,
2
where Cx = ut/x, Cy = vt/y, sx = t t/x2 , and sy = t t/y 2 . The
greatest disadvantage to this method is the time-step limitation associated with these
stability constraints.

3. Backward Euler for all terms


A fully-implicit method could be employed by using backward Euler for all terms to
yield
   
n+1 = n t An+1
x (
n+1
) + An+1
y (n+1 ) + t Dxn+1 (n+1 ) + Dyn+1 (n+1 ) .

The disadvantage to this discretization is that it requires the inverse of at least a


pentadiagonal matrix. Numerous methods exist to combat this problem, which involves
methods for numerical linear algebra to invert a sparse matrix. The most common
method is operator splitting, which is also known as approximate factorization, and
splits the directional operators over two time steps such that

= n t [Ax ( ) Dx ( )] ,
 
n+1 = t An+1
y (n+1 ) Dyn+1 (n+1 ) .

This is computational less intensive and substantially easier to program because it


requires tridiagonal inverses rather than a pentadiagonal inverse. Furthermore, the
temporal accuracy is retained if the method is at most second-order accurate in time.

Вам также может понравиться