Chapter 12 Numerical Simulation: The Stream Function - Vorticity Method
Chapter 12 Numerical Simulation: The Stream Function - Vorticity Method
Chapter 12 Numerical Simulation: The Stream Function - Vorticity Method
w = (0, 0, w) = 0, 0,
x y
12-1
2 2
+
= w
x 2 y 2
,
w w
+
=0
x 2 y 2
2
This is a pair of linear, elliptic PDEs. The boundary conditions with specified
velocity are
v normal = specified
v tangential = specified = O(U )
BC =
v n ds
boundary
wBC = v boundary
x
,
Lx
v* =
v
w
, *=
, w* =
U
wo
o
y* =
y
L
, = x
Ly
Ly
o 2 * o 2 *
+ 2
= w *
2
2
2
Lx wo x * Ly wo y *
,
2
2w*
2 w*
+
=0
x *2
y *2
*
*
, vy * = o
vx * = o
U Lx x *
U Ly y *
12-2
o
2 = 1,
Lx wo
U
wo =
Lx
=1
U Lx
, o = Lx U
The PDE and definitions with the * dropped are now as follows.
2
2
2
+
= w
x 2
y 2
2
2w
2 w
+
=0
x 2
y 2
vx =
, vy =
y
x
v y
v
w=
x
x
y
12-3
JMAX
JM1
yj
3
2
1
1
JM1
JMAX
xi
Finite difference grid for discretizing PDE (grid point formulation)
The unit square is now discretized into JMAX by JMAX grid points where
the boundary conditions and dependent variables will be evaluated. The grid
spacing is = 1/( JMAX 1) . The first and last row and column are boundary
values.
The partial derivatives will be approximated by finite differences. For
example, the second derivative of vorticity is discretized by a Taylor's series.
2
2
3
3
4
4
w w w w
wi +1 = wi +
+ 2 + 3 + 4
x i 2 x i 6 x i 24 x x
2
2
3
3
4
4
w w w w
wi 1 = wi
+
+
2
3
4
x i 2 x i 6 x i 24 x x
2 w wi 1 2 wi + wi +1 2 4 w 4 w
2 =
+
24 x 4 x x 4 x
2
x i
w 2 wi + wi +1
= i 1
+O 2
2
( )
The finite difference approximation to the PDE at the interior points results
in the following set of equations.
12-4
i +1, j + i 1, j + 2 i , j +1 + 2 i , j 1 2(1 + 2 ) i , j + 2 wi , j = 0
wi +1, j + wi 1, j + 2 wi , j +1 + 2 wi , j 1
2(1 + 2 ) wi , j = 0
i, j = 2, 3, L JMAX 1
The vorticity at the boundary is discretized and expressed in terms of the
components of velocity at the boundary, the stream function values on the
boundary and a stream function value in the interior grid. (A greater accuracy is
possible by using two interior points.) The stream function at the first interior
point (i=2) from the x boundary is written with a Taylor's series as follows.
2
2
3
+
2 = 1
2 + O( )
x
2
x
1
2
2( 2 1 ) 2
m
+ O ( )
2 =
2
x 1
x 1
=
BC
1
2( 2 1 ) 2 BC
v y + O ( )
2
v y
v
x
y
x
BC
2
v BC
= 2 x
y
x 1
2( 2 1BC )
2 BC
vxBC
m vy
+ O ( )
y
BC
2 2 ( 2 1BC ) 2 vxBC v y
=
+
+ O ( )
2
j = j 1 +
( vx ) j 1 + ( vx ) j /
2
12-5
i , j
ui , j =
wi , j
The pair of equations for each grid point can be represented in the following form
ai , j u i +1, j + bi , j ui 1, j + ci , j ui , j +1 + di , j u i , j 1 + ei , j ui , j = fi , j
i, j = 2, 3, L JMAX 1
Each coefficient is a 22 matrix. For example,
ei , j ,1,1 i , j + ei , j ,1,2 wi , j
ei , j u i , j =
ei , j ,2,1 i , j + ei , j ,2,2 wi , j
The components of the 22 coefficient matrix are the coefficients from the
difference equations. The first row is coefficients for the stream function equation
and the second row is coefficients for the vorticity equation. The first column is
coefficients for the stream function variable and the second column is the
coefficients for the vorticity variable. For example, at interior points not affected
by the boundary conditions,
1
ai , j =
0
1
bi , j =
0
ci , j
0
1
0
1
2 0
=
2
0
2 0
di , j =
2
0
2(1 + 2 )
2
ei , j =
0
2(1 + 2 )
0
fi , j =
0
12-6
The coefficients for the interior grid points adjacent to a boundary are modified as
a result of substitution the boundary value of stream function or the linear
equation for the boundary vorticity into the difference equations. The stream
function equation is coupled to the vorticity with the eij coefficient and the vorticity
equation is coupled to the stream function through the boundary conditions. For
example, at a x = 0 boundary, the coefficients will be modified as follows.
i=2
f (i, j ,1) = f (i, j ,1) b(i, j ,1,1) * 1,BCj
f (i, j , 2) = f (i, j , 2) b(i, j , 2, 2) *(2* 1,BCj / 2 2* vvBC ( j ) /
vxBC
)
y
2,2
w
2,2
u 2,2
3,2
u
3,2
=
w3,2
x=
u JM 1, JM 1
JM 1, JM 1
wJM 1, JM 1
12-7
0
2
4
6
8
10
12
14
16
18
0
10
nz = 83
15
Most of the elements of the coefficient matrix are zero. In fact, the
coefficient matrix is a block pentadiagonal sparse matrix and only the nonzero
coefficients need to be stored and processed for solving the linear system of
equations. The non-zero coefficients of the coefficient matrix are stored with the
row-indexed sparse storage mode and the linear system of equations is solved
by preconditioned biconjugate gradient method (Numerical Recipes, 1992).
The row-indexed sparse matrix mode requires storing the nonzero
coefficients in the array, sa(k), and the column number of the coefficient in the
coefficient matrix in the array, ija(k), where k = 1, 2, . The indices that are
needed to identify the coefficients are the i,j grid location (i,j = 2, 3, , JMAX-1),
the m equation and dependent variable identifier (m = 1 for stream function; = 2
for vorticity), and the IA row index of the coefficient matrix (IA = 1, 2, 3, 4, ,
2(JMAX-2)2). The coefficient matrix has two equations for each grid point, the
first for the stream function and the second for vorticity. The total number of
equations is NN = 2(JMAX-2)2.
The diagonal elements of the coefficient array are first stored in the sa(k)
array. The first element of ija(k), ija(1) = NN+2 and can be used to determine the
size of the coefficient matrix. The algorithm then cycles over the pairs of rows in
the coefficient matrix while keeping track of the i,j locations of the grid point and
cycling over equation m = 1 and 2. The off-diagonal coefficients are stored in
sa(k) and the column number in the coefficient matrix stored in ija(k). As each
row is completed, the k index for the next row is stored in the first NN elements of
ija.
A test problem for this code is a square box that has one side sliding as to
impart a unit tangential component of velocity along this side. All other walls are
12-8
stationary. The stream function, vorticity, and velocity contours for this problem
with a 2020 grid is illustrated below.
s.dat
20
18
16
14
12
10
8
6
4
2
2
10
12
14
16
18
20
w.dat
20
18
16
14
12
10
8
6
4
2
2
10
12
14
16
18
12-9
Vorticity contours for square
with top side sliding
20
Velocity Arrays
25
20
15
10
10
15
20
25
12-10
FORTRAN on Owlnet
Modern FORTRAN compilers in the MSWindows are very user friendly.
They have built in project workspace routines, documentation, and integrated
editor and debugger. If you use the FORTRAN compiler on Owlnet, it is useful to
know how to use make files to compile and link FORTRAN code. The following
is an example make file. You may give it the name, makefile, with no extension.
f77 -c streamf1.f;
f77 -c bc1.f;
f77 -c coef1.f;
f77 -c asolve.f;
f77 -c atimes.f;
f77 -c dsprsax.f;
f77 -c dsprstx.f;
f77 -c linbcg.f;
f77 -c snrm.f;
f77 -o exe streamf1.o bc1.o coef1.o asolve.o atimes.o
dsprsax.o dsprstx.o linbcg.o snrm.o
You have to give yourself permission to execute the make file with the one-time
command,
chmod +x makefile
The line with the c option compiles the source code and makes an object code
file with the extension of .o. The line with the o option links the object files into
the executable file called exe. This executable file can be executed by typing its
name, exe, on the command line.
12-11
This example makefile is not very efficient because it will compile every
source code listed. There are instructions to recompile only the source code that
has been modified or "touched" since the last time the makefile was invoked.
However, I do not recall the instructions.
If you are not familiar with FORTRAN, you should get a paperback book
on FORTRAN-77 or FORTRAN-90. An example is D. M. Etter, Structured
FORTRAN 77 for Engineers and Scientists. The following is a tutorial from the
CAAM 211 webpage.
http://www.caam.rice.edu/~caam211/JZoss/project1.html
Computer facilities that have compilers usually have an interactive
debugger. However, I have not found how to access the debugger on owlnet.
The debugger with the Microsoft FORTRAN Powerstation (now Compaq
FORTRAN) is very easy to use.
12-12
t
x
y x 2 y 2
dt
t
t* =
to
2
U to * w * to 2 w *
w * U to * w *
2 w*
+
+
= 2
+
vx
vy
2
t * Lx x *
y *2
Lx y * Lx x *
Two of the dimensionless groups can be set to unity by expressing the reference
time in terms of the ratio of the characteristic velocity and characteristic length.
The remaining dimensionless group is the Reynolds number.
U to
Lx
= 1 to =
U
Lx
to 1
2=
=
Lx U Lx Re
12-13
(v w )
i
j ,i
= vi ,i w j + vi w j ,i
but
vi ,i = 0, for incompressible flow
thus
vi w j ,i = ( vi w j )
,i
or
v w = v w
2
v y w 2 w
w v w
2 w
Re + x +
=
+
x
y x 2
y 2
t
We will first illustrate how to compute the transient, linear problem before
tackling the nonlinear terms. Stability of the transient finite difference equations
is greatly improved if the spatial differences are evaluated at the new, n+1, time
level while the time derivative is evaluated with a backward-difference method.
n +1
n
wi , j
w wi , j wi , j
+ O(t ) =
+ O(t )
t
t
t
wi , j = win, +j 1 win, j
Recall that the finite difference form of the steady state equations were
expressed as a system of equations with coefficients, a, b, , ect. The vorticity
equation for the i,j grid point will be rewritten but now with the transient term
included. It is convenient to solve for w rather than wn+1 at each time step.
2 Re n +1
wi , j
t
2 Re
t
f ' = f a win+1, j b win1, j c win, j +1 d win, j 1 e win, j
e' = e
Since the variable in the linear system of equations is now w rather than w, the
equations for the stream function also need to be modified.
12-14
tnew = told
wspec
wmax
The initial time step size needs to be specified, and the new time step may be
averaged with the old or constrained to increase by not greater than some factor.
Now that we have a means of calculating the transients solution, this
approach can be used to treat the nonlinear terms. Recall that when the
equations were linear, the system of equations had constant coefficients and the
conjugate-gradient linear solver solved the linear system of equations.
Ax = F
The convective derivatives have a product of velocity and vorticity, which can be
expressed as a product of the derivative of stream function and vorticity. One
approximation would be to use the value of the stream function from the old time
step to calculate the coefficients for the new time step. An alternative is use a
predictor-corrector approach, similar to the Runge-Kutta solution for quasilinear
ordinary differential equations. The "predictor" step estimates the solution at the
new time step using the coefficients calculated from the stream function of the
previous time step. This gives an estimate of the stream function at the new time
step. This estimated stream function is then used to evaluate the coefficients for
the "corrector" step. The steps in the calculations are as follows.
A(x n ) x n+1* = F
A(x n +1* ) x n +1 = F
12-15
The choice of the finite difference expression for the convective derivative
is very important for the stability of the solution. We will illustrate here treatment
of only the x derivative. Suppose i-1, i, and i+1 are the grid points where the
stream function and vorticity are evaluated and i and i+ are the mid-points
where the velocity-vorticity products are evaluated.
u w ( u w )i +1/ 2 ( u w )i 1/ 2
x
x
The dependent variables are known only at the grid points and interpolation will
be needed to evaluate in between location. If the product is evaluated at i
and i+ by using the arithmetic average of the values at the grid points on
either side, the numerical solution will tend to oscillate if the convective transport
dominates the diffusive (viscous) transport. It is preferable to determine the
upstream direction from the sign of ui+1/2 or ui-1/2 and use the vorticity from the
upstream grid point. This is illustrated below.
ui-1/2 = 0.5*(u(i,j)+u(i-1,j))
if ui-1/2 >0 then
(uw)i-1/2 = ui-1/2 wi-1 ;
else
(uw)i-1/2 = ui-1/2 wi ;
endif
ui+1/2 = 0.5*(u(i,j)+u(i+1,j))
if uI+1/2 >0 then
(uw)i+1/2 = ui+1/2 wi ;
else
(uw)i+1/2 = ui+1/2 wi+1 ;
endif
b'=b+ Re ui-1/2
e'=e+ Re ui-1/2
e'=e - Re ui+1/2
a'=a - Re ui+1/2
The y-direction will be similar except the aspect ratio, , must be included.
These modifications to the coefficients must be made before the coefficients are
updated for the boundary conditions.
Calculation of Pressure
The vorticity-stream function method does not require calculation of
pressure to determine the flow field. However, if the force or drag on a body or a
conduit is of interest, the pressure must be computed to determine the stress
field. Here we will derive the Poisson equation for pressure and determine the
boundary conditions using the equations of motion. If the pressure is desired
only at the boundary, it may be possible to integrate the pressure gradient
determined from the equations of motion. The dimensionless equations of
motion for incompressible flow of a Newtonian fluid are as follows.
12-16
dv * v *
v *
=
+ v * * v* =
+ * ( v * v*) =
dt * t *
t *
1
* P * +
*2 v *
Re
where
v* =
U
P
v
x
, x* = , t* = t , P* =
, * = L
U
L
L
U 2
P = p g z , Re =
U L
Here all coordinates were scaled with respect to the same length scale. The
aspect ratio must be included in the final equation if the coordinates are scaled
with respect to different length scales. We will drop the * and use x and y for the
coordinates and u and v as the components of velocity.
The following derivation follows that of Hoffmann and Chiang (1993). The
equations of motion in 2-D in conservative form is as follows.
u (u 2 ) (u v)
P 1 2u 2u
+
+
=
+
+
t
x
y
x Re x 2 y 2
v (u v) (v 2 )
P 1 2v 2v
+
+
=
+
+
t
x
y
y Re x 2 y 2
u
u u
2u u v
2v v u
2u
2 P 1
+
2
+
2
u
+
+
u
+
+
v
=
+
2u
2
2
t x
x x
x
x y
xy x y
xy
x
Re x
Two pair of terms cancels because of the equation of continuity for
incompressible flow.
u u v
+ =0
x x y
2v
2u
u v
u
+u 2 = u + = 0
xy
x
x x y
Thus
u u
2u v u
2u
2 P 1
u
v
+
+
+
+
=
+
( 2u )
t x x
x 2 x y
xy
x 2 Re x
2
12-17
v v
2 v u v
2v
2 P 1
+
+
v
+
+
u
=
+
2v )
(
2
2
Re y
t y y
y
y x
xy
y
The x and y-components of the above equations are now added together and
several pairs of terms cancels pair-wise.
u v
+ =0
t x y
2u 2 v
u v
+
= + =0
2
x
xy x x y
2u 2v u v
+
= + =0
xy y 2 y x y
2u 2u 2 v 2 v 2 u v 2 u v
+
+
+
=
+ +
+ =0
x x 2 y 2 y x 2 y 2 x 2 x y y 2 x y
Therefore the equations reduce to
2
2 P 2 P
u v
u v
+
+
=
2
2 + 2
y x
y
x y
x
2
u v u v
u v
=0
+ = + +2
x y
x y x y
from which
2
u v
u v
+ = 2
x y
x y
2
2 P 2 P
u v u v
2 + 2 = 2
x
x y
12-18
2 2 2 2
2 P 2 P
+
= 2 2
2
x 2 y 2
x y
xy
This is the equation when the coordinates have the same reference length. If the
coordinates are normalized with respect to different lengths, then the equation is
as follows.
2
2
2
2
2
2 P
2 P
2
+
= 2 2
2
x 2
y 2
x y
xy
The Poisson equation for pressure needs to have boundary conditions for
solution. The equations of motion give an expression for the pressure gradient.
The normal derivative of pressure at the boundary can be determined for the
Neumann-type boundary condition. The equations of motion usually simplify at
boundaries if the boundary has no slip BC or if it has parallel flow in the direction
either parallel or normal to the boundary. For example, for no-slip
P 2 2 v
=
, at y = c, u = v = 0
x Re y 2
P 1 2u
=
, at x = c, u = v = 0
y Re x 2
If the flow is parallel and in the direction normal to the boundary
P 2 2u
=
,
x Re y 2
y = c, v = 0, u = u ( y )
P 1 2 v
=
, x = c, u = 0, v = v( x)
y Re x 2
Cylindrical-Polar Coordinates
The code for the numerical solution of the Navier-Stokes equations in
Cartesian coordinates can be easily modified to cylindrical-polar coordinates.
The coordinate transformation is first illustrated for the Laplacian operator.
1
=
r
r r r
2
2
1
+ r 2 2 ,
r1 r r2 ,
0 o
The independent variables are made dimensionless with respect to the boundary
parameters.
12-19
r* =
, * = ,
r1
o
1 r*
r2
= , 0 * 1
r1
The Lapacian operator with the dimensionless coordinates after dropping the * is
now,
2 =
1 1
r
r12 r r r
2
1 1
,
+
2
2
2
o r
1 r ,
0 1
ln r
= ln r ,
ln
0 z 1, =
r = exp ( z / )
dz
=
r dr z
1
r
r r r
1
ln ( r2 / r1 )
r z
2
2
=
2
2
r z
=
1
= 2
r1
2
2 2 2 2
1
+ 2
, 0 z 1, 0 1, =
2
2
2
r
o
r z
The finite difference expression for the Laplacian will be same as that for
Cartesian coordinates with ( z , ) substituted for (x,y) except for 2 and r2 factors.
0 zi 1, 0 j 1, i, j = 1, 2,K , JMAX
1
JMAX 1
zi = ( i 1) , j = ( j 1)
12-20
=
v =
r
r z
1 ( r v ) vr
w=
r r
r
( r v ) vr
= 2
z
r
r
2
2
2 2
= 2
r z 2 r 2 2
vr =
w1BC =
2 2
2 BC vrBC
BC
m
(
)
2
1
r2 2
r
r
BC
2 2
2 BC ( rv )
BC
= 2 2 ( 2 1 )
vr + 2
r
r
r
z
The stream function at the boundaries are expressed different from that in
Cartesian coordinates.
d = ( r vr / ) d , at z boundary
d = ( r v / ) dz , at boundary
12-21
(u w)
x
( v w)
y
1 ( r u w)
r
r
( r u w)
= 2
r
z
2 ( r u w )i +1/ 2 ( r u w )i 1/ 2
r
( v w)
r
( v w ) j +1/ 2 ( v w ) j 1/ 2
r
The code should be written so one can have either Cartesian coordinates
or transformed cylindrical-polar coordinates. A parameter will be needed to
identify the choice of coordinates, e.g. icase=1 for Cartesian coordinates and
icase=2 for transformed cylindrical-polar coordinates. Also, another parameter
should be specified to identify the choice of boundary conditions, e.g., ibc=1 for
radial flow, ibc=2 for Couette flow, and ibc=3 for flow around a cylinder.
Test cases with known solutions should be used to verify the code. The
first case is radial, potential flow from a line source and the second is Couette
flow in the annular region between two cylindrical surfaces.
vr = 1/ r
radial flow
v = 0
vr = 0
Couette flow
v = ( r 1/ r ) / ( 1/ )
Flow around a cylinder needs a boundary condition for the flow far away
from the cylinder. The flow very far away may be uniform translation. However,
this condition may be so far away that it may result in loss of resolution near the
cylinder. Another boundary condition that may be specified beyond the region of
influence of the boundary layer is to use the potential flow past a cylinder. This
boundary condition will not be correct in the wake of cylinder where the flow is
disturbed by the convected boundary layer buts its influence may be minimized if
the outer boundary is far enough.
vr = (1 1/ r 2 ) cos
Potential flow past cylinder
v = (1 + 1/ r 2 ) sin
Potential flow will not be a valid approximation along the boundaries close to
the cylinder. Here, one may assume a surface of symmetry, at least for the
upstream side.
12-22