Boundary conditions Inflow and outflow

Computational Fluid Dynamics
http://www.nd.edu/~gtryggva/CFD-Course/!
Computational Fluid Dynamics
Outline!
Boundary Conditions for Inflow and Outflow!
Solving the NavierStokes Equations-II!
Compact schemes!
Conservation of energy!
Higher order in time for !
the ψ-ω formulation!
Grétar Tryggvason!
Spring 2013!
Computational Fluid Dynamics
Computational Fluid Dynamics
The Artificial Compressibility Method !
(Chorin, 1967, JCP 2, 12-26)!
∂u
= −A(u) + ν∇ 2 u − ∇p
∂t
∂ p −1
=
∇⋅u
∂ t c2
c is a numerical parameter, in effect an artificial
velocity of sound. At steady state ! ∇ ⋅ u = 0
Computational Fluid Dynamics
Boundary conditions!
Fully enclosed flow!
!Driven cavity!
!
Internal flow (inflow & outflow)!
!
External flow!
!Flow over bodies!
Boundary conditions!
Inflow and outflow!
Computational Fluid Dynamics
For fully enclosed domains, such as in the driven
cavity problem, the application of the boundary
conditions is relatively straight forward.!
For domains with inflows it is usually reasonable to
specify the velocity profile at the inlet!
The major problem is how to handle outflow
boundaries in such a way that the fluid leaves in a
“physically plausible” way!
Computational Fluid Dynamics
Computational Fluid Dynamics
P!
u!
The Backward Facing Step Problem!
u!
vnx+1,j!
vnx+2,j!
unx,j! Pnx,j! unx+1,j!
u = u(y)
v =0
∂v
=0
∂x
Velocity
given!
∂u
=0
∂x
v!
v!
P!
u!
∂u
=0
∂x
u(nx+1,j)=u(nx,j);!
∂v
=0
∂x
v(nx+2,1:ny+1)=v(nx+1,1:ny+1);!
u!
For the pressure, obtain an equation by applying
conservation of mass to the control volume next to
the boundary!
p(nx,j)=(1/2)*(p(nx,j+1)+p(nx,j-1)-(h/dt)*(v(nx+1,j+1)-v(nx+1,j)));!!
Computational Fluid Dynamics
Computational Fluid Dynamics
Simplified Backward Facing Step Problem!
Example!
u = u(y)
v =0
∂v
=0
∂x
Velocity
given!
∂u
=0
∂x
Velocity
gradient
given!
Computational Fluid Dynamics
Computational Fluid Dynamics
Velocity!
Velocity+vorticity!
20
18
18
16
16
14
14
12
12
10
10
8
8
6
6
4
4
2
2
0
0
5
10
15
20
25
30
35
5
10
15
20
25
30
Computational Fluid Dynamics
Computational Fluid Dynamics
Pressure!
Periodic Boundary conditions!
In many cases it is possible to use periodic boundary
conditions, where what flows out through one
boundary reappears flowing in through the opposite
boundary. Such conditions are particularly suitable for
theoretical studies of idealized flows. For such
boundaries it is easiest to specify the pressure drop,
but by adjusting the pressure gradient it is possible to
specify the volume flux!
0.5
0
-0.5
-1
-1.5
-2
-2.5
40
30
20
15
20
10
10
5
0
0
Inflow!
Computational Fluid Dynamics
Computational Fluid Dynamics
External flow!
Other ways to deal with free-stream boundaries!
!Include potential flow perturbation!
!Compute flow from vorticity distribution!
!Map the boundary at infinity to a finite distance!
Free stream (uniform
flow, for example)!
Free
outflow!
Boundary of
computational
domain!
Computational Fluid Dynamics
Compact schemes!
Fundamentally, the specification of the boundary
conditions does not have a unique solution and is also
faced by experimentalists. However, by taking the
boundaries far away and checking the solution for the
effect of moving the boundaries, good results can be
obtained!
Computational Fluid Dynamics
Compact Schemes!
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.!
Computational Fluid Dynamics
Compact Schemes!
Computational Fluid Dynamics
Compact Schemes!
By a Taylor series expansion the following forth order relations
between the values of f and the derivatives of f can be derived!
∂ fi
∂ 2 fi
Δx +
∂x
∂ x2
∂ fi
∂ 2 fi
f i−1 = f i −
Δx +
∂x
∂ x2
f i+1 = f i +
3
Δx 2 ∂ f i
+ 3
2
∂x
3
Δx 2 ∂ f i
− 3
2
∂x
4
Δx 3 ∂ f i Δx 4
+
+ O(Δx 5 )
6
∂ x 4 24
4
3
4
Δx ∂ f i Δx
+
+ O(Δx 5 )
6
∂ x 4 24
Adding!
f i+1 + f i−1 = 2 f i + f i′′Δx 2 + f i iv
Δx
+ O(Δx 6 )
12
Δx 4
+ O(Δx 6 )
12
Eliminating the fourth derivative!
f i+1
′′ + 10 f i′′+ f i−1
′′ =
(2)!
)
3
Δx 2 ∂ f i
+ 3
2
∂x
3
Δx 2 ∂ f i
− 3
2
∂x
4
Δx 3 ∂ f i Δx 4
+
+ O(Δx 5 )
6
∂ x 4 24
4
3
4
Δx ∂ f i Δx
+
+ O(Δx 5 )
6
∂ x 4 24
f i+1
′ + f i−1
′ = 2 f i′+ f i′′′Δx 2 + f i iv
(3)!
(4)!
(1)!
(2)!
Δx
+ O(Δx 6 )
12
Subtracting 2 from 1!
Δx 3
f i+1 − f i−1 = 2 f i′Δx + f i′′′
+ O(Δx 5 )
3
(3)!
(4)!
Eliminating the third derivative!
( )
12
f − 2 f i + f i−1 + O Δx 4
Δx 2 i+1
(
∂ fi
∂ 2 fi
Δx +
∂x
∂ x2
∂ fi
∂ 2 fi
f i−1 = f i −
Δx +
∂x
∂ x2
f i+1 = f i +
Adding and taking the first derivative:!
4
4
Taking the second derivative:!
f i+1
′′ + f i−1
′′ = 2 f i′′+ f i iv Δx 2 + f i vi
(1)!
By a Taylor series expansion the following forth order relations
between the values of f and the derivatives of f can be derived!
f i+1
′ + 4 f i′+ f i−1
′ =
Computational Fluid Dynamics
( )
3
f − f i−1 + O Δx 4
Δx i+1
(
)
Computational Fluid Dynamics
Solution of the vorticity-streamfunction equations!
By a Taylor series expansion the following forth order
relations between the values of f and the derivatives of
f can be derived!
⎛ ∂ 2ω ∂ 2ω ⎞
∂ω ∂ψ ∂ω ∂ψ ∂ω
=
−
+ ν⎜ 2 + 2 ⎟
∂t ∂x ∂y ∂ y ∂x
∂x ⎠
⎝ ∂x
2
2
∂ψ ∂ψ
+
= −ω
∂x 2 ∂x 2
3
( f i+1, j − f i−1, j )
h
3
( f y )i, j +1 + 4( f y )i, j + ( f y )i, j−1 = h ( f i, j +1 − f i, j−1)
( f x ) i+1, j + 4( f x ) i, j + ( f x ) i−1, j =
Use “compact schemes” to find
approximations for the spatial derivatives!
(1)!
(2)!
O(h4)
12
( f i+1, j − 2 f i, j + f i−1, j )
h2
12
( f yy )i, j +1 + 10( f yy )i, j + ( f yy )i, j−1 = h 2 ( f i, j +1 − 2 f i, j + f i, j−1)
( f xx ) i+1, j + 10( f xx ) i, j + ( f xx ) i−1, j =
Computational Fluid Dynamics
Computational Fluid Dynamics
The vorticity-streamfunction equations at grid point i,j are!
⎛ ∂ψ ⎞ ⎛ ∂ω ⎞
⎛ ∂ω ⎞
⎛ ∂ψ ⎞ ⎛ ∂ω ⎞
⎜ ⎟ = ⎜ ⎟ ⎜ ⎟ −⎜ ⎟ ⎜ ⎟
⎝ ∂t ⎠ i, j ⎝ ∂x ⎠ i, j ⎝ ∂y ⎠ i, j ⎝ ∂y ⎠ i, j ⎝ ∂x ⎠ i, j
⎛⎛ ∂ 2ω ⎞
⎛ ∂ 2ω ⎞ ⎞
+ ν ⎜⎜⎜ 2 ⎟ + ⎜ 2 ⎟ ⎟⎟
∂
x
⎝
⎠
⎝ ∂x ⎠ i, j ⎠
⎝
i, j
⎛ ∂ 2ψ ⎞
⎛ ∂ 2ψ ⎞
⎜ 2 ⎟ + ⎜ 2 ⎟ = −ω i, j
⎝ ∂x ⎠ i, j ⎝ ∂y ⎠ i, j
1. Given the vorticity, ω, we solve tridiagonal
equations (1-4) for! ω x , ω y , ω xx , ω yy
2. For ψ use (3) and (4) plus the elliptic equation
ψ xx , ψ yy , ψ
for the streamfunction (6) for!
(5)!
(6)!
3. Then use 1 and 2 for (tridiagonal systems)! ψ x , ψ y
4. Everything on the right hand side of (5) is now
known to O(h4) accuracy and !
∂ψ
∂t
To find the time derivative, we need!
ψ x , ψ y , ψ xx , ψ yy , ω x , ω y , ω xx , ω yy
can be found!
(3)!
(4)!
Computational Fluid Dynamics
Computational Fluid Dynamics
The main advantage of compact schemes
is that it is somewhat easier to implement
boundary conditions than for high order
schemes that use a broad stencil !
Conservation of
kinetic energy!
Computational Fluid Dynamics
Computational Fluid Dynamics
Conservation of kinetic energy on a centered
regular mesh!
Consider two different discretizations of the
nonlinear term!
Consider:!
∂f
∂f
+ f
=0
∂t
∂x
Define:! E kin =
1
2
∫
∂f
∂f
=−f
≈ − f i ( f i+1 − f i−1 ) /2h
∂t
∂x
f 2 dx
Multiply by f and integrate!
⎛ ∂f
∫ ⎜⎝ f ∂t + f
2
and!
∂f ⎞
⎟dx = 0
∂x ⎠
∂f
1 ∂f 2
1 2
2
=−
≈ − ( f i+1
− f i−1
) /2h
∂t
2 ∂x
2
Therefore:!
d
dt
1
∫2f
2
dx = − ∫
1 ∂f 3
dx = 0
3 ∂x
Both conserve f!
The kinetic
energy is
conserved!
Is f2 conserved?!
Computational Fluid Dynamics
Check conservation:!
Computational Fluid Dynamics
Combine both schemes:!
∂f
1 ⎧
(1− α ) f 2 − f 2 ⎫⎬
≈ − ⎨α f i ( f i+1 − f i−1 ) −
( i+1 i−1)⎭
∂t
2h ⎩
2
First scheme:!
d
dt
∫
⎧1
1 2
h ⎛ ∂f 2 ⎞
2
2 ⎫
f dx = −∑ f j ⎜
⎟ = −∑ ⎨ f j ( f j +1 − f j−1 )⎬
⎩2
⎭
2
2 ⎝ ∂x ⎠ j
1
1
2
2
2
2
= … + f j−1 ( f j − f j−2 ) + f j ( f j +1 − f j−1 ) + … ≠ 0
2
2
Second scheme:!
d
dt
1
∫2f
2
⎛ ∂f ⎞
dx = −∑ f j h⎜ f ⎟ = −∑{ f j2 ( f j +1 − f j−1 )}
⎝ ∂x ⎠ j
2
= … + f j−1
( f j − f j−2 ) + f j2 ( f j +1 − f j−1) + … ≠ 0
Write out the terms for the kinetic energy!
∫
∂f 2
1 ⎧
(1− α ) f f 2 − f 2 ⎫⎬
dx ≈ − ∑ ⎨α f j2 ( f j +1 − f j−1 ) −
j ( j +1
j−1 )
∂t
2 ⎩
2
⎭
2
= … + α f j−1
( f j − f j−2 ) +
α f j2 ( f j +1 − f j−1 ) −
(1− α ) f
(1− α ) f
2
2
j
(f
2
j +1
j−1
(f
2
j
2
− f j−2
)+
2
− f j−1
) +… = 0
Computational Fluid Dynamics
2
2
= … + α ( f j−1
f j − f j−1
f j−2 ) +
α ( f j2 f j +1 − f j2 f j−1 ) −
α−
(1− α ) = 0
2
(1− α )
2
(1− α )
2
(f
j
(f
j−1
Computational Fluid Dynamics
2
f j2 − f j−1 f j−2
)+
2
f j2+1 − f j f j−1
) +… = 0
3α −1
=0
2
α=
1
3
∂f
1
2
2
≈ − { f i ( f i+1 − f i−1 ) − ( f i+1
− f i−1
)}
∂t
6h
⎧
⎫
1 f + f i + f i−1
= − ⎨ i+1
( f i+1 − f i−1)⎬
⎭
2h ⎩
3
Conserves both f and
The same idea is used in Arakawa’s scheme
(JCP 119, 1966)!
Consider the vorticity advection equation!
∂ω
+ u ⋅ ∇ω = 0
∂t
Rewrite the nonlinear terms to introduce the Jacobian!
u ⋅ ∇ω = −
giving!
∂ω
+ J (ψ,ω ) = 0
∂t
f2!
Computational Fluid Dynamics
The Jacobian can be written in several ways!
∂ψ ∂ω ∂ψ ∂ω
J (ψ,ω ) =
−
∂x ∂y ∂y ∂ x
∂ ⎛ ∂ω ⎞ ∂ ⎛ ∂ω ⎞
= ⎜ψ
⎟
⎟ − ⎜ψ
∂x ⎝ ∂ y ⎠ ∂y ⎝ ∂x ⎠
∂ ⎛ ∂ψ ⎞ ∂ ⎛ ∂ψ ⎞
= ⎜ω
⎟ − ⎜ω
⎟
∂y ⎝ ∂ x ⎠ ∂x ⎝ ∂y ⎠
since!
∂ ⎛ ∂ω ⎞ ∂ψ ∂ω
∂ 2ω
−ψ
⎜ψ
⎟=
∂x ⎝ ∂ y ⎠ ∂x ∂ y
∂x∂y
∂ψ ∂ω ∂ψ ∂ω
+
= J (ψ,ω )
∂y ∂x ∂ x ∂y
Computational Fluid Dynamics
we also have!
J (ψ,ω ) = −J (ω,ψ )
since!
J (ψ,ω ) =
⎛ ∂ω ∂ψ ∂ω ∂ψ ⎞
∂ψ ∂ω ∂ψ ∂ω
−
= −⎜
−
⎟
∂x ∂y ∂y ∂ x
⎝ ∂x ∂y ∂y ∂ x ⎠
Discretization of the different forms of
the Jacobian give schemes with slightly
different conservation properties !
and so on!
Computational Fluid Dynamics
Discretization!
J1i, j =
1
{(ω i+1, j − ω i−1, j )(ψ i, j +1 − ψ i, j−1)
4h 2
− (ω i, j +1 − ω i, j−1 )(ψ i+1, j − ψ i−1, j )}
1
J i,2 j = 2 {ω i+1, j (ψ i+1, j +1 − ψ i+1, j−1 ) − ω i−1, j (ψ i−1, j +1 − ψ i−1, j−1 )
4h
− ω i, j +1 (ψ i+1, j +1 − ψ i−1, j +1 ) − ω i, j−1 (ψ i+1, j−1 − ψ i−1, j−1 )}
J i,3 j =
1
{−ψi+1, j (ω i+1, j +1 − ω i+1, j−1) + ψ i−1, j (ω i−1, j +1 − ω i−1, j−1)
4h 2
+ ψ i, j +1 (ω i+1, j +1 − ω i−1, j +1 ) − ψ i, j−1 (ω i+1, j−1 − ω i−1, j−1 )}
Computational Fluid Dynamics
Arakawa showed that!
J1i, j =
1 1
(Ji, j + Ji,2 j + Ji,3 j )
3
Conserves both the vorticity and the kinetic energy!
Arakawa also presented a fourth order scheme with
the same properties!
Computational Fluid Dynamics
Computational Fluid Dynamics
Higher order!
in time for the vorticitystreamfunction
formulation!
Due to the relatively straightforward coupling
between the elliptic equation for the
streamfunction and the vorticity advectiondiffusion equation, the algorithms discussed
already can be used with ease.!
Computational Fluid Dynamics
Computational Fluid Dynamics
Leapfrog!
Runge Kutta methods: take intermidiate steps!
n−1
ω i,n +1
j − ω i, j
= −J i,n j + ν∇ 2hω i,n−1
j
2Δt
2nd order Runge-Kutta!
Adams-Bashford/Crank-Nicholson!
n
ω i,n +1
1
ν 2 n +1
j − ω i, j
= − ( 3J i,n j − J i,n−1
(∇ hω i, j + ∇ 2hω i,n j )
j )+
Δt
2
2
∇ 2hψ i,n j = −ω i,n j
Δt
ω˜ i, j = ω i,n j + (−J i,n j + ν∇ 2hω i,n j )
2
Half step!
Predictor-corrector!
ω˜ i, j − ω i,n j
= −J i,n j + ν∇ 2hω i,n j
Δt
∇ 2hψ˜ i, j = −ω˜ i, j
˜ i, j
ω i,n +1
1
ν
j −ω
= − ( J i,n j + J˜i, j ) + (∇ 2hω i,n j + ∇ 2hω˜ i, j )
Δt
2
2
ω˜ i, j = ω i,n j + Δt (− J˜i, j + ν∇ 2hω˜ i, j )
Computational Fluid Dynamics
Computational Fluid Dynamics
4th order Runge-Kutta method!
∇ψ
2
h
n
i, j
= −ω
4th order Runge-Kutta method (continued)!
n
i, j
2
ω˜ i,n +1/
= ω i,n j +
j
˜ i,n +1
∇ 2hψ˜ i,n +1
j = −ω
j
Δt
(−Ji,n j + ν∇ 2hω i,n j )
2
First half step!
ω˜
n +1
i, j
(
2
2
= ω + Δt −J˜˜i,n +1/
+ ν∇ 2hω˜˜ i,n +1/
j
j
n
i, j
)
Second half step!
(
Δt
2
2
−J i,n j − 2 J˜i,n +1/
− 2 J˜˜i,n +1/
− J˜i,n +1
j
j
j
6
2
2
+ ν∇ 2hω i,n j + 2ν∇ 2hω˜ i,n +1/
+ 2ν∇ 2hω˜˜ i,n +1/
+ ν∇ 2hω˜ i,n +1
j
j
j )
n
ω i,n +1
j = ω i, j +
2
2
∇ 2hψ˜ i,n +1/
= −ω˜ i,n +1/
j
j
Δt
2
2
2
ω˜˜ i,n +1/
= ω i,n j + (− J˜i,n +1/
+ ν∇ 2hω˜ i,n +1/
)
j
j
j
2
2
2
∇ 2hψ˜˜ i,n +1/
= −ω˜˜ i,n +1/
j
j
Final step!
corrected
final value!
Predicted
final value!
t
t + Δt /2
t + Δt
Computational Fluid Dynamics
Generating higher order methods for the
Navier-Stokes equations in the vorticity/
streamfunction form is relatively straight
forward and any method developed for the
advection diffusion equation can be used
without much difficulty!
Computational Fluid Dynamics
Outline!
Boundary Conditions for Inflow and Outflow!
Compact schemes!
Conservation of energy!
Higher order in time for !
the ψ-ω formulation!