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

Computational Fluid Dynamics

Computational Fluid Dynamics



http://www.nd.edu/~gtryggva/CFD-Course/! Objectives!

A Finite Difference Code


for the Navier-Stokes Develop an understanding of the steps involved in
solving the Navier-Stokes equations using a numerical
Equations in Vorticity/ method!

Streamfunction! Write a simple code to solve the driven cavity


problem using the Navier-Stokes equations in vorticity
Form! form!

Short discussion about why looking at the vorticity is


Grtar Tryggvason ! sometimes helpful!
Spring 2011!

Computational Fluid Dynamics


Computational Fluid Dynamics

Outline! The Driven Cavity Problem!

The Driven Cavity Problem! Moving wall!


The Navier-Stokes Equations in Vorticity/
Streamfunction form!
Boundary Conditions!
The Grid!
Finite Difference Approximation of the Vorticity/ Stationary
Streamfunction equations! walls!
Finite Difference Approximation of the Boundary
Conditions!
Iterative Solution of the Elliptic Equation!
The Code!
Results!
Convergence Under Grid Refinement!

Computational Fluid Dynamics


Computational Fluid Dynamics

The vorticity/streamfunction equations:! The vorticity/streamfunction equations:!

Solve the incompressibility conditions!


" !u !u !u !p 1 #% ! 2 u ! 2u &
! +u +v = " + + !u !v
"y !t !x !y !x Re $ !x 2 !y2 ' + =0
!x !y
! !v !v !v !p 1 %# ! 2 v ! 2 v &
+u +v = " + + by introducing the stream function!
!x !t !x !y !y Re $ !x 2 !y 2 ' !" !"
u= ; v=#
!y !x
!" !" !" 1 #% ! 2 " ! 2" &
+u +v = + Substituting:!
!t !x !y Re $ !x 2 !y 2 ' ! !" ! !"
"v "u # =0
!= # !x !y !y !x
"x "y
Computational Fluid Dynamics
Computational Fluid Dynamics

The vorticity/streamfunction equations:! The vorticity/streamfunction equations:!

The Navier-Stokes equations in vorticity-stream


Substituting! function form are:!
!" !" Advection/diffusion equation!
u= ; v=# !" !$ !" !$ !" 1 %' ! 2" ! 2" (
!y !x =# + + +
!t !y !x !x !y Re & !x 2 !y 2 )
into the definition of the vorticity!
"v "u Elliptic equation!
!= # ! 2" ! 2"
"x "y + 2 = #$
yields! !x 2 !y
! 2" ! 2"
+ 2 = #$
!x 2 !y Recall the advection-
f f
+u +v
f 2 f 2 f
= D 2 + 2
diffusion equation! t x y x y

Computational Fluid Dynamics


Computational Fluid Dynamics

Boundary Conditions for the Streamfunction! Boundary Conditions for the Streamfunction!

At the right and ! At the top and the!


the left boundary:! bottom boundary:!

"# #$
u = 0! =0 v =0!" =0
"y #x
! # = Constant ! $ = Constant

Computational Fluid Dynamics


Computational Fluid Dynamics

Boundary Conditions for the Streamfunction! Boundary Conditions for the Vorticity!

The normal velocity is zero since the streamfunction


Since the boundaries is a constant on the wall, but the zero tangential
meet, the constant velocity must be enforced:!
must be the same on
all boundaries! At the right and left boundary:! At the bottom boundary:!
#$ "#
v =0!" =0 u=0! =0
! = Constant #x "y
At the top boundary:!
"#
u = U wall ! = U wall
"y
Computational Fluid Dynamics
Computational Fluid Dynamics

Boundary Conditions for the Vorticity! Summary of Boundary Conditions!

!" ! 2"
= Uwall; # wall = $ 2
The wall vorticity must be found from the streamfunction. !y !y
The stream function is constant on the walls. !

At the right and the left boundary:!


!" !"
$ 2% =0 =0
! 2" ! 2" !x !x
+ 2 = #$ ! " wall = # 2 ! = Constant
!x 2 !y $x ! 2" ! 2"
# wall = $ # wall = $
Similarly, at the top and the bottom boundary:! !x 2 !x 2
! 2" ! 2" $ 2%
+ 2 = #$ ! " wall = # !" ! 2"
!x 2 !y $y2 = 0; # wall = $ 2
!y !y

Computational Fluid Dynamics


Computational Fluid Dynamics

Discretizing the Domain! Finite Difference Approximations!

To compute an approximate solution numerically,


we start by laying down a discrete grid:!
Then we replace the equations at each grid point
j=NY! by a finite difference approximation!

! i, j and " i , j Grid n


1 ') ! 2" ! 2" #*
n n
!" # !& !" # !& !" #
n
boundaries
stored at =% + + +
!t $ i, j
coincide
each grid
with domain
!y !x $ i, j !x !y $ i, j Re ( !x 2 !y 2 $ i, j
point!
boundaries!
n n
! 2" #% ! 2" #
+ 2 % = &' i,n j
j=2!
j=1! !x $ i, j !y $ i, j
2

i=1! i=2! i=NX!

Computational Fluid Dynamics


Computational Fluid Dynamics

Finite Difference Approximations! Finite Difference Approximations!

Finite difference approximations!


Use the notation developed earlier:!

!f (x) f (x + h) " f (x " h) ! f (x) h 3 2


= " +!
!x 2h !x 3 12 (x, y)
fi , j +1 = f (x, y + h)
! f (x) f (x + h) " 2 f (h) + f (x " h) ! f (x) h
2 4 2
j+1

= " +! fi , j = f (x,y)
!x 2 h2 !x 4 xx
j

!f (t) f (t + "t) # f (t) ! 2 f (t) "t fi +1, j = f (x + h, y)
= # +! j-1

!t "t !t 2 2
i -1 i i+1

Computational Fluid Dynamics
Computational Fluid Dynamics

Finite Difference Approximations! Finite Difference Approximations!

Laplacian! !" !$ !" !$ !" 1 %' ! 2" ! 2" (


=# + + +
!t !y !x !x !y Re & !x 2 !y 2 )
!2 f ! 2 f
+ = The advection equation is:!
!x 2 !y 2
! i,n +1
j " ! i, j
n

fi n+1, j ! 2 fi,nj + fi!1,


n
f n ! 2 f i,nj + fi n, j !1 =
2
j
+ i, j +1 = #t
h h2 % $ n " $ i,n j"1 (% ! i+1, ( % $ i+1, (% ! i,n j +1 " ! i,n j"1 (
j " ! i"1, j j " $ i"1, j
n n n n

"' i, j +1 *' *+' *' *


fi +1, j + fi !1 , j + fi, j +1 + fi , j !1 ! 4 fi , j
n n n n n
& 2h )& 2h ) & 2h )& 2h )
h2 1 % ! i+1, j + ! i"1, j + ! i, j +1 + ! i, j"1 " 4! i, j (
n n n n n

+ ' 2 *
Re & h )

Computational Fluid Dynamics


Computational Fluid Dynamics

Finite Difference Approximations! Finite Difference Approximations!

The vorticity at the new time is given by:!


The elliptic equation is:!
n n n n
i,n+1 = i,n j + t
i, j +1 i, j 1

i+1, j i1, j
2 2
+ =
j
2h 2h
x2 y2
i+1,
n
j
i1,
n
j
i,n j +1 i,n j 1
+
2h 2h
1 i+1, j + i1, j + i, j +1 + i, j 1 4 i, j i+1, + i1, + i,n j +1 + i,n j 1 4 i,n j
n n n n n n n
+ 2 j j
= i,n j
Re h h2

Computational Fluid Dynamics


Computational Fluid Dynamics

Finite Difference Approximations! Discrete Boundary Condition!

These equations allow us to obtain the solution at


Consider the bottom wall (j=1):!
interior points!
j=ny! ! i, j = 0 Need to find! ! wall = ! i, j =1
on the boundary!
j=3
given:!

Need vorticity j=2


! = Constant
on the
!" ! 2"
boundary!! j=1

Uwall = U wall ; # wall = $ 2
!y !y
j=2! i -1 i i+1

j=1!
i=1! i=2! i=nx!
Computational Fluid Dynamics
Computational Fluid Dynamics

Discrete Boundary Condition! Discrete Boundary Condition!

"! i, j =1 " 2! i , j =1 h 2
j=3
given:! ! i, j = 2 = ! i, j =1 + h+ + O(h3 )
"y "y 2 2
j=2
! = Constant
!" ! 2" Using:! # 2$ i, j =1 #$ i, j =1
j=1

Uwall = U wall ; # wall = $ 2 ! wall = " ; Uwall =
!y !y #y 2 #y
i -1 i i+1
this becomes:!
h2
Expand the streamfunction!
! i, j = 2 = ! i, j =1 + Uwallh " # wall + O(h 3 )
2
"! i, j =1 " 2! i , j =1 h 2 Solving for the wall vorticity:!
! i, j = 2 = ! i, j =1 + h+ + O(h3 )
! wall = (" i , j =1 # " i , j =2 )
"y "y 2 2 2 2
+ Uwall + O(h)
h2 h

Computational Fluid Dynamics


Computational Fluid Dynamics

Solving the elliptic equation! Time Step!

The elliptic equation:!


! in+1, j + ! in"1, j + ! ni, j +1 + ! ni, j "1 " 4! i,n j Limitations on the time step!
= "# i,n j
h2
Rewrite as! ! "t 1 (|u | + | v |)!t
# #2
! i,n+1
j = 0.25 (! i +1, j + ! i"1, j + ! i, j +1 + ! i, j "1 + h # i, j )
n n n n 2 n
h2 4 "

Solve by SOR!

! "i, j+1 = # 0.25 (! "i +1, j + ! "i$1,+1j + !i," j +1 + ! "i, +1


j$1 + h % i, j )
2 n

+ (1$ # )! "i, j

Computational Fluid Dynamics


Computational Fluid Dynamics

Solution Strategy! Solution Strategy!

Initial vorticity given! Initial vorticity given!


for i=1:MaxIterations!
for i=2:nx-1; for j=2:ny-1!
s(i,j)=SOR for the stream function!
Solve for the stream function! Solve for the stream function! end; end!
end!

Find vorticity on boundary! Find vorticity on boundary! v(i,j)=!

for i=2:nx-1; for j=2:ny-1!


Find RHS of vorticity equation! Find RHS of vorticity equation! rhs(i,j)=Advection+diffusion!
end; end!

v(i,j)=v(i,j)+dt*rhs(i,j)!
Update vorticity in interior! Update vorticity in interior!

t=t+!t! t=t+!t!
Computational Fluid Dynamics
Computational Fluid Dynamics

The Code! Results:!

1 clf;nx=9; ny=9; MaxStep=60; Visc=0.1; dt=0.02; % resolution & governing parameters


2 MaxIt=100; Beta=1.5; MaxErr=0.001; % parameters for SOR iteration
3 sf=zeros(nx,ny); vt=zeros(nx,ny); w=zeros(nx,ny); h=1.0/(nx-1); t=0.0;
4 for istep=1:MaxStep, % start the time integration 17 by 17!
5 for iter=1:MaxIt, % solve for the streamfunction
6
7
w=sf;
for i=2:nx-1; for j=2:ny-1
% by SOR iteration Dt=0.01!
8
9
sf(i,j)=0.25*Beta*(sf(i+1,j)+sf(i-1,j)...
+sf(i,j+1)+sf(i,j-1)+h*h*vt(i,j))+(1.0-Beta)*sf(i,j);
D=0.1!
10 end; end;
11 Err=0.0; for i=1:nx; for j=1:ny, Err=Err+abs(w(i,j)-sf(i,j)); end; end;
12 if Err <= MaxErr, break, end % stop if iteration has converged
13 end;
14 vt(2:nx-1,1)=-2.0*sf(2:nx-1,2)/(h*h); % vorticity on bottom wall
15 vt(2:nx-1,ny)=-2.0*sf(2:nx-1,ny-1)/(h*h)-2.0/h; % vorticity on top wall
16 vt(1,2:ny-1)=-2.0*sf(2,2:ny-1)/(h*h); % vorticity on right wall
17 vt(nx,2:ny-1)=-2.0*sf(nx-1,2:ny-1)/(h*h); % vorticity on left wall
18 for i=2:nx-1; for j=2:ny-1 % compute
19 w(i,j)=-0.25*((sf(i,j+1)-sf(i,j-1))*(vt(i+1,j)-vt(i-1,j))... % the RHS
20 -(sf(i+1,j)-sf(i-1,j))*(vt(i,j+1)-vt(i,j-1)))/(h*h)... % of the
21 +Visc*(vt(i+1,j)+vt(i-1,j)+vt(i,j+1)+vt(i,j-1)-4.0*vt(i,j))/(h*h); % vorticity
22 end; end; % equation
23 vt(2:nx-1,2:ny-1)=vt(2:nx-1,2:ny-1)+dt*w(2:nx-1,2:ny-1); % update the vorticity
24 t=t+dt % print out t
25 subplot(121), contour(rot90(fliplr(vt))), axis('square'); % plot vorticity
26 subplot(122), contour(rot90(fliplr(sf))), axis('square');pause(0.01) % streamfunction
27 end;

Computational Fluid Dynamics


Computational Fluid Dynamics

Results:! Results:!

Streamfunction! Vorticity!
17 by 17!
Dt=0.01!
0.1 25

20
D=0.1!
0.08
15
0.06 10

5
!" " i, j +1 $ "i, j$1
ui, j = #
0.04
0
0.02
-5 !y 2h
0 -10
20 20
!" " i+1, j $" i$1, j
v i, j = $ #$
15 20 15 20
15 15

!x
10 10
5
5
10
5
5
10
2h
0 0 0 0

Computational Fluid Dynamics


Computational Fluid Dynamics

Results:!
9 by 9 grid! 17 by 17 grid!

Why is vorticity !
Streamfunction at t = 1.2!
important?!

Vorticity at t = 1.2!
Computational Fluid Dynamics
Computational Fluid Dynamics

Vorticity! Vorticity!

Helmholtz decomposition:! For incompressible flow with constant density and viscosity,
Any vector field can be written as a sum of ! taking the curl of the momentum equation yields:!
u = +

Take divergence! + u = ( )u + 2
t
u = = 2 = 0
Take the curl! or:!
D
u = ( ) = = ( )u + 2
Dt
By a Gauge transform this can be written as!
Helmholtzs theorem:!
2 = Inviscid Irrotational flow remains irrotational!

Computational Fluid Dynamics


Computational Fluid Dynamics

Vorticity! Flow over a body!

In two-dimensions:! = (0,0, ) = (0,0, ) Irrotational outer flow!

v u
=
x y
or:! Rotational wake!
D
= 2 =
2

Dt

D Boundary layer: the


Zero viscosity: ! =0 The vorticity of a fluid particle
Dt flow is viscous and
does not change!!
rotational!

Computational Fluid Dynamics


Computational Fluid Dynamics

Boundary Layers!

u u u 1 P 2 u 2 u
Advection and t
+u +v =
x y
+ +
x x 2 y 2

diffusion! f f 2 f
+U =D 2
Boundary layers! t x x
Computational Fluid Dynamics
Computational Fluid Dynamics

Boundary Layers! Boundary Layers!

Consider the steady state balance of advection and diffusion! Rearrange!


D df 1 df U
f =0 U f =1 f C1 = =
x =0 x=L
U dx ( f C1 ) dx D
or!
f 2f df U
Governed by:! U =D 2 = dx
x x ( f C1 ) D
Solve this equation analytically!
Integrate!
df D d 2 f d D df
= f =0 df U U
dx U dx 2 dx U dx ( f C ) = D dx
1
ln ( f C1 ) =
D
x + C2
D df
Integrate:! f = C1
U dx f = exp (Ux / D) exp( C2 ) + C1

Computational Fluid Dynamics


Computational Fluid Dynamics

Boundary Layers! Boundary Layers!

f = exp (Ux / D) exp( C2 ) + C1 f = exp (Ux / D) exp( C2 ) + C1


Boundary conditions!
1
C1 = exp(C2 ) exp(C2 ) =
At! x =0: f =0 0 = exp(C2 ) + C1 C1 = exp(C2 ) exp(UL/D) 1
At! x = L: f =1 1 = exp(UL/ D) exp(C2 ) + C1
exp(Ux / D) 1
1 = exp(UL/ D) exp(C2 ) exp(C2 ) f=
exp(UL/D) 1
1 = exp(C2 )[exp(U / D) 1]
exp (Rx / L) 1 UL
1 f = R=
exp( C2 ) = exp( R) 1 D
exp (UL/ D) 1

Computational Fluid Dynamics


Computational Fluid Dynamics

Boundary Layers! Boundary Layers!

r=20;for i=1:100,x(i)=(i-1)/99;end;!
for i=1:100,f(i)=(exp(r*x(i))-1)/(exp(r)-1);end;! Scaling:! 1
plot(x,f)!
1 df D d 2 f 0.9
R=1 !L/R=1!
=
dx U dx 2
0.8
0.9
R=5 !L/R=0.2!
R=1! 0.8
0.7

R=5! 0.7
0.6 R=10 !L/R=0.1!
R=10! Estimate the
0.6
0.5
R=20 !L/R=0.05!
R=20!
0.5 thickness of the 0.4

0.4 boundary Layer! 0.3

0.2
0.3

1 D 1 DL L
= =
0.1
0.2

0.1 U 2 UL R 0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Computational Fluid Dynamics
Computational Fluid Dynamics

Boundary Layers! Objectives!

f 2 f 2 f
2D! Solution of:! U
x
= D 2 + 2
x y
Develop an understanding of the steps involved in
solving the Navier-Stokes equations using a numerical
method!
U=1! D
D=0.025! Write a simple code to solve the driven cavity
U
f problem using the Navier-Stokes equations in vorticity
f=0
=0 form!
x
Short discussion about why looking at the vorticity is
sometimes helpful!

f=1

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