wpi computational fluid dynamics i - unicampphoenics/site_phoenics/apostilas/cfd-1_u michigan... ·...
TRANSCRIPT
Computational Fluid Dynamics IPPPPIIIIWWWW
A Finite Difference Code for the Navier-Stokes
Equations in Vorticity/Stream Function
FormulationInstructor: Hong G. ImUniversity of Michigan
Fall 2001
Computational Fluid Dynamics IPPPPIIIIWWWW
Develop an understanding of the steps involved in solving the Navier-Stokes equations using a numerical method
Write a simple code to solve the “driven cavity” problem using the Navier-Stokes equations in vorticityform
Objectives:
Computational Fluid Dynamics IPPPPIIIIWWWW• The Driven Cavity Problem• The Navier-Stokes Equations in Vorticity/Stream
Function form• Boundary Conditions• Finite Difference Approximations to the Derivatives• The Grid• Finite Difference Approximation of the
Vorticity/Streamfunction equations• Finite Difference Approximation of the Boundary
Conditions• Iterative Solution of the Elliptic Equation• The Code• Results• Convergence Under Grid Refinement
Outline
Computational Fluid Dynamics IPPPPIIIIWWWW
Moving wall
Stationary walls
The Driven Cavity Problem
Computational Fluid Dynamics IPPPPIIIIWWWW
++−=++
2
2
2
21yu
xu
xp
yuv
xuu
tu
∂∂
∂∂ν
∂∂
ρ∂∂
∂∂
∂∂
Nondimensional N-S Equation
Incompressible N-S Equation in 2-D
Nondimensionalization,/~ Uuu = ,/~ Lxx = 2/~ Upp ρ=,/~ LtUt =
++−=
++
2
2
2
2
2
22
~~
~~
~~
~~~
~~~
~~
yu
xu
LU
xp
LU
yuv
xuu
tu
LU
∂∂
∂∂ν
∂∂
∂∂
∂∂
∂∂
++−=++
2
2
2
2
~~
~~
~~
~~~
~~~
~~
yu
xu
ULxp
yuv
xuu
tu
∂∂
∂∂ν
∂∂
∂∂
∂∂
∂∂
Re1
Computational Fluid Dynamics IPIW
∂u∂t
+ u ∂u∂x
+ v ∂u∂y
= −∂p∂x
+1
Re∂ 2u∂x2 +
∂ 2u∂y2
∂v∂t
+ u ∂v∂x
+ v ∂v∂y
= −∂p∂y
+1
Re∂ 2v∂x2 +
∂ 2v∂y2
−∂∂y
∂∂x
∂ω∂t
+ u ∂ω∂x
+ v ∂ω∂y
=1Re
∂ 2ω∂x2 +
∂ 2ω∂y2
ω =∂v∂x
−∂u∂y
The vorticity/stream function equations
The Vorticity Equation
Computational Fluid Dynamics IPIW
0=+yv
xu
∂∂
∂∂
xv
yu
∂∂ψ
∂∂ψ −== ,
which automatically satisfies the incompressibility conditions
Define the stream function
∂∂x
∂ψ∂y
−∂∂y
∂ψ∂x
= 0
by substituting
The vorticity/stream function equations
The Stream Function Equation
Computational Fluid Dynamics IPIW
∂2ψ∂x2 +
∂2ψ∂y2 = −ω
ω =∂v∂x
−∂u∂y
u =∂ψ∂y
; v = −∂ψ∂x
Substituting
into the definition of the vorticity
yields
The vorticity/stream function equations
Computational Fluid Dynamics IPIW
∂ω∂t
= −∂ψ∂y
∂ω∂x
+∂ψ∂x
∂ω∂y
+ 1Re
∂ 2ω∂x2 +
∂ 2ω∂y2
∂ 2ψ∂x2 +
∂ 2ψ∂y2 = −ω
The Navier-Stokes equations in vorticity-stream function form are:
Elliptic equation
Advection/diffusion equation
The vorticity/stream function equations
Computational Fluid Dynamics IPIWBoundary Conditions for the Stream Function
u = 0 ⇒∂ψ∂y
= 0
⇒ ψ = Constant
At the right and the left boundary:
Computational Fluid Dynamics IPIW
v = 0 ⇒∂ψ∂x
= 0
⇒ ψ = Constant
At the top and thebottom boundary:
Boundary Conditions for the Stream Function
Computational Fluid Dynamics IPIW
Since the boundaries meet, the constant must be the same on all boundaries
ψ = Constant
Boundary Conditions for the Stream Function
Computational Fluid Dynamics IPIWBoundary Conditions for the Vorticity
At the right and left boundary:
At the top boundary:
The normal velocity is zero since the stream function is a constant on the wall, but the zero tangential velocity must be enforced:
v = 0 ⇒∂ψ∂x
= 0 u = 0 ⇒∂ψ∂y
= 0
At the bottom boundary:
wallwall Uy
Uu =∂
⇒= ∂ψ
Computational Fluid Dynamics IPIW
At the right and the left boundary:
Similarly, at the top and the bottom boundary:
⇒ ω wall = −∂ 2ψ∂x 2
⇒ ω wall = −∂ 2ψ∂y2
The wall vorticity must be found from the streamfunction. The stream function is constant on the walls.
∂2ψ∂x2 +
∂ 2ψ∂y2 = −ω
∂ 2ψ∂x2 +
∂ 2ψ∂y2 = −ω
Boundary Conditions for the Vorticity
Computational Fluid Dynamics IPIW∂ψ∂y
= Uwall; ωwall = −∂ 2ψ∂y2
∂ψ∂y
= 0; ωwall = −∂ 2ψ∂y2
∂ψ∂x
= 0
ωwall = − ∂ 2ψ∂x 2
Summary of Boundary Conditions
ψ = Constant
∂ψ∂x
= 0
ωwall = − ∂ 2ψ∂x 2
Computational Fluid Dynamics IPIWFinite Difference Approximations
To compute an approximate solution numerically, the continuum equations must be discretized. There are a few different ways to do this, but we will use FINITE DIFFERENCE approximations here.
Computational Fluid Dynamics IPIW
i=1 i=2 i=NXj=1j=2
j=NY
ψ i, j and ω i , j
Stored at each grid point
Discretizing the Domain
Uniform mesh (h=constant)
Computational Fluid Dynamics IPIW
When using FINITE DIFFERENCE approximations, the values of f are stored at discrete points and the derivatives of the function are approximated using a Taylor series:
Start by expressing the value of f(x+h) and f(x-h)in terms of f(x)
Finite Difference Approximations
h h
f(x-h) f(x) f(x+h)
Computational Fluid Dynamics IPIW
!++−−+=6
)(2
)()()( 2
3
3 hx
xfh
hxfhxfxxf
∂∂
∂∂
Finite difference approximations
Finite Difference Approximations
!++−+−+=12
)()()(2)()( 2
4
4
22
2 hx
xfh
hxfhfhxfx
xf∂
∂∂
∂
""
∂f (t)∂t
=f (t + ∆t) − f (t)
∆t+
∂ 2 f (t)∂t 2
∆t2
+!
2nd order in space, 1st order in time
Computational Fluid Dynamics IPIWFinite Difference Approximations
For a two-dimensional flow discretize the variables on a two-dimensional grid
fi , j = f (x,y)fi +1, j = f (x + h, y)fi , j +1 = f (x, y + h)
(x, y)
i -1 i i+1
j+1
j
j-1
Computational Fluid Dynamics IPIWFinite Difference Approximations
Laplacian
∂ 2 f∂x2 +
∂ 2 f∂y2 =
fi +1, jn − 2 fi, j
n + fi−1, jn
h2 +fi, j +1
n − 2 fi, jn + fi , j −1
n
h2 =
fi +1, jn + fi −1, j
n + fi, j +1n + fi , j −1
n − 4 fi , jn
h2
Computational Fluid Dynamics IPIW
−++++
−
−+
−
−−
=∆−
−+−+
−+−+−+−+
+
2,1,1,,1,1
1,1,,1,1,1,11,1,
,1
,
4Re1
2222
h
hhhh
t
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
ωωωωω
ωωψψωωψψ
ωωUsing these approximations, the vorticity equation becomes:
Finite Difference Approximations
+++−= 2
2
2
2
Re1
yxyxxyt ∂ω∂
∂ω∂
∂∂ω
∂∂ψ
∂∂ω
∂∂ψ
∂∂ω
Computational Fluid Dynamics IPIW
−++++
−
−−
−
−∆−=
−+−+
−+−+
−+−++
2,1,1,,1,1
1,1,,1,1
,1,11,1,,
1,
4Re1
22
22
h
hh
hht
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
nji
njin
jin
ji
ωωωωω
ωωψψ
ωωψψωω
The vorticity at the new time is given by:
Finite Difference Approximations
Computational Fluid Dynamics IPIW
ψ i +1, jn +ψ i −1, j
n +ψ i, j +1n +ψ i, j −1
n − 4ψ i, jn
h2 = −ω i, jn
The stream function equation is:
∂ 2ψ∂x2 +
∂ 2ψ∂y2 = −ω
Finite Difference Approximations
Computational Fluid Dynamics IPIW
Discretize the domainψ i, j = 0
i=1 i=2 i=nxj=1j=2
j=ny
i =1i = nxj =1j = ny
Discretized Domain
for
Computational Fluid Dynamics IPIW
i -1 i i+1
Discrete Boundary Condition
j=3
j=2
j=1
ψ i, j = 2 =ψ i, j =1 +∂ψ i, j =1
∂yh +
∂ 2ψ i , j =1
∂y2h2
2+ O(h3 )
ωwall = ω i, j =1Uwall
Computational Fluid Dynamics IPIW
ψ i, j = 2 =ψ i, j =1 + Uwallh −ωwallh2
2+ O(h3)
ωwall = ψ i , j =1 −ψ i , j =2( ) 2h2 +Uwall
2h
+O(h)
ωwall = −∂ 2ψ i, j =1
∂y2 ; Uwall =∂ψ i, j =1
∂y
Solving for the wall vorticity:
Using:
This becomes:
Discrete Boundary Condition
ψ i, j = 2 =ψ i, j =1 +∂ψ i, j =1
∂yh +
∂ 2ψ i , j =1
∂y2h2
2+ O(h3 )
Computational Fluid Dynamics IPIW
ωwall = ψ i , j =1 −ψ i , j =2( ) 2h2 +Uwall
2h
+O(h)
At the bottom wall (j=1):
Discrete Boundary Condition
Similarly, at the top wall (j=ny):
At the left wall (i=1):
At the right wall (i=nx):
Fill the blank
Fill the blank
( ) )(2221,, hO
hU
h wallnyjinyjiwall +−−= −== ψψω
Computational Fluid Dynamics IPIW
ψ i, jn+1 = 0.25 (ψ i +1, j
n +ψ i−1, jn +ψ i, j +1
n +ψ i, j −1n + h2ω i, j
n )
ψ i +1, jn +ψ i −1, j
n +ψ i, j +1n +ψ i, j −1
n − 4ψ i, jn
h2 = −ω i, jn
Solving the elliptic equation:
Rewrite as
j
j-1
j+1
i i+1i-1
Solving the Stream Function Equation
Computational Fluid Dynamics IPIW
ψ i, jn+1 = β 0.25 (ψ i+1, j
n +ψ i−1, jn +1 +ψ i, j +1
n +ψ i , j −1n+1 + h2ω i , j
n )
+ (1− β )ψ i, jn
Successive Over Relaxation (SOR)
If the grid points are done in order, half of the points have already been updated:
j
j-1
j+1
i i+1i-1
Solving the Stream Function Equation
Computational Fluid Dynamics IPIW
Limitations on the time step
ν∆th2 ≤ 1
4(| u | + | v |)∆t
ν≤ 2
Time Step Control
Computational Fluid Dynamics IPIW
for i=1:MaxIterationsfor i=2:nx-1; for j=2:ny-1
s(i,j)=SOR for the stream functionend; end
end
for i=2:nx-1; for j=2:ny-1rhs(i,j)=Advection+diffusion
end; end
Solution Algorithm
Solve for the stream function
Find vorticity on boundary
Find RHS of vorticity equation
Initial vorticity given
t=t+∆t
Update vorticity in interior
v(i,j)=
v(i,j)=v(i,j)+dt*rhs(i,j)
Computational Fluid Dynamics IPIW1 clf;nx=9; ny=9; MaxStep=60; Visc=0.1; dt=0.02; % resolution & governing parameters2 MaxIt=100; Beta=1.5; MaxErr=0.001; % parameters for SOR iteration3 sf=zeros(nx,ny); vt=zeros(nx,ny); w=zeros(nx,ny); h=1.0/(nx-1); t=0.0;4foristep=1:MaxStep, % start the time integration5 foriter=1:MaxIt, % solve for the streamfunction6 w=sf; % by SOR iteration7 fori=2:nx-1; forj=2:ny-18 sf(i,j)=0.25*Beta*(sf(i+1,j)+sf(i-1,j)...9 +sf(i,j+1)+sf(i,j-1)+h*h*vt(i,j))+(1.0-Beta)*sf(i,j);10 end; end;11 Err=0.0; fori=1:nx; forj=1:ny, Err=Err+abs(w(i,j)-sf(i,j)); end; end;12 ifErr <= MaxErr, break, end % stop if iteration has converged13 end;14 vt(2:nx-1,1)=-2.0*sf(2:nx-1,2)/(h*h); % vorticityon bottom wall15 vt(2:nx-1,ny)=-2.0*sf(2:nx-1,ny-1)/(h*h)-2.0/h; % vorticityon top wall16 vt(1,2:ny-1)=-2.0*sf(2,2:ny-1)/(h*h); % vorticityon right wall17 vt(nx,2:ny-1)=-2.0*sf(nx-1,2:ny-1)/(h*h); % vorticityon left wall18 fori=2:nx-1; forj=2:ny-1 % compute19 w(i,j)=-0.25*((sf(i,j+1)-sf(i,j-1))*(vt(i+1,j)-vt(i-1,j))... % the RHS20 -(sf(i+1,j)-sf(i-1,j))*(vt(i,j+1)-vt(i,j-1)))/(h*h)... % of the21 +Visc*(vt(i+1,j)+vt(i-1,j)+vt(i,j+1)+vt(i,j-1)-4.0*vt(i,j))/(h*h); % vorticity22 end; end; % equation23 vt(2:nx-1,2:ny-1)=vt(2:nx-1,2:ny-1)+dt*w(2:nx-1,2:ny-1); % update the vorticity24 t=t+dt % print out t25 subplot(121), contour(rot90(fliplr(vt))), axis('square'); % plot vorticity26 subplot(122), contour(rot90(fliplr(sf))), axis('square');pause(0.01) % streamfunction27 end;
MATLAB Code
Computational Fluid Dynamics IPIWnx=17, ny=17, dt = 0.005, Re = 10, Uwall = 1.0
Solution Fields
Computational Fluid Dynamics IPIWnx=17, ny=17, dt = 0.005, Re = 10, Uwall = 1.0
Solution Fields
Computational Fluid Dynamics IPIWStream Function at t = 1.2
Accuracy by Resolution
x
y
0 0.25 0.5 0.750
0.5
19 × 9 Grid
x
y
0 0.25 0.5 0.750
0.5
117 × 17 Grid
Computational Fluid Dynamics IPIWVorticity at t = 1.2
Accuracy by Resolution
x
y
0 0.25 0.5 0.750
0.5
19 × 9 Grid
x
y
0 0.25 0.5 0.750
0.5
117 × 17 Grid
Computational Fluid Dynamics IPIWMini-Project
Add the temperature equation to the vorticity-streamfunction equation and compute the increase in heat transfer rate:
Mini-project:
Computational Fluid Dynamics IPIWConvection
∂T∂t
+ u∂T∂x
+ v∂T∂y
= α∂ 2T∂x2 +
∂ 2T∂y2
α =D
ρcp
where
Computational Fluid Dynamics IPIWNatural convection
Natural convection in a closed cavity. The left vertical wall is heated.
0
Computational Fluid Dynamics IPIWNatural convection
Natural convection in a closed cavity. The left vertical wall is heated.
125
Computational Fluid Dynamics IPIWNatural convection
Natural convection in a closed cavity. The left vertical wall is heated.
250
Computational Fluid Dynamics IPIWNatural convection
Natural convection in a closed cavity. The left vertical wall is heated.
375
Computational Fluid Dynamics IPIWNatural convection
Natural convection in a closed cavity. The left vertical wall is heated.
500
Computational Fluid Dynamics IPIWNatural convection
Natural convection in a closed cavity. The left vertical wall is heated.
750
Computational Fluid Dynamics IPIWNatural convection
Natural convection in a closed cavity. The left vertical wall is heated.
1000
Computational Fluid Dynamics IPIW
200 400 600 800 10000
0.05
0.1
0.15
0.2
Natural convection
Heat Transfer Rate
Conduction only
Natural convection