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

2-D Navier Stokes Solution

Lid-Driven Cavity Flow


Copyright Brian G. Higgins (2009)
Introduction
These notes are based on the work of Jenny Hwang who studied cavity flow as part off her ECH198
project at UCDavis. We will examine the solution of the 2-D Navier Stokes equations for an incompress-
ible fluid using the vorticity transport equation. The particular problem we will examine is flow in a
rectangular cavity, driven by the motion of the lid.

Mathematical Formulation
The velocity components of the flow are given in terms of the stream function y
¶∂y ¶∂y
u= , v=- (1)
¶∂y ¶∂x
Here u is the component of velocity in the x-coordinate direction defined by the unit vector i and v is the
component of velocity in the y-coordinate direction defined by the unit vector j. Thus
v = u Hx, yL i + v Hx, yL j (2)

In two-dimensional flow the vorticity is given by


w = w Hx, yL k (3)

where k is the unit vector directed along the z axis. The equation of continuity for the flow is given by
“ ÿv = 0 (4)

or in component form
¶∂u ¶∂v
+ =0 (5)
¶∂x ¶∂y
From the definition of the stream function y we see that the equation of continuity is satisfied identically
¶∂2 y ¶∂2 y
- =0 (6)
¶∂x ¶∂y ¶∂y ¶∂x
The vorticity w of the flow is defined in terms of velocity field by
¶∂v ¶∂u
w = “ äv = - k (7)
¶∂x ¶∂y
Substituting in for the stream function gives
¶∂2 y ¶∂2 y
w = “ äv = - - k (8)
¶∂x2 ¶∂y2
2 CavityFlow.nb

Thus we have
“2 y = -w (9)

Thus if the vorticity is known everywhere in the flow the stream function(and hence the velocity compo-
nents) is determined by solving a Poisson equation. Of course, at the outset we do not know the vortic-
ity but it is possible to find an additional equation for the vorticity by writing the momentum equations in
terms of vorticity. For an incompressible Newtonian fluid the balance of linear momentum gives
¶∂v
r + v ÿ “v = -“p + m “2 v + rg (10)
¶∂t
The conservative body force rg can be written as the gradient of a scalar potential f:
“f = -r g (11)

We can eliminate the pressure p from the momentum equations by taking the curl of Eqn. (10). Thus
¶∂“äv
r + “ äHv ÿ “vL = -“ ä“p + m “2 “äv - “ ä“f (12)
¶∂t
Now noting that the curl of the gradient of a scalar is zero
“ ä“f = 0, “ ä“p = 0 (13)

we get
¶∂w
r + “ äHv ÿ “vL = m “2 w (14)
¶∂t
Using indicial notation one can readily show that for w = wHx, yL k, the vorticity Eq. (14) becomes
¶∂w ¶∂y ¶∂w ¶∂y ¶∂w
+ - = n “2 w (15)
¶∂t ¶∂y ¶∂x ¶∂x ¶∂y
where n = mê r is the kinematic viscosity. Thus for steady two-dimensional flow in a rectangular cavity we
need to solve the following system of equations
“2 y = -w

(16)
1 ¶∂y ¶∂w ¶∂y ¶∂w
“2 w = : - >
n ¶∂y ¶∂x ¶∂x ¶∂y
These equations must be solved subject to the boundary conditions on y and w on the walls of the
cavity. The cavity is oriented such that the bottom wall of the cavity is aligned along the positive x- axis.
We locate the origin of the x-y coordinate system at the left bottom corner so that the left wall of the
cavity is aligned with the y-axis. Let the length of the cavity by a and the height of the cavity be b. Thus
the corners of the cavity are located at H0, 0L, Ha, 0L, Ha, bL, H0, bL
The no penetration condition (the walls of the cavity are impervious) mean that
vÿn = 0 (17)

where n is the outward directed unit normal to the walls of the cavity. Thus we have
BC1 : v Hx, 0L = 0
BC2 : u Ha, yL = 0
(18)
BC3 : v Hx, bL = 0
BC4 : u H0, yL = 0
The no-slip boundary condition implies that the tangential velocity along the walls of the cavity be equal
to the velocity of the wall:
CavityFlow.nb 3

The no-slip boundary condition implies that the tangential velocity along the walls of the cavity be equal
to the velocity of the wall:
v ÿ t = Vc (19)

where t is a unit vector tangent to the wall of the cavity and Vc is the motion of the walls. Thus we have
BC5 : u Hx, 0L = 0
BC6 : v Ha, yL = 0
(20)
BC7 : u Hx, bL = V
BC8 : v H0, yL = 0

Dimensionless Form
It is convenient numerically to make the equations for y and w dimensionless. This means we need to
introduce the appropriate scalings for the dimensionless variables. If b is the height of the cavity and a
is the width of the cavity, then the appropriate dimensionless variables are
` x ` y ` y ` wa a Va
x= , y= , y= , w= , g = , Re = (21)
a b Va V b n
The dimensionless form of the governing equations becomes
` `
¶∂2 y 2
¶∂2 y `
+g = -w (22)
`2 `2
¶∂x ¶∂y
` ` ` ` ` `
¶∂2 w 2
¶∂2 w ¶∂y ¶∂w ¶∂y ¶∂w
+g = Re g : ` ` - ` ` > (23)
`2 `2 ¶∂y ¶∂x ¶∂x ¶∂y
¶∂x ¶∂y
` `
defined on the domain 0 § x § 1, 0 § y § 1. The boundary conditions are defined by Eq. (22)
` `
` ` 2
¶∂2 y ` ` 2
¶∂2 y
w Ix, 0M = -g , w Ix, 1M = -g
`2 `2
¶∂y `y=0 ¶∂y `y=1
` `
¶∂2 y ¶∂2 y (24)
` ` ` `
w I0, yM = - , w I1, yM = -
`2 `2
¶∂x `x=0 ¶∂x `x=1
` ` ` ` ` ` ` `
y Ix, 0M = 0, y Ix, 1M = 0, y I0, yM = 0, y I1, yM = 0
In the analysis that follows we will drop the ^ notation for dimensionless variables.

Finite Difference Formulation


In this section we plan to develop an iterative solution for solving the steady 2-D Navier Stokes equa-
tions. Our method is based on the procedure used by Burggraft (see Reference section) with a minor
change in choice of dimensionless variables.
Our first step is to discretize the dimensionless form of the stream function and vorticity equations
¶∂2 y ¶∂2 y
+ g2 = -w
¶∂x2 ¶∂y2
(25)
¶∂2 w ¶∂2 w ¶∂y ¶∂w ¶∂y ¶∂w
+ g2 = Re g : - >
¶∂x2 ¶∂y2 ¶∂y ¶∂x ¶∂x ¶∂y
Let the x domain of the cavity has Nx nodes starting from i = 1, 2, ..., Nx , and the y-domain have Ny
nodes starting from j = 1, 2, …, Ny . The nodes of our mesh are separated by a distance h. The dis-
cretization of the Poisson equation at (i th , j th ) node is
4 CavityFlow.nb

Let the x domain of the cavity has Nx nodes starting from i = 1, 2, ..., Nx , and the y-domain have Ny
nodes starting from j = 1, 2, …, Ny . The nodes of our mesh are separated by a distance h. The dis-
cretization of the Poisson equation at (i th , j th ) node is
yi+1,j - 2 yi,j + yi-1,j yi,j+1 - 2 yi,j + yi,j-1
+ g2 = -w Ixi , yj M (26)
h2 h2
Likewise we discretize the vorticity transport equation at (i th , j th ) node:
wi+1,j - 2 wi,j + wi-1,j wi,j+1 - 2 wi,j + wi,j-1
+ g2 = f Iwi,j , yi,j M (27)
h2 h2
where
yi,j+1 - yi,j-1 wi+1,j - wi-1,j yi+1,j - yi-1,j wi,j+1 - wi,j-1
f Iwi,j , yi,j M = Re g : - > (28)
2h 2h 2h 2h
We apply these equations to the internal nodes of the cavity, i.e., nodes starting from
i = 2, 3, ..., Nx - 1 and j = 2, 3, …, Ny - 1. Note because we have used central difference formulas, the
boundary nodes of the cavity are included by these formulas.
Let us write Eq. (26) as
1
Iyi+1,j + yi-1,j + g2 Iyi,j+1 + yi,j-1 MM + h2 w Ixi , yj M - yij = 0 (29)
2
2 I1 + g M
Thus if we have the exact values for the nodal values, then the LHS of Eq. 29 is identically zero
Hence let us define the LHS of Eq. 29 as the residual at the i, node
1
Ri,j = Iyi+1,j + yi-1,j + g2 Iyi,j+1 + yi,j-1 MM + h2 w Ixi , yj M - yi,j (30)
2
2 I1 + g M
In a smilar way we define the residual for Eq. 26
1
Li,j = Iwi+1,j + wi-1,j + g2 Iwi,j+1 + wi,j-1 MM
2
2 I1 + g M
(31)
Re
- g 8yi,j+1 - yi,j-1 wi+1,j - wi-1,j - yi+1,j - yi-1,j wi,j+1 - wi,j-1 < - wi,j
4
Thus if the values of wi, j and yi, j are exact on the nodes spanned by the residual functions, then
Ri,j = 0, Li,j = 0 (32)

We then construct the following iterative equations for the k + 1 iterative

i,j = F Hy, wL ª yi,j + p Ri,j


yk+1 k k k

(33)
wk+1
i,j = G Hy, wL ª
k
wki,j +p Lki,j

where p is a relaxation parameter that lies in the range 0 < p § 1. The actual value will depend on Re
and has to be determined by numerical experimentation.
Equation (33) represents a fixed point iteration scheme. At the fixed point yp , wp we have

yp = F Iyp , wp M
(34)
wp = G Iyp , wp M
CavityFlow.nb 5

at any grid node as RIyp , wp M = 0, and LIyp , wp M = 0.


All that remains is to determine the values of y and w on the boundary of the cavity.
The BCs for y are
BC1 : yi,1 = 0, i = 1, Nx

BC2 : yNx ,j = 0, j = 1, …, Ny
(35)
BC3 : yi,Ny = 0, i = 1, …, Nx

BC4 : y1,j = 0, j = 1, …, Ny
The boundary conditions for w require additional effort. From Eqn. (22) we have along the left wall of the
cavity Ii = 1, j = 1, 2, …, Ny )
1
w1,j = - Iy2,j - 2 y1,j + y0,j + g2 Iy1,j+1 - 2 y1,j + y1,j-1 MM (36)
h2
This expression involves the fictitious node y0, j . We can eliminate this term using the no-slip boundary
condition on the side wall, viz.,
¶∂y
v=- = 0 at x = 0 (37)
¶∂x
Using central differences we can write this condition as
¶∂y y2,j - y0,j
- =0 ï- =0 (38)
¶∂x 1,j 2h
This formula can be used to eliminate y0, j that appears in Eqn.(33) and noting that
y1, j = y1, j+1 = y1, j-1 = 0 we get
2
BC5 : w1,j = - Iy2,j M, j = 2, …, Ny - 1 (39)
h2
In a similar manner we get the following expression for the stream function on the other walls of the
cavity
yi+1,j - 2 yi,j + yi-1,j yi,j+1 - 2 yi,j + yi,j-1
w Ixi , yj M = - + g2 (40)
h2 h2
2
BC6 : wi,1 = - g2 Hyi,2 L, i = 1, 2, …, Nx
2
h
2
BC7 : wNx ,j = - IyNx -1,j M, j = 2, …, Ny - 1 (41)
h2
2 g2 h
BC8 : wi,Ny = - yi,Ny -1 + , i = 1, 2, …, Nx
h2 g
Note that BC8 is applied on the moving lid, and we get the extra term as the tangential velocity is non-
zero.
An alternative way to specify the vorticity on the bounday is to make use of one-sided finite difference
formulas that do not involve the use of fictitious nodes. See Ref 3 for additional details.
6 CavityFlow.nb

This completes the finite difference formulation.

Mathematica Implementation
We start by defining the mesh size, and grid spacing. Note we have selected the mesh spacing to be
the same in the x and y directions. The parameters Nx & Ny denote the mesh size in the x and y coordi-
nate directions. As our initial guess for w and y we assume that w=0, and y=0 at all the interior nodes of
the cavity. The Reynolds Number for these calculations was set at Re=100. The aspect ratio of the
cavity is 1, which means a = 1, b = 1, and g = 1. Next, we define a residual template for the finite
difference formula defined on the domain defined by Eqn.(28). The Dirichlet boundary conditions for y
and the BCs for w on the walls of the cavity are generated as a list. First, we set the value of maximum
allowable residual value. We use a set of nested For loops to execute the iteration algorithm given by
Eq.(29). At each step of the iteration we determine the maximum value of Lki, j . The iteration is halted
if max Lki, j < e@iD . The calculations can be speeded up by reducing the number of nodes and increas-
ing the maximum allowable residual at a node point. However, by reducing the residual we sacrifice
accuracy. We wrap the For loops with function Timing to document how much time it takes Mathemat-
ica to run through the loops.
Grid Parameters
a = 1; b = 1; Nx = 31; Ny = 31; Re = 100; p = 1.0; g = 1.;
h = a ê HNx - 1L êê N;
InitialvorticityDist = Table@w@i, jD = 0, 8i, 2, Nx - 1<, 8j, 2, Ny - 1<D êê Flatten;
InitialSFDist = Table@y@i, jD = 0, 8i, 2, Nx - 1<, 8j, 2, Ny - 1<D êê Flatten;
Finite Difference Equations
R@i_, j_D :=
1
Iy@i + 1, jD + y@i - 1, jD + g2 Hy@i, j - 1D + y@i, j + 1DL + h2 w@i, jDM - y@i, jD
2 I1 + g2 M
1
L@i_, j_D := Iw@i + 1, jD + w@i - 1, jD + g2 Hw@i, j - 1D + w@i, j + 1DLM -
2
2 I1 + g M
Re
g HHy@i, j + 1D - y@i, j - 1DL Hw@i + 1, jD - w@i - 1, jDL -
4
Hy@i + 1, jD - y@i - 1, jDL Hw@i, j + 1D - w@i, j - 1DLL - w@i, jD

Boundary Conditions
SFBC1 = Table@y@i, 1D = 0, 8i, 1, Nx<D;
SFBC2 = Table@y@Nx, jD = 0, 8j, 2, Ny - 1<D;
SFBC3 = Table@y@i, NyD = 0, 8i, 1, Nx<D;
SFBC4 = Table@y@1, jD = 0, 8j, 2, Ny - 1<D;
VortBC1 = TableAw@1, jD = - 2 y@2, jD ë h2 , 8j, 2, Ny - 1<E;
VortBC2 = TableAw@i, 1D = - 2 g2 y@i, 2D ë h2 , 8i, 1, Nx<E;
VortBC3 = TableAw@Nx, jD = - 2 y@Nx - 1, jD ë h2 , 8j, 2, Ny - 1<E;
h
VortBC4 = TableBw@i, NyD = - 2 g2 y@i, Ny - 1D + ì h2 , 8i, 1, Nx<F;
g
CavityFlow.nb 7

Relaxation Algorithm
e@1D = 0.005;
t@1D =
TimingBForBk = 1, Max@Abs@Table@L@i, jD, 8i, 2, Nx - 1<, 8j, 2, Ny - 1<DDD > e@1D, k ++,

ForBi = 2, i < Nx, i ++,

ForBj = 2, j < Ny, j ++,


ynew@i, jD = y@i, jD + p R@i, jD; wnew@i, jD = w@i, jD + p L@i, jD;
y@i, jD = ynew@i, jD; w@i, jD = wnew@i, jD; w@1, jD = - 2 y@2, jD ë h2 ;
w@i, 1D = - 2 g2 y@i, 2D ë h2 ; w@Nx, jD = - 2 y@Nx - 1, jD ë h2 ;
h
w@i, NyD = - 2 g2 y@i, Ny - 1D + ì h2 FFFF ê. 8x_, y_< Ø x
g
13.6839

Stream Function Field Plot


We organize the discrete values of the stream function into an array that we can plot using
ListContourPLot
SFData1 = Transpose@Partition@Flatten@Table@y@i, jD, 8i, 1, Nx<, 8j, 1, Ny<DD, NyDD;

eplt1 = ListContourPlot@SFData1, Contours Ø 8- 0.1, - 0.08, - 0.05, - 0.02, - 0.001<,


ContourShading Ø False, AspectRatio Ø Automatic, ContourStyle Ø Blue,
DataRange Ø 880, 1<, 80, 1<<, FrameLabel Ø 8"x", "y"<,
ImageSize Ø 300, PlotLabel -> "Stream Function Plot"D
Stream Function Plot
1.0

0.8

0.6
y

0.4

0.2

0.0
0.0 0.2 0.4 0.6 0.8 1.0
x

Vorticity Field Plot


VortData1 = Transpose@Partition@Flatten@Table@w@i, jD, 8i, 1, Nx<, 8j, 1, Ny<DD, NyDD;
8 CavityFlow.nb

eplt1 = ListContourPlot@VortData1,
Contours Ø 8- 4, - 2, - 0.5, - 0.1, 0.2, 0.3, 0.5, 1<, ContourShading Ø False,
AspectRatio Ø Automatic, ContourStyle Ø Blue, DataRange Ø 880, 1<, 80, 1<<,
FrameLabel Ø 8"x", "y"<, ImageSize Ø 300, PlotLabel -> "Vorticity Field"D
Vorticity Field
1.0

0.8

0.6
y

0.4

0.2

0.0
0.0 0.2 0.4 0.6 0.8 1.0
x

Reference
The following references were helpful in putting together these notes.
† 1. B. Bradie, A Friendly Introduction to Numerical Analysis, Pearson/Prentice Hall 2006
† 2. O. R. Burggraft, The structure of steady separated flows, J. Fluid Mech. 33, 39 (1966)
† 3. C. Pozrikidis, Introduction to Theoretical and Computational Fluid Dynamics, Oxford University
Press, 1998

You might also like