The Advection-Diffusion equation!: ∂u ∂t + u ∂u ∂x + v ∂u ∂y = − 1 ρ ∂P ∂x + µ ρ ∂ ∂x + ∂ ∂y ⎛ ⎝ ⎜ ⎞ ⎠ ⎟
The Advection-Diffusion equation!: ∂u ∂t + u ∂u ∂x + v ∂u ∂y = − 1 ρ ∂P ∂x + µ ρ ∂ ∂x + ∂ ∂y ⎛ ⎝ ⎜ ⎞ ⎠ ⎟
The Advection-Diffusion
equation
Grtar Tryggvason
Spring 2013
http://www.nd.edu/~gtryggva/CFD-Course/
Computational Fluid Dynamics
!u
!t
+ u
!u
!x
+ v
!u
!y
= "
1
#
!P
!x
+
#
!
2
u
!x
2
+
!
2
u
!y
2
$
%
&
'
(
)
Navier-Stokes equations
!u
!x
+
!v
!y
= 0
Parabolic part
Hyperbolic part
Elliptic equation
Summary
The Navier-Stokes equations contain three equation types
that have their own characteristic behavior
Depending on the governing parameters, one behavior can
be dominant
The different equation types require different solution
techniques
For inviscid compressible ows, only the hyperbolic part
survives
Computational Fluid Dynamics
U!t
2D
"1 &
D!t
h
2
"
1
2
!f
!t
+U
!f
!x
= D
!
2
f
!x
2
f
j
n+1
! f
j
n
"t
+U
f
j +1
n
! f
j!1
n
2h
= D
f
j +1
n
!2 f
j
n
+ f
j!1
n
h
2
1D Advection/diffusion equation
Forward in time/centered in space (FTCS)
Stability limits
R =
UL
D
!t =
2D
U
& !t =
h
2
2D
!t "0 For high and low D
Computational Fluid Dynamics
!f
!t
+U
!f
!x
= D
!
2
f
!x
2
O !t, h
2
( )
FTCS
U!t
2D
"1 &
D!t
h
2
"
1
2
O !t, h ( ) Upwind
U!t
h
+ 2
D!t
h
2
"1
O !t
2
, h
2
( )
L-W
U!t
h
"
#
$
%
&
'
2
( 2
D!t
h
2
"
#
$
%
&
' (1
O !t
2
, h
2
( )
C-N Unconditionally stable
Computational Fluid Dynamics
Steady state solution to the advection/diffusion equation
U
!f
!x
= D
!
2
f
!x
2
Exact solution
f =
exp R
L
x / L ( ) !1
exp R
L ( ) !1
R
L
=
UL
D
f = 0
f =1
U
L
Computational Fluid Dynamics
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
R
L
=1
R
L
=5
R
L
=10
R
L
=20
Computational Fluid Dynamics
The Cell Reynolds
number
Computational Fluid Dynamics
U
!f
!x
= D
!
2
f
!x
2
U
f
j +1
! f
j!1
2h
= D
f
j +1
!2 f
j
+ f
j!1
h
2
Centered difference approximation
Numerical solution of:
U
f
j
! f
j!1
h
= D
f
j +1
!2 f
j
+ f
j!1
h
2
Upwind
Computational Fluid Dynamics
U
f
j +1
! f
j !1
2h
= D
f
j +1
!2 f
j
+ f
j !1
h
2
Uh
2
2hD
f
j +1
! f
j !1
( ) = f
j +1
! 2 f
j
+ f
j !1
R =
Uh
D
Where:
Rearrange:
Rearrange:
R! 2 ( ) f
j +1
+ 4 f
j
! R + 2 ( ) f
j !1
= 0
Centered difference approximation
Computational Fluid Dynamics
f
j
= q
j
Divide by
Solution
Substitute:
R! 2 ( )q
j +1
+ 4q
j
! R+ 2 ( )q
j !1
= 0
R! 2 ( )q
2
+ 4q
1
! R+ 2 ( ) = 0
q
j !1
R! 2 ( ) f
j +1
+ 4 f
j
! R + 2 ( ) f
j !1
= 0
Computational Fluid Dynamics
Solving for q gives two solutions:
q
1
=1
and
The general solution is:
R! 2 ( )q
2
+ 4q
1
! R+ 2 ( ) = 0
q
2
=
2 + R
2 ! R
f
j
= C
1
q
1
j
+ C
2
q
2
j
f
j
= C
1
+ C
2
2 + R
2 ! R
"
#
$
%
j
or
Computational Fluid Dynamics
Apply the boundary conditions
f
0
= C
1
+ C
2
2 + R
2 ! R
"
#
$
%
0
= C
1
+ C
2
= 0
f
N
= C
1
+ C
2
2 + R
2 ! R
"
#
$
%
N
= 1
f
j
=
2 + R
2 ! R
"
#
$
%
j
!1
2 + R
2 ! R
"
#
$
%
N+1
!1
The nal solution is:
Computational Fluid Dynamics
U
f
j
! f
j!1
h
= D
f
j +1
!2 f
j
+ f
j!1
h
2
R+ 2 ( ) f
j
! R+1 ( ) f
j!1
! f
j +1
= 0
R =
Uh
D
f
j
= q
j
q
2
! R+ 2 ( )q
1
+ R+1 ( ) = 0
f
j
=
1! 1+ R ( )
j
1! 1+ R ( )
N
Solution
Upwind
Try solutions
giving
or
Computational Fluid Dynamics
f
j
=
2 + R
2 ! R
"
#
$
%
j
!1
2 + R
2 ! R
"
#
$
%
N+1
!1
f =
exp R
L
x / L ( ) !1
exp R
L ( ) !1
R
L
=
UL
D
R =
Uh
D
Exact solution
Centered differences
Upwind
f
j
=
1! 1+ R ( )
j
1! 1+ R ( )
N
Computational Fluid Dynamics
Upwind
Exact
Centered
Computational Fluid Dynamics
Upwind
Exact
Centered
Computational Fluid Dynamics
Upwind
Exact
Centered
Computational Fluid Dynamics
When centered differencing is used for the
advection/diffusion equation, oscillations may
appear when the Cell Reynolds number is
higher than 2. For upwinding, no oscillations
appear. In most cases the oscillations are
small and the cell Reynolds number is
frequently allowed to be higher than 2 with
relatively minor effects on the result.
R =
Uh
D
< 2
Computational Fluid Dynamics
2D example
!f
!t
+U
!f
!x
+V
!f
!y
= D
!
2
f
!x
2
+
!
2
f
!y
2
"
#
$
%
&
'
f =1
Flow
f = 0
f = 0
Computations
using centered
differences on a
32 by 32 grid
Computational Fluid Dynamics
D=0.02
t=1.5088
Re
cell
=3.2258
Computational Fluid Dynamics
D=0.01
t=1.5088
Re
cell
=6.4516
Computational Fluid Dynamics
D=0.005
t=1.5088
Re
cell
=12.9032
Computational Fluid Dynamics
D=0.02
t=1.50
0
5
10
15
0
5
10
15
0
0.5
1
1.5
0
5
10
15
20
25
30
0
5
10
15
20
25
30
0
0.5
1
1.5
Re
cell
=3.2258
Re
cell
=6.6716
Fine grid
Coarser grid
Computational Fluid Dynamics
Stability in
terms of Fluxes
Computational Fluid Dynamics
f
j !1
f
j
f
j +1
F
j !1 / 2
= Uf
j !1
n
= 1
F
j +1 / 2
= Uf
j
n
= 0
Consider the following initial conditions:
1
During one time step, U!t of f ows into cell j,
increasing the average value of f by U!t/h.
U =1
!t
h
= 1.5" U =1.5
Stability in terms of uxes
Computational Fluid Dynamics
f
i+1
Consider the following initial conditions:
1
f
j !1
f
i
F
j !1 / 2
= Uf
j !1
n
= U
F
j +1 / 2
= Uf
j
n
= 0
f
j
n+1
= f
j
n
!
"t
h
(F
j +1 / 2
n
! F
j !1 / 2
n
) = 0 !1.5(0 !1) =1.5
Stability in terms of uxes
Computational Fluid Dynamics
f
j +1
1
f
j !1
f
j
F
j !1 / 2
= Uf
j !1
n
=U
F
j +1 / 2
= Uf
j
n
=1.5U
f
j
n+1
= f
j
n
!
"t
h
(F
j +1 / 2
n
! F
j !1 / 2
n
) = 0 !1.5(1.5 !1) = 0.75
f
j +1
n+1
= f
j +1
n
!
"t
h
(F
j + 3/ 2
n
! F
j +1/ 2
n
) = 0 !1.5(0 !1.5) = 2.25
Stability in terms of uxes
Computational Fluid Dynamics
f
j +1
1
f
j !1
f
j
F
j !1 / 2
= Uf
j !1
n
=U
F
j +1 / 2
= Uf
j
n
= 0.75U
Taking a third step will result in an even larger positive value,
and so on until the compute encounters a NaN (Not a Number).
F
j +1 / 2
= Uf
j
n
= 2.25U
Stability in terms of uxes
Computational Fluid Dynamics
If U!t/h > 1, the average value of f in cell j will be
larger than in cell j-1. In the next step, f will ow out
of cell j in both directions, creating a larger negative
value of f. Taking a third step will result in an even
larger positive value, and so on until the compute
encounters a NaN (Not a Number).
Stability in terms of uxes
Computational Fluid Dynamics
MOVIE FROM MATLAB
% one-dimensional advection by rst order upwind.
n=80; nstep=100; dt=0.0125; length=2.0;
h=length/(n-1);y=zeros(n,1);f=zeros(n,1);f(1)=1.0;
for m=1:nstep,m
hold off, plot(f); axis([1, n, -0.5, 1.5]);
pause(0.01);
y=f;
for i=2:n-1,
f(i)=y(i)-(dt/h)*(y(i)-y(i-1)); %upwind
end;
end;
Stability in terms of uxes
Computational Fluid Dynamics
f
j +1
Consider the following initial conditions:
1
f
j !1
f
j
F
j !1/ 2
=
U
2
( f
j !1
n
+ f
j
n
) =1.0 F
j +1/ 2
=
U
2
( f
j
n
+ f
j +1
n
) = 0.5
f
j
n+1
= f
j
n
!
"t
h
(F
j +1/ 2
n
! F
j !1/ 2
n
) = 1.0 ! 0.5(0.5 !1) =1.25
So cell j will overow immediately!
By considering the uxes, it is easy to see why the
centered difference approximation is always unstable.
Stability in terms of uxes
Computational Fluid Dynamics
Advection by
Higher Order
Methods
Computational Fluid Dynamics
For the advection terms, the methods
described for hyperbolic equations, including
ENO, can all be applied, yielding stable and
robust methods that can be forgiving for
low resolution.
QUICK, where a third order upstream
differencing is used is also popular.
Computational Fluid Dynamics
s=1
f
1
s=2
f
2
s=3
f
3
s=4
f
4
s=5/2
At s = 5/2
!f
2
!x
"
#
$
i
%
1
h
f
i+1/ 2
2
& f
i&1/ 2
2
{ }
=
1
64h
3 f
i+1
+ 6 f
i
& f
i&1
[ ]
2
& 3 f
i
+ 6 f
i&1
& f
i&2
[ ]
2
{ }
f
5/ 2
= 1/8 ( ) 3f
3
+ 6 f
2
! f
1
[ ]
!f
!t
+
1
2
!f
2
!x
= D
!
2
f
!x
2
Use to solve:
Computational Fluid Dynamics
Centered
Upwind
QUICK
!f
!t
+
1
2
!f
2
!x
= D
!
2
f
!x
2
Computational Fluid Dynamics
0 5 10 15 20 25 30 35 40
0
1
2
3
4
5
6
7
8
9
10
0 5 10 15 20 25 30 35 40
0
1
2
3
4
5
6
7
8
9
10
Re_cell=20
Re_cell=10
!f
!t
+
1
2
!f
2
!x
= D
!
2
f
!x
2
Centered
Upwind
QUICK
Computational Fluid Dynamics
! f
!t
+ u
! f
!x
= 0
f
j
*
= f
j
n
!
"t
h
u
j
n
f
j +1/ 2
n
! f
j !1/ 2
n
( )
f
j
n+1
= f
j
n
!
"t
h
1
2
u
j
n
f
j +1/ 2
n
! f
j !1/ 2
n
( ) + u
j
*
f
j +1/ 2
*
! f
j !1/ 2
*
( ) ( )
f
j +1/ 2
=
f
j
+
1
2
amin !f
j
+
, !f
j
"
( ), if
1
2
u
j
+ u
j +1 ( ) > 0
f
j
"
1
2
amin !f
j +1
+
, !f
j +1
"
( ), if
1
2
u
j
+ u
j +1 ( ) < 0
#
$
%
&
%
!f
j
+
= f
j +1
" f
j
!f
j
"
= f
j
" f
j "1
amin a, b ( ) =
a, a < b
b, b ! a
"
#
$
%
$
Second order ENO scheme for the linear advection equation
Computational Fluid Dynamics
Second order ENO
Re_cell=20
!f
!t
+
1
2
!f
2
!x
= D
!
2
f
!x
2
0 5 10 15 20 25 30 35 40
0
1
2
3
4
5
6
7
8
9
10
Centered
Upwind
QUICK
Upwind
ENO
Computational Fluid Dynamics
! f
!t
+ u
! f
!x
= 0
Second order ENO scheme for the linear advection equation
Upwind
ENO
Computational Fluid Dynamics
Higher order
in space
Computational Fluid Dynamics
Higher order nite difference approximations
The simplest approach is to use more points:
h h
f(x-2h) f(x-h) f(x) f(x+h) f(x+2h)
Computational Fluid Dynamics
!f
!x
"
#
$
j
=
f
j%2
%8 f
j%1
+ 8 f
j +1
% f
j +2
12h
+ O(h
4
)
!
2
f
!x
2
"
#
$
j
=
% f
j%2
+16 f
j%1
% 30 f
j
+16 f
j +1
% f
j +2
12h
2
+ O(h
4
)
Centered
Skewed
!f
!x
"
#
$
j
=
f
j%2
%6 f
j%1
+ 3 f
j
+ 2 f
j +1
6h
+ O(h
3
)
Computational Fluid Dynamics
Compact schemes
Computational Fluid Dynamics
The standard way to obtain higher order
approximations to derivatives is to include more
points. This can lead to very wide stencils and near
boundaries this requires a large number of ghost
points outside the boundary. This can be overcome by
compact schemes, where we derive expressions
relating the derivatives at neighboring points to each
other and the function values.
Compact Schemes
Computational Fluid Dynamics
By a Taylor series expansion the following forth order relations
between the values of f and the derivatives of f can be derived
(1)
(2)
(3)
(4)
Adding
f
i +1
= f
i
+
! f
i
!x
"x +
!
2
f
i
!x
2
"x
2
2
+
!
3
f
i
!x
3
"x
3
6
+
!
4
f
i
!x
4
"x
4
24
+ O("x
5
)
f
i #1
= f
i
#
! f
i
!x
"x +
!
2
f
i
!x
2
"x
2
2
#
!
3
f
i
!x
3
"x
3
6
+
!
4
f
i
!x
4
"x
4
24
+ O("x
5
)
!! f
i +1
+ !! f
i "1
= 2 !! f
i
+ f
i
iv
#x
2
+ f
i
vi
#x
4
12
+ O(#x
6
)
f
i +1
+ f
i !1
= 2 f
i
+ "" f
i
#x
2
+ f
i
iv
#x
4
12
+ O(#x
6
)
Taking the second derivative:
Eliminating the fourth derivative
!! f
i +1
+10 !! f
i
+ !! f
i "1
=
12
#x
2
f
i +1
" 2 f
i
+ f
i "1
( ) + O #x
4
( )
Compact Schemes
Computational Fluid Dynamics
By a Taylor series expansion the following forth order relations
between the values of f and the derivatives of f can be derived
(1)
(2)
(3)
(4)
f
i +1
= f
i
+
! f
i
!x
"x +
!
2
f
i
!x
2
"x
2
2
+
!
3
f
i
!x
3
"x
3
6
+
!
4
f
i
!x
4
"x
4
24
+ O("x
5
)
f
i #1
= f
i
#
! f
i
!x
"x +
!
2
f
i
!x
2
"x
2
2
#
!
3
f
i
!x
3
"x
3
6
+
!
4
f
i
!x
4
"x
4
24
+ O("x
5
)
! f
i +1
+ ! f
i "1
= 2 ! f
i
+ !!! f
i
#x
2
+ f
i
iv
#x
4
12
+ O(#x
6
)
Adding and taking the rst derivative:
Subtracting 2 from 1
! f
i +1
+ 4 ! f
i
+ ! f
i "1
=
3
#x
f
i +1
" f
i "1
( ) + O #x
4
( )
f
i +1
! f
i !1
= 2 " f
i
#x + """ f
i
#x
3
3
+ O(#x
5
)
Eliminating the third derivative
Compact Schemes
Computational Fluid Dynamics
To solve the nonlinear advection-diffusion equation
!f
i +1
!x
+ 4
!f
i
!x
+
!f
i "1
!x
=
3
#x
f
i +1
" f
i "1
( ) + O #x
4
( )
!
2
f
i +1
!x
2
+10
!
2
f
i
!x
2
+
!
2
f
i "1
!x
2
=
12
#x
2
f
i +1
" 2 f
i
+ f
i "1
( ) + O #x
4
( )
!f
i
!t
= " f
i
!f
i
!x
+ D
!
2
f
i
!x
2
And use the values to compute the RHS. The time integration is
then done using a high order time integration method.
we rst solve nd the rst and second derivatives using the
expressions derived above:
Compact Schemes
Computational Fluid Dynamics
A large number of advanced numerical
methods have been developed for
hyperbolic, parabolic and elliptic
equations. These methods can be applied
directly to the Navier-Stokes equations,
although the structure of the equations
generally requires us to pay close
attention in which order the solution
proceeds.