Post on 19-Oct-2020
Computational Fluid Dynamics
The Advection-Diffusion equation!
Grétar Tryggvason !Spring 2013!
http://www.nd.edu/~gtryggva/CFD-Course/!Computational Fluid Dynamics
�
∂u∂t
+ u∂u∂x
+ v∂u∂y
= −1ρ∂P∂x
+µρ
∂ 2u∂x 2
+∂ 2u∂y2
⎛ ⎝ ⎜ ⎞
⎠ ⎟
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 flows, only the hyperbolic part survives!
Computational Fluid Dynamics
�
UΔt2D
≤1 & DΔth2
≤ 12
�
∂f∂t
+U ∂f∂x
= D∂ 2 f∂x 2
�
f jn+1 − f j
n
Δt+U
f j+1n − f j−1
n
2h= D
f j+1n − 2 f j
n + f j−1n
h2
1D Advection/diffusion equation!
Forward in time/centered in space (FTCS)!
Stability limits!R =
ULD
�
Δt = 2DU
& Δt = h2
2D
�
Δt→ 0 For high and low D!
Computational Fluid Dynamics
�
∂f∂t
+U ∂f∂x
= D∂ 2 f∂x 2
�
O Δt,h2( )FTCS!
�
UΔt2D
≤1 & DΔth2
≤ 12
�
O Δt,h( )Upwind!
�
UΔth
+ 2DΔth2
≤1
�
O Δt 2,h2( )L-W!
�
UΔth
⎛ ⎝ ⎜
⎞ ⎠ ⎟ 2
≤ 2 DΔth2
⎛ ⎝ ⎜
⎞ ⎠ ⎟ ≤1
�
O Δt 2,h2( )C-N! Unconditionally stable!
Computational Fluid Dynamics
Steady state solution to the advection/diffusion equation!
U∂f∂x
= D∂ 2 f∂x2
Exact solution!
�
f =exp RL x /L( ) −1exp RL( ) −1
�
RL = ULD
�
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 10
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
RL=1!RL=5!RL=10!RL=20!
Computational Fluid Dynamics
The Cell Reynolds number!
Computational Fluid Dynamics
�
U ∂f∂x
= D∂ 2 f∂x 2
�
Uf j+1 − f j−12h
= Df j+1 − 2 f j + f j−1
h2
Centered difference approximation!
Numerical solution of:!
�
Uf j − f j−1h
= Df j+1 − 2 f j + f j−1
h2
Upwind!
Computational Fluid Dynamics
Ufj+1 − f j−12h
= Df j+1 − 2 f j + f j−1
h2
Uh2
2hDfj+1 − fj−1( ) = fj+1 − 2 fj + fj−1
R =UhD
Where:!
Rearrange:!
Rearrange:!
R− 2( ) fj+1 + 4 fj − R + 2( ) fj−1 = 0
Centered difference approximation!
Computational Fluid Dynamics
fj = qj
Divide by !
Solution!
Substitute:!
R− 2( )qj+1 + 4qj − R+ 2( )qj−1 = 0
R− 2( )q2 + 4q1 − R+ 2( ) = 0
q j−1
R− 2( ) fj+1 + 4 fj − R + 2( ) fj−1 = 0
Computational Fluid Dynamics
Solving for q gives two solutions:!
q1 =1 and!
The general solution is:!
R− 2( )q2 + 4q1 − R+ 2( ) = 0
q2 =2 + R2 − R
fj = C1q1j + C2q2
j
fj = C1 + C22 + R2 − R
⎛ ⎝
⎞ ⎠
jor!
Computational Fluid Dynamics
Apply the boundary conditions!
f0 = C1 + C22 + R2 − R
⎛ ⎝
⎞ ⎠
0
= C1 + C2 = 0
fN = C1 + C22 + R2 − R
⎛ ⎝
⎞ ⎠
N
= 1
fj =
2 + R2 − R
⎛ ⎝
⎞ ⎠
j
−1
2 + R2 − R
⎛ ⎝
⎞ ⎠
N +1
−1
The final solution is:!
Computational Fluid Dynamics
�
Uf j − f j−1h
= Df j+1 − 2 f j + f j−1
h2
�
R + 2( ) f j − R +1( ) f j−1 − f j+1 = 0R =
UhD
�
f j = q j
�
q2 − R + 2( )q1 + R +1( ) = 0
�
f j =1− 1+ R( ) j
1− 1+ R( )NSolution!
Upwind!
Try solutions!
giving!
or!
Computational Fluid Dynamics
fj =
2 + R2 − R
⎛ ⎝
⎞ ⎠
j
−1
2 + R2 − R
⎛ ⎝
⎞ ⎠
N +1
−1
�
f =exp RL x /L( ) −1exp RL( ) −1
�
RL = ULD
R =UhD
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 = UhD
< 2
Computational Fluid Dynamics
2D example!
�
∂f∂t
+U ∂f∂x
+V ∂f∂y
= D ∂ 2 f∂x 2
+ ∂ 2 f∂y 2
⎛
⎝ ⎜
⎞
⎠ ⎟
�
f =1Flow!
�
f = 0
�
f = 0
Computations using centered differences on a 32 by 32 grid!
Computational Fluid Dynamics
D=0.02!t=1.5088!
Recell=3.2258!
Computational Fluid Dynamics
D=0.01!t=1.5088!
Recell=6.4516!
Computational Fluid Dynamics
D=0.005!t=1.5088!
Recell=12.9032!
Computational Fluid Dynamics
D=0.02!t=1.50!
0
5
10
15
0
5
10
150
0.5
1
1.5
05
1015
2025
30
05
1015
2025
300
0.5
1
1.5
Recell=3.2258! Recell=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
Fj−1 / 2 = Ufj−1n = 1
Fj+1 / 2 = Ufjn = 0
Consider the following initial conditions:!
1
During one time step, U∆t of f flows into cell j, increasing the average value of f by U∆t/h.!
U = 1
Δ th
= 1.5 ⋅U = 1.5
Stability in terms of fluxes!Computational Fluid Dynamics
fi+1
Consider the following initial conditions:!
1f j−1 fi
Fj−1 / 2 = Ufj−1n = U
Fj+1 / 2 = Ufjn = 0
f jn+1 = fj
n −Δth(Fj+1 / 2
n − Fj−1 / 2n ) = 0 − 1.5(0 −1) = 1.5
Stability in terms of fluxes!
Computational Fluid Dynamics
f j+11
f j−1 f j
Fj−1 / 2 = Ufj−1n =U Fj+1 / 2 = Ufj
n = 1.5U
f jn+1 = fj
n −Δth(Fj+1 / 2
n − Fj−1 / 2n ) = 0 − 1.5(1.5 − 1) = 0.75
f j+1n+1 = fj+1
n −Δth(Fj+ 3/ 2
n − Fj+1/ 2n ) = 0 −1.5(0 −1.5) = 2.25
Stability in terms of fluxes!Computational Fluid Dynamics
f j+11
f j−1 f j
Fj−1 / 2 = Ufj−1n =U
Fj+1 / 2 = Ufjn = 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).!
Fj+1 / 2 = Ufjn = 2.25U
Stability in terms of fluxes!
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 flow 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 fluxes!Computational Fluid Dynamics
MOVIE FROM MATLAB!% one-dimensional advection by first 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 fluxes!
Computational Fluid Dynamics
fj+1
Consider the following initial conditions:!
1fj−1 fj
Fj−1/ 2 =U2( fj−1
n + fjn ) =1.0 Fj+1/ 2 =
U2( fj
n + f j+1n ) = 0.5
fjn+1 = fj
n −Δth(Fj+1/ 2
n − Fj−1/ 2n ) = 1.0 − 0.5(0.5 −1) =1.25
So cell j will overflow immediately!!
By considering the fluxes, it is easy to see why the centered difference approximation is always unstable.!
Stability in terms of fluxes!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!f1!
s=2!f2!
s=3!f3!
s=4!f4!
s=5/2!
At s = 5/2!
�
∂f 2
∂x⎞
⎠ ⎟ i
≈ 1h
fi+1/ 22 − fi−1/ 2
2{ }
= 164h
3 fi+1 + 6 f i − fi−1[ ]2 − 3 f i + 6 f i−1 − f i−2[ ]2{ }�
f5 / 2 = 1/8( ) 3 f3 + 6 f2 − f1[ ] �
∂f∂t
+ 12∂f 2
∂x= D∂ 2 f
∂x 2
Use to solve:!
Computational Fluid Dynamics
Centered!
Upwind!QUICK!
�
∂f∂t
+ 12∂f 2
∂x= D∂ 2 f
∂x 2
Computational Fluid Dynamics
0 5 10 15 20 25 30 35 400
1
2
3
4
5
6
7
8
9
10
0 5 10 15 20 25 30 35 400
1
2
3
4
5
6
7
8
9
10
Re_cell=20!Re_cell=10!
�
∂f∂t
+ 12∂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 −Δthu jn f j+1/2
n − f j−1/2n( )
f jn+1 = f j
n −Δth12ujn f j+1/2
n − f j−1/2n( ) + uj
* f j+1/2* − f j−1/2
*( )( )
f j+1/2 =f j + 1
2 amin Δf j+ ,Δf j
−( ), if 12 uj + uj+1( ) > 0
f j − 12 amin Δf j+1
+ ,Δf j+1−( ), if 1
2 uj + uj+1( ) < 0⎧⎨⎪
⎩⎪
Δf j+ = f j+1 − f j Δf j
− = f j − f j−1
amin a,b( ) =a, a < bb, b ≤ a
⎧⎨⎪
⎩⎪
Second order ENO scheme for the linear advection equation!
Computational Fluid Dynamics
Second order ENO!
Re_cell=20!
�
∂f∂t
+ 12∂f 2
∂x= D∂ 2 f
∂x 2
0 5 10 15 20 25 30 35 400
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 finite 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(h4 )
�
∂ 2 f∂x 2
⎞
⎠ ⎟ j
=− f j−2 +16 f j−1 − 30 f j +16 f j+1 − f j+2
12h2+ O(h4 )
Centered
Skewed
�
∂f∂x
⎞ ⎠ ⎟ j
=f j−2 − 6 f j−1 + 3 f j + 2 f j+1
6h+ O(h3)
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!
fi+1 = fi +∂ fi
∂xΔx +
∂ 2 fi
∂x2
Δx2
2+∂ 3 fi
∂x3
Δx3
6+∂ 4 fi
∂x4
Δx4
24+ O(Δx5)
fi−1 = fi −∂ fi
∂xΔx +
∂ 2 fi
∂x2
Δx2
2−∂ 3 fi
∂x3
Δx3
6+∂ 4 fi
∂x4
Δx4
24+ O(Δx5)
′′fi+1 + ′′fi−1 = 2 ′′fi + fi
ivΔx2 + fivi Δx4
12+ O(Δx6 )
fi+1 + fi−1 = 2 fi + ′′fi Δx2 + fi
iv Δx4
12+ O(Δx6 )
Taking the second derivative:!
Eliminating the fourth derivative!
′′fi+1 +10 ′′fi + ′′fi−1 =
12Δx2 fi+1 − 2 fi + fi−1( ) + O Δx4( )
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)!
fi+1 = fi +∂ fi
∂xΔx +
∂ 2 fi
∂x2
Δx2
2+∂ 3 fi
∂x3
Δx3
6+∂ 4 fi
∂x4
Δx4
24+ O(Δx5)
fi−1 = fi −∂ fi
∂xΔx +
∂ 2 fi
∂x2
Δx2
2−∂ 3 fi
∂x3
Δx3
6+∂ 4 fi
∂x4
Δx4
24+ O(Δx5)
′fi+1 + ′fi−1 = 2 ′fi + ′′′fi Δx2 + fi
iv Δx4
12+ O(Δx6 )
Adding and taking the first derivative:!
Subtracting 2 from 1!
′fi+1 + 4 ′fi + ′fi−1 =
3Δx
fi+1 − fi−1( ) + O Δx4( )
fi+1 − fi−1 = 2 ′fi Δx + ′′′fi
Δx3
3+ O(Δx5)
Eliminating the third derivative!
Compact Schemes!
Computational Fluid Dynamics
To solve the nonlinear advection-diffusion equation!
∂fi+1
∂x+ 4
∂fi
∂x+∂fi−1
∂x=
3Δx
fi+1 − fi−1( ) + O Δx4( )
∂2 fi+1
∂x2 +10∂2 fi
∂x2 +∂2 fi−1
∂x2 =12Δx2 fi+1 − 2 fi + fi−1( ) + O Δx4( )
∂fi
∂t= − fi
∂fi
∂x+ D
∂2 fi
∂x2
And use the values to compute the RHS. The time integration is then done using a high order time integration method.!
we first solve find the first 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.!