practical working computer code. On the ... methods to solve them, and their ultimate coding in a high-level computer language. ...... 101 X(I)=0.5*(XU(I+1)+XU(I)).
Program NATCON: For the numerical solution of buoyancy-driven laminar and turbulent flows in differentially heated cavities
by Mahesh Prakash. CSIRO Mathematical and Information Services Private Bag 10, Clayton South, 3169 Özden F. Turan, and Graham R. Thorpe. School of Architectural, Civil and Mechanical Engineering Victoria University PO Box 14428 Melbourne, Australia, 8001
Occasional Paper Number 1 July 2006
PROGRAM NATCOM
PREFACE
Books on computational fluid dynamics (CFD) are often quite theoretical and general, and as such they do not provide users with definitive advice on how to translate the theory into a practical working computer code. On the other hand commercial CFD packages require users to have little or no theoretical knowledge, and they are menu-driven and applications orientated. There are therefore gaps between generalized theory, the writing of ‘own-code’ and commercial CFD packages. Furthermore, for all of their flexibility commercial CFD packages are often unable to solve the precise problem posed by the user, and user-defined functions have to be written. This requires at least some knowledge of how CFD codes are structured. Students and researchers new to the field of CFD need an interface that relates the differential equations that govern heat, mass and momentum transfer in fluids to CFD codes. If students had access to such an interface their rate of progress could be much higher. This report aims to bridge the gap between theory and application.
The report correlates the equations that govern fluid flow and heat transfer with a FORTRAN 90 code. The program uses the finite volume method, as this has become a widely used technique amongst CFD practitioners. Procedures for discretising the partial differential equations that govern the physics along with how the resulting linear algebraic equations are solved have been described in detail. The grid generation procedure has been discussed at some length, as this is important if the discretisation procedure is to be accurate. The implementation of the hybrid discretisation scheme is illustrated, and it is felt that this will facilitate users to experiment with other schemes. The effects of turbulence are captured using a k-ε model that has been modified to account for near wall effects.
It is strongly recommended that readers use this report along with the book by Patankar (1980) in order to maximize the benefits of this document. Before developing the code the authors had access to the TEACH code that has become ubiquitous, and it shares a similar structure and nomenclature of the TEAM code developed at the University of Manchester (Craft et al., 2002). Users are advised to retain this structure when making modifications to the program so that it i
PROGRAM NATCOM
retains a certain universality.
The program has been validated against other programs and
experimental data as described in Prakash’s PhD thesis (2001).
The source code for the case of buoyancy-driven laminar and turbulent flows in differentially heated cavities may be obtained from the authors.
The authors would like to acknowledge Dr Yuguo Li, Dr Li Chen, Dr Jun-de Li and Dr Longde Zhao for their valuable contributions and comments.
M. Prakash Ö. F. Turan G. R. Thorpe
ii
PROGRAM NATCOM
CONTENTS PREFACE
i
CONTENTS
iii
1.
INTRODUCTION
1
2.
PROBLEM DESCRIPTION
2
3.
GOVERNING EQUATIONS AND BOUNDARY CONDITIONS
4
3.1
Laminar solutions
3.2
Turbulent solutions 3.2a Modifications for low Reynolds number models
3.3
Boundary conditions 3.3a Boundary conditions for k and ε
4.
NON-DIMENSIONAL EQUATIONS
5.
SUBROUTINES INIT AND READDATA (GRID GENERATION, INITIALIZATION AND READING THE INPUT DATA FILE)
10
6.
PROGRAM FLOW CHART
23
7.
SUBROUTING LISOLV (GAUSS-SIEDEL LINE BY LINE SOLVER)
24
SUBROUTINES CALCU AND CALCV (MOMENTUM EQUATIONS)
28
SUBROUTING CALCP (PRESSURE CORRECTION EQUATION)
37
SUBROUTINE PROPS (MODIFICATION TO FLUID PROPERTIES)
42
SUBROUTINE CALCT (THERMAL ENERGY EQUATION)
43
SUBROUTINE CALCTE (EQUATION FOR TURBULENT KINETIC ENERGY)
45
8.
9.
10.
11.
12.
8
iii
PROGRAM NATCOM
13.
14.
15.
16.
17.
SUBROUTINE CALCED (ENERGY DISSIPATION EQUATION)
49
SUBROUTINE PROMOD (BOUNDARY CONDITIONS)
53
SUBROUTINE UPDATE (UNSTEADY CALCULATIONS)
57
SUBROUTINE DUMP (RESTARTING CALCULATIONS)
58
INPUT AND OUTPUT
58
17.1
Input
17.2
Output
18.
MAIN PROGRAM
63
19.
REFERENCES
70
iv
PROGRAM NATCOM
1.
INTRODUCTION There are conceptual barriers between the mathematical formulation of fluid mechanics
problems in terms of continuous equations, the discretisation of the equations and numerical methods to solve them, and their ultimate coding in a high-level computer language. This work is essentially didactic in that it aims to reduce these barriers and help students to understand how cfd codes actually work. They will then be in a good position to write their own codes, understand other people’s codes, and commercial cfd packages will no longer appear to be solely menu-driven ‘black boxes’. This report contains a detailed description of the program NATCON that solves, using the finite volume method, the equations that govern two-dimensional buoyancy driven turbulent flows in a rectangular enclosure.
Natural convection flow occurs due to a temperature difference
imposed on the opposite walls of the enclosure. The problem description is presented in Section 2. The program has a provision to solve steady and unsteady problems with laminar or turbulent flows. The standard k-ε model originally proposed by Harlow and Nakayama (1967) with some modification for natural convection flows (described in Section 3) is used as the turbulence model.
Low Reynolds number k-ε models can also be used with some minor
modifications to the program. This is also described in Section 3. A description of the nondimensional equations is given in Section 4. A proper choice of the non-dimensional scheme can have a significant saving on the computer time by way of a reduction in the rounding off errors. The concept of staggered grid to solve the discretized partial differential equations along with grid generation is described in Section 5. Section 5 also describes subroutines READDATA and INIT. The Gauss Seidel line by line solver, used to solve all the partial differential equations is described in Section 7. Section 8 describes subroutines CALCU and CALCV in which the momentum equations are encoded. The SIMPLE algorithm described in Patankar and Spalding (1972) is used to ensure that continuity of mass is conserved. The pressure correction equation forms the backbone of the SIMPLE algorithm, which, along with subroutine CALCP is described in Section 9. Section 10 describes subroutine PROPS that can be used to make changes to the fluid properties. Section 11 describes subroutine CALCT for the thermal energy equation. Sections 12
1
PROGRAM NATCOM
and 13 describe subroutine CALCTE and CALCED for the turbulent kinetic energy and energy dissipation respectively. Subroutine PROMOD that is used to assign boundary conditions to all the variables is described in Section 14. Section 15 describes subroutine UPDATE that is used for unsteady state calculations to update variables after each time iteration. Section 16 describes subroutine DUMP used to restart calculations using a previously calculated field. The input required for the program and the output in numerical and graphical form are described in Section 17. The main program is listed in Section 18.
2.
PROBLEM DESCRIPTION Consider a closed rectangular cavity, which, is subjected to different thermal boundary
conditions. The cavity can have a fluid heated from below with adiabatic vertical walls. This gives rise to a Rayleigh-Benard type of flow. One can also have the vertical walls at different temperatures with adiabatic horizontal walls. All other instances such as conducting horizontal walls with vertical walls at different temperatures, and a cavity with tilted axes are special cases which can be easily achieved with some minor modifications to the present program. A particularly simple case that illustrates the key features of buoyancy driven flows is a cavity that has differentially heated vertical walls and floors that are adiabatic. Figure 1 shows the heating from the side case as a representative system with the rectangular cavity filled with a fluid.
In the figure, Q is the heat flux and is zero for the adiabatic horizontal walls, Th represents the temperature of the hot wall, Tc represents the temperature of the cold wall, H is the total height and L is the total length of the rectangular cavity. Vector g represents acceleration due to gravity. Since the heat flux Q is the first derivative of temperature with respect to space this condition can be mathematically represented as
∂T = 0 at y=0 and y=H. ∂y
The problem satisfies the following conditions:
(a) The fluid is “almost” incompressible and satisfies the Boussinesq approximation [details can be found in Gray and Giorgini (1976)] which implies that the variation of
2
PROGRAM NATCOM
density with temperature is negligible except in the buoyancy term of the equation of motion. The buoyancy term occurs in the y-component equation of motion, Equation 3 in Section 3. The density in the buoyancy term is linearized according to
ρ( T ) = 1 − β ( T − To ) ρ ( To )
(1)
where, ρ is the fluid density, T is the local fluid temperature, To is a reference temperature and β is the thermal expansion coefficient of the fluid. L Q=0
g
Th
Tc
H
Y X
Q=0
Figure 1. Square cavity that has, vertical walls maintained at different temperatures, and floors that are adiabatic.
(b) All other thermodynamic and transport properties of the fluid are constant.
(c) The z dimension is much greater than the x and y dimensions and thus the problem can be considered as essentially two-dimensional.
The requirements for these assumptions to be valid must be carefully examined before using the standard program. If any of these assumptions were not valid for a nonstandard problem the program would have to be modified so that it satisfies the specific requirements of the problem.
3
PROGRAM NATCOM
3.
GOVERNING EQUATIONS AND BOUNDARY CONDITIONS The following set of partial differential equations is solved in the present program.
1.
Equation of continuity: ∂ρ ∂( ρu ) ∂( ρv ) + + =0 ∂t ∂x ∂y
(2)
in which t represents time, u and v are the components of the fluid velocity in the x and y directions respectively. 2.
Momentum equation in the x direction:
ρ
⎛ ∂u ∂v ⎞⎤ ∂u ∂u ∂u ∂p ∂ ⎡ ⎛ ∂u ⎞⎤ ∂ ⎡ + ρu + ρv = − + ⎢(µ + µ t )⎜ 2 ⎟⎥ + ⎢(µ + µ t )⎜⎜ + ⎟⎟⎥ ∂t ∂x ∂y ∂x ∂x ⎣ ⎝ ∂x ⎠⎦ ∂y ⎣ ⎝ ∂y ∂x ⎠⎦
Unsteady term
Advection
Pressure
(3)
Diffusion
in which p is pressure, µ the fluid viscosity and µt the eddy or turbulent viscosity. 3.
Momentum equation in the y direction:
ρ
⎛ ∂v ⎞⎤ ∂ ⎡ ⎛ ∂u ∂v ⎞⎤ ∂v ∂v ∂v ∂p ∂ ⎡ + ρu + ρv = − + ⎢(µ + µ t )⎜⎜ 2 ⎟⎟⎥ + ⎢(µ + µ t )⎜⎜ + ⎟⎟⎥ ∂t ∂x ∂y ∂y ∂y ⎣ ⎝ ∂y ⎠⎦ ∂x ⎣ ⎝ ∂y ∂x ⎠⎦ + ρgβ ( T − To )
(4)
Buoyancy
4.
Thermal energy equation:
ρ
µ ∂T ∂T ∂T ∂ ⎡⎛ µ + ρu + ρv = + t ⎢⎜⎜ ∂t ∂x ∂y ∂x ⎣⎝ Pr σ T
⎞ ∂T ⎤ ∂ ⎡⎛ µ µ ⎟⎟ ⎥ + ⎢⎜⎜ + t ⎠ ∂x ⎦ ∂y ⎣⎝ Pr σ T
⎞ ∂T ⎤ ⎟⎟ ⎥ ⎠ ∂y ⎦
(5)
T is the local fluid temperature, Pr is the fluid Prandtl number and σT is the turbulent
Prandtl number for temperature.
5.
Turbulent kinetic energy equation:
4
PROGRAM NATCOM
ρ
µt ∂k ∂k ∂k ∂ ⎡⎛ + ρu + ρv = ⎢⎜⎜ µ + ∂t ∂x ∂y ∂x ⎢⎣⎝ σk
⎞ ∂k ⎤ ∂ ⎡⎛ µ ⎟⎟ ⎥ + ⎢⎜⎜ µ + t σk ⎠ ∂x ⎥⎦ ∂y ⎢⎣⎝
⎞ ∂k ⎤ ⎟⎟ ⎥ + Pk + Gk − ρε + D ⎠ ∂y ⎥⎦ (6)
k is the turbulent kinetic energy, σk is the turbulent Prandtl number for k and ε is the rate of
energy dissipation. D represents a term which arises when low Reynolds number turbulence models are implemented. 6.
Equation for the rate of energy dissipation:
ρ
∂ε ∂ε ∂ε ∂ ⎡⎛ µt + ρu + ρv = ⎢⎜⎜ µ + ∂t ∂x ∂y ∂x ⎢⎣⎝ σε
⎞ ∂ε ⎤ ∂ ⎡⎛ µ ⎟⎟ ⎥ + ⎢⎜⎜ µ + t σε ⎠ ∂x ⎥⎦ ∂y ⎢⎣⎝
⎞ ∂ε ⎤ ⎟⎟ ⎥ + ⎠ ∂y ⎥⎦
( cε 1 f 1 ( Pk + cε 3 G k ) − ρcε 3 f 2 ε )
ε
k
+E
(7)
with 2 2 ⎛ ⎛ ∂u ⎞ 2 ⎛ ∂u ∂v ⎞ ⎞⎟ ⎛ ∂v ⎞ ⎜ + ⎟ Pk = µ t 2⎜ ⎟ + 2⎜⎜ ⎟⎟ + ⎜⎜ ⎜ ⎝ ∂x ⎠ ∂y ∂x ⎟⎠ ⎟ ∂y ⎠ ⎝ ⎝ ⎝ ⎠
Gk = −
µt ∂T gβ ∂y σT
µ t = ρc µ f µ
k2
ε
E is a term which occurs when low Reynolds number turbulence models are used.
σε is the turbulent Prandtl number for ε. The following values are empirical constants used in the standard k-ε model. cµ=0.09, cε1=1.44, cε2=1.92, σT=0.9, σk=1.0, σε=1.3, fµ=f1=f2=1.0.
3.1
Laminar Solutions For laminar solutions, Equations (6) and (7) are not used for calculations and the eddy
viscosity, µt, is taken as zero. The variables u, v, p and T are instantaneous quantities for laminar calculations. One can either use a steady approach or a transient approach for laminar calculations. In the former case the time derivatives in Equations (2), (3), (4) and (5) are set to zero. Since no
5
PROGRAM NATCOM
modifications are carried out in arriving at the unsteady formulation, the solution obtained would approximate to a true transient solution. 3.2
Turbulent Solutions For turbulent solutions, Equations (6) and (7) are solved simultaneously with Equations (2),
(3), (4) and (5). Variables, u, v, p and T are, time averaged quantities for turbulent calculations. Here again one can either use a steady approach or approach the steady state solution by integrating through time.
The time derivatives in the time-averaged, Navier-Stokes equation represent the large time behaviour according to Henkes (1990). However the nature of the transient solution will depend on the type of turbulence model used. Thus the transient solution cannot be called a true transient. The eddy viscosity, µt, is introduced in the form of a modification to the fluid viscosity as described in Section 10. Quantities D and E represent terms that need to be added for low Reynolds number k-ε models. For the standard k-ε model, D and E are set equal to zero.
More recent experimental data on natural convection in a differentially heated cavity have been provided by Ampofo and Karayiannis (2003) against which the various models may be compared.
3.2a
Modification for low Reynolds number models
Low Reynolds number models of Chien (1982) and Jones and Launder (1972) are given as examples. 1.
Low Reynolds number k-ε model of Chien (1982) cµ=0.09, cε1=1.35, cε2=1.8, σT=0.9, σk=1.0, σε=1.3
2 fµ=1-exp(-0.0115x+), f1=1.0, f 2 = 1 − exp( −(Ret / 6 ) 2 ) , 9 D = −2 µ
2.
k 2 µε , E = − 2 exp( −0.5 x + ) . 2 xn xn
Low Reynolds number k-ε model of Jones and Launder (1972) 6
PROGRAM NATCOM
cµ=0.09, cε1=1.44, cε2=1.92, σT=0.9, σk=1.0, σε=1.3 ⎛ − 2 .5 ⎞ ⎟⎟ , f1=1.0, f 2 = 1 − 0.3 exp( − Ret2 ) , f µ = exp⎜⎜ ⎝ 1 + Ret / 50 ⎠ ⎡⎛ ∂ k D = −2 µ ⎢⎜⎜ ⎢⎝ ∂x ⎣
3.3
2
⎞ ⎛∂ k ⎟ +⎜ ⎟ ⎜ ∂y ⎠ ⎝
⎞ ⎟ ⎟ ⎠
2⎤
µ ⎥ , E = 2µ t ρ ⎥ ⎦
⎡⎛ ∂ 2 u ⎞ 2 ⎛ ∂ 2 v ⎞⎤ ⎢⎜ ⎟ +⎜ ⎟⎥ . ⎢⎜⎝ ∂y 2 ⎟⎠ ⎜⎝ ∂x 2 ⎟⎠⎥ ⎣ ⎦
Boundary Conditions For calculations involving laminar flow natural boundary conditions are applied for u, v and
T. The no-slip and impermeable boundary condition is applied to the u and v velocities.
For the temperature, T=Th
at x=0 at x=L
T=Tc
∂T = 0 at y=0 ∂y ∂T = 0 at y=H ∂y For calculations of turbulent flow wall functions can be introduced for velocities and temperature as well as for k and ε. However in the present formulation, wall functions are used only for k and ε and the other variables are solved up to the wall.
3.3a
Boundary conditions for k and ε Standard k-ε model.
1. k=
(u )
* 2
cµ f µ
(u ) ,ε=
* 3
κy
at the first inner grid point.
τw where u* is friction velocity defined by u* = ρ
7
PROGRAM NATCOM
where τ w is the wall shear stress calculated from τ w =
µ ⎛ ∂u ⎞ ⎜ ⎟ ρ ⎜⎝ ∂y ⎟⎠ w
κ is Von Karman’s constant=0.41 and
y is the normal distance from the wall.
2.
Low Reynolds number models of Chien and Jones and Launder. k = ε = 0 at the wall.
4.
NON-DIMENSIONAL EQUATIONS
A non-dimensional form of the equations reduces the number of independent parameters in the equations and makes the solutions more general for a given set of parameters. It aids in saving computer time by increasing the speed of convergence of the solution. The non-dimensional equations are derived in such a way that only the fluid Prandtl number and Rayleigh number are the dimensionless parameters. The fluid Prandtl number is defined as Pr =
Cpµ kf
, where Cp is the specific heat of the fluid
and kf is the fluid thermal conductivity. The Rayleigh number is defined as Ra =
ρ 2 gβ∆TH 3 Pr , µ2
where g is acceleration due to gravity and ∆T is the temperature difference between the hot and cold wall.
In case of natural convection flows, for low Prandtl number fluids like gases as well as low viscosity liquids, the convective acceleration term is balanced by the buoyancy term in the momentum equation. Let the subscript ref, represent a reference value for all variables and superscript * represent the non-dimensional variable.
Thus one can write, T − Tref p y u v k x ε u* = , v* = , T* = , x* = , y * = , p * = , ε* = , k* = , u ref u ref Th − Tc H H p ref ε ref k ref
ρ* =
µ ρ µ t , µ* = , µ t* = t , t * = ρ ref µ ref µ ref t ref
.
8
PROGRAM NATCOM
Using the above non-dimensional variables one can equate the convective acceleration term and buoyancy term in Equation (3) and arrive at: u ref = gβ∆TH . By equating the convective 2 acceleration term with the pressure term one then obtains: p ref = ρu ref . The reference temperature
is taken as (Tc+Th)/2. The reference density and viscosity are taken as the fluid density and viscosity respectively.
The reference time tref, is taken as the ratio of the reference length scale and the reference velocity scale, i.e. t ref =
H gβ∆TH
.
The reference values for turbulent kinetic energy and energy dissipation are derived with the aid of perturbation theory which is described in Wilcox (1993) and are respectively given as: k ref =
2 u ref
, ε ref =
3 u ref
H
.
Using the non-dimensional parameters and dropping the superscript * from all the variables, Equations (2) through (7) can be written as, 1.
Equation of continuity:
∂ρ ∂( ρu ) ∂( ρv ) =0 + + ∂y ∂x ∂t
2.
ρ
3.
ρ
(8)
Momentum equation in the x direction:
∂p ∂u ∂u ∂u =− + + ρv + ρu ∂x ∂y ∂x ∂t
Pr ∂ ⎡ (µ + µt )⎛⎜ 2 ∂u ⎞⎟⎤⎥ + ⎢ Ra ∂x ⎣ ⎝ ∂x ⎠⎦
⎛ ∂u ∂v ⎞⎤ Pr ∂ ⎡ ⎢(µ + µt )⎜⎜ + ⎟⎟⎥ (9) Ra ∂y ⎣ ⎝ ∂y ∂x ⎠⎦
Momentum equation in the y direction:
∂p ∂v ∂v ∂v =− + + ρu + ρv ∂y ∂y ∂x ∂t
⎛ ∂v ⎞⎤ Pr ∂ ⎡ ⎢(µ + µt )⎜⎜ 2 ⎟⎟⎥ + Ra ∂y ⎣ ⎝ ∂y ⎠⎦
9
⎛ ∂u ∂v ⎞⎤ Pr ∂ ⎡ ⎢(µ + µt )⎜⎜ + ⎟⎟⎥ Ra ∂x ⎣ ⎝ ∂y ∂x ⎠⎦
PROGRAM NATCOM
+ ( T − To )
3.
ρ
Thermal energy equation:
∂T ∂T ∂T = + ρv + ρu ∂y ∂x ∂t
4.
ρ
∂ ⎡⎛ µt Pr ⎞ ∂T ⎤ 1 ⎟ ⎥+ ⎢⎜⎜ µ + σ T ⎟⎠ ∂x ⎦⎥ Pr Ra ∂x ⎣⎢⎝
µt Pr ⎞ ∂T ⎤ ∂ ⎡⎛ 1 ⎟ ⎥ ⎢⎜⎜ µ + σ T ⎟⎠ ∂y ⎦⎥ Pr Ra ∂y ⎣⎢⎝
(11)
Turbulent kinetic energy equation:
∂k ∂k ∂k = + ρv + ρu ∂y ∂x ∂t
5.
ρ
(10)
Pr ∂ ⎡⎛ µt ⎢⎜⎜ µ + Ra ∂x ⎢⎣⎝ σk
⎞ ∂k ⎤ ⎟⎟ ⎥ + ⎠ ∂x ⎥⎦
µt Pr ∂ ⎡⎛ ⎢⎜⎜ µ + σk Ra ∂y ⎢⎣⎝ − ρε
⎞ ∂k ⎤ ⎟⎟ ⎥ + Pk + Gk ⎠ ∂y ⎥⎦
µt Pr ∂ ⎡⎛ ⎢⎜⎜ µ + σε Ra ∂y ⎣⎢⎝
⎞ ∂ε ⎤ ⎟⎟ ⎥ + ⎠ ∂y ⎦⎥
(12)
Equation for energy dissipation:
∂ε ∂ε ∂ε + ρu + ρv = ∂t ∂x ∂y
µt Pr ∂ ⎡⎛ ⎢⎜⎜ µ + σε Ra ∂x ⎣⎢⎝
⎞ ∂ε ⎤ ⎟⎟ ⎥ + ⎠ ∂x ⎦⎥
( cε 1 f 1 ( Pk + cε 3 G k ) − ρcε 2 f 2 ε )
ε
k
(13)
with ⎛ ∂v ⎞ ⎛ ∂u ∂v ⎞ Pr ⎛⎜ ⎛ ∂u ⎞ Pk = µ t + ⎟ 2⎜ ⎟ + 2⎜⎜ ⎟⎟ + ⎜⎜ ∂y ⎠ ∂y ∂x ⎟⎠ Ra ⎜ ⎝ ∂x ⎠ ⎝ ⎝ ⎝ µ t ∂T 1 Gk = − Pr Ra σ T ∂y 2
µt =
2
2
⎞ ⎟ ⎟ ⎠
Ra k2 ρc µ f µ Pr ε
The non-dimensional forms of the equations are now used along with their boundary conditions. The temperatures Th and Tc become equal to 1 and 0 on a non-dimensional scale.
5. SUBROUTINES INIT AND READDATA (GRID GENERATION, INITIALIZATION AND READING THE INPUT DATA FILE) The calculation of all variables (i.e., vectors u and v and scalars p, T, k and ε) at one point leads to a non-uniform pressure filed being represented as a uniform pressure field. Also, a physically unrealistic velocity field seems to satisfy the discretized continuity equation. These problems associated with the primitive variable formulation have been described in Patankar 10
PROGRAM NATCOM
(1980). The problem is overcome by using a different set of points to calculate vectors and scalars. This is called the staggered grid concept where the calculation points for vectors are staggered with respect to the calculation points for scalars. Such a staggered grid for velocity components was first used by Harlow and Welch (1965).
In the staggered grid, the velocity components are calculated for the points that lie on the faces of a control volume. Thus, the x-component of velocity u is calculated at the faces that are normal to the x-direction. The locations for u are shown in Figure 2 by short arrows, while the grid points (hereafter called the main grid points) are shown by the intersections of the solid lines; the dashed lines indicate the control-volume faces.
y x
Figure 2. Staggered locations for u Note that with respect to the main grid points, the u locations are staggered only in the x direction. Similarly the v locations are staggered only in the y direction. Scalar variables like T, p, k and ε are calculated at the main grid points.
11
PROGRAM NATCOM
Grids are developed, by using algebraic functions for grid spacing (non-uniform or uniform grid spacing). The staggered grid points are first developed. They are represented as xu(i) and yv(j) for x and y directions respectively. The main grid points are then calculated by using the staggered grid locations. Figure 3 shows the staggered and main grid locations xu(i) and x(i) respectively for the x direction on a 7x7 grid. Note that the boundary of the diagram is the physical boundary of the cavity. The staggered grid starts with xu(2) whereas the main grid starts with x(1). Note that xu(2) = x(1) and xu(ni) = x(ni) with ni = 7. This representation allows the imposition of natural boundary
conditions for scalar and vector quantities. In the x direction, calculations for u velocity starts at xu(3) and ends at xu(ni-1)=xu(6) whereas calculations for scalars and v velocity start at x(2) and
end at x(ni-1) = x(6). Similarly in the y direction, calculations for v velocity starts at yv(3) and ends at yv(nj-1) = yv(6) whereas calculations for scalars and u velocity start at y(2) and end at y(nj-1) = y(6).
XU(2) =X(1)
X(2)
XU(6)
XU(3)
X(6)
Figure 3. Main and Staggered grid locations for a 7x7 grid
12
XU(7) =X(7)
PROGRAM NATCOM
The staggered grid generation is given as GRID GENERATION FUNCTIONS in SUBROUTINE READDATA and the development of the main grids from the staggered grids is shown as CALCULATE GEOMETRICAL QUANTITIES in SUBROUTINE INIT.
This part of the program is given below: NIM1=NI-1 NJM1=NJ-1 NIM2=NI-2 NJM2=NJ-2 C
GRID GENERATION FUNCTIONS (development of the staggered grid. This is a part C of
SUBROUTINE READDATA) DO 101 I=2,NI XU(I)=ELBYH*((I-2)/FLOAT(NIM2)-1/(2*3.14159)*SIN(2*3.14159*(I-2) 1/FLOAT(NIM2))) 101 CONTINUE DO 105 J=2,NJ YV(J)=((J-2)/FLOAT(NJM2)-1/(2*3.14159)*SIN(2*3.14159*(J-2) 1/FLOAT(NJM2))) 105 CONTINUE In the example presented above a sine function is used for generating the staggered grid in the x and y directions. This function can be expressed mathematically as:
xu (i ) i − 2 1 i ⎞ ⎛ sin ⎜ 2π = − ⎟ H i max 2π ⎝ i max ⎠
i=imin, imax
yv( j ) j−2 1 i ⎞ ⎛ sin ⎜ 2π = − ⎟ H j max 2π ⎝ i max ⎠
j=jmin,jmax
where imin=jmin=2, imax=NI-2 and jmax=NJ-2
.
The sine function gives rise to a non-uniform grid which is closely spaced near the wall and sparsely spaced away from the wall. Similarly any other function can be used to define the staggered grid. ELBYH represents the ratio of the length to the height of the cavity. Once the staggered grid is generated, the main grids are created by using the staggered grid co-ordinates in SUBROUTINE INIT. X(I) and Y(J) represent the main grid locations. 13
PROGRAM NATCOM
SUBROUTINE INIT INCLUDE 'common.h' C
CALCULATE GEOMETRICAL QUANTITIES X(1)=XU(2) X(NI)=XU(NI) DO 101 I=2,NIM1 101 X(I)=0.5*(XU(I+1)+XU(I)) Y(1)=YV(2) Y(NJ)=YV(NJ) DO 102 J=2,NJM1 102 Y(J)=0.5*(YV(J+1)+YV(J))
C
DXPW(1)=0.0 (DXPW(I), distance between two consecutive main grid points in the x-direction
C
starting from X(2) to X(NI))
C
DXEP(NI)=0.0 (DXEP(I), distance between two consecutive main grid points in the x-direction
C
starting from X(1) to X(NIM1))
DO 103 I=1,NIM1 DXEP(I)=X(I+1)-X(I) 103 DXPW(I+1)=DXEP(I)
C
DYPS(1)=0.0 (DYPS(J), distance between two consecutive main grid points in the y-direction
C
starting from Y(2) to Y(NJ))
C C
DYNP(NJ)=0.0 (DYNP(J), distance between two consecutive main grid points in the y-direction starting from Y(1) to Y(NJM1))
DO 104 J=1,NJM1 DYNP(J)=Y(J+1)-Y(J) 104 DYPS(J+1)=DYNP(J)
14
PROGRAM NATCOM
C
DXPWU(1)=0.0 DXPWU(2)=0.0 (DXPWU(I), distance between two consecutive staggered grid locations in the x-
C
direction starting from XU(3) to XU(NI))
C
DXEPU(1)=0.0 DXEPU(NI)=0.0 (DXEPU(I), distance between two consecutive staggered grid locations in the x-
C
direction starting from XU(2) to XU(NIM1)) DO 105 I=2,NIM1 DXEPU(I)=XU(I+1)-XU(I) 105 DXPWU(I+1)=DXEPU(I)
C
DYPSV(1)=0.0 DYPSV(2)=0.0 (DYPSV(J), distance between two consecutive staggered grid locations in the y-
C
direction starting from YV(3) to YV(NJ))
C
DYNPV(1)=0.0 DYNPV(NJ)=0.0 (DYNPV(J), distance between two consecutive staggered grid locations in the y-
C
direction starting from YV(2) to YV(NJM1))
DO 106 J=2,NJM1 DYNPV(J)=YV(J+1)-YV(J)
106 DYPSV(J+1)=DYNPV(J)
C
DO 107 I=1,NI 107 SEW(I)=DXEPU(I) (SEW(I), area associated with the non-staggered control volume in the x-direction)
C
DO 108 J=1,NJ 108 SNS(J)=DYNPV(J) (SNS(J), area associated with the non-staggered control volume in the y-direction)
C
DO 109 I=1,NI 109 SEWU(I)=DXPW(I) (SEWU(I), area associated with the staggered control volume in the x-direction)
110
DO 110 J=1,NJ SNSV(J)=DYPS(J) 15
PROGRAM NATCOM
C
(SNSV(J), area associated with the staggered control volume in the y-direction)
As already mentioned the walls of the cavity are located at the staggered locations in order to facilitate the application of the no-slip and impermeable boundary conditions. Thus XU(2), XU(NI), YV(2) and YV(NJ) are located on the cavity walls. The main grid locations, X(1), X(NI), Y(1) and Y(NJ) are set equal to XU(2), XU(NI), YV(2) and YV(NJ) respectively. X(1), X(NI), Y(1) and Y(NJ) are dummy points and are not used for calculations. Such an allocation also enables the use of natural boundary conditions for temperature at the wall. All other non-staggered locations are positioned in between the staggered locations.
Before carrying out calculations all the necessary data are read in by using SUBROUTINE READDATA. This subroutine in turn reads in the data file “IN.DAT”.
SUBROUTINE READDATA INCLUDE 'common.h' C
The include statement in FORTRAN does away with all common statements. This
C
information is stored in the include file common.h.
1 C
LOGICAL INCALU,INCALV,INCALP,INPRO,INCALK,INCALD,INCALM ,INCALT,INHY,INCEN,STEADY These are logicals and are defined at the end of this listing. OPEN(2,FILE='in.dat')
C C
The file in.dat contains input parameters and is given in Section 17. GRID, ITERATION AND COMPARISON PARAMETERS READ(2,'(/////)') READ(2,*)GREAT,NITER,SMALL,NFTSTP,NLTSTP,STEADY,TFIRST WRITE(*,*)"GREAT NITER SMALL NFTSTP NLTSTP STEADY TFIRST" WRITE(*,*)GREAT,NITER,SMALL,NFTSTP,NLTSTP,STEADY,TFIRST READ(2,*) IF(STEADY)NFTSTP=1 IF(STEADY)NLTSTP=1 IF(STEADY) DT(1)=GREAT READ(2,*)IT,JT WRITE(*,*)"IT JT" WRITE(*,*)IT,JT READ(2,'(/)')
16
PROGRAM NATCOM
READ(2,*)NSWPU,NSWPV,NSWPP,NSWPK,NSWPD,NSWPT WRITE(*,*)"NSWPU NSWPV NSWPP NSWPK NSWPD NSWPT" WRITE(*,*)NSWPU,NSWPV,NSWPP,NSWPK,NSWPD,NSWPT READ(2,'(/)') READ(2,*)NI,NJ,ELBYH WRITE(*,*)"NI NJ ELBYH" WRITE(*,*)NI,NJ,ELBYH C
TIME STEP FOR UNSTEADY CALCULATIONS READ(2,'(/)') READ(2,*)TSTEP WRITE(*,*)"TSTEP" WRITE(*,*)TSTEP
C
DEPENDENT VARIABLE, DISCRETIZATION AND RESTART OPTIONS READ(2,'(/)') READ(2,*)INCALU,INCALV,INCALP,INCALK,INCALD,INPRO,INCALT WRITE(*,*)"INCALU INCALV INCALP INCALK INCALD INPRO INCALT" WRITE(*,*)INCALU,INCALV,INCALP,INCALK,INCALD,INPRO,INCALT READ(2,*) READ(2,*)INCALB,INHY,INCEN,VALUE WRITE(*,*)"INCALB INHY INCEN VALUE" WRITE(*,*)INCALB,INHY,INCEN,VALUE
C
FLUID PROPERTIES READ(2,'(/)') READ(2,*)DENSIT,PRANDL,VISCOS,CPP WRITE(*,*)"DENSIT PRANDL VISCOS CPP" WRITE(*,*)DENSIT,PRANDL,VISCOS,CPP
C
ALPHAF represents the thermal diffusivity of the fluid and is defined as α = ALPHAF=VISCOS/(DENSIT*PRANDL)
C
C
TURBULENCE CONSTANTS READ(2,'(/)') READ(2,*)CMU,CD,C1,C2,CAPPA,ELOG,PRTE,PRANDT WRITE(*,*)"CMU CD C1 C2 CAPPA ELOG PRTE PRANDT" WRITE(*,*)CMU,CD,C1,C2,CAPPA,ELOG,PRTE,PRANDT READ(2,*) READ(2,*)F1,F2 WRITE(*,*)"F1,F2" WRITE(*,*)F1,F2 PRED represents σε, the turbulent Prandtl number for ε. PRED=CAPPA*CAPPA/(C2-C1)/(CMU**.5) 17
µ ρ Pr
PROGRAM NATCOM
PFUN=PRANDL/PRANDT PFUN=9.24*(PFUN**0.75-1.0)*(1.0+0.28*EXP(-0.007*PFUN)) C
BOUNDARY VALUES READ(2,'(/)') READ(2,*)TH,TC WRITE(*,*)"TH TC" WRITE(*,*)TH,TC
C
INTERNAL HEAT GENERATION AND RAYLEIGH NUMBER READ(2,'(/)') READ(2,*)QGENER,RALI WRITE(*,*)"QGENER RALI" WRITE(*,*)QGENER,RALI
C
TREF represents the reference temperature.
C
BEITA represents β, the thermal expansion coefficient of the fluid.
C
DELT represents ∆T. TREF=(TC+TH)/2 BEITA=1/(273.15+TREF) DELT=TH-TC
C
PRESSURE CALCULATION READ(2,'(/)') READ(2,*)IPREF,JPREF WRITE(*,*)"IPREF JPREF" WRITE(*,*)IPREF,JPREF
C
PROGRAM CONTROL AND MONITOR READ(2,'(/)') READ(2,*)MAXIT,IMON,JMON,URFU,URFV WRITE(*,*)"MAXIT IMON JMON URFU URFV" WRITE(*,*)MAXIT,IMON,JMON,URFU,URFV READ(2,*) READ(2,*)URFP,URFE,URFK,URFT WRITE(*,*)"URFP URFE URFK URFT" WRITE(*,*)URFP,URFE,URFK,URFT READ(2,*) READ(2,*)URFG,URFVIS,INDPRI,SORMAX WRITE(*,*)"URFG URFVIS INDPRI SORMAX" WRITE(*,*)URFG,URFVIS,INDPRI,SORMAX
C
CAVITY DIMENSIONS H=((RALI*VISCOS*ALPHAF)/(DENSIT*9.81*BEITA*DELT))**0.3333 C EL represents L the length of the cavity 18
PROGRAM NATCOM
EL=H*ELBYH C
GRID GENERATION FUNCTIONS NIM1=NI-1 NJM1=NJ-1 NIM2=NI-2 NJM2=NJ-2
DO 101 I=2,NI XU(I)=ELBYH*((I-2)/FLOAT(NIM2)-1/(2*3.14159)*SIN(2*3.14159*(I-2) 1/FLOAT(NIM2))) 101 CONTINUE DO 105 J=2,NJ YV(J)=((J-2)/FLOAT(NJM2)-1/(2*3.14159)*SIN(2*3.14159*(J-2) 1/FLOAT(NJM2))) 105 CONTINUE C
NON-DIMENSIONALISATION
C
UREF represents uref, the reference value for velocity. UREF=ALPHAF*(PRANDL*RALI)**0.5/H
C
R1 and R2 are the non-dimensional numbers given by
Pr and Ra
Pr Ra
R1=(PRANDL/RALI)**0.5 R2=(PRANDL*RALI)**0.5 CLOSE(2) RETURN END
Following is a listing of the quantities read in from the input data file in.dat. C
GREAT represents a large number that is sometimes used for comparison or for some special purpose like assigning the boundary condition for ε=∞.
C
NITER represents the iteration counter for iterations in a single time step.
C
SMALL represents a small number that is used for some special purpose in the program such as preventing division by zero.
C
NFTSTP represents the first iteration step for time iterations.
19
PROGRAM NATCOM
C
NLTSTP represents the last iteration step for time iterations.
C
STEADY is a LOGICAL . IF STEADY is TRUE then the unsteady terms are omitted from the calculation procedure.
C
TFIRST represents the starting value assigned to time t.
C
IT and JT represent the maximum values that NI and NJ can have. If NI and NJ exceed the value of IT and JT respectively, new values have to be assigned to IT and JT. The program should then be recompiled.
C
NSWPU, NSWPV, NSWPP, NSWPK, NSWPD, NSWPT are the total number of internal iterations used to calculate u, v, p’, k, ε and T respectively.
C
NI and NJ are the total number of grids in the x and y directions respectively.
C
ELBYH represents the ratio of length to height of the cavity.
C
TSTEP represents the time step for unsteady calculations.
C
LOGICALS INCALU, INCALV, INCALP, INCALK, INCALD, INPRO, INCALT activate SUBROUTINES CALCU, CALCV, CALCP, CALCTE, CALCED, PROPS, CALCT respectively.
C
LOGICAL INCALB activates the buoyancy terms.
C
LOGICALS INHY and INCEN activate the hybrid and central schemes respectively.
C
If VALUE equals one, the program uses an initial field that has been fed in by the user. If VALUE equals zero, the program uses the solution that has been dumped in the DUMP file as the initial field. Thus for any fresh calculations, VALUE should always be one.
C
DENSIT-fluid density.
C
PRANDL-fluid Prandtl number.
C
VISCOS-fluid viscosity.
C
CMU-turbulence model constant, cµ.
C
CD-damping factor, fµ.
C
C1-turbulence model constant, cε1.
20
PROGRAM NATCOM
C
C2-turbulence model constant, cε2.
C
CAPPA-Von Karman’s constant, κ.
C
ELOG- represents cκ where c is given by lnc=5.5 and κ is Von Karman’s constant.
C
PRTE-represents σκ.
C
PRANDT-represents turbulent Prandtl number, σT.
C
F1-damping factor, f1.
C
F2-damping factor, f2.
C
TH-temperature of the hot wall, Th.
C
TC-temperature of the cold wall, Tc.
C
QGENER-internal heat generation equals zero for the present problem.
C
CPP-specific heat of the fluid, CP.
C
RALI-Rayleigh number.
C
IPREF, JPREF-position of reference value for guessed pressure.
C
MAXIT-maximum number of space iterations (i.e., number of iterations inside one time step).
C
IMON, JMON- monitoring location for different variables.
C
URFU-under-relaxation factor for u.
C
URFV-under-relaxation factor for v.
C
URFP-under-relaxation factor for p.
C
URFE-under-relaxation factor for ε.
C
URFK-under-relaxation factor for k.
C
URFT-under-relaxation factor for T.
C
URFG-under-relaxation factor for µ/Pr or (µ+µt)/Pr.
C
URFVIS-under-relaxation factor for µ or (µ+µt).
C
INDPRI-number of iterations after which labels are printed on the screen.
C
SORMAX-convergence criterion.
The variables are initialized in SUBROUTINE INIT immediately after the subsection CALCULATE GEOMETRICAL QUANTITIES. C
Note that the following is a part of SUBROUTINE INIT
C
SET VARIABLES TO SMALL VALUE
21
PROGRAM NATCOM
C
UO(I,J), VO(I,J), PO(I,J), TO(I,J), TEO(I,J), EDO(I,J), DENO(I,J) represent the old value (i.e.,values at the previous time iteration for the respective variables) DO 200 I=1,NI DO 200 J=1,NJ
C
SMALL is used as an initial field to prevent division by zero. U(I,J)=SMALL UO(I,J)=SMALL V(I,J)=SMALL VO(I,J)=SMALL P(I,J)=SMALL PO(I,J)=SMALL PP(I,J)=SMALL T(I,J)=0.5 TO(I,J)=0.5 TE(I,J)=SMALL TEO(I,J)=SMALL ED(I,J)=SMALL EDO(I,J)=SMALL DEN(I,J)=1.0+SMALL DENO(I,J)=1.0+SMALL VIS(I,J)=1.0+SMALL GAMH(I,J)=1.0+SMALL DU(I,J)=0.0 DV(I,J)=0.0
C
DU(I,J) and DV(I,J) are quantities associated with the velocity correction equation.
C
The velocity correction equation is discussed in Section 9. SU(I,J)=0.0
C
SU(I,J) represents the overall source term and is equivalent to term b in Patankar
C
(1980).
SP(I,J)=0.0 C SP(I,J) represents SP in S=SC+SP. 200 CONTINUE DO 201 J=1,NJ T(1,J)=1.0 201 T(NI,J)=0.0 RETURN END
22
PROGRAM NATCOM
6. PROGRAM FLOW CHART Initialization and Input of Data INIT and READDATA
Time Loop for Unsteady Calculations
Guess the Pressure field Solve the momentum equations (u and v velocity) to arrive at a guessed velocity CALCU and CALCV
Solve the pressure correction equation CALCP
Compute new pressure field by adding the pressure correction to the guessed pressure
Calculate the new velocities from their old values using the velocity correction formulae
Treat the new pressure field as the guessed pressure field.
No
Solve equations for k, ε and T CALCTE, CALCED, CALCT
Yes
Converged?
Yes
time