Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Simulation of 2-D Unsteady Recirculating Flow

inside a square Cavity

Prepared by

Venu Agarwal

Submitted to

Dr. S.P Vanka

I. Introduction:
The objective of this project is to develop a computer program for two-dimensional unsteady
recirculating flows with constant properties (density and viscosity) in a square cavity with top
wall sliding at a given velocity. Two dimensional Navier Stokes equation are solved using first
order time and second-order space discretization. An explicit time discretization scheme for
both convection and diffusion terms is used. Three cases are considered corresponding to
Reynolds number: 50, 100 and 200, using a square grid of size 1 unit with 40*40 grid intervals
(42 x 42 finite difference points).

II. Partial Differential Equations Solved:


The two dimensional continuity equation is as follow:

+
=0

()

X- Momentum equation:

2 2
+(
+
)=
+ ( 2+ 2)

()

Y momentum equation:

2 2
+(
+
)=
+ ( 2+ 2)

()

III. Geometry:

IV. Finite Difference form of the equations

A. Continuity equation
(+1, 1, ) (,+1 ,1 )
+
=0
2
2
B. X momentum equation
The various terms in X momentum equation are discretized as follows:
Unsteady term
+1

,
)
(,
=

+1

,
)
(,
=

Advection terms

(+1,
)
1,

(,+1
)
,1

(+1,
)
1,

(,+1
)
,1

Diffusion term
2
2

2,
+1,
(+1,
)

2,
+,1
(,+1
)

2
2

2,
+1,
(+1,
)

2,
+,1
(,+1
)

Pressure Term

+1
+1
(+1,
1,
)

=
,
2
+1
+1
(,+1
,1
)

=
,
2

V.

Boundary Conditions and discretization at the boundary

Velocity Boundary Condition


Let

A.

uB be the boundary velocity

Left boundary condition:

(uB)left=0 &

(1,
+2,
)/2 = (uB)left
B.

Right boundary condition:

(v1,
+v2,
)/2 = (vB)left

(uB)right=0 &

(+1,
+,
)/2 = (uB)right
C.

Top boundary condition:

(uB)top=1.0

(,+1
+,
)/2 = (uB)top
D.

Bottom boundary condition:

(vB)left=0

(vB)right=0

(v+1,
+v,
)/2 = (vB)right

&

(vB)top=0

(v,+1
+v,
)/2 = (vB)top

(uB)bottom=0

&

(vB)bottom=0

(,1
+,2
)/2 = (uB)bottom (v,1
+v,2
)/2 = (vB)bottom

Pressure Boundary Condition


Left boundary condition:

p(1,j) = p(2,j)

Right boundary condition:

p(nx+1,j) = p(nx,j)

Top boundary condition:

p(i,ny+1) = p(i,ny)

Bottom boundary condition: p(i,1) = p(i,2)

VI. Solution Algorithm


The convection and Diffusion terms are written as

Cun
Cvn

Dnu
Dnv

=
=

u u
x
u v
x

2
2
2 v
2

v u

y
v v

+
+

2
2
2 v
2

n
un
i1,j )
n (ui+1,j
ui,j
2x

n
vn
i1,j )
n (vi+1,j
ui,j
2x

=
=

n
un
i,j1 )
n (ui,j+1
vi,j
2y

n
vn
i,j1 )
n (vi,j+1
vi,j
2y

2,
+1,
(+1,
)

(v
+1, 2v, +v1, )

2,
+,1
(,+1
)

(v
,+1 2v, +v,1 )

A. Determination of intermediate velocities


From the velocities at nth time step, intermediate velocities , are computed as
follows:

)=
,
,

Cun + un

Cvn + vn

(v

v
) =
,
,

Intermediate velocities are then calculated at half grid points by taking average of
neighbouring velocities

+1/2, =

(, + +1, )/2

v,1/2 =

(v, + v,1 )/2

B. Pressure Poisson Equation


From the intermediate velocities at half grid points, pressure field at n+1 is calculated
as follows:
+1/2,
1/2, )
(

+1
+1
(,
1,
)

,+1/2 v
,1/2 )
(v

+1
+1
(,
,+1
)

+1
+1
(,
,1
)

+1
+1
(,
+1,
)

=0

From the above Pressure Poisson equation, we get a penta diagonal system of equations,
which are solved using SOR technique.
Finally, after computing intermediate velocities at the grid points and pressure fields at
n+1, velocities at n+1 time step can be computed by plugging into the equation.
+1
,

+1
+1
1,
+1,
= , (
)

+1
v,

+1
+1
,1
,+1
= v, (
)

VII. Convergence Criteria and runs performed:


The criteria for convergence is based on the residuals or the maximum time step reached.
The residual is calculated after each time step as follow
R = ( sum (unew - uold) 2 )1/2 / (Nx . Ny) , summed over all grid points.
The steady state is considered to converge when R reaches a value less than 1.0e-5, or a

minimum of 10 time units has reached.


The time step is taken as 0.001 and 10000 time iterations were performed to reach
the steady state of 10 units, for different Reynolds number.

VIII.

Results:

Case I:

Re=50

Case II:

Re=100

Case III: Re=200

IX. Discussion and comparison with previous researchers


For the u component of the velocity, as seen from the results along the vertical
centreline of the cavity, the magnitude decreases as we move away from the
moving top boundary, becomes zero at about the centre of the cavity and then
reversing the flow direction, achieves a negative maximum velocity and then again
goes to zero at the bottom wall. The thing to observe from the graphs of different
Reynolds number is that, the position of umax (in the negative direction) moves
more and more towards the bottom wall with increasing Reynolds number, but
the magnitude of umax (more or less) remains same for all the Re (50,100 &200).
The results for v component velocity along a horizontal line passing through the
geometric centre of the square cavity, shows a gradually decrease in velocity as
we move towards the centre and development of narrow boundary layers along
the walls.
With increase in Reynolds numbers the Vmax inside the cavity increases ( upto
0.3 m/s). But for all Reynolds number v component of the velocity approaches
zero at the geometric centre and then increases to some maximum value and then
again becomes zero at the walls.
Streamline plots for different Reynolds number gives insight into the vortex
formation taking place inside the square cavity. Increasing the Reynolds number
causes bigger vortex to be formed at the bottom corners of the cavity.
Pressure contours shows, discontinuity in the pressure at the top corners of the
square cavity, with pressure variation being higher at the corners than at the
interior of the cavity.

Comparisons with previous researchers

Fig 1.

Fig 2.
Comparison of the above obtained results were done with the already published results for
lid-driven cavity through the above two figures.
Fig 1 shows the variation of u component of the velocity along the vertical centreline, and the
variation of v component of the velocity along the horizontal centreline, for Re=200. The trend
agrees to a large extent with the results obtained by the present study. The u max is reached
at around 0.4 unit above the bottom plate and v component velocity attains a maximum of
about 0.3 m/s and becomes zero at the centre along with flow reversal taking place about the

centre. The same trend was observed for both the u and v component velocity in the present
study for Re=200.
In the Fig 2. , variation of u and v component of velocity along the centreline is seen with
respect to different Reynolds number from studies of different researchers. The general
trend seen is, that by increasing the Reynolds number, the position of umax approaches the
bottom wall, with the magnitude of umax increasing with Reynolds number.
The trend observed for v component of velocity from Fig 2, also agrees with the results
obtained. The vmax increases with Reynolds number but at the centre of the cavity v remains
zero irrespective of the Reynolds number.
Hence quantitatively we can say that results obtained in the present study agrees significantly
with the already published results by researchers.

IX. References
1. Lid Driven Sqaure Cavity Flow: Numerical Solution with 1024*1024 Grid by Carlos
Henrique Marchi, Robert Suero, Luciano Kiyoshi Araki
2. CFD simulations for Lid Driven Cavity Flow at Moderate Reynolds Number by Reyad
Omari

X. Appendix
Implicit double precision(a-h,o-z)
Parameter (nx=40)
Parameter (ny=40)
DIMENSION u(nx+2,ny+2),v(nx+2,ny+2),p(nx+2,ny+2)
DIMENSION ae(nx+2,ny+2),aw(nx+2,ny+2),an(nx+2,ny+2),as(nx+2,ny+2)
DIMENSION a(nx+2,ny+2),uh(nx+2,ny+2),vh(nx+2,ny+2),s(nx+2,ny+2)

c
c

open(unit=9,file='centreline_u_200_2.0.txt')
open(unit=10,file='v.txt')
open(unit=11,file='p.txt')

xl=1.0
yl=1.0
Re=200.0
ntmax=2000
niter=200
rho=1.2
omega=1.4
utop=1.0
dx=xl/nx
dy=yl/ny
dxsq=dx**2
dysq=dy**2

c
c
c
c

c
c

vis = rho * utop * xl / Re


vis=2*10**(-5.0)
utop=vis*Re/(rho*xl)
dt = 1.0 / (utop/dx + utop/dy + 2.0*vis/(rho *dxsq) +
1
2.0*vis/(rho *dysq))
dt=0.001
time=0.0d0

conux,conuy,convx,convy=0.0d0
diffux,diffuy,diffvx,diffvy,temp=0.0d0
temp=0.0d0

c---------Defining the initial velocities and pressure


do i=2,nx+1
do j=2,ny+1
u(i,j)=0.0
v(i,j)=0.0
p(i,j)=0.0
enddo
enddo

c-----------Defining the initial velocties at the boundary--------do i=2,nx+1


c--Lower boundary
u(i,1)=0.0d0
v(i,1)=0.0d0
p(i,1)=0.0d0
c--Upper boundary
u(i,ny+2)=2*utop-u(i,ny+1)
v(i,ny+2)=0.0
p(i,ny+2)=0.0
enddo
do j=2,ny+1
c--left boundary
u(1,j)=0.0d0
v(1,j)=0.0d0
p(1,j)=0.0d0
c--Right boundary
u(nx+2,j)=0.0
v(nx+2,j)=0.0
p(nx+2,j)=0.0
enddo

c----------Defining the coefficients of Pressure Possion Equation


do i=2,nx+1
do j=2,ny+1
aw(i,j)=1.0/dxsq

ae(i,j)=1.0/dxsq
an(i,j)=1.0/dysq
as(i,j)=1.0/dysq
a(i,j)=2.0/dxsq+2.0/dysq
if (i.eq.2)then
aw(i,j)=0.0
a(i,j)=1.0/dxsq+2.0/dysq
endif
if (i.eq.nx+1)then
ae(i,j)=0.0
a(i,j)=1.0/dxsq+2.0/dysq
endif
if (j.eq.2)then
as(i,j)=0.0
a(i,j)=2.0/dxsq+1.0/dysq
endif
if (j.eq.ny+1)then
an(i,j)=0.0
a(i,j)=2.0/dxsq+1.0/dysq
endif
enddo
enddo
c-------------------------------------------------------------Time iteration begins
do itime=1,ntmax
sumu=0.0d0
sumv=0.0d0
c-------Updating the intermediate velcoites
do i=2,nx+1
do j=2,ny+1
conux=rho*u(i,j)*(u(i+1,j)-u(i-1,j))/(2.0*dx)
conuy=rho*v(i,j)*(u(i,j+1)-u(i,j-1))/(2.0*dy)
convx=rho*u(i,j)*(v(i+1,j)-v(i-1,j))/(2.0*dx)
convy=rho*v(i,j)*(v(i,j+1)-v(i,j-1))/(2.0*dy)
diffux=vis*(u(i+1,j)-2.0*u(i,j)+u(i-1,j))/dxsq
diffuy=vis*(u(i,j+1)-2.0*u(i,j)+u(i,j-1))/dysq
diffvx=vis*(v(i+1,j)-2.0*v(i,j)+v(i-1,j))/dxsq

diffvy=vis*(v(i,j+1)-2.0*v(i,j)+v(i,j-1))/dysq

uh(i,j)=u(i,j)+dt/rho*(-conux-conuy+diffux+diffuy)
vh(i,j)=v(i,j)+dt/rho*(-convx-convy+diffvx+diffvy)
enddo
enddo

c-------Updating the intermediate velcoities at the boundaries


do i=2,nx+1
vh(i,1)=-vh(i,2)
vh(i,ny+2)=-vh(i,ny+1)
enddo
do j=2,ny+1
uh(1,j)=-uh(2,j)
uh(nx+2,j)=-uh(nx+1,j)
enddo
c------Determining the constants for Pressure Poisson equation
do i=2,nx+1
do j=2,ny+1
s(i,j)=(rho/dt)*((uh(i-1,j)-uh(i+1,j))/(2.0*dx))+
1
rho*((vh(i,j-1)-vh(i,j+1))/(2.0*dy*dt))
enddo
enddo

c--------SOR for pressure poission equation


do iter=1,niter
do i=2,nx+1
do j=2,ny+1
temp=(aw(i,j)*p(i-1,j)+ae(i,j)*p(i+1,j)+as(i,j)*p(i,j-1)+
1
an(i,j)*p(i,j+1)+s(i,j))/a(i,j)

p(i,j)=omega*temp+(1-omega)*p(i,j)
print *, temp
enddo
enddo
enddo

c-------Updating the Pressure at the boundaries


do i=2,nx+1
p(i,1)=p(i,2)
p(i,ny+2)=p(i,ny+1)
enddo
do j=2,ny+1
p(1,j)=p(2,j)
p(nx+2,j)=p(nx+1,j)
enddo

c--------Updating the actual velocities

do i=2,nx+1
do j=2,ny+1
u(i,j)=uh(i,j)+(dt/rho)*(p(i-1,j)-p(i+1,j))/(2.0*dx)
v(i,j)=vh(i,j)+(dt/rho)*(p(i,j-1)-p(i,j+1))/(2.0*dy)
enddo
enddo

c-------Updating the actual velocities at the boundaries


do i=2,nx+1
u(i,1)=-u(i,2)
v(i,1)=-v(i,2)
u(i,ny+2)=2*utop-u(i,ny+1)
v(i,ny+2)=(-v(i,ny+1))
enddo
do j=2,ny+1
u(1,j)=-u(2,j)

v(1,j)=-v(2,j)
u(nx+2,j)=-u(nx+1,j)
v(nx+2,j)=-v(nx+1,j)
enddo
c------------------------------------Error computation
do i=2,nx+1
do j=2,ny+1
sumu=sumu+(u(i,j)-uh(i,j))**(2.0d0)
sumv=sumv+(v(i,j)-vh(i,j))**(2.0d0)
enddo
enddo
erroru=(sumu**0.5)/(nx*ny)
errorv=(sumv**0.5)/(nx*ny)
time=time+dt
print *,time,itime,erroru,errorv

enddo
c---------------------------------------------------------Time iteration ends

c--------Writing to the output files


DO j = 2,ny+1
c DO i = 2,nx+1
x = (i-1)*dx -0.5*dx
y = (j-1)*dy -0.5*dy
c

WRITE(9,*) x, y, u(i,j), v(i,j), p(i,j)


WRITE(9,*) u(20,j),v(j,20)
c
enddo
enddo
close(9)

stop
END

You might also like