You are on page 1of 27

Computers & GeosciencesVol. 20, No. 3, pp.

265-291, 1994

Pergamo.

0098-3004(93)E0011-4

Copyright 1994 Elsevier Science Ltd


Printed in Great Britain. All rights reserved
0098-3004/94 $7.00 + 0.00

F D F L O W : A F O R T R A N - 7 7 SOLVER F O R 2-D
INCOMPRESSIBLE FLUID FLOW
C. M . LEMOS
Department of Coastal and Estuarine Dynamics, Instituto Hidrografico, R. das Trinas 49,
1296 Lisbon-Codex, Portugal

(Received 13 April 1993; accepted 25 October 1993)


A b s t r a c t - - l n this work, a F O R T R A N - 7 7 program for solving two-dimensional (2-D) incompressible flows
is presented. The algorithm is based on finite difference approximations of the m o m e n t u m and continuity
equations, and consists of two stages. In the first stage, a temporary field is obtained using conservative
approximations of the m o m e n t u m equations, either implicit or explicit, with the old pressure gradient.
In the second stage, the advanced-time velocity and pressure are obtained using an iterative method,
in such a way that the incompressibility constraint is satisfied. The program was written in a modular
form, and can be used to obtain accurate solutions to some difficult fluid-flow problems with small PCs.
This capability was tested by its application to lid-dtiven cavity flow and flow past a backward-facing step,
with Reynolds number up to 10,000.
The model described herein might be useful for both educational and professional purposes. Because
of its simple design, the program can be taken as a starting point to test other numerical schemes, or to
treat more advanced problems than those considered in this work, such as thermally coupled flow,
free-surface flow, and 3-D flow.

Key Words: Navier-Stokes equations, Finite differences, Computer program, Personal computers.

NOMENCLATURE

FN = subset of c~fZon which Neumann-type conditions are imposed


At = time step
Ax = mesh spacing in the x-direction
Ay = mesh spacing in the y-direction
v = kinematic viscosity
fZ = domain for the fluid-flow problem
= closure of f~
~f~ = boundary of fL = FD + FN

Dij = discrete divergence in cell i,j


f = (fx, f~.) = vector of the external force field
i = index for computational cells in the xdirection
/_ = identity operator
I = number of interior cells in the x-direction
I M A X = total number of cells in the x-direction
j = index for computational cells in the ydirection
= number of interior cells in the y-direction
J M A X = total number of cells in the y-direction
L~ = first difference in the x-direction
Lx., = second difference in the x-direction
L r = first difference in the y-direction
L~.r = second difference in the y-direction
n = index for time level
n = (ny, n,) = outward unit normal vector
p = kinematic pressure (pressure divided by constant density)
Q~ = generic difference scheme for the convectiondiffusion part of the m o m e n t u m equations,
involving y-derivatives only
Q = genetic difference scheme for the convectiondiffusion part of the m o m e n t u m equations
t = time
u = (u, v) = velocity vector
u b = (u b, vb) = boundary velocity
u0 = (u0, v0) = initial velocity
u* = (u*, v*) = temporary velocity, such that ~ x u* =

INTRODUCTION
I n this w o r k , a F O R T R A N - 7 7 p r o g r a m is p r e s e n t e d
a n d d o c u m e n t e d t h a t i m p l e m e n t s a finite difference
s o l u t i o n a l g o r i t h m for t h e i n c o m p r e s s i b l e N a v i e r S t o k e s e q u a t i o n s in t w o d i m e n s i o n s . T h i s p r o g r a m
w a s d e v e l o p e d p r i m a r i l y as a n e d u c a t i o n a l tool f o r
t e a c h i n g c o m p u t a t i o n a l fluid d y n a m i c s o n s m a l l P C s .
T h e s o l u t i o n a l g o r i t h m c o n s i s t s o f t w o stages. In t h e
first stage, a t e m p o r a r y velocity field u* is c a l c u l a t e d
from the momentum equation, with the pressure
g r a d i e n t e v a l u a t e d at t h e old t i m e level (nAt). T w o
finite difference s c h e m e s were i m p l e m e n t e d for t h e
c o m p u t a t i o n o f this t e m p o r a r y s o l u t i o n , o n e explicit
a n d a n o t h e r implicit ( f r a c t i o n a l - s t e p ) , w h i c h a r e b o t h
c o n s e r v a t i v e . In t h e s e c o n d stage, t h e a d v a n c e d - t i m e
velocity u ' + l a n d p r e s s u r e p ' + l a r e c a l c u l a t e d f r o m
t h e t e m p o r a r y s o l u t i o n u* u s i n g a p r e s s u r e - v e l o c i t y
i t e r a t i o n s c h e m e , so t h a t u" +1 satisfies t h e c o n t i n u i t y
equation.

Vxu,~-u*~O
velocity, used in the implicit
momentum
calculations
x = (x, y) = position vector
F o = subset of c~fZ on which Ditichlet-type conditions are imposed

fi=(:4, f) = auxiliary

265

266

C.M. LEMOS

After the introduction of the governing equations,


the essential aspects of incompressible fluid dynamics
are reviewed in the second section of this paper.
The basic solution algorithm is presented in the
third section, which describes the explicit and
implicit methods for the finite difference representation of the momentum equations, and the pressure-velocity iteration method for satisfying the
continuity equation. The fourth and fifth sections are
concerned with the discretized initial and boundary
conditions and the stability constraints for the explicit finite difference approximations, respectively.
Finally, the computer program and some sample
calculations of lid-driven cavity flow, and flow past a
backward-facing step are described. Appendices 1-4
contain listings of the programs referred to in the
text.

GOVERNING EQUATIONS
The 2-D motion of an incompressible fluid
of uniform properties in a domain ~ with
smooth boundary ~3fL can be stated as an initialboundary value problem as follows: determine
u = ( u ( x , t ) , v ( x , t ) ) and p ( x , t ) V x = ( x , y ) =
f~ + c ~ for t > 0, such that
Ou
--

c2t

+ Vp + V . (uu - v V u ) = f,

v . u = 0,

(I)

(2)

where t is the time, u is the velocity, p is the


pressure divided by the constant density (or energy
per unit mass resulting from the pressure field),
v is the kinematic viscosity, and f = ( f , , f y ) is the
vector of the external force field, V is the nabla
operator, and denotes the tensor product. The
momentum Equation (1) is written in the conservative or divergence form, which is appropriate for
the derivation of numerical schemes that ensure
conservation of the physical quantities in a discrete
sense (Roache, 1972).
To define a well-posed problem, the governing
equations must be supplemented by appropriate
initial and boundary conditions. The boundary
conditions may be of Dirichlet or Neumann type,
that is
u = ub(x,t)

Vx FD,

(3)

- ? + v ~-~" = F . ( x , t )
and

~/gr

V7 n = F A x : )

Vx FN,

(4)

where a f l = F o + F N ,
and n and z denote the
normal and tangential directions. These conditions

correspond to either velocity or stress specified


on the boundary, respectively. If df~ = FD(Fs = g ) ,
then ub must be compatible with Equation (2),
that is

ub'ndS=O,t>:O.

(5)

n
Also, if FN = ff there are no boundary conditions for
the pressure. The initial condition u0(x ) = u(x,0) must
satisfy the incompressibility constraint
V ' u0 = 0,

(6)

and its normal component must be continuous at the


boundary for t = 0,
n.u0(x)=n.ub

VXFD.

(7)

The tangential component of the velocity may not be


continuous at the boundary, and in general vortex
sheets may be present on F D for t = 0.
The main difficulty associated with the solution
of Equations (1)-(2) is the absence of an evolution
equation for p. The pressure gradient is a conservative field which keeps the flow always and
everywhere nondivergent, that is maintains conservation of mass. Thus, if the momentum equation
without the pressure gradient was advanced in time
using a consistent scheme ~ for the convectiondiffusion part, the (auxiliary) advanced-time field
u* =[1 + A t ~ ] ( u " ) would contain the correct
vorticity, but V. u* #-0. Subtracting the correct
pressure gradient then projects u* onto its divfree part (Chorin, 1968). Writing (u" * ~ - u*)/At =
--Vp "+L, applying the divergence operator, and
making use of the condition V u" + ~= 0, it is seen
that the pressure may be determined (up to an
arbitrary constant) by solving the following PoissonNeumann problem (Chorin, 1968; Peyret and Taylor,
1983):
Wp ~+ ~= ~-~ V" u*,

@"+'
- -

On

'

(u " ~

= -n.

(8a)

-u*)

At

(8b)

After Vp "+1 is determined, u * - A t V p "+1 will


have the correct vorticity and divergence, and hence
be determined uniquely by virtue of Helmholtz's
decomposition theorem (e.g. Chorin and Marsden,
1979; Gustafson, 1987). Likewise, if the auxiliary
velocity field was calculated using the old pressure
gradient Vp ~, the pressure correction 6p = p "+ ~- p"
would be obtained as the solution of the same
Poisson-Neumann problem with p n + ~ replaced by
6p, and u"+ ~= u* - A t V ( 6 p ) . This strategy for splitting the velocity and pressure calculations is typical
of many algorithms (e.g. Chorin, 1968; Peyret and
Taylor, 1983) for incompressible fluid dynamics,
including the one presented in this work. A recent

267

FORTRAN solver for 2-D incompressible fluid flow


survey of the theory of splitting (projection) methods
is given in Quartapelle (1992).

- -THE BASIC

4Ay

ALGORITHM

The governing equations were discretized by


a staggered mesh consisting of I J interior
rectangular cells of uniform width Ax and height
Ay (see Fig. 1). The fluid region is surrounded by
a layer of fictitious (exterior) cells, which are used
to impose boundary conditions. The fluid velocities
and pressure are defined at the cell positions
shown in Figure 2 (left). This staggered grid
arrangement [known as the MAC mesh, after its
introduction by Hariow and Welch (1965) in conjunction with the Marker-And-Cell method] ensures a
tight coupling between the u, v, and p solutions
at adjacent grid points, avoiding even-odd decoupling in the pressure solution. In computer codes
fractional indices cannot be used. The correspondence between u;+j,,2o, Ui-l/2,j, Ui,j+ I/2, Ui,j-1/2, and
the indices used in the code, is shown in Figure 2. For
the sake of clarity, all difference equations will be
written as they occur in the F O R T R A N program.
The solution algorithm consists of two stages.
In the first stage, a temporary velocity field (u*,v*)
is computed using finite difference approximations
of the momentum equation with the pressure gradient
evaluated at the old time level. Two different schemes
were implemented, one explicit and another implicit.
In the second stage, the continuity equation is
satisfied using an implicit pressure-velocity relaxation scheme (Chorin, 1968; Viecelli, 1971; Bulgarelli,
Casulli, and Greenspan, 1984) which is equivalent
to the solution of Equations (8a)-(8b), followed by
u"+ J = u* - AtVp "+~.
When the explicit method is used, the temporary
field u * = (u*,v*) is computed using the ForwardTime-Centered-Space (FTCS) scheme:

-- - -

4Ax

Pi,j+l --Pi, j

v * = vT,j + At

kx

[(v ,"j+, + v")2 _ (v 7. + v ~,

[(U inj+ 1 + U inj ) (U 7+ I,y

,)21

-~- U in/)

- ( u 7 ,.j+~+u7 ~.j)(v,"/+vL,.,)]
+v

vT+ l , j - 2v~: + vT,_ 1,/


AX 2
/) n

+v

--

un

22vi4+ , o - l + f , ~ .
Ax

i,j+l

(10)

The explicit FTCS approximation of the momentum


equations can be made more accurate and stable by
introducing upstream curvature correction terms in
the interpolations for the convective fluxes (e.g. the
QUICK scheme of Leonard, 1979), with moderate
additional programming and computational effort.
However, Leonard's scheme also is explicit, and thus
subject to stability constraints.
When the implicit method is selected, the temporary velocity field (u*,v*) is calculated using the
following fractional-step method:
1

At(tJ - u " ) =

--Lx(t?t2)+vL~x(lJ),

(11)

At (3 - v") = - Lx([th3]) + vL~,(t3),

(12)

At (u* - ~) = -Ly([UV]*) + vL,.~.(u*)


--Lx( p n ) + f y n +

12

(13)

At (v* - g) = - Ly([v 2],) + vL,.,. (v *)


* __

,,

ui/-ui'i+At
1

- - - -

PT+l,j--pinj

[ ( U n+ I

4Ax

- Ly(p" ) + J ,.. +12

Ax

where (fi,f) is a new auxiliary velocity, and the


operators L~, L,., L,~ and L,, are defined as
follows:

j -~- u in,j )2 -- (U ~j dr- u ni l,j ]~2]]

&(4,) = Ax (~'+ ,.2.; - , ~_~.,),

4Ay [(u ,"j+, + u 7,/) (v 7+ ~./+ v 7,)


--(ldin, j'~-uin, j

+v

+v

l)(Idn+l,j-I-~tdT`j

u n + I , j - - 2U~,j "~-un

L,,(4) = ~

I)1

l,j

(O,,, ~, ~ - 4 , , ,

,:),

Ax 2
,,j + u"
,,j- I L}
uT./+,- 2u~'
Ax 2
t-

(14)

L~(~a)= ~x2(~gi+ l,.;-- 249,,i + 49i ,./),


1

(9)

L,,.(c~)=~y2(~bij+l- 2C~,.i+qS,. l),

268

C. M. LEMOS
dNI~X

II'I/~X

~+1

Figure 1. Finite difference mesh.

in which qb is a generic variable The new auxiliary


velocities ~ and t3 do not require extra storage
space.
To obtain an efficient solution method, the following linearizations are introduced:
[~]2 = [u ,,]2+

[a~]

2u "(t~ -- u ") + ~(At ~),

[uv]" + u (c) - v ") + (~.t :),

Substituting these expressions into Equations


(11)-(14), four implicit linear equations for fi, ~, u*,
and v* are obtained. These linear equations then are
solved in two half-steps, taken in alternating directions. In the first half-step, fi and t~ are obtained from
the finite difference equations:

fi~4+ AtL*([2u "f]i.J) - v AtLxx(f~4)

[uv]* = [fig] + f (u* -- fi) + d)(At 2),


[v ~]* = [t)]2 +

2~ (v* - ~ ) + C(At 2).

=u~y + AtLx(Iu2]~y),

(15)

vi,j + AtLx([u "v]~4) - v ~tL~d6,


. . .j) .= v "j..

(16)

These equations define tridiagonal systems of the


form

Vi,j
l

I dbi a j
b3
d2

Pi,j

Ilu ,j

Ut.l,dl m

Oi,&l
q i, j+l/2
l
1l

Pi,j
I

" .

, 07)

in which b~, dl, ai are the coefficients behind, on,


and ahead of the main diagonal; qS~are the unknowns;
and RHS~ are the coefficients on the right-hand
side.
For Equation (15) we have

0
d3

a2

~bi= fi,,i,

(18a)

At
bi = - ut ~ - s,,

(18b)

Al

4 = 1 + % - u~) ~ x + 2s~

I~lUi+1/2,d

Al

a, = ur ~
1

qi,&lt2
Figure 2. Location of variables in typical mesh cell:
fractional indices (left), and integer indices used in code
(right).

- s~,

At

RHSi=u,,.,+--(Ur-U?),Ax

(18c)

(18d)

(18e)

"
+ u "i.j,,
~
"
"
ur= 1/2(Ui+l,j
u)= 1/2(uij+ui_l,j),
s~ = vAt/Ax 2, for I = I . . . . . IMAX-1.
with

269

FORTRAN solver for 2-D incompressible fluid flow


For Equation (16), we have
~ i = Ui,j ,

(19a)

At
b, = - ~ ul ~ - s~,

(19b)

1
At
d , = 1 + ~ ( U r - - Ut)~X +2S~,

(19c)

ai

p~!
n !"!
I,J --, 1"
10 ~- - Ape,j,
!.! - - *

u ,o

~.)

At

u ~,j + ~

Ap~o,

(24a)
(24b)

u!n)l,j_.,u!,)
___At APio,
- '' - ~'J A x

(24c)

1 At
= ~ u, -~x - sx,

(19d)

!n! -4- A t
V !"!
Api.j,
t,J ~ V 1,) - -

(24d)

RHSi = v ~j,

(19e)

v~")
A t api, j,
" J - ' ---* v !"!
" ' - ' - X-}y

(24e)

in which u~ and ul are now u~= l/2(uT, j + l + U i ~ j ) ,


uj= 1/2(uT_l,j+t +uT_l,:), for I = 1. . . . . IMAX-I.
The tridiagonal systems defined by Equations (18)
and (19) are solved using the Thomas algorithm
[see Roache (1972) or Peyret and Taylor (1983) for a
detailed description], sweeping in the x-direction for
successive values of J, with J = 2 . . . . , JMAX-I.
In the second half-step, u* and v* are obtained
from the finite difference approximations
U *j + A t Z y ( [ V u * ] i , j )

The pressures and the four velocities at the faces


of the cell I,J then are adjusted to reflect this change:

--

vAtLyy(U *j)

= a~o - A t L x ( p 7o) + f ~ + l/2At,

(20)

v *j + AtL,.([2fv*kj) - vAtLyy(V ,.*)


= g,j + A/Ly([~]~j) - AtLy(p,~,j) + f y ~/2At.

(21)

These equations lead to tridiagonal systems for


u* and v*, which may be solved using the Thomas
algorithm, sweeping in the y-direction for successive
values of I, with I = 2 , . . . , IMAX-1. The boundary
values for u*, v*, ~, and :3 at the mesh boundaries are
incorporated in the tridiagonal systems, by overwriting the coefficients b,, d~, a~, and RHS~, as will
be shown later.
The temporary field (u*,v*) obtained in the first
stage, in general, will not satisfy the continuity
equation, because the correct advanced-time pressure
gradient is not known yet. To satisfy the continuity
equation, pressures and velocities are adjusted iteratively for each computational cell, in such a way
that the discrete divergence left by the first stage is
annihilated. The finite difference approximation of
the continuity equation is
1
D'/(u"+') - Axx (" ~''+~ - u ~'_+:j)

1 (vn+l
n+l
+A-YY" ' j - v / . j _ , ) = 0 .

(22)

The iterative solution of Equation (22) is done as


follows. Let I") and ~n+J~ denote iteration levels. The
pressure change required to drive the discrete divergence in cell I,J to zero is

Di'j(ll(n))
Ap,,j= 2At(i/Ax2 + i/ky2).

(23)

The iteration defined by Equations (23) and (24) is


performed until the maximum residual divergence
in the mesh falls below a certain tolerance parameter
E, whose typical value is of d9(10-3). If E is too
small, a large number of iterations must be performed
for each time step, decreasing the computational
efficiency. If E is too large, the flow becomes
"numerically compressible", and the residual divergences may introduce instabilities in the momentum
equations. To accelerate the convergence of the
iterative procedure, the pressure correction usually is
multiplied by an over-relaxation factor co with
values between 1 and 2. A value of co = 1.7 may be
optimum.
INITIAL AND BOUNDARY CONDITIONS
The initial condition for the velocity must satisfy
Equations (6) and (7) in a discrete sense. This may be
a difficult task for Equation (6) when a nontrivial
starting condition is imposed, and there are internal
obstacles. Nevertheless, if Equations (5) and (7) are
satisfied, it is possible to project (Uo,Vo) onto its
d i v - f r e e part, and hence obtain a valid initial condition. Another possibility is the combination of a
cold-start with the boundary condition Ub = (0,0) for
t = 0, followed by a gradual change of the velocity on
the boundary to the desired value.
The boundary conditions are imposed in the
first stage of the calculation and during the
pressure-velocity iteration, using the fictitious cells
surrounding the mesh. The way the boundary conditions are treated depends on whether the velocity is
calculated explicitly or implicitly. This process now
will be illustrated for the left boundary (see Fig. 3),
and for both types of velocity calculation.
If the velocity is calculated explicitly, as occurs for
Equations (9), (10), and (24), and the boundary
condition to be imposed is of the form ub = (ub,vb) on
c3f~, the velocities in the fictitious cell 1,J are set as
follows:
Ul, j ~----U b ,

Vl,j = 2vb - v2.j.

For the particular situation of a no-slip wall, these


conditions become uLj= 0 and v L j = - v = j . If the

270

C. M. LEMOS

U1"i1

I U2'j+l

These boundary values for the auxiliary fields f


and ~ can be included in the tridiagonal systems (l 8)
and (19) if
d I =

1, a I = 0, RHSj = (Ub)7+ C2

for Equation (18) and

dl = , al -- , RHS1 = (t'b)~'+ 12

Ul'j

I u2'j

-- fl,j

Figure 3. Schematization of boundary conditions for left


boundary.
boundary is to be a rigid free-slip wall, the normal
velocity and the gradient of the tangential velocity
should be zero. In this situation, the appropriate
boundary conditions are
Ul, j =

Free-slip conditions may be used to simulate inviscidfluid behavior when the discrete mesh is too coarse to
capture the details of the boundary layer.
When implicit methods are used, it is necessary
to prescribe boundary values for the temporary fields.
If the time-accuracy of the interior scheme is to be
preserved, these boundary values must be prescribed
in such a way that the implicit operators can be
inverted. Therefore, the boundary conditions for
(f,f) and (u*,v*) are
g + l + AtLx (p n + i )
_ A t f ~ + 112 +

Vb = ( I - - A t Q y ) v

-{- UZ,j = A x (gb)7 + I/2

which fits into the tridiagonal scheme if dl = - 1 ,


a l = 1, and R H S a = A x ( g b ) y
+1/2. In the computer
code, the coefficients for the tridiagonal equations
corresponding to the left and right boundaries are
calculated in a separate subroutine. The Thomas
elimination algorithm is performed a f t e r the boundary equations have been formed.
STABILITY CONSIDERATIONS

0,

~l,j ~ U2,j"

tJb = ( I - A t Q y ) u

for Equation (19). If the derivative O u / O x = gb is to


be prescribed at the left boundary, then

(At 2),

~ + 1 + AtL~. ( p "+ 1 )

_ Atf~+ 1/2+ C(At 2),


u * = u ~ +1 + A t L x ( p

" + ~ -- p") +

O(At 2),

v * = v ~,+ ~ + A t L y ( p

"+ ~ - p " )

C(At 2),

where Qy is the approximation for the convection~liffusion part of the momentum equations,
involving only y-derivatives. Because p " + l is not
known during the first stage, the approximation
p " +~ ~-p" may be satisfactory, at the cost of some
loss of formal accuracy. For first-order accuracy,
it is enough to set fib=U~,+l/2, 38=Vg+~/2,
U* = U~+1 , and v* = v[',+1 . In the present work, this
simple but satisfactory solution was adopted. More
complicated boundary conditions can be imposed
using the technique described next, with additional
programming effort. Consider the situation when
the velocity is to be prescribed, in the first half-step.
The discretized boundary conditions take the form
/41,j = (/db)~,+ 1 2

~,,j + ~:,j = (~O7 + '/:

The purpose of stability analyses is to determine


the conditions for which, upon repeated application
of the numerical scheme on the initial conditions, the
error remains bounded once the time step and mesh
spacing have been fixed. In incompressible flow computations, instabilities may be generated either in the
discretized momentum equation or in the pressure
solution. In the algorithm described here, pressurerelated instabilities are not important because there is
no need for (derived) pressure boundary conditions,
and also because the residual divergence is used as
the convergence criterion. The greatest problems
concerning stability are posed by the explicit approximation for the momentum equation. Because this
equation is nonlinear, a complete stability analysis is
not available. Nevertheless, approximate stability
conditions may be obtained by "freezing the nonlinearity". A Fourier-von Neumann analysis of the 2-D
FTCS scheme gives the following constraints for the
maximum permissible time step (e.g. Hirt, Nichols,
and Romero, 1975):
Ax 2Ay 2
At ~<2v (Ax 2 + Ay 2),

(25)

2v
At ~< max{u2 + t~2}'

(26)

At~<min

lul' ]~i"

(27)

Condition (25) is the most restrictive for highly


viscous flows, whereas condition (26) is limiting
for convection-dominated flow. Finally, the third
inequality is the Courant-Friedrichs-Levy (CFL)
condition, which states that material cannot move
more than one cell in one time step.
A Fourier-von Neumann analysis of the linearized
implicit fractional-step scheme described here, with
the pressure gradient and body force terms neglected,

FORTRAN solver for 2-D incompressible fluid flow

271

FDFLO W.INC

shows that it is unconditionally stable (see e.g.


Mitchell and Griffiths, 1980; Smith, 1985). This is a
considerable advantage, especially for the numerical
computation of flows with high Reynolds number.
Nevertheless, nonlinear instabilities may develop
in long-term integrations of high-Re flows or geophysical flows with small dissipation, when the
aliasing phenomenon associated with wavelengths
shorter than twice the mesh spacing can lead to
significant contamination of the long wavelength
solution (e.g. Haltiner and Williams, 1980).

This is an INCLUDE file containing the definitions


for the program constants (parameters) and the
global variables, and a list with a short description of
each variable. The global definitions contained in
FDFLOW.INC are used by both the main solver
(FDFLOW) and the post processor (FPLOT). The
list of global variables is useful as a reference for
preparing the input data for a new problem, and
for reading and modifying the code.
FDFLO W.FOR

PROGRAM DESCRIPTION

In this section, the computer implementation of the


algorithm is described. The graphical representations
of the results generated by the calculations are
produced by a separate post-processing program,
which calls only a few basic graphics primitives.
This simplifies the structure of the main solver and
gives the user a greater flexibility of operation. The
F O R T R A N calls to the graphics primitives are
compatible with the PLOT88 library (Young and
Van Woert, 1990). A F O R T R A N interface also is
provided, which constructs "*.PLT" files in the
format used by the VIEW and PLOT programs of
the G R A P H E R / S U R F E R packages by Golden
Software.
The computer code was written in four separate
files: FDFLO W.INC, FDFLO W.FOR, FPLOT.FOR,
and GRFPRIM.FOR. The source code contained
in these files is listed in Appendices 1-4. A brief
description of the code now will be presented.

This file contains the main program (FDFLOW)


that implements the solution algorithm (see Fig. 4).
The program was written in subroutine form, each
subroutine performing a single task. At the start of
each subprogram unit, there is a short header describing its function. The code contained in this file
consists of the following program units:
FDFLO W (main program)
The main program starts with an initialization
section, and then prints the initial conditions for the
field variables to a disk file. After this initial stage, the
program provides cyclic control over the calculation,
by calling subroutines ADVANCE, STEP1, STEP2,
and PRINTF. The calculation is stopped when the
time-to-finish (TWFIN) has been reached.
ADVANCE
This subroutine stores the advanced-time field
variables into the corresponding old-time arrays,
and increments the calculational time and the cycle
counter.

MAIN CYCLE
SETUP:
Read input data
Compute model constants
Initialize field uariables

PRINTF:

nDVANCE: Advance time


Update field ~ control
variables
t

STEPI: Compute temporary


velocity (u.,u.)

STEP2: Pressure-uelocitg iteration


Compute (u n+l ,u n*l ,pn*l )
v
PRINTF: Print cgcle information

Print initial conditions

Print uariables to disk


n
?

(r >: T FI, ]

Figure 4. Structure chart of FDFLOW program.

272

C.M. LEMOS

BCEXP

This subroutine sets the boundary conditions on


all mesh boundaries when the velocity is evaluated
explicitly, by overwriting the values stored in the
layer of fictitious cells surrounding the mesh. This
subroutine must be called after the calculation of u i,j*
and v *j with Equations (9) and (10), and after each
pressure-velocity iteration. The explicit boundary
conditions must be coded by hand for each specific
problem. They also must be compatible with the
implicit boundary conditions specified in subroutine
BC1MP, if the implicit method is selected for the first
stage. If FN =if, the explicit boundary conditions
must verify Equation (5).
BCIMP

This subroutine sets the boundary conditions


for all mesh boundaries when the velocity is calculated implicitly (METHOD =2), using the technique described in the section concerned with the
boundary conditions. The implicit boundary conditions must be coded by hand for each specific
problem, and also must be compatible with the
explicit boundary conditions specified in subroutine
BCEXP. The arguments for this subroutine are
INDEX:

ISTEP:

IVAR:

the index which is constant in the tridiagonal system of equations; this index
is J in the first half-step and I in the
second half-step, and is required only
when the boundary conditions depend
on the position along the boundary.
= 1 in the first half-step; = 2 in the
second half-step.
= 1 for u-velocity; = 2 for v-velocity.

PRINTF

This subroutine outputs the calculational time,


the current cycle, and the number of iterations for
convergence in the pressure-velocity iteration to
terminal or system console. It then tests if the time
for the next output has been reached (T >i TWPRT).
When this condition is true, the subroutine creates a
F L O W n n n . O U T file, and writes the current time,
cycle, number of iterations for convergence in the
pressure-velocity iteration, and formatted tables of
the u,v and p arrays to the disk file. nnn is obtained
from the current value of the PRCOUNT integer
variable. After the results are written on the disk file,
the time for the next printout and the counter for the
output files are incremented. The F L O W n n n . O U T
output files are used by the post processor to produce
graphical representations of the numerical solution.
SETUP

This
subroutine
opens
the
input
file
F D F L O W . D A T , and reads the input parameters
needed for each specific calculation. The preparation
of the F D F L O W . D A T file for a sample calculation
is described in the next section. After the input

parameters are read, the index bounds for the field


arrays and some constants necessary to the calculation are initialized. The initial velocity and pressure
arrays are initialized with U(I,J)= UI, V(I,J)= VI,
and P(I,J) = 0 on every interior cell. BCEXP then is
called to set the boundary conditions for the first
step.
STEPI

This subroutine computes the temporary solution


(u*, v*) from u n v", and p n using either the explicit
or the implicit methods as described. Subroutines
BCEXP or BCIMP are called to impose the boundary
conditions. The temporary solution obtained in
STEP1 is advanced to the (n 1) At time level in the
STEP2 subroutine.
STEP2

This subroutine computes the advanced-time


velocity and pressure fields u ~+~, v n+1, and p "+
from the temporary velocity (u*,v*), using
Equations (23) and (24).
TRIDA G

This subroutine solves tridiagonal systems of linear


equations, using the Thomas algorithm.
FPLOT.FOR

This file contains the post-processing program,


FPLOT.FOR, which constructs graphical representations of the computed velocity field. The user needs
to specify the name of the F L O W n n n . O U T file to be
represented, and a reference velocity VELMX. This
latter is used internally to scale the velocity vector.
Typically, VELMX should be equal to the maximum
velocity expected in the calculation.
The velocity vectors are plotted using two auxiliary
routines, CONVERT and DRWVEC. Subroutine
CONVERT converts "world" coordinates in the
window [XMIN,XMAX] [YMIN,YMAX] to plotting coordinates in the viewpoint [2.83,10.83] x
[0.33,8.33], with XMIN = 0, YMIN = 0, XMAX =
i,Ax,
Y M A X = ~ * A y . Subroutine DRWVEC
draws a segment between two points, and optionally
appends a small tip to the endpoint of the segment
(see Appendix 3 for further details). Only five graphical primitives are called. For a detailed description
of these primitives, see Young and Woert (1990)
or the description of G R F P R I M . F O R presented next.
The post processor can be run on a PC by linking
with the PLOT88 library, or using the PLOT
and VIEW programs by Golden Software using
GRFPRIM.FO R.
GRFPRIM.FOR

This file contains six subroutines that construct


"*.PLT" files: PLOTS, which opens the drawing file;
PLOT, which moves the pen, draws line segments,
and closes the plotting file; SYMBOL, which draws
a character string; NUMBER, which converts a real

FORTRAN solver for 2-D incompressible fluid flow


number to a character string and draws it; C O L O R ,
which changes the current pen color; and F A C T O R ,
which applies a scale factor to the plot. For the details
of operation of each of these subroutines, the reader
is referred to the headers following each subprogram
definition (Appendix 4). When compiled and linked
with FPLOT.FOR, these subroutines will generate
a " , . P L T " file that can be viewed on a PC screen,
or plotted, using the V I E W / P L O T programs.
SAMPLE

Table 1. Input data


for test problem
10

IBAR

10

JBAR

1.E-01

DELX

1.E-01

DELY

1.0-02

DELT

O.OE+O0

UI

O.OE+O0

VI

3.00

T~FIN

1.0

PRTDT

1.5

OMG

1.OE-01

NU

O.OE+O0

GX

O.OE+O0

GY

1.0E-03

EPSI

METHOD

TEST PROBLEM

In this section, the details of the operation of the


F D F L O W program are described. To help debug the
program in new installations, listings of the computed
results for a simple test problem will be presented.
The test problem considered is the calculation of the
flow in a square cavity of unit dimensions driven
by the uniform translation of the top lid (see Fig. 5).
The remaining boundaries are no-slip.
Table 1 shows the contents of the F D F L O W . D A T
file for the test problem. The labels on the
right column are included for readability, and are
discarded by the S E T U P subroutine. A crude
mesh of 10 l0 cells ( I B A R = 10, J B A R = 10) was
used. The mesh increments were D E L X = 0.1 and
D E L Y = 0.1. The time step was D E L T = 0.01. The
kinematic viscosity was N U = 0 . 1 .
The overrelaxation factor for the pressure-velocity iteration
was O M G = 1.5 and the tolerance for the maximum
cell divergence was EPSI = 10 3. The time-to-finish
was T W F I N = 3.0 sec and the solution was printed
with an interval of P R T D T = 1.0 sec. The boundary
conditions were programmed by hand in subroutines
B C E X P and BCIMP. These conditions correspond
to the cavity flow calculation reported in Greenspan
and Casulli (1988). Before starting a new calculation,
the user must check if the dimensions of the arrays
specified in the P A R A M E T E R statement in the
FDFLOW.INC file are appropriate for the desired
number of mesh cells. If this is not the situation, this
statement must be changed and the code recompiled.
The maximum permissible time step also must be
checked, if the explicit method is to be used.
After about 1 sec, the flow became steady. Tables 2,
3, and 4 and show listings of the computed u,v,
Y

273

u : (t,0)
P

and p fields. Figure 6 shows a graphical representation of the final steady solution. The results are
virtually identical to those reported by Greenspan
and Casulli (1988), the differences being the result of
their use of nonconservative differencing for the
convection terms. This sample test problem took
13sec (including disk I/O) on a 486DX/33MHzbased PC, using the Microsoft F O R T R A N compiler
(version 5.0).
APPLICATIONS
In order to test the accuracy and efficiency of
the computer program, two numerical studies were
performed: the calculation of lid-driven cavity flow
at high Reynolds number, and the calculation of
the flow past a backward-facing step for three
different Reynolds numbers. This last problem will
serve to illustrate how to define internal obstacles and
outflow boundary conditions by simple changes
in the code.

Cavity )qow at high ReynoMs number


u = (o,o)

(0,o)

u = (0,o)
Figure 5. Definition sketch for cavity flow pattern.

The computation of lid-driven cavity flows at


high Reynolds number has become a "'standard" for
testing new algorithms for incompressible flows.
F r o m the physical viewpoint the problem is of
considerable importance, for it provides a typical
example of separated flow which displays several
ranges of behavior of the Navier Stokes equations.

274

C. M. LEMOS
Table 2. Calculated horizontal velocity for test problem, T = 2.0 sec
I=
J= 12
J= i i
J= I0
J= 9
J= 8
J= 7
J= 6
J= 5
J= 4
J= 3
J= 2
J= I

2.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000

1.736
0.264
-0.027
-0.060
-0.052
-0.041
-0.032
-0.024
-0.017
-0.010
-0.002
0.002

3
1.521
0.479
0.053
-0,078
-0.106
-0.101
-0.086
-0.068
-0.050
-0.032
-0.011
0.011

4
1.392
0.608
0.151
-0.058
-0.135
-0.150
-0.137
-0.114
-0.086
-0.056
-0.022
0.022

F r o m the viewpoint of the numerical computation,


this is a good test problem because of its simple
boundary conditions. The previous numerical studies
have shown that a large primary vortex is formed
near the center of the cavity, together with secondary
and tertiary vortices near the corners. The complexity
of the flow topology and of the transient dynamics
increases with the Reynolds number.
To test the accuracy and efficiency of the present
algorithm, a numerical simulation of cavity flow with
Re = 10,000 was performed. The viscosity was set
to v = 10 4 m 2 s e c - ' , and a mesh with 100 x 100
cells with Ax = A y = 1 0 - : m was selected. This
spatial resolution was adequate to capture the
details of the boundary layers. The good stability
properties of the implicit method allowed the use of
a time step At = 10 -2 (corresponding to a Courant
number of 1 near the top lid). Because the flow
evolves slowly, the time-to-finish was set to 70 sec.
No changes were needed in the coded boundary
conditions.
Figure 7 shows several "snapshots" of the flow,
which illustrate the complexity of the transient
behavior. The qualitative development of the flow
was emphasized by dividing the velocities by their
magnitudes. It is observed that a large primary vortex

U(I,J)
5
1.324
0.676
0.222
-0.032
-0.147
-0.181
-0.173
-0.146
-0.113
-0.076
-0.031
0.031

6
1.298
0.702
0.252
-0.020
-0.152
-0.194
-0.188
-0.160
-0.124
-0.083
-0.035
0.035

7
1.309
0.691
0.238
-0.030
-0.154
-0.190
-0.180
-0.151
-0.115
-0.077
-0.032
0.032

8
1.363
0.637
0.177
-0.058
-0.150
-0.166
-0.149
-0.120
-0.089
-0.058
-0.023
0.023

9
1.485
0.515
0.077
-0.084
-0.124
-0.118
-0.097
-0.074
-0.052
-0.032
-0.011
0.011

10
1.711
0.289
-0.016
-0.069
-0.065
-0.050
-0.036
-0.025
-0.017
-0.010
-0.002
0.002

was formed near the center of the cavity. Most of


the kinetic energy of the flow was concentrated in
this primary vortex. Three secondary vortices were
formed near the bottom corners and the upperleft corner, which are associated physically with
the separation of the decelerating boundary layers
(Lighthill, 1963). Near the bottom corners, the
velocities were small, the flow evolving close to the
Stokes regime. The computed solution also showed
tiny tertiary vortices adjacent to the bottom corners.
The appearance of this sequence of eddies of decreasing strength was reported in the numerical work of
Gresho and others (1984).
In the sample test problem discussed in the previous section, the number of pressure iterations was
large during the first few time steps, and then decayed
rapidly in a monotonic way. Because for Re = 10 the
flow is diffusion-dominated, the solution evolved
quickly to the steady state. The behavior of the
solution for Re = 10,000 was qualitatively different.
The number of iterations needed to satisfy the continuity equation decayed more slowly, and usually
increased for a few cycles. Such behavior corresponds
to the slow formation and development of the vortex
structures, followed by the nonlinear interaction
between them. This calculation took 3 h and 5 min

Table 3. Calculated vertical velocity ~ r test problem, T = 2.0 sec

I=
J= 12
J= 11
J= 10
J= 9
J= 8
J= 7
J= 6
J= 5
J= 4
J= 3
J= 2
J= 1

0.000
0.000
-0.264
-0.238
-0.177
-0.125
-0.084
-0.052
-0.028
-0.012
-0.002
0.000

0.000
0.000
0.264
0.238
0.177
0.125
0.084
0.052
0.028
0.012
0.002
0.000

0.000
0.000
0.215
0.295
0.277
0.224
0.163
0.109
0.064
0.031
0.009
0.000

0.000
0.000
0.129
0.226
0.246
0.217
0.168
0.117
0.072
0.036
0.011
0.000

V(I,J)
5

0.000
0.000
0.068
0.139
0.165
0.154
0.123
0.088
0.055
0.028
0.009
0.000

0.000
0.000
0.026
0.056
0.068
0.064
0.050
0.035
0.022
0.011
0.004
0.000

0.000
0.000
-0.011
-0.025
-0.035
-0.038
-0.034
-0.027
-0.018
-0.010
-0.003
0.000

0.000
0.000
-0.054
-0.115
-0.144
-0.140
-0.116
-0.084
-0.054
-0.028
-0.009
0.000

0.000
0.000
-0.122
-0.221
-0.247
-0.222
-0.173
-0.120
-0.074
-0.037
-0.012
0.000

I0

0.000
0.000
-0.226
-0.318
-0.303
-0.244
-0.176
-0.115
-0.067
-0.032
-0.009
0.000

FORTRAN solver for 2-D incompressible fluid flow

275

Table 4. Calculated pressure for test problem, T = 2.0 sec

I=
J= 12
J= 11
J= 10
J= 9
J= 8
J= 7
J= 6
J= 5
J= 4
J= 3
J= 2
J= 1

0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000
0.000

0.000
-1.915
-1.064
-0.604
-0.350
-0.206
-0.125
-0.084
-0.070
-0.072
-0.083
0.000

3
0.000
-0.876
-0.740
-0.525
-0.349
-0.227
-0.150
-0.107
-0.087
-0.084
-0.093
0.000

P(I,J)
5

0.000
-0.458
-0.488
-0.404
-0.299
-0.210
-0.146
-0.108
-0.089
-0.086
-0.094
0.000

0.000
-0.272
-0.319
-0.291
-0.231
-0.170
-0.123
-0.094
-0.079
-0.076
-0.082
0.000

to complete o n a P C - c o m p a t i b l e 486 machine running at 33 MHz.

Flow past a backward-facing step, at Re = 100, 1000,


and 10,000
The third p r o b l e m considered here is the c o m p u tation of the flow past a backward-facing step
(Fig. 8). F o r a given step geometry the properties of
the flow, particularly the p o i n t of reattachment, are
a function o f the Reynolds number. Such properties
are i m p o r t a n t in the numerical modeling o f the
b e h a v i o r of heat exchangers, reactors, c o m b u s t i o n
machines, a n d m a n y practical problems concerning
internal flows. A similar p r o b l e m e n c o u n t e r e d in river

6
0.000
-0.162
-0.192
-0.185
-0.153
-0.116
-0.087
-0.069
-0.060
-0.057
-0.060
0.000

0.000
-0.057
-0.065
-0.070
-0.063
-0.052
-0.043
-0.039
-0.037
-0.035
-0.032
0.000

0.000
0.000
0.000
0.093
0.365
0.910
0.098
0.338
0.690
0.069
0.241
0.430
0.040
0.150
0.240
0.018
0.082
0.120
0.002
0.037
0.049
-0.010
0.010
0.011
-0.016 -0.003 -0.005
-0.016 -0.005 -0.006
-0.008
0.004
0.003
0.000
0.000
0.000

a n d coastal engineering is the scouring caused by


artificial structures.
This p r o b l e m will serve to illustrate h o w the program can be a d a p t e d to treat new problems by
simple changes in the code. In this application, it was
required to (i) impose the b o u n d a r y condition
u = (1,0) at the inlet; (ii) block certain internal cells in
the mesh, in order to define the geometry of the step;
a n d (iii) formulate a n outflow (radiative) condition
on the right boundary. To study the influence of the
Reynolds n u m b e r on the flow, three different simulations were performed, with v = 10 2, v = 10 -3. a n d
v = 10 -4 (v = i/Re). The c o m p u t a t i o n a l d o m a i n was
discretized using a mesh o f 120 x 20 ceils for the first

= 2 . O0
7

t
1
CYCLE=2OO

,"

1
,-

Ro

10

,"

=I O

VELMX=I.@O
Figure 6. Steady-state velocity field obtained in test problem.

3os OL pue '0g 'gE '01 = 1 aoj '000'01 = o~I ql!A~ molqoad ,~o U /~I!A~,O aoj aOlO0A

~(I!OOI0Apoz!lv, tuao N

L ~ang!::I
SL'=XWq3A

,,,,,,,,,,,,

.....

..-~......

....

,,,,,,,,,,,,,,,

.~

, , , ,

. . . . . .

. . . . . .

,,,,,,,,,,,
0000L =

l~lllllllllh,,. . . . . " - = ~ : " ' ; ' ~ I I i @ l l i l l i l

~'=~

" " ' ......" = = "

l[tFt~v...~..'~:::::;,
8

~._....

IkE

:::::
,

.. '. : :: : ,: :: ::::sss;.-.-;y,
.
.

: " :

~~.~Z~2

.~,{'{SS~l

~tt~.--"....~
LO'OL =

,,.

,~TT-::!

0
h~--~.~'~YT,;;s .......

::: : .....

~ ....

- ....

~1

~z'=x"]~^

"
:!

I,...--:>.~::_~-'=--'-~

LOOS=37~D

"'""""'"

~ :: - - - : ~ . . . . %~,,,'vvvHz~l
........

~ss~.;;;,,,,,;.~,,,~ ~c_,]

.............

.......

,,

,"z:

--

~i.~

LO " 0 S =

..%//HHZIUII~

"~',',",~,",'-.".\',.'.".~.~HQ~.~.~

cq

l/

/1/111,11~11

Oosg=3qg'kg/

~xxxx~......~.'///l/lll/~l

9Z'=XWq3A

---

tl

~x~xx~xxxx~.......:...~_.:~

0000L =

oa!

000L=37DID

'i~X,<~...~...~7__~.~z,/l//lllliJ/ll

[.~______________i

00"0L =

FORTRAN solver for 2-D incompressible fluid flow

277

= (0,0}

Ld

C)

Ls

= 10,0}

L d = 12

Hd

',--,

s-I1

Hs
I

Hd = 2

(0,0)

L s = 1.4

H s = 1

Figure 8. Definition sketch for problem of flow past backward-facing step.

two simulations, and a mesh of 240 x 40 cells for


the simulation with Re = 10,000. The time step was
At = 10 -2, and the calculations were done using the
implicit scheme.
The step was created by blocking those cells for
which I ~< IBAR/5 + 1 and J ~< J B A R / 2 + 1. To generate the outflow boundary, the conditions Ou/Sx = 0
and Ov/6y = 0 were imposed during the implicit
m o m e n t u m calculation, but not during the pressure
iteration (following the method of Hirt, Nichols, and
Romero, 1975). The definition of the internal obstacle
and special boundary conditions was done as follows.
In subroutine BCEXP, the statements for prescribing
U(IMAX-l,J)
and V(IMAX,J) were eliminated,
because during the pressure iteration these boundary
conditions were not applied. Also in BCEXP, another
loop was added to impose U(I,J) = 0 and V(I,J) = 0

Be

:]00

Fie

~]OOO

for I ~< IBAR/5 + ! and J ~< J B A R / 2 + 1. In subroutine BCIMP, a statement was added in the
block ISTEP = I / I V A R = 1 to put R H S X ( I ) = 1.0
for I N D E X > J B A R / 2 +
1, fixing the boundary
condition at the inlet. Also in BCIMP, the homogeneous Neumann conditions for u and v were imposed on the outlet boundary, using the method as
described. In subroutine STEP1, it was necessary
to add the statements D D X ( I ) = 1 . E + 3 0 and
DDY(J) = 1.E + 30 whenever I ~< IBAR/5 + 1 and
J ~< J B A R / 2 + 1. This simple procedure effectively
sets U(I,J) = 0 and V(I,J) = 0 for all cells defining the
step. In subroutine STEP2, a statement was included
in the main loop, to skip all obstacle cells.
Figure 9 shows the computed velocity distributions, each one corresponding to a different
Reynolds number. It is observed that as the Reynolds

Be

~10@OO

i. . . . . . . . . . . . . ... . . . . . ... . . . . . ... ... . . . . . . . . .:.i.i.i .] .i ]. ]. ]. i. Z. .2. .:.2. i. i.2. .] :

..

? i ~ ? ~ i ! i i ] i ! i ] i } ] : : ! ! Z i:i:::: i

...... ! ] ;il

Figure 9. Flow past backward-facing step, for Re = 100 (top), Re = 1000 (middle), and Re = 10.000
(bottom).

278

C.M. LEMOS

number increased from 100 to 1000, the point


of reattachment moved away from the step. For
R e = 100, the flow adapted itself quickly to the
expansion. The velocity profile was nearly parabolic
at the end of the step, and near the open boundary.
For Re = 1000, the pattern of the eddying motion
downstream of the step became more complicated,
and the flow separated from the upper boundary.
For R e = 10,000 the flow pattern, became even
more complicated. The main stream was dispersed by
meandering around a series of strong vortices. The
interaction between the main stream and the vortex
system created an intricate transient. In fact, the flow
represented in Figure 9 was highly unsteady.
SUMMARY
A F O R T R A N - 7 7 program for the computation
of 2-D incompressible flows was presented. The
system was designed to be operated on PCs using
low-cost software, for both educational and professional purposes. Educational applications encompass testing different numerical schemes for the
Navier-Stokes equations, illustrating the influence
of the Reynolds number on the flow pattern, instability and separation, and programming issues.
Professional applications include the study of steady
flows in channels and ducts, and the investigation
of scouring resulting from currents near coastal protection structures. To help new users debug the code,
the numerical results for a simple test case were
described in detail.
The quality and flexibility of the program were
illustrated by the results obtained in two classical test
problems, lid-driven cavity flow and flow past a
sudden expansion of a duct, with Reynolds numbers
up to 10,000. The fine details of the solutions, as
well as the complexity of the transient behavior at
high Reynolds number, were captured well. All simulations reported in this work were calculated using an
80486-based PC. The calculations also illustrated
how the program can be changed to meet practical
needs (e.g. definition of new geometries or new types
of boundary conditions).
Because of its modular structure, the code
described herein can be used as a foundation for
the development of more sophisticated versions. For
example, new physical phenomena, such as thermal
coupling, surface and internal gravity waves, etc. can
be introduced by adding new global variables, and
new subroutines to solve the transport equations
for the new fields. At the time of writing, work is
under way to develop a version of the present algorithm for Boussinesq fluids with an arbitrary equation
of state and distributed heat sources, incorporating
several types of boundary conditions. This type of
model can be useful for studying the evolution of the

near and intermediate field of plumes, either in


the atmosphere or in the ocean. The present model
also can be extended to treat 3-D flows in a straightforward way.
Acknowledgments--The author wants to express his gratitude and appreciation to Prof. Daniel A. Rodrigues for his
incentive and encouragement, and also for his helpful and
stimulating discussions.
REFERENCES

Bulgarelli, U., Casulli V., and Greenspan, D., 1984, Pressure


methods for the numerical solution of free surface fluid
flows: Pineridge Press, Swansea, 323 p.
Chorin, A. J., 1968, Numerical solution of the Navier
Stokes equations: Mathematics of Computation, v. 22,
p. 742-762.
Chorin A. J., and Marsden, J., 1979, A mathematical
introduction to fluid mechanics: Springer Verlag, New
York, 168 p.
Greenspan, D., and Casulli, V., 1988, Numerical analysis
for applied mathematics, science and engineering:
Addiso~Wesley Publ. Co., New York, 341 p.
Gresho, P. M., Chan, S. T., Lee, R. L., and Upson,
C. D., 1984, A modified finite element method
for solving the time-dependent, incompressible Navie~
Stokes equations: Int~. a. Jour. Num. Meth. in Fluids,
v. 4, no. 7, p. 619~i40.
Gustafson, K. E., 1987, Introduction to partial differential
equations and Hilbert space methods (2nd ed.): John
Wiley & Sons, New York, 409 p.
Haltiner, G. J., and Williams, R. T., 1980, Numerical
prediction and dynamic meteorology. (2nd ed.): John
Wiley & Sons, New York, 477 p.
Harlow, F. H., and Welsh, J. E., 1965, Numerical calculation of time-dependent viscous incompressible flow:
Physics of Fluids, v. 8, p. 2182-2189.
Hirt, C. W., Nichols, B. D., and Romero, N. C., 1975,
SOLA: a numerical solution algorithm for transient fluid
flows: Los Alamos Scientific Lab. Rept. LA-5852, 50 p.
Leonard, B. P., 1979, A stable and accurate convective
modelling procedure based on quadratic upstream
interpolation: Comp. Meth. Appl. Mech. Eng., v. 19,
no. 1, p. 59-98.
Lighthill, M. J., 1963, in Rosenhead, L., Ed. Laminar
boundary layers: Oxford Univ. Press, London, p. 687.
Mitchell, A. R., and Griffiths, D. F., 1980, The finite
difference method in partial differential equations: John
Wiley & Sons, London, 267 p.
Peyret, R., and Taylor, T. D., 1983, Computational methods
for fluid flow: Springer Verlag, New York, 358 p.
Quartapelle, L., 1992, Solution of the time-dependent
incompressible Navier-Stokes equations by finite
elements: Lecture Series 1992-04, von-K~irmfin Institute
for Fluid Dynamics, Rhode Saint Gen6se-Belgium,
154p.
Roache, P., 1972, Computational fluid dynamics: Hermosa
Publ., Albuquerque, New Mexico, 446 p.
Smith, G. D., 1985, Numerical solution of partial differential equations: finite difference methods: Oxford Univ.
Press, Oxford, 337 p.
Viecelli, J. A., 1971, A computing method for incompressible flows bounded by moving walls: Jour. Comp.
Physics, v. 4, no. 1, p. 119-143.
Young, T. L., and Van Woert, M. L., 1990, Plot88 Software
Library Reference Manual (3rd. ed.): Plot Works Inc.,
Ramona, California, 342 p.

FORTRAN solver for 2-D incompressible fluid flow


APPENDIX

279

FDFLO W.INC Listing


::::::::::::::::::::::::::
C INCLUDE f i l e c o n t a i n i n g

FILE "FDFLO~.INC" : =========================


g l o b a l v a r i a b l e s f o r FDFLOW.FOR a n d FPLOT.FOR

PARAMETER (IBAR2=IO2,JBAR2:102)
PARAMETER (I0=9)
REAL NU
REAL.8 T
INTEGER.4 CYCLE,PRCOUNT
COMMON UN(IBAR2,JBAR2),VN(IBAR2,JBAR2),U(IBAR2,JBAR2),
& V(IBAR2,JBAR2),P(IBAR2,JBAR2),XFLUX(IBAR2,JBAR2),
YFLUX(IBAR2,JBAR2),IBAR,JBAR,IMAX,JMAX,
&
&
&
&

IM1,JM1,DELX,DELY,RDX,RDY,DELT,UI,VI,T~FIN,TWPRT,
PRTDT,OMG,BETA,T,ITER,CYCLE,NU,GX,GY,EPSI,METHOD,PRCOUNT,
BBX(IBAR2),DDX(IBAR2),AAX(IBAR2),RHSX(IBAR2),
BBY(JBAR2),DDY(JBAR2),AAY(JBAR2),RHSY(JBAR2),SX,SY,
DTDX,DTDY

C
INPUT PARAMETERS (READ FROM FILE " F D F L O ~ . D A T " ) :
IBAR

C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C
C

CAGEO 20/3--B

JBAR
DELX
DELY
DELT
UI
VI
TNFIN
PRTDT
OMG
NU
GX
GY
EPSI
METHOD

:
:

:
:
:

:
:

:
:

NUMBER OF CELLS IN THE X-DIRECTION


NUMBER OF CELLS IN THE Y-DIRECTION
MESH SPACING ALONG THE X-DIRECTION
MESH SPACING ALONG THE Y-DIRECTION
TIME STEP
X-COMPONENT OF VELOCITY USED FOR INITIALIZING MESH
Y-COMPONENT OF VELOCITY USED FOR INITIALIZING MESH
PROBLEM TIME TO END CALCULATION
TIME INCREMENT BETWEEN SUCCESSIVE OUTPUTS
OVER-RELAXATION FACTOR USED IN THE PRESSURE ITERATION
KINEMATIC VISCOSITY
BODY ACCELERATION ALONG POSITIVE X-DIRECTION
BODY ACCELERATION ALONG POSITIVE Y-DIRECTION
PRESSURE ITERATION CONVERGENCE CRITERION
=1 FOR EXPLICIT MOMENTUM CALCULATION
=2 FOR IMPLICT MOMENTUMCALCULATION

OTHER GLOBAL VARIABLES :

BETA
:
T
ITER
:
CYCLE :
PRCOUNT:
BBX

VELOCITY COMPONENT IN THE X-DIRECTION, TIME LEVEL


VELOCITY COMPONENT IN THE Y-DIRECTION, TIME LEVEL
PRESSURE
VELOCITY COMPONENT IN THE X-DIRECTION, TIME LEVEL
VELOCITY COMPONENT IN THE Y-DIRECTION, TIME LEVEL
AUXILIARY ARRAY, USED TO STORE TRANSPORT FLUXES
AUXILIARY ARRAY, USED TO STORE TRANSPORT FLUXES
TOTAL NUMBER OF CELLS IN THE X-DIRECTION
TOTAL NUMBER OF CELLS IN THE Y-DIRECTION
= IMAX-1
= JMAX-1
= 1.0/DELX
= 1.0/DELY
PRESSURE ITERATION RELAXATION FACTOR
PROBLEM TIME
PRESSURE ITERATION COUNTER
COMPUTATIONAL TIME CYCLE
OUTPUT FILE COUNTER, USED TO NAME OUTPUT FILES
AUXILIARY VECTOR FOR TRIDIAGONAL ELIMINATION

DDX
AAX

AUXILIARY VECTOR FOR TRIDIAGONAL ELIMINATION


AUXILIARY VECTOR FOR TRIDIAGONAL ELIMINATION

V
P
UN
VN
XFLUX
YFLUX
IMAX
JMAX
IM1

:
:
:

JM1
RDX
RDY

N+I
N+I
N
N

280

C . M . LEMOS
RBSX
BBY
DDY
AAY
RHSY
DTDX
DTDY
SX
SY

:
:
:
:
:
:
:
:
:

AUXILIARY VECTOR FOR TRIDIAGONAL


AUXILIARY VECTOR FOR TRIDIAGONAL
AUXILIARY VECTOR FOR TRIDIAGONAL
AUXILIARY VECTOR FOR TRIDIAGONAL
AUXILIARY VECTOR FOR TRIDIAGONAL
= DELT/DELX
= DELT/DELY
= NU*DELT/(DELX*DELX)
= NU*DELT/(DELY*DELY)

PROGRAM CONSTANTS (PARAMETERS)

IBAR2
JBAR2
IO

:
:
:

ELIMINATION
ELIMINATION
ELIMINATION
ELIMINATION
ELIMINATION

MAXIMUMNUMBER OF CELLS IN THE X-DIRECTION


MAXIMUMNUMBER OF CELLS IN THE Y-DIRECTION
LOGICAL UNIT FOR INPUT/0UTPUT

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

APPENDIX
FDFLOW.FOR

2
Listing

C. . . . . . . . . . . . . . . . . . . . .
== PROGRAM "FDFLOW.FOR" : . . . . . . . . . . . . . . . . . . . . . . . .
C=:=== A FORTRAN p r o g r a m f o r c o m p u t i n g i n c o m p r e s s i b l e
fluid flows

PROGRAM FDFLOW
INCLUDE ~FDFLOW.INC ~
** I N I T I A L I Z E VARIABLES AND PRINT INITIAL DATA
CALL SETUP
CALL PRINTF
C
C
C

** START MAIN CYCLE


10

C
C
C

CONTINUE
** ADVANCE TIME
CALL ADVANCE
** COMPUTE TEMPORARY VELOCITIES
CALL STEP1
** COMPUTE ADVANCED-TIME VELOCITIES AND PRESSURE
CALL STEP2
** PRINT CYCLE INFORMATION k FIELD VARIABLES
CALL PRINTF
I F ( T . G T . T W F I N ) STOP ~End o f P r o g r a m ~
GOTO 10
END

SUBROUTINE ADVANCE
INCLUDE ~FDFLOW.INC ~
** ADVANCE TIME
DO 10 I = I , I M A X
DO 10 J = I , J M A X

======

FORTRAN solver for 2-D incompressible fluid flow

10

UN(I,J)=U(I,J)
VN(I,J)=V(I,J)
CONTINUE
T=T+DELT
CYCLE=CYCLE+I
RETURN
END

SUBROUTINE BCEXP
INCLUDE ~FDFLOW.INC ~
** SET BOUNDARY CONDITIONS WHEN VELOCITY IS CALCULATED EXPLICITLY
** BC'S MUST BE CODED BY HAND FOR EACH SPECIFIC PROBLEM

200
C

500

DO 200 J=I,JMAX
U(1,J):O.O
V(1,J)=-V(2,J)
U(IM1,J)=O.O
V(IMAX,J)=-V(IM1,J)
CONTINUE
DO 500 I=I,IMAX
V(I,JM1)=O.O
U(I,JMAX)=2.0-U(I,JM1)
V(I,1)=O.O
U(I,1)=-U(I,2)
CONTINUE
RETURN
END

SUBROUTINE BCIMP(INDEX,ISTEP,IVAR)
INCLUDE ~FDFLOW.INC ~
INTEGER INDEX,ISTEP,IVAR
** SET BOUNDARY CONDITIONS WHEN VELOCITY IS CALCULATED IMPLICITLY
** BC~S MUST BE CODED BY HAND FOR EACH SPECIFIC PROBLEM
INDEX IS J IN THE FIRST HALF-STEP AND I IN THE SECOND HALF-STEP
ISTEP IS 1 IN THE FIRST HALF-STEP AND 2 IN THE SECOND HALF-STEP
IVAR IS 1 FOR U-VELOCITY, AND 2 FOR V-VELOCITY
I F ( I S T E P . E Q . 1 ) THEN
I F ( I V A R . E q . 1 ) THEN
DDX(1)=I.O
AAX(1)=O.O
RHSX(1)=O.O

DDX(IMI)=I.O
BBX(IM1)=O.O
RHSX(IM1)=O.O
ELSEIF (IVAR.EQ.2) THEN
DDX(1):O.5
AAX(1)=0.5
RHSX(1):O.O
DDX(IMAX)=O.5
BBX(IMAX)=0.5

RHSX(IMAX):O.O
ENDIF
ENDIF
I F ( I S T E P . E Q . 2 ) THEN
I F (IVAR.EQ.1) THEN
DDY(1)=0.5

AAY(1)=0.5

RHSY(~)=O.O
DDY(JMAX)=0.5
BBY(JMAX)=0.5
RHSY(JMAX)=I.0

281

282

C.M. LEMOS
ELSEIF ( I V A R . E q . 2 ) THEN
DDY(1)=I.O
AAY(1)=O.O
RHSY(1)=O.O
DDY(JM1)=I.O
BBY(JM1)=O.O
RBSY(JM1)=O.O
ENDIF
ENDIF
RETURN
END

SUBROUTINE PRINTF
INCLUDE 'FDFLOW.INC'
CHARACTER*II FILENAME
** PRINT CYCLE INFORMATION AND FIELD VARIABLES

20

40
41
42
46
47
48
50

WRITE ( * , 5 0 ) ITER,T,CYCLE
IF (CYCLE.LE.O.OR.T+I.E-O6.GE.TWPRT) THEN
FILENAME=' '
FILENAME(I:4)='FLOW'
~RITE(FILENAME(5:7),46) PRCOUNT+IO0
FILENAME(8:II)='.OUT~
OPEN(IO,FILE=FILENAME,STATUS=~UNKNOWN ' )
WRITE ( 1 0 , 4 0 ) ITER
WRITE (I0,41) T
WRITE (I0,42) CYCLE
WRITE(IO,47)
DO 20 I=I,IMAX
DO 20 J=I,JMAX
WRITE(IO,48) I , J , U ( I , J ) , V ( I , J ) , P ( I , J )
CONTINUE
CLOSE(IO)
TWPRT=TWPRT+PRTDT
PRCOUNT=PRCOUNT+I
ENDIF
RETURN
FORMAT(IS,' ITER')
FORMAT(F8.3, ~ T ~)
FORMAT(IS,'
CYCLE')
FBRMAT(I3)
FORMAT(3X,'I',3X,'J',7X,~U',12X,'V~,13X,'P
')
FORMAT(2(IX,13),3(IX,IPE12.5))
FORMAT(IOX,'ITER=',I5,1OX,'TIME=',IPEI2.5,1OX,'CYCLE=',I6)
END

SUBROUTINE SETUP
INCLUDE 'FDFLOW.INC'
** READ INPUT PARAMETERS
OPEN(IO,FILE:'FDFLOW.DAT',STATUS=~OLD ' )
READ ( I 0 , . )
IBAR
READ ( I 0 , . )
JBAR
READ ( I O , . ) DELX
READ ( I O , . ) DELY
READ ( I O , . ) DELT
READ ( I O , . ) UI
READ ( I O , . ) VI
READ ( I 0 , . )
TWFIN
READ ( I O , . ) PRTDT
READ ( I O , . ) OMG
READ ( I 0 , . )
NU
READ ( I O , . ) GX
READ ( I 0 , . )
GY

FORTRAN solver for 2-D incompressible fluid flow


READ ( I O , . )
READ ( I O , . )
CLOSE(IO)

EPSI
METHOD

** COMPUTE MODEL PARAMETERS AND INITIALIZE CONTROL VARIABLES


IMAX=IBAR+2
JMAX=JBAR+2
IMI=IMAX-1
JMI=JMAX-1
RDX=I.O/DELX
RDY=I.0/DELY
T=O.O
ITER=O
CYCLE=O
T~PRT:O.O
BETA=OMG/(2.0,DELT,(RDX,RDX+RDY,RDY))
PRCOUNT=O
SX=NU*DELT*RDX**2
SY=NU*DELT*RDY**2
DTDX=DELT*RDX
DTDY=DELT*RDY
** SET INITIAL U, V, AND P FIELDS

10

DO 10 I=2,IM1
DO 10 J=2,JM1
U(I,J)=UI
V(I,J):VI
P(I,J)=O.O
CONTINUE
CALL BCEXP
RETURN
END
SUBROUTINE STEP1
INCLUDE 'FDFLOW.INC ~
** COMPUTES TEMPORARY VELOCITIES USING THE OLD PRESSURE GRADIENT

GOTO (1000,2000) METHOD


1000 CONTINUE
C
** EXPLICIT METHOD (METHOD = 1)
C
C
DO 10 J=I,JM1
DO 10 I=I,IM1
XFLUX(I+I,J)= P ( I + l , J ) + O . 2 5 * ( U N ( I , J ) + U N ( I + l , J ) ) * * 2
&
-NU.RDX.(UN(I+I,J)-UN(I,J))
YFLUX(I,J+I)= 0 . 2 5 . ( V N ( I , J ) + V N ( I + I , J ) ) . ( U N ( I , J ) + U N ( I , J + I ) )
-NU*RDY*(UN(I,J+I)-UN(I,J))
CONTINUE
10
DO 20 J=2,JM1
DO 20 I =2 , I M I - 1
U(I,J):UN(I,J)+DELT*(-RDX*(XFLUX(I+I,J)-XFLUX(I,J))
-RDY*(YFLUX(I,J+I)-YFLUX(I,J))+GX)
20
CONTINUE
DO 30 J=l,JM1
DO 30 I=I,IM1
XFLUX(I+I,J)= 0 . 2 5 * ( V N ( I , J ) + V N ( I + I , J ) ) * ( U N ( I , J ) + U N ( I , J + I ) )
- N U . R D X . ( V N ( I +I ,J) - V N ( I ,J) )
YFLUX(I,J+I)= P ( I , J + 1 ) + O . 2 5 . ( V N ( I , J ) + V N ( I , J + 1 ) ) * * 2
&
-NU.RDY.(VN(I,J+I)-VN(I,J))
30 CONTINUE
DO 40 J=2,JMI-1
DO 40 I=2,IM1
V(I,J)=VN(I,J)+DELT.(-RDX.(XFLUX(I+I,J)-XFLUX(I,J))
-RDY*(YFLUX(I,J+I)-YFLUX(I,J))+GY)

283

C.M. LEMOS

284

40 CONTINUE
CALL BCEXP
RETURN

C
2000 CONTINUE
C
** IMPLICIT METHOD (METHOD = 2 )
C
C
** STEP 1, EQ. 1
C
C
DO 100 J=2,JM1
DO 110 I=2,1M1-1
UR=O.5*(UN(I+I,J)+UN(I,J))
UL=O.b.(UN(I,J)+UN(I-1,J))
BBX(I)=-DTDX*UL-SX
DDX(1)= I.O+DTDX*(UR-UL)+2.0*SX
AAX(I)= DTDX*UR-SX
RHSX(I)=UN(I,J)+DTDX*(UR**2-UL**2)
110 CONTINUE
CALL B C I M P ( J , I , 1 )
CALL TRIDAG(BBX,DDX,AAX,RHSX,IM1)
DO 120 I = I , I M 1
120 U ( I , J ) = R H S X ( I )
100 CONTINUE
C
C
C

** STEP 1, EQ. 2

DO 200 J=2,JMI-I
DO 210 I=2,IMI
UR=O.5*(UN(I,J+I)+UN(I,J))
UL=O.5.(UN(I-1,J+I)+UN(I-1,J))
BBX(1)=-O.5*DTDX*UL-SX
DDX(I)= I.O+0.5.DTDX.(UR-UL)+2.0.SX
AAX(1)= 0.5.DTDX.UR-SX
RHSX(I)=VN(I,J)
210 CONTINUE
CALL BCIMP(J,1,2)
CALL TRIDAG(BBX,DDX,AAX,RHSX,IMAX)
DO 220 I=I,IMAX
220 V ( I , J ) = R H S X ( I )
200 CONTINUE

C
C
C

** PREPARE FOR STEP 2;

COPY TEMPORARY SOLUTION TO UN AND VN ARRAYS

DO 230 J=2,JM1
DO 230 I=I,IMAX
VN(I,J)=V(I,J)
230 U N ( I , J ) = U ( I , J )
C
C
C

** STEP 2, EO. 1

DO 300 I=2,1MI-I
DO 310 J=2,JMI
VT=O.5*(VN(I,J)+VN(I+I,J))
VB=O.5*(VN(I,J-I)+VN(I+I,J-1))
BBY(J)=-O.5*VB*DTDY-SY
DDY(J)= I.O+0.5*(VT-VB)*DTDY+2.0*SY
AAY(J)= 0.5*VT*DTDY-SY
RHSY(J)=UN(I,J)-DTDX*(P(I+I,J)-P(I,J))+GX*DELT
310 CONTINUE
CALL BCIMP(I,2,1)
CALL TRIDAG(BBY,DDY,AAY,RHSY,JMAX)
DO 320 J=I,JMAX
320 U ( I , J ) : R H S Y ( J )
300 CONTINUE

C
C
C

** STEP 2,

EQ. 2

FORTRAN solver for 2-D incompressible fluid flow

DO 400 I=2,IMI
DO 410 J=2,JMI-I

VT=O.5*(VN(I,J)+VN(I,J+I))
VB=O.5*(VN(I,J)+VN(I,J-1))
BBY(J)=-DTDY*VB-SY
BDY(J)= I.O+(VT-VB)*DTDY+2.0*SY
AAY(J)= DTDY.VT-SY
RHSY(J)=VN(I,J)+DTDY.(VT**2-VB**2-P(I,J+I)+P(I,J))+GY.DELT
410 CONTINUE
CALL B C I M P ( I , 2 , 2 )
CALL TRIDAG(BBY,BDY,AAY,RHSY,JM1)
DO 420 J : I , J M 1
420 V ( I , J ) = R H S Y ( J )
400 CONTINUE
RETURN
END

SUBROUTINE STEP2
INCLUDE ~FDFLO~.INC ~
** ITERATIVELY ADJUSTS PRESSURE AND VELOCITIES

10
C
C
C

ITER=O
FLAG:I.0
IF(FLAG.EO.O.O) GOTO 30
ITER=ITER+I
I F ( I T E R . G F . 5 0 0 0 ) STOP ~ P r e s s u r e f a i l e d
FLAG=O.O

t o c o n v e r g e !~

** COMPUTE UPDATED CELL PRESSURE AND VELOCITIES


DO 20 J=2,JMI
DO 20 I=2,1M1
D=RDX*(U(I,J)-U(I-I,J))+RDY.(V(I,J)-V(I,J-I))
IF(ABS(D).GE.EPSI) FLAG=I.0
DELP=-BETA.D
P(I,J)=P(I,J)+DELP
U(I,J)=U(I,J)+DELT*RDX*DELP
U(I-I,J)=U(I-1,J)-DELT.RDX.DELP
V(I,J)=V(I,J)+DELT.RDY.DELP
V(I,J-I)=V(I,J-1)-DELT*RDY.DELP
CONTINUE

20
C
C
C

** SET BOUNDARY CONDITIONS


CALL BCEXP
GOTO 5
RETURN
END

30

SUBROUTINE TRIDAG(BB,DD,AA,CC,NN)
DIMENSION A A ( . ) , B B ( . ) , C C ( . ) , D D ( . )
** THIS SUBROUTINE PERFORMS TRIDIAGBNAL ELIMINATION
BB=COEFFICIENT BEHIND DIAGONAL
DD=COEFFICIENT ON DIAGONAL
AA=COEFFICIENT AHEAD OF DIAGONAL
CC:R.H.S. VECTOR; CONTAINS THE SOLUTION ON RETURN
NN=NUMBER OF EQUATIONS
NOTE: DD AND CC ARE OVERWRITTEN BY THE SUBROUTINE
DO 10 I=2,NN
DD(I)=DD(I)-AA(I-1).(BB(I)/DD(I-1))
10

CC(I):CC(I)-CC(I-1)*(BB(I)/nn(I-1))

285

286

C.M. LEMOS
CC(NN)=CC(NN)/DD(NN)
DO 20 I=2,NN
J=NN-I+I
20 CC(J)=(CC(J)-AA(J)*CC(J+I))/DD(J)
RETURN
END
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

APPENDIX 3

FPLOT.FOR Listing
C ........................ PROGRAM "FPLOT.FOR" : . . . . . = = . . . . . . . . . . . . . .
C=== Post-processing program for visualization of the velocity field

PROGRAM FPLflT
INCLUDE 'FDFLOW.INC'
COMMON /WINDOW/ XMIN,YMIN,XMAX,YMAX
CHARACTER*11FILENAME

OPEN (IO,FILE=~FDFLOW.DAT~,STATUS='OLD,)
READ (IO,.) IBAR
READ (IO,.) JBAR
READ (IO,.) DELX
READ (IO,.) DELY
READ ( I 0 , . )
READ ( I O , . )
READ ( I O , . )
READ ( I 0 , . )
READ (IO,.)
READ (IO,.)
READ (I0,.)
READ (I0,.)
READ (IO,.)
READ (I0,*)
CLOSE(IO)

DELT
UI
VI
TWFIN
PRTDT
0MG
NU
GX
GY
EPSI

XMAX=DELX*FLOAT(IBAR)
YMAX=DELY*FLOAT(JBAR)
XMIN=O.O
YMIN=O.O

IMAX=IBAR+2
JMAX=JBAR+2
IMI=IMAX-I
JMI=JMAX-I
PRINT *,~Filename for plot ?~
READ (*,'(A)') FILENAME
OPEN (IO,FILE=FILENAME,STATUS='OLD')
READ (IO,*) ITER
READ (IO,.) T
READ ( I O , . ) CYCLE
READ ( I O , ' ( A ) ' )
DO 10 I=I,IMAX

DO I0 J=I,JMAX
10 READ (IO,*) I I , J J , U ( I , J ) , V ( I , J ) , P ( I , J )

PRINT *,~Maximum velocity expected in problem ?~


READ (*,*) VELMX
VELMXI=AMINI(DELX,DELY)/VELMX
CALL PLOTS(O,91,91)
CALL FACTOR(0.89)
C
C

** DRAW A FRAME AROUNDTHE PLOT

FORTRAN solver for 2-D incompressible fluid flow

CALL
CALL
CALL
CALL

DRWVEC(XMIN,YMIN,XMIN,YMAX,O)
DRWVEC(XMIN,YMAX,XMAX,YMAX,O)
DRWVEC(XMAX,YMAX,XMAX,YMIN,O)
DRWVEC(XMAX,YMIN,XMIN,YMIN,O)

** DRAW PLOT BORDER AND LEGEND


CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL
CALL

PLOT(O.OI,O.01,3)
PLOT(O.01,8.5,2)
PLOT(ll.O,8.5,2)
PLOT(11.0,O.01,2)
PLOT(O.01,0.01,2)
SYMBOL(O.15,8.13,0.175,'T
=',0.0,6)
NUMBER(999.0,999.0,O.175,SNGL(T),O.O,2)
SYMBOL(O.15,5.53,0.175,'CYCLE=',O.O,6)
NUMBER(999.0,999.0,O.175,FLOAT(CYCLE),O.O,-1)
SYMBOL(O.15,2.93,0.175,'Re
=',0.0,6)
NUMBER(999.0,999.0,O.175,SNGL(1.OD+O/DBLE(NU))+l.E-3,0.O,-1)
SYMBOL(O.15,0.33,0.175,'VELMK:',O.O,6)
NUMBER(999.,999.0,O.175,VELMK,O.O,2)

** DRAW THE VELOCITY VECTORS


DO 20 I=2,IM1
DO 20 J=2,JM1
XC=(FLOAT(I)-I.5).DELX
YC=(FLOAT(J)-I.5).DELY
XEND=XC+O.5.(U(I,J)+U(I-1,J)).VELMX1
YEND=YC+O.5.(V(I,J)+V(I,J-1)).VELMX1
20 CALL DRWVEC(XC,YC,XEND,YEND,1)
CALL PLOT(O.O,O.O,999)
STOP 'End o f FPLOT program'
END

SUBROUTINE DRWVEC(XINI,YINI,XEND,YEND,TIP)
COMMON /WINDOW/ XMIN,YMIN,XMAX,YMAX
REAL XINI,YINI,XEND,YEND,XMIN,YMIN,XMAX,YMAX
REAL XP1,YP1,XP2,YP2,XT1,YT1,XT2,YT2
INTEGER TIP
CALL CBNVERT(XINI,YINI,XP1,YP1)
CALL CONVERT(XEND,YEND,XP2,YP2)
CALL PLOT(XPI,YP1,3)
CALL PLOT(XP2,YP2,2)
IF (TIP.Eq.O) RETURN
**

DRAW T I P

OF ARROW I F T I P : I

UE=XP2-XP1
VE=YP2-YP1
XTl=XP2+O.125.(-2.0.UE-VE)
XT2=KP2+O.125*(-2.0.UE+VE)
YTl=YP2+O.125*(-2.0*VE+UE)
YT2=YP2+O.125*(-2.0*VE-UE)
CALL PLOT(XT1,YT1,2)
CALL PLOT(XT2,YT2,2)
CALL PLOT(XP2,YP2,2)
RETURN
END
SUBROUTINE CONVERT(X,Y,XPLOT,YPLOT)
COMMON /WINDOW/ XMIN,YMIN,XMAX,YMAX
REAL X,Y,XMIN,YMIN,XMAX,YMAX,XPLOT,YPLOT
CAGEO 2 0 i 3 ~ ;

287

288

C.M. LEMOS

DX=XMAX-XMIN
DY=YMAX-YMIN
D=AMAXI(DX,DY)
SF=I.O/D
XSHFT=O.5.(1.0-DX.SF)
YSHFT=O.5.(1.0-DY.SF)
XPLOT=((X-XMIN).SF+XSHFT).8.0+2.83
YPLOT=((Y-YMIN).SF+YSHFT).8.0+0.33
RETURN
END
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

APPENDIX

GRFPR1M.FOR Listing

C. . . . .
C. . . . .

G R A P H I C SPRIMITIVES FOR GENERATING "*.PLT" FILES


......
IN THE FORMAT OF THE VIEW/PLOT PROGRAMS BY Golden S o f t w a r e . . . . . .

SUBROUTINE PLOTS(IDUMMY,IOPORT,MODEL)

************************************************************************
C
C
C

C
C

INITIALIZES PLOT FILE


ARGUMENTS IDUMMY,IOPORT AND MODEL INCLUDED FOR COMPATIBILITY WITH
PLOT88 (Young h Van W o e r t , 1990)

.
.
*

.
.

************************************************************************
CHARACTER*12 PLTFILE
IDI=IDUMMY
ID2=IOPORT

10
20
30

ID3=MODEL
PRINT * , ~ F i l e n a m e f o r p l o t f i l e
READ ( * , 1 0 ) PLTFILE
OPEN(UNIT=90,FILE=PLTFILE)
CALL COLOR(7,IERR)
FORMAT(A)
FORMAT ( A , 2 F l O . 5 )
FORMAT ( A , F I O . 5 )
RETURN
END

>'

SUBROUTINE PLOT(X,Y,IPEN)

C***********************************************************************
C
C

DRAWS A LINE FROM CURRENT PEN POSITION TO POINT ( X , Y ) ,

C
C
C
C
C

IPEN=2
PEN UP
IPEN=3
PEN DOWN
IPEN=999 CLOSE PLOT FILE (END DRAWING)

C
C

NOTE:
....

WITH:

THIS SUBROUTINE IS NOT ENTIRELY COMPATIBLE WITH THE


PLOT88 LIBRARY

.
*
.
.
.
.
.
*
.

************************************************************************
IF ( I P E N . E O . 9 9 9 ) THEN
CLOSE ( 9 0 )
ENBIF
IF ( I P E N . E Q , 2 ) THEN
WRITE ( 9 0 , 1 0 ) ~PA ' , X , Y
ENDIF
IF ( I P E N . E Q . 3 ) THEN

F O R T R A N solver for 2-D incompressible fluid flow

10

289

WRITE ( 9 0 , 1 0 )
'MA ' , X , Y
ENDIF
FORMAT ( A , 2 F l O . 5 )
RETURN
END

SUBROUTINE SYMBOL(X,Y,HEIGHT,CTEXT,ANGLE,NC)
************************************************************************
C
*
C DRAWS A CHARACTER STRING
.
C
.
C
X,Y
: LOWER LEFT CORNER OF FIRST CHARACTER TO BE DRAWN;
*
C
I F X = 9 9 9 . 0 AND/OR Y = 9 9 9 . 0 , APPEND CTEXT TO THE LAST
*
C
TEXT STRING
.
C HEIGHT
= HEIGHT OF EACH CHARACTER
.
C
I F X = 9 9 9 . 0 AND/OR Y = 9 9 9 . 0 , THE HEIGHT OF THE LAST
*
C
TEXT STRING IS USED

C CTEXT
= TEXT TO BE DRAWN
.
C
ANGLE
= ANGLE ABOUT THE Z - A X I S , IN DEGREES
*
C
I F X = 9 9 9 . 0 AND/OR Y = 9 9 9 . 0 , THE ANGLE OF THE LAST
*
C
TEXT STRING I S USED
.
C
NC
= NUMBER OF CHARACTERS TO BE DRAWN
*
C
.
C
.
C
NOTE:
THIS SUBROUTINE IS NOT ENTIRELY COMPATIBLE WITH THE
*
C ....
PLOT88 LIBRARY
.
C
.
CHARACTER C T E X T * ( * )
CHARACTER*80 STPLflT,STSAVE
SAVE
XPLOT=X
YPLOT=Y
ANGPLOT=ANGLE
HPLOT=HEIGHT
STPLOT:CTEXT(I:NC)
IF (X.EQ.999.0.OR.Y.EQ.999.0)
THEN
XPLOT=XSAVE
YPLOT=YSAVE
ANGPLOT=ANGSAVE
HPLflT=HSAVE
STPLflT=STSAVE(I:LSTRING(STSAVE))//CTEXT(I:NC)
ENDIF
WRITE ( 9 0 , 1 0 )
~PS~,XPLOT,YPLOT,HPLOT,ANGPLOT, ~ "~
&
STPLOT(I:LSTRING(STPLOT)),'"'
XSAVE=XPLOT
YSAVE=YPLOT
HSAVE:HPLOT

10

ANGSAVE=ANGPLOT
STSAVE=STPLOT
FORMAT ( A , 4 F l O . 5 , 3 A )
RETURN
END

Continued overleaf

290

C . M . LEMOS
SUBROUTINE NUMBER(X,Y,HEIGHT,FPN,ANGLE,NDEC)
************************************************************************
C

C
C
C
C
C
C
C
C
C

CONVERTS A REAL NUMBER TO A CHARACTER STRING, AND DRAWS THE LATTER

ANGLE

X,Y

= LOWER LEFT CORNER OF FIRST CHARACTER TO BE DRAWN;


I F X = 9 9 9 . 0 AND/OR Y = 9 9 9 . 0 , APPEND FPN TO THE LAST
TEXT STRING
= HEIGHT OF EACH CHARACTER
I F X : 9 9 9 . 0 AND/OR Y = 9 9 9 . 0 , THE HEIGHT OF THE LAST
TEXT STRING IS USED
= REAL NUMBER TO BE CONVERTED
= ANGLE ABOUT THE Z - A X I S , IN DEGREES;
I F X = 9 9 9 . 0 AND/OR Y = 9 9 9 . 0 , THE ANGLE OF THE LAST
TEXT STRING IS USED
= FORMAT OPTION :

HEIGHT

FPN

C
C
C

NDEC

C
C
C
C
C

0 , WRITE INTEGER PART OF FPN PLUS A DECIMAL POINT


, WRITE FPN IN F-FORMAT WITH NDEC DIGITS
-1
, WRITE INTEGER PART OF FPN
>0

NOTE:
....

C
C

THIS SUBROUTINE IS NOT ENTIRELY COMPATIBLE WITH THE


PLOT88 LIBRARY

*
*
*
*

*
*
*

************************************************************************

CHARACTER RNUMBER*20,FM*20
RNUMBER=~
FM=~

100
110

120
130

140

I F ( N D E C . E Q . - 1 ) THEN
IRNUM = INT(FPN)
WRITE(RNUMBER,IO) IRNUM
ENDIF
I F ( N D E C . G E . O ) THEN
W R I T E ( F M , 2 0 ) NDEC
WRITE(RNUMBER,FM) FPN
ENDIF
DO 100 I = 1 , 2 0
IF(RNUMBER(I:I).NE.'
' ) GOTO 110
CONTINUE
CONTINUE
DO 120 J = I , 2 0
IF(RNUMBER(J:J).Eq.'
' ) GOTO 130
CONTINUE
CONTINUE
NCHAR=J-I
DO 140 NC=I,NCHAR
RNUMBER(NC:NC)=RNUMBER(NC+I-I:NC+I-1)
CONTINUE
RNUMBER(NCHAR+I:20)=~ ,
CALL SYMBOL (X,Y,HEIGHT,RNUMBER,ANGLE,NCHAR)

C
10
20

FORMAT(IIO)
FORMAT('(F15.',I1,')')
RETURN
END

SUBROUTINE FACTOR(FACT)
************************************************************************
C
C APPLIES A SCALE FACTOR
C
************************************************************************

10

W R I T E ( 9 0 , 1 0 ) 'SC
FORMAT ( A , 2 F 1 0 . 5 )
RETURN
END

',FACT,FACT

.
.
.

291

FORTRAN solver for 2-D incompressible fluid flow


FUNCTION LSTRING(STRING)
************************************************************************

FINDS THE NUMBER OF NON-BLANK CHARACTERS IN A CHARACTER STRING

C
C
C
C
C

*
NOTE: T h i s f u n c t i o n was e x t r a c t e d from " P r o g r a m m i n g w i t h FORTRAN 77"*
....
by J . A s h c r o f t , R. H. E ] d r i d g e , H. W. P a u l s o n and G. A. W i l s o n *
S h e r i d a n H o u s e , I n c . , N . Y . , 1981
.
*

************************************************************************

CHARACTER STRING.(*)
DO 10 I = L E N ( S T R I N G ) , I , - 1
I F ( S T R I N G ( I : I ) . N E . ' ' ) THEN
LSTRING=I
RETURN
ENDIF
CONTINUE
LSTRING=O
RETURN
END

10

SUBROUTINE COLOR(IC,IERR)
************************************************************************
C

C
C
C

SETS CURRENT PEN COLOR

IERR

IC

= COLOR INDEX, 1 =< IC =< 15 (FOR VGA SCREEN)


= RETURN ERROR CODE (=0 FOR NO ERROR, =1 IF AN ERROR
HAS BEEN DETECTED)

C
C
IERR=O

IF(IC.LT.I.OR.IC.GT.15)

THEN

IERR=I

RETURN

10

ENDIF
WRITE ( 9 0 , 1 0 )
FORMAT(A,I2)
RETURN
END

'SP ' ,

IC

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

*
*
*
*

*
*

You might also like