Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Computational Fluid Dynamics Fundamentals Course 2

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

Computational Fluid Dynamics

Fundamentals Course 2
Table of Contents

Foreward 4

How To Use This Course 5

Dirichlet and Neumann Boundary Conditions 7

Transport Equations in 2D 24

Wall Functions 42

2
Disclaimer

The exercises, software, code and equations in this course are for educational and demonstrative
purposes only. They should not be used to analyse, design, test, accredit or validate real
scientific/engineering/mathematical structures and flow systems. For such applications,
appropriate trained, qualified and accredited engineers/scientists should be consulted. Fluid
Mechanics 101 and Dr. Aidan Wimshurst are not accountable or liable in any form for the
use or misuse of the information contained in this course beyond the specific educational and
demonstrative purpose for which it was intended.

3
Foreward

Welcome to Part 2 of my Computational Fluid Dynamics Fundamentals Course! This course is a


natural extension of the previous course (Part 1) and uses the same foundational ideas and
approach. The aim of Part 2 is to introduce new concepts that were not covered in Part 1 and are
essential for understanding the CFD solution process. Neumann (fixed gradient) boundary
conditions are introduced for the first time and are compared with the Dirichlet (fixed value)
boundary conditions from the previous course. Having studied these foundational boundary
conditions, more complex boundary conditions (inlet, outlet, symmetry etc.) can be readily
understood. This course then proceeds to assess the flux balances for all the cells in the mesh
and extends the CFD analysis to 2D structured meshes.

In the final section of the course, wall functions are introduced for the first time. Wall functions
are used by all modern CFD codes to ensure that the correct wall shear stress, wall heat flux
and near wall turbulence are computed when the mesh is coarse. The wall functions required
for the shear stress and heat flux are derived and a comprehensive example is provided to show
how they are implemented. To my knowledge this is the first time such an example has
been provided (in a textbook or reference of any form) and should really help your understanding
of how wall functions are really implemented by CFD codes. As before, the entire process is
transparent and documented/explained and no specific CFD code is required, as working examples
are provided in Python and Excel.

I am really excited to bring you this course and know that you will find it as useful as I have.
The interactive exercises may even answer some long standing technical questions that you never
found the answer to.

All the best


Aidan

4
How To Use This Course

This course contains a comprehensive set of equations, explantations and diagrams, which are
all contained in this PDF book. As you proceed through Chapter 1, 2 and 3, worked
examples are provided. When instructed, it is advied that you open the example code (either in
Microsoft Excel or in a suitable text editor/graphical user interface (GUI) for Python). Here
you will be able to examine the code, modify the input variables and run the CFD simuations
yourself. This is where the majority of the learning is likely to take place and is highly
encouraged for all readers.

All of the exercises can be completed using either the Excel or Python scripts. Use
whichever approach is more appealing and straightforward for you to follow. Alternatively,
you can use the equations that are provided in the text to write your own code/scripts to
solve the equations! The aim of this course is not to develop knowledge of a specific language
or CFD code, but to learn and observe the overall process. Hence, it is highly encouraged for
you to take your preferred approach.

5
Chapter 1
Dirichlet and Neumann Boundary Conditions
1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

1 Dirichlet and Neumann Boundary Conditions


In this chapter, the finite volume discretisation of the 1D diffusion equation from the previous
course will be revisited. The diffusion equation will be used to introduce Neumann (fixed
gradient) boundary conditions for the first time and revisit Dirichlet (fixed value) boundary
conditions. While a general diffusion equation can be used to describe many transported
quantities, the diffusion equation for thermal energy (temperature) will be considered in this
course, as it is the easiest to physically interpret. Mathematically, the general scalar transport
equation for thermal energy (temperature) for incompressible (low speed) flows is:

∂ (ρcp T )
+ ∇ · (ρcp T U ) = ∇ · (k∇T ) +S (1)
| ∂t
| {z }
{z } | {z }
Diffusion
Convection
Unsteady

where T is the temperature, ρ is the density, cp is the specific heat capacity at constant
pressure, k is the thermal conductivity, U is the velocity vector and S is a source of thermal
energy. Some readers may recognise this equation as the transport equation for enthalpy. To
observe the transport equation for enthalpy (h), define h = cp T and substitute in to equation
1:
∂(ρh)
+ ∇ · (ρU h) = ∇ · (k∇T ) + S (2)
∂t
However, this form of the thermal energy equation will not be used in this course, as temper-
ature is an easier variable to interpret and follow than enthalpy.
The focus of this chapter will be the diffusion and source terms in equation 1, since
the convection term was considered in the previous course and the unsteady term will be
considered in a later course. Neglecting the convection and unsteady terms in equation 1, the
diffusion equation for thermal energy is:
0
∂ (ρc T
p
*) :0
 + ∇ · (ρc
 p
T U ) = ∇ · (k∇T ) + S (3)
∂t 

0 = ∇ · (k∇T ) + S (4)
Expanding the gradient (∇) and divergence (∇·) operators into Cartesian coordinates (x, y, z):
! ! !
∂ ∂T ∂ ∂T ∂ ∂T
0= k + k + k +S (5)
∂x ∂x ∂y ∂y ∂z ∂z

To clearly demonstrate how Dirichlet and Neumann boundary conditions are implemented by
CFD solvers, the diffusion equation will only be considered in 1D (the x direction) in this
chapter. 2D geometries will be considered later in Chapter 2 of this course. In 1D, the
diffusion equation for thermal energy (temperature) is:
! *0
! *0
!
∂ ∂T ∂ ∂T ∂ ∂T
 

 
0= k + k + k +S (6)
∂x ∂x ∂y ∂y
 ∂z ∂z

!
d dT
0= k +S (7)
dx dx
The majority of modern CFD codes use the finite volume method to solve the transport
equations for the various flow variables (velocity, temperature, pressure etc.). In the previous

Dr. Aidan Wimshurst, Fluid Mechanics 101 7


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

1D Bar
Control Volume

Figure 1: A 1D finite volume of fluid with volume V , which has been isolated from the bar.

course, the finite volume method was reviewed in detail. To avoid repetition, only a concise
overview of the finite volume method will be provided here, to ensure that the derivation and
solution presented is continuous and coherent. Further detail can be found in the previous
course. The first stage in the finite volume method is to integrate the transport equation over
a finite-sized control volume (cell). As shown in Figure 1, a 1D cell can be thought of as a
slice through a thin 1D bar or rod. Integrating the 1D diffusion equation (equation 7) over
this cell: Z " ! #
d dT
0= k + S dV (8)
V dx dx
Integration and addition are commutative operations (is doesn’t matter what order they are
carried out in). Hence, the finite volume integral can be split into two separate integrals and
each one can then be considered in turn.
Z " !#
d dT Z
0= k dV + [S] dV (9)
V dx dx V

As shown in the previous course, Gauss’s divergence theorem is used to replace the volume
integral of the diffusion term with a surface integral. Recall (from the previous course) that
the divergence theorem for a general vector field B is written as:
Z Z
(∇ · B) dV = (B · n̂) dA (10)
V A

where n̂ is the unit normal vector pointing out of the control volume and A is the surface area
of the control volume. In 1D Cartesian coordinates, the divergence theorem can be written:
!
Z
∂Bx ∂By ∂Bz Z
+ + dV = (Bx nx + By ny + Bz nz ) dA (11)
V ∂x ∂y ∂z A

0 0

0
!
 ∂Bx ∂By
7 ∂Bz 0
Z Z

 ∂x +  +  dV = Bx nx + 
Byny + 
*

Bz nz dA
:

 (12)
V ∂y ∂z 
A

!
Z
∂Bx Z
dV = (Bx nx ) dA (13)
V ∂x A

For the heat diffusion equation B = k∇T . Hence Bx = k ∂T /∂x in 1D. Applying the 1D
divergence theorem to the 1D heat diffusion equation leads to:
Z " #
dT Z
0= k nx dA + [S]dV (14)
A dx V

Dr. Aidan Wimshurst, Fluid Mechanics 101 8


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Left face Right face

Figure 2: A diagram to show the face normal vectors on the left and right faces of the 1D
cell. The cell normal vectors always point out of the cell.

The source term is averaged over the control volume, so it can be moved outside the volume
integral.
Z " #
dT Z
0= k nx dA + S dV (15)
A dx V
Z " #
dT
0= k nx dA + SV (16)
A dx
Recall that the unit normal vector (nx ) always points out of the cell. As shown in Figure 2,
on the left face of the cell (l), the unit normal vector is negative. Conversely, the unit normal
vector is positive on the right face of the cell (r).
" # " #
dT dT
0 = kA − kA + SV (17)
dx r
dx l

This finite volume discretisation is valid for all cells in the mesh. However, different simplifi-
cations are required for interior and boundary cells before the equations can be solved.

Interior Cells
Start with the general finite volume discretisation of the 1D diffusion equation.
" # " #
dT dT
0 = kA − kA + SV (18)
dx r
dx l

To simplify and solve this equation for the interior cells, the temperature gradient on the cell
faces (l and r) needs to be expressed in terms of temperatures at the cell centroids (L, R and
P ). This is because the unknowns in the matrix equations are the temperatures at the cell
centroids and other variables need to be expressed in terms of these temperatures. Hence,
the temperature (and other variables) are calculated and stored at the cell centroids, rather
than the nodes or faces. This approach is called a cell-centred finite volume method and
is used by the CFD codes OpenFOAM, ANSYS Fluent and Star CCM+ but not ANSYS CFX
(which uses a node based finite volume method).
Throughout this course, the lower case subscripts (l and r) will be used to refer to cell
faces, while upper-case subscripts (L, R and P ) will be used to refer to cell centroids, as shown
in Figure 3. This notation has been chosen because the temperatures at the cell centroids are
the unknowns in the system. The necessary simplification of the gradients on the cell faces
can be accomplished with linear interpolation, which is often called central-differencing. To

Dr. Aidan Wimshurst, Fluid Mechanics 101 9


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Left Cell Left Face Right Face Right Cell

Figure 3: A diagram to show the difference between the temperatures on the cell faces (Tl
and Tr ) and the temperature at the cell centroids (TL and TR ).

Left face Right face

Figure 4: Central differencing (linear interpolation) of the temperature gradient on the left
face of the cell using the values at the cell centroids of the interior cell (TP ) and the left cell
(TL ).

help understand this simplification, remember that the spatial gradient of temperature can be
thought of as:
dT ∆T Change in Temperature
∼ = (19)
dx ∆x Distance
As shown in Figure 4, the temperature gradient on the left face can be expressed using central
differencing as: !
dT TP − TL
= (20)
dx l dLP
where dLP is the distance between the cell centroids L and P . In a similar manner, the
temperature gradient on the right face can also be expressed using central differencing:
!
dT TR − TP
= (21)
dx r
dP R

Substitute this simplification into the 1D diffusion equation (equation 18).


TR − TP TP − TL
   
kr Ar − kl Al + SV = 0 (22)
dP R dLP
The 1D diffusion equation can now be solved for the temperatures at the cell centroids (TL , TR
and TP ). To simplify this process, rearrange the equation and collect the terms in terms of
temperature of the interior cell (TP ), temperature of the left cell (TL ) and the temperature
of the right cell (TR ).
! ! !
kl Al kr Ar kl Al kr Ar
TP + = TL + TR + SV (23)
dLP dP R dLP dP R

Dr. Aidan Wimshurst, Fluid Mechanics 101 10


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

At this stage, it is useful to introduce some new notation to simplify the finite volume dis-
cretisation. This new notation makes it easier to compare the finite volume discretisation of
interior cells, boundary cells and add additional terms to the equation later on. The approach
adopted in the previous course was to introduce the notation D = k/d. This quantity can be
thought of as the diffusive flux of heat per unit area through the cell face and has units of
W/m2 K. Using this notation, the finite volume discretiation becomes:
TP (Dl Al + Dr Ar ) = TL (Dl Al ) + TR (Dr Ar ) + SV (24)
For consistency with other equations that will be introduced later, write the above equation
in the following form:
ap TP = aL TL + aR TR + Su
TP (Dl Al + Dr Ar + 0) = TL (Dl Al ) +TR (Dr Ar ) + |{z}
SV (25)
| {z } | {z } | {z }
ap aL aR Su

This equation is valid for all cells in the mesh, except for the boundary cells. The boundary
cells have to be considered separately.
Equation 23 can also be written using summation notation:
X
ap TP = aN TN + Su
N

X kN AN kN AN
ap = |n̂| aN = |n̂| Su = SV (26)
N |dP N | |dP N |
where the summation is taken over the N cell neighbours. For 1D cells, N = 2. However, for
2D and 3D meshes, the summation notation becomes more useful as each cell has multiple
cell neighbours and the finite volume discretisation can become quite long (this will be shown
in Chapter 2)! Also notice that in the summation notation, the magnitude of the unit normal
vector |n̂| and the vector |d| are used. This is permissible because the unit normal vector
and the vector d are parallel with eachother. In turn this is because the mesh used in this
course is structured and orthogonal. Special treatment is required for non-orthogonal and
unstructured meshes. However, the special treatment required for these meshes will not be
considered in this course (for brevity).

Boundary Cell (Left) - Dirichlet Boundary Condition


Now the boundary conditions on the left hand boundary cell will be considered, starting with
the Dirichlet (fixed temperature) condition. Figure 5 shows a schematic diagram of this cell,
with a fixed temperature Tw applied at the wall. The general finite volume discretisation for
the 1D diffusion equation is:
! !
dT dT
kA − kA + SV = 0 (27)
dx r
dx l

The right face of the boundary cell is connected to an interior cell. Hence, the same central
differencing scheme for the temperature gradient from the previous section can be used for
the right face. However, the left face is connected to a boundary. As shown in Figure 5, the
temperature gradient term for the left face is:
!
dT TP − Tw
= (28)
dx l
dLP /2

Dr. Aidan Wimshurst, Fluid Mechanics 101 11


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Boundary Cell (Left) Right Cell

Figure 5: The left boundary cell with temperature TP at its centroid. The shared face
between the boundary cell and the right cell is at a temperature Tr and the wall has a
temperature Tl = Tw .

The factor of 1/2 is required as the distance from the cell centroid to the face is 1/2 of
dLP (the distance from the cell centroid to the cell centroid of the adjacent cell). The finite
volume discretisation of the 1D heat-diffusion equation for the left boundary cell is now:
!
TR − TP TP − Tw
 
kr A r − kl Al + SV = 0 (29)
dP R dLP /2
Again, introduce the notation D = k/d for the diffusive heat flux per unit area.
TP (2Dl Al + Dr Ar ) = TR (Dr Ar ) + Tw (2Dl Al ) + SV (30)
For consistency with the interior cell, write in the standard form:
ap Tp = aL TL + aR TR + Su (31)
TP (0 + Dr Ar + 2Dl Al ) = TL (0) +TR (Dr Ar ) + Tw (2Dl Al ) + SV (32)
| {z } |{z} | {z } | {z }
aP aL aR Su

For comparison with the interior cell, the boundary cell (left) has the following coefficients:
aL = 0 aR = Dr Ar ap = aL + aR − Sp (33)
SP = −2Dl Al Su = SV + Tw (2Dl Al ) (34)
It follows that the boundary temperature Tw enters the equation through the source terms Su
and Sp . The left coefficient aL is also set to zero, as this face is not connected to an interior
cell. Using summation notation, the finite volume discretisation for the boundary cell can be
written: X
ap TP = aN TN + Su
N
!
X kN AN kw Aw kN AN
ap = |n̂| + |n̂| aN = |n̂|
N |dP N | |dLP |/2 |dP N |
!
kw Aw
Su = SV + Tw |n̂| (35)
|dLP |/2
When using summation notation, it should be noted that aN = 0 for the left boundary face
and the summation for aP does not include the left boundary face. The wall temperature
enters the equation through the source terms Su and Sp as before.

Dr. Aidan Wimshurst, Fluid Mechanics 101 12


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Boundary Cell (Left) Right Cell

Figure 6: The left boundary cell with a temperature TP at its centroid. The shared face
between the boundary cell and the right cell is at a temperature Tr and a fixed heat flux of
qw is applied at the left boundary face. Positive qw indicates heat passing out of the domain.

Boundary Cell (Left) - Neumann Boundary Condition


Figure 6 shows a schematic diagram of the same boundary cell, but with a fixed heat flux (per
unit area) qw applied at the left wall, instead of a fixed temperature Tw . Mathematically, the
heat flux from the wall (per unit area) qw is given by Fourier’s law:
qw = −k∇T · n̂ [W/m2 ] (36)
!
∂T ∂T ∂T
qw = −k , , · (nx , ny , nz ) (37)
∂x ∂y ∂z
!
∂T ∂T ∂T
qw = −k nx + ny + nz (38)
∂x ∂y ∂z
where n̂ is the unit normal vector out of the cell into the wall. The negative sign is required
to ensure that the heat flows in the opposite direction to the temperature gradient (high
temperature to low temperature). In 1D, Fourier’s Law for the wall heat flux reduces to:

0 0
 ∂T ∂T ∂T
7 
qw = −k  nx +  ny +  nz  (39)
 ∂x ∂y ∂z

dT
qw = −k nx [W/m2 ] (40)
dx
Hence, the fixed heat flux boundary condition is a type of Neumann boundary condition, as
the heat flux (qw ) is being used to set the temperature gradient at the wall. To understand
how heat flux boundary conditions are applied, the finite volume discretisation for a general
1D cell needs to be revisited.
! !
dT dT
kA nx + kA nx +SV = 0 (41)
dx r
dx l
| {z } | {z }
Heat Flux Right Face Heat Flux Left Face

The underlined terms in the above equation actually represent the heat flux out of the left
and right faces of the cell. To understand why, consider Fourier’s Law in 1D across an interior
face in the mesh:
dT
q = −k nx [W/m2 ] (42)
dx

Dr. Aidan Wimshurst, Fluid Mechanics 101 13


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

(a) (b)
Boundary Cell (Left) Interior Cells

Figure 7: Diagram to show the sign convention for positive heat flux through the (a)
boundary and (b) interior faces of the mesh.

Substitute this form of Fourier’s Law into the finite volume discretisation for the interior cells
(equation 41):
(−qr Ar ) + (−ql Al ) +SV = 0 (43)
| {z } | {z }
As the unit normal vector always points out of the cells, each underlined term in the above
equation represents a heat flux out of the cell, across its faces (except for the source term
SV ). Once again, the negative sign ensures that the heat flows in the opposite direction to
the temperature gradient (high temperature to low temperature).
When considering the left boundary cell in Figure 6, a fixed heat flux qw is applied at the
left face.
dT
qw = −kl nx [W/m2 ] (44)
dx
It should be noted that the heat flux out of the wall into the fluid is equal and opposite
the heat flux out of the fluid into the wall. For consistency, the convention of positive heat
flux passing out of the fluid cell into the wall will be taken as positive (qw > 0), while
heat flux passing out of the wall into the fluid will be taken as negative (qw < 0). Figure 7
shows a schematic diagram to highlight the heat flux sign convention adopted for boundary
and interior cells. Returning to Figure 6, the heat flux across the right face (interior face) of
the left boundary cell can be calculated using central differencing from the previous section.
Hence, the finite volume discretisation for this boundary cell becomes:
TR − TP
 
kr Ar − qw Al + SV = 0 (45)
dP R
As the boundary heat flux per unit area (qw ) has units of W/m2 , it is multiplied by the face
area to obtain the correct units of W. To simplify this equation further, the diffusive heat flux
per unit area (D = k/d) will be introduced again.

Dr Ar (TR − Tp ) − qw Al + SV = 0 (46)

TP (Dr Ar ) = TR (Dr Ar ) − qw Al + SV (47)


For consistency with the interior cell, write in the standard form:

ap Tp = aL TL + aR TR + Su (48)

TP (0 + Dr Ar + 0) = TL (0) +TR (Dr Ar ) + −qw Al + SV (49)


| {z } |{z} | {z } | {z }
aP aL aR Su

Dr. Aidan Wimshurst, Fluid Mechanics 101 14


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Hence, the boundary cell (left) has the following coefficients when a Neumann condition is
applied:
aL = 0 aR = Dr Ar ap = aL + aR − Sp (50)
SP = 0 Su = SV − qw Al (51)
Using summation notation, the finite volume discretisation for boundary cells with Neumann
boundary conditions can be written:
X
ap TP = aN TN + Su
N
!
X kN AN kN AN
ap = |n̂| aN = |n̂| Su = SV − qw Al
N |dP N | |dP N |
As before, the coefficient aN = 0 for boundary faces. Notice that unlike the Dirichlet boundary
condition, the Neumann boundary condition (qw ) only makes a contribution to Su and not
aP .

Summary of Coefficients
A summary of the finite volume coefficients is provided in the table below for interior and
boundary cells. Notice that the only difference between the Dirichlet and Neumann boundary
conditions is the coefficients Su and Sp .

Dirichlet Boundary Condition

Cell Type aL aR aP Sp Su
Boundary (L) 0 Dr Ar al + ar − S p −2Dl Al Tw (2Dl Al ) + SV
Interior Dl Al Dr Ar al + ar − S p 0 SV
Boundary (R) Dl Al 0 al + ar − S p −2Dr Ar Tw (2Dr Ar ) + SV

Neumann Boundary Condition

Cell Type aL aR aP Sp Su
Boundary (L) 0 Dr Ar al + ar − Sp 0 −qw Al + SV
Interior Dl Al Dr Ar al + ar − Sp 0 SV
Boundary (R) Dl Al 0 al + ar − Sp 0 −qw Ar + SV

The summation notation can also be summarised in a table. However, rather than arrang-
ing by cell type, this table is arranged by the face type on each cell. The contribution of each
face to the cell total is then given (noting that we sum over the N cell faces):

Dr. Aidan Wimshurst, Fluid Mechanics 101 15


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Summation Notation

Face Type aP aN Su
kN AN kN AN
Interior |n̂| |n̂| 0
|dP N | |dP N | !
kw Aw kw Aw
Dirichlet |n̂| 0 Tw |n̂|
|dLP |/2 |dLP |/2

Neumann 0 0 −qw Aw

If the above (summation notation) table is used to assemble the equations, it should be
remembered that the additional volumetric source contribution (SV ), which is not included
in the table, is still required.

Assemble and Solve the Equations


As shown in the previous course, once the coefficients (aP , aL , aR , Su ) have been calculated,
the finite volume equations can be assembled in matrix form. Start by writing an equation
for each cell in the mesh. If the mesh has 5 cells, then the equations are:

Cell 1 Boundary Cell (Left) aP 1 T1 = aR1 T2 + Su1


Cell 2 Interior Cell aP 2 T2 = aL2 T1 + aR2 T3 + Su2
Cell 3 Interior Cell aP 3 T3 = aL3 T2 + aR3 T4 + Su3
Cell 4 Interior Cell aP 4 T4 = aL4 T3 + aR4 T5 + Su4
Cell 5 Boundary Cell (Right) aP 5 T5 = aL5 T4 + Su5

where the coefficients aP , aL , aR and Su are given in the summary in the previous section.
Rearrange the equations, so that all the temperatures (TP , TL and TR ) are on the left hand
side and the source terms (Su ) are on the right hand side.

Cell 1 Boundary Cell (Left) aP 1 T1 − aR1 T2 = Su1


Cell 2 Interior Cell −aL2 T1 + aP 2 T2 − aR2 T3 = Su2
Cell 3 Interior Cell −aL3 T2 + aP 3 T3 − aR3 T4 = Su3
Cell 4 Interior Cell −aL4 T3 + aP 4 T4 − aR4 T5 = Su4
Cell 5 Boundary Cell (Right) −aL5 T4 + aP 5 T5 = Su5

These equations can now be written concisely in matrix form (AT = B):
    
aP 1 −aR1 0 0 0 T1 Su1
−aL2 aP 2 −aR2 0 0  T2  Su2 
    
    
 0
 −aL3 aP 3 −aR3 0  T3  = Su3 
    (52)
 0

0 −aL4 aP 4 −aR4  T4 
 
Su4 
 
0 0 0 −aL5 aP 5 T5 Su5

Dr. Aidan Wimshurst, Fluid Mechanics 101 16


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

(a) (b)

1 2 3 4 5

Boundary Cells
Figure 8: An example problem to demonstrate 1D heat diffusion in a bar. Two cases will
be considered: (a) a fixed temperature (TA ) of 100◦ C at the left end of the bar and (b) a
fixed heat flux (qw ) of 100 W/m2 at the left end of the bar.

Notice that the matrices have a diagonal banded structure. This is because the mesh is struc-
tured (the cells are ordered in a regular pattern) and the coefficients represent the connectivity
to the neighbouring cells. The banded structure of the matrices will change slightly in later
chapters, when 2D meshes are considered.
Commercial CFD solvers populate the matrices by calculating the coefficients (al , ap and
ar ) automatically for the user and then solve the matrix equations. In the next section, the
entire process will be demonstrated with an example problem. A mesh will be defined, the
coefficients will be calculated and then the matrices will be constructed and solved.

Example Problem - Heat Diffusion in a Bar


To demonstrate the difference between the Neumann and Dirichlet boundary conditions an
example problem will now be considered. Consider 1D steady-state diffusion of heat in a
bar, as shown in Figure 8 (b). For ease of comparison, this example problem has the same
geometry, mesh and material properties as the previous course. However, at the left hand end,
a heat flux boundary condition will be applied (Figure 8 (b)), rather than a fixed temperature
boundary condition (Figure 8 (a)), as was applied in the previous course. The bar has a
length of 5m, a cross-sectional area of 0.1 m2 and a thermal conductivity of 100 W/mK. The
temperature at the right end of the bar (TB ) is 200◦ C. There is a constant heat source (S)
of 1000 W/m3 in the bar. At the left end of the bar, a fixed heat flux (qw ) of 100 W/m2
will be applied, rather than a fixed temperature (TA ) of 100◦ C, as was applied in the previous
course.

Step 1: Divide the Geometry into a Mesh


For the example in Figure 8, divide the geometry into a mesh of 5 cells of equal length. The
length of each cell (Lcell ) is given by:
L 5
Lcell = = = 1m (53)
N 5

Dr. Aidan Wimshurst, Fluid Mechanics 101 17


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Because the cells are uniformly distributed and have equal size, the distance between cell
centroids d is equivalent to the length of the cells. Hence:

dLP = dP R = d = 1m (54)

Step 2: Assign Material Properties


The thermal conductivity k and the cross-sectional area A are the same for every cell in the
mesh. Hence, the parameter DA is given by:
kA 100 ∗ 0.1
DA = = = 10 [W/K] (55)
d 1
The volumetric heat source in each cell is given by:

SV = SALcell = 1000 ∗ 0.1 ∗ 1 = 100 [W] (56)

Step 3: Calculate Matrix Coefficients


Now calculate the coefficients required to assemble the matrices. The most straightforward
way is to fill in the table of coefficients:

Neumann Boundary Conditions (at the left end of the bar)

aL aR Sp Su aP
Boundary (Left) 0 10 0 90 10
Interior 10 10 0 100 20
Boundary (Right) 10 0 -20 4100 30

For comparison, the matrix coefficients for the same problem with a Dirichlet boundary
condition (fixed temperature) at the left end are shown below. The differences between the
two sets of matrix coefficients are highlighted in red.

Dirichlet Boundary Conditions (at the left end of the bar)

aL aR Sp Su aP
Boundary (Left) 0 10 -20 2100 30
Interior 10 10 0 100 20
Boundary (Right) 10 0 -20 4100 30

Alternatively, the summation notation summary table can be filled in (noting that an
additional source SV = 100W is required in each cell):

Dr. Aidan Wimshurst, Fluid Mechanics 101 18


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Dirichlet Boundary Conditions (at the left end of the bar)

Face Type aP aN Su
Interior 10 10 0
Dirichlet (Left) 20 0 2000
Dirichlet (Right) 20 0 4000
Neumann (Left) 0 0 -10

Step 4: Assemble the Matrices


Assign the coefficients to their correct locations in the matrix. Note that the final matrices will
be identical, regardless of the method used to calculate the coefficients (summation notation,
D = k/d, or otherwise).
For the Neumann (fixed heat flux) boundary condition at the left end:
    
10 −10 0 0 0 T1 90
−10 20 −10 0 0  T2   100 
    
    
 0
 −10 20 −10 0  T3  =  100 
    (57)
 0

0 −10 20 −10  T4 
 
 100 
 
0 0 0 −10 30 T5 4100

and for the Dirichlet boundary condition (fixed temperature) at the left end:
    
30 −10 0 0 0 T1 2100
−10 20 −10 0 0  T2   100 
    
    
 0
 −10 20 −10 0  T3  =  100 
    (58)
 0

0 −10 20 −10  T4 
 
 100 
 
0 0 0 −10 30 T5 4100

Once again, the differences between the Dirichlet and Neumann boundary conditions are
highlighted in red.

Step 5: Solve the Equations


Now that the matrices have been assembled, the matrix equation can solved with an appro-
priate iterative method. As with the previous course, different algorithms to solve the matrix
equation AT = B will not be considered, as details can be found in any comprehensive text
on linear algebra. Instead, the default algorithms used by Excel and Python will be used, as
this is not the focus of this course.

Run the Example Problem Yourself!


Now, open either the Excel spreadsheets or the Python source code and solve the problem
with the Neumann boundary condition (fixed heat flux) yourself. For the Dirichlet boundary
condition, you can use the source code from the previous course.

Dr. Aidan Wimshurst, Fluid Mechanics 101 19


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

(a) (b)

Figure 9: Temperature variation along the 1D bar with a heat flux of (a) 100 W/m2 and
(b) 1000 W/m2 applied at the left end.

Excel neumannBoundaryConditions.xlsx

Python neumannBoundaryConditions.py

Examine the calculation of the coefficients, the assembly of the matrices and run the code.
You can even try changing the strength of the heat flux at the left hand end of the bar (qw ),
or even set an adiabatic condition (zero heat flux, qw = 0).

Results
Figure 9 shows the temperature distribution in the bar with a heat flux of 100 W/m2 applied
at the left hand end. For comparison, the analytical solution is also shown:
S  2  qw
T = L − x2 + (x − L) + TB (59)
2k k
By changing the heat flux at the left boundary from 100 W/m2 to 1000 W/m2 , Figure 9(b)
shows that the temperature of the left end of the bar is not fixed. The heat flux qw implicitly
sets the temperature gradient at the left end of the bar (as the thermal conductivity k is fixed)
and the temperature profile develops to match this gradient.
dT
qw = −k nx (60)
dx
As a result, when a heat flux boundary condition is applied in a CFD code, the boundary
temperature on that surface develops as part of the solution. To calculate the boundary
temperature from the CFD solution (Tw ), the temperature must be extrapolated from the
temperature at the cell centroid T1 . Central differencing can be used to extrapolate the
boundary temperature from the temperature at the cell centroids.
!
T1 − TA kL AL
qw AL = −kL AL nx Dl Al = (61)
dLP /2 dLP

Dr. Aidan Wimshurst, Fluid Mechanics 101 20


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

Left face Right face

Figure 10: A diagram to show the the heat flux out of the cell across the left (Ql ) and
right (Qr ) faces of the cell.

qA A L
TA = T1 + (62)
2Dl AL nx
The use of central differencing to extrapolate and calculate the boundary temperature can be
found in both the Excel spreadsheet and Python source code. Note that for the left boundary
face, the unit normal vector (nx ) points in the negative x direction, so nx = −1.

Heat Balancing
Once a CFD solution has been computed, a heat balance can be written for each of the cells
in the mesh as an additional check of the solution. To understand the heat balance, start
with the general finite volume discretisation for the interior cells:
TP − TL TR − TP
   
kl Al nx + kr Ar nx + SV = 0 (63)
dLP dP R
The heat flux out of the left face of the cell (Ql ) is:
TP − TL
 
Ql = −kl Al nx [W] (64)
dLP
and the heat flux out of the right face of the cell (Qr ) is:
TR − TP
 
Qr = −kr Ar nx [W] (65)
dP R
The negative sign is required to ensure that the heat flows in the opposite direction to the
temperature gradient and the unit normal vector ensures that heat fluxes out of the cell
are positive. Substitute these definitions into the general finite volume discretisation for the
interior cell:
−Ql − Qr + SV = 0 (66)
For the left boundary cell, the distance from the boundary cell centroid to the wall is dLP /2,
so the heat flux balance is:
−2Ql − Qr + SV = 0 (67)
Likewise, for the right boundary face:

−Ql − 2Qr + SV = 0 (68)

Physically, these equations state that the sum of the heat fluxes into the cell (positive heat
sources S generate heat in the cell) is equal to zero. The equation will now be evaluated

Dr. Aidan Wimshurst, Fluid Mechanics 101 21


1 DIRICHLET AND NEUMANN BOUNDARY CONDITIONS

explicitly, using the temperatures that were computed at the cell centroids. Remember that
this is a post-processing operation and the temperatures are now known. As the matrix solvers
are (generally) iterative, there will be some error in solving the finite volume equations. This
error in the heat balance in each cell is given by:

Error = −Ql − Qr + SV (69)

The table below summarises the heat balance for each cell in the mesh:

Cell Ql [W] Qr [W] SV [W] Error


1 10 90 100 0
2 -90 190 100 0
3 -190 290 100 0
4 -290 390 100 0
5 -390 490 100 0

Total heat flux out of the bar = 10 + 490 = 500W


Total heat generated in the bar = 100 + 100 + 100 + 100 + 100 = 500W

The heat balance is useful as we can easily observe that the total heat flux out of the left
and right faces of the bar (highlighted in red in the table), balances the total heat generated
in the bar (500W). As both heat fluxes are positive, this indicates that heat is flowing out of
the bar at both ends, with the majority of the heat flowing out of the right face as it is at
a lower temperature (see Figure 9). As a further check, we can also see that the heat flux
boundary condition has been applied correctly to the left boundary cell (cell 1):

QA = qw A = 100 ∗ 0.1 = 10 W (70)

It may be noted that for this problem, the error in the heat balance in every cell is zero. This is
because a direct matrix solver has been used to solve the equations. However, real CFD codes
use iterative matrix solvers and a small error will generally exists in every cell in the mesh.
This error is often called the residual of the equation. As a vector, the root-mean-square and
maximum values of the vector are often computed and reported to the user (instead of the
entire vector) as a measure of the convergence of the solution.
q
RMS = Error 12 + Error 22 + Error 32 + Error 42 + Error 52 (71)

MAX = max (Error 1, Error 2, Error 3, Error 4, Error 5) (72)


These are the values that are typically shown to the user as convergence graphs in the
graphical user interface (GUI) of the CFD code.

Dr. Aidan Wimshurst, Fluid Mechanics 101 22


Chapter 2
Transport Equations in 2D
2 TRANSPORT EQUATIONS IN 2D

2 Transport Equations in 2D
The heat diffusion equation will now be solved in 2D (x and y) rather than just 1D (x)
using the finite volume method. This same approach can be used to integrate and solve any
transport equation (momentum, turbulence, species concentration etc.) under consideration.
Starting with the heat diffusion equation in vector notation:
0 = ∇ · (k∇T ) + S (73)
In 2D Cartesian coordinates, the derivatives can be expanded to give:
! !
∂ ∂T ∂ ∂T
0= k + k +S (74)
∂x ∂x ∂y ∂y
Following the same approach as the previous chapter, integrate the equation over a finite
control volume (cell) with volume V .
Z " ! ! #
∂ ∂T ∂ ∂T
0= k + k + S dV (75)
V ∂x ∂x ∂y ∂y
Once again, split the integral into diffusion and source components. This is permissible as
integration and addition are commutative operations (they can be performed in any order
without changing the result).
Z " ! !#
∂ ∂T ∂ ∂T Z
0= k + k dV + [S] dV (76)
V ∂x ∂x ∂y ∂y V

As before, the source term is averaged over the control volume, so that it can be moved
outside the integral.
Z " ! !#
∂ ∂T ∂ ∂T Z
0= k + k dV + S dV (77)
V ∂x ∂x ∂y ∂y V

Z " ! !#
∂ ∂T ∂ ∂T
0= k + k dV + SV (78)
V ∂x ∂x ∂y ∂y
The volume integral of the diffusion term can be simplified using Gauss’s divergence theorem.
Recall (from the previous course) that the divergence theorem for a general vector field B is
written as: Z Z
(∇ · B) dV = (B · n̂) dA (79)
V A
!
Z
∂Bx ∂By ∂Bz Z
+ + dV = (Bx nx + By ny + Bz nz ) dA (80)
V ∂x ∂y ∂z A

where n̂ is the unit normal vector pointing out of the control volume and A is the surface
area of the control volume. In 2D, the divergence theorem can be written:
!
Z
∂Bx ∂By Z
+ dV = (Bx nx + By ny ) dA (81)
V ∂x ∂y A

For the 2D heat diffusion equation B = k∇T . Hence Bx = k ∂T /∂x and By = k ∂T /∂y.
Applying the 2D divergence theorem to the 2D heat diffusion equation leads to:
Z " #
∂T ∂T
0= k nx + k ny dA + SV (82)
A ∂x ∂y

Dr. Aidan Wimshurst, Fluid Mechanics 101 24


2 TRANSPORT EQUATIONS IN 2D

Figure 11: A diagram to show the face normal vectors on the left (l), right (r), top (t) and
bottom (b) faces of the 2D cell. The cell normal vectors always point out of the cell.

The cell has a finite number of faces (N ). For a quadrilateral cell N = 4, while for a triangular
cell N = 3. Hence, the surface integral over the entire surface can be replaced with an integral
over each of the N faces of the cell.
" #
XZ ∂T ∂T
0= k nx + k ny dA + SV (83)
N A ∂x ∂y
In the second-order finite volume method, the flow quantities all vary linearly across the face.
The integral across the face can therefore be reduced to the value at the centre of the face
(a constant value). " #Z
X ∂T ∂T
0= k nx + k ny dA + SV (84)
N ∂x ∂y A
" #
X ∂T ∂T
0= k nx + k ny A + SV (85)
N ∂x ∂y
It may be noted that this is equivalent to:
X
0= [kA (∇T · n̂)] + SV (86)
N

To simplify the equation further, consider the 2D quadrilateral cell in Figure 11. The cell has
a left face (l), a right face (r), a top face (t) and a bottom face (b). The unit normal vectors
always point out of the cell. As the x direction is positive left to right and the y direction is
positive bottom to top, the unit normal vectors on each face are:

Face nx ny
Left (l) -1 0
Right (r) 1 0
Bottom (b) 0 -1
Top (t) 0 1

Hence, the finite volume discretisation can be simplified further:


! ! ! !
∂T ∂T ∂T ∂T
0 = kA − kA + kA − kA + SV (87)
∂x r
∂x l
∂y t
∂y b

Dr. Aidan Wimshurst, Fluid Mechanics 101 25


2 TRANSPORT EQUATIONS IN 2D

Top Cell

Left Cell Right Cell

Bottom Cell

Figure 12: A diagram to show the distance between the cell centroid and the left cell
(dLP ), right cell (dP R ), bottom cell (dBP ) and top cell (dP T ).

This discretisation is valid for all cells in the mesh that are the same shape and orientation as
the quadrilateral cell in Figure 11 (a regular structured mesh). To simplify further, the interior
and boundary cells need to be considered separately.

Interior Cells
Starting with the general finite volume discretisation for the 2D quadrilateral cell:
! ! ! !
∂T ∂T ∂T ∂T
0 = kA − kA + kA − kA + SV (88)
∂x r
∂x l
∂y t
∂y b

Central differencing will be used for all of the diffusion terms. Using the notation in Figure
12 for the distances between the cell centroids (d):
TR − TP TP − TL TT − TP TP − TB
0 = kr A r − kl Al + kt At − kb Ab + SV (89)
dP R dLP dP T dBP
As before, the lowercase subscript notation (l, r, b, t) is used to refer to the faces of the cell
and the uppercase subscript notation (L, R, B, T, P ) is used to refer to the cell centroids. For
simplicity, introduce the diffusive flux per unit area D = k/d, which has units of W/m2 K.

0 = Dr Ar (TR − TP ) − Dl Al (TP − TL ) + Dt At (TT − TP ) − Db Ab (TP − TB ) + SV (90)

Rearrange and group the terms by cell centroid temperatures (TP , TR , TL , TT , TB ).

TP [Dl Al + Dr Ar + Db Ab + Dt At ] = TL [Dl Al ] + TR [Dr Ar ]


+ TB [Db Ab ] + TT [Dt At ] + SV (91)

Manipulate the equation slightly (add a zero to the TP bracket) to express in standard form.

TP [Dl Al + Dr Ar + Db Ab + Dt At + 0] = TL [Dl Al ] +TR [Dr Ar ]


| {z } | {z } | {z }
ap aL aR

+ TB [Db Ab ] +TT [Dt At ] + |{z}


SV (92)
| {z } | {z }
aB aB Su

Dr. Aidan Wimshurst, Fluid Mechanics 101 26


2 TRANSPORT EQUATIONS IN 2D

Top Cell

Right Cell

Bottom Cell

Figure 13: The boundary cell at the left of the domain with temperature TP at its centroid.
The wall (the left face of the cell) is at a fixed temperature Twall and is shown in red.

The standard form is similar to the standard form used for the 1D diffusion equation.

ap TP = aL TL + aR TR + aB TB + aT TT + Su [2D]
ap TP = aL TL + aR TR + Su [1D] (93)

With the following coefficients for interior cells:

ap = aL + aR + aT + aB − Sp
aL = Dl Al aR = Dr Ar aB = Db Ab aT = Dt At
Sp = 0 Su = SV (94)

Using summation notation (from the previous chapter), the finite volume discretisation is
identical to the 1D discretisation from the previous chapter.
X
ap TP = aN TN + Su
N

X kN AN kN AN
ap = |n̂| aN = |n̂| Su = SV (95)
N |dP N | |dP N |
The summation notation becomes more useful as the number of faces (N ) increases. Hence,
it is often used by real CFD codes (and given in user manuals) as cells in 2D and 3D meshes
may have many faces and it is easier to keep track of all the terms in the finite volume
discretisation.

Boundary Cells - Dirichlet Boundary Conditions


Figure 13 shows a boundary cell on the left of the domain, which will be used to simplify
the finite volume discretisation for boundary cells. Starting with the general finite volume
discretisation for the 2D heat diffusion equation:
! ! ! !
∂T ∂T ∂T ∂T
0 = kA − kA + kA − kA + SV (96)
∂x r
∂x l
∂y t
∂y b

Dr. Aidan Wimshurst, Fluid Mechanics 101 27


2 TRANSPORT EQUATIONS IN 2D

The right, top and bottom faces are connected to interior cells. Hence, the heat diffusion
through these faces can be simplified using the same treatment as the interior cells.
!
∂T
0 = Dr Ar (TR − TP ) − kA + Dt At (TT − TP ) − Db Ab (TP − TB ) + SV (97)
∂x l

In this chapter, fixed value (Dirichlet) boundary conditions will be applied on the left face.
However, the method used in the previous chapter for Neumann boundary conditions could be
applied instead if desired. The left boundary face is at a temperature Twall and the distance
to the wall is half the distance to the next cell centroid. Hence the heat diffusion through the
left face is: !
∂T TP − Twall
kA = kl Al = 2Dl Al (Tp − Twall ) (98)
∂x l dLP /2
Substitute into the finite volume discretisation:

0 = Dr Ar (TR − TP ) − 2Dl Al (Tp − Twall ) + Dt At (TT − TP ) − Db Ab (TP − TB ) + SV (99)

Rearrange and group the terms by cell centroid temperatures (TP , TR , TL , TT , TB ).

TP [0 + Dr Ar + Db Ab + Dt At + 2Dl Al ] = TL [0] + TR [Dr Ar ]


+ TB [Db Ab ] + TT [Dt At ]
+ Twall [2Dl Al ] + SV (100)

The equation is now in standard form:

TP [0 + Dr Ar + Db Ab + Dt At + 2Dl Al ] = TL [0] +TR [Dr Ar ] (101)


| {z } |{z} | {z }
ap aL aR

+ TB [Db Ab ] +TT [Dt At ] (102)


| {z } | {z }
aB aT

+ Twall [2Dl Al ] + SV (103)


| {z }
Su

With the following coefficients:

ap = aL + aR + aT + aB − Sp
aL = 0 aR = Dr Ar aB = Db Ab aT = Dt At
Sp = −2Dl Al Su = Twall (2Dl Al ) + SV (104)

Using summation notation (from the previous chapter), the finite volume discretisation is
identical to the 1D discretisation from the previous chapter.
X
ap TP = aN TN + Su
N
!
X kN AN kw Aw kN AN
ap = |n̂| + |n̂| aN = |n̂|
N |dP N | |dLP |/2 |dP N |
!
kw Aw
Su = SV + Twall |n̂| (105)
|dLP |/2
Once again it should be remembered that when using the summation notation aN = 0 for
the boundary faces and the summation for aP does not include the boundary faces.

Dr. Aidan Wimshurst, Fluid Mechanics 101 28


2 TRANSPORT EQUATIONS IN 2D

Top Cell

Right Cell

Bottom Cell

Figure 14: The boundary cell at the left of the domain with temperature TP at its
centroid. A fixed heat flux qwall is applied at the wall (the left face of the cell).

Boundary Cells - Neumann Boundary Conditions


Now consider the case where a fixed heat flux (Neumann boundary condition) is applied
to the left boundary face, as shown in Figure 14. Starting with the general finite volume
discretisation for the 2D heat diffusion equation:
! ! ! !
∂T ∂T ∂T ∂T
0 = kA − kA + kA − kA + SV (106)
∂x r
∂x l
∂y t
∂y b

The right, top and bottom faces are connected to interior cells. Hence, the heat flux through
these faces can be simplified using the same treatment as the interior cells.
!
∂T
0 = Dr Ar (TR − TP ) − kA + Dt At (TT − TP ) − Db Ab (TP − TB ) + SV (107)
∂x l

With a Neumann boundary condition, the heat flux per unit area out of the left face of the
cell is:
∂T
qwall = −kl nx (108)
∂x
Note that the unit normal vector for this cell nx = −1. Hence:
∂T
qwall = kl (109)
∂x
Hence, the finite volume discretisation now becomes:

0 = Dr Ar (TR − TP ) − qwall Al + Dt At (TT − TP ) − Db Ab (TP − TB ) + SV (110)

Rearrange and group the terms by cell centroid temperatures (TP , TR , TL , TT , TB ).

TP [0 + Dr Ar + Db Ab + Dt At + 0] = TL [0] + TR [Dr Ar ]
+ TB [Db Ab ] + TT [Dt At ]
− qwall Al + SV (111)

Dr. Aidan Wimshurst, Fluid Mechanics 101 29


2 TRANSPORT EQUATIONS IN 2D

The equation is now in standard form:

TP [0 + Dr Ar + Db Ab + Dt At + 0] = TL [0] +TR [Dr Ar ]


| {z } |{z} | {z }
ap aL aR

+ TB [Db Ab ] +TT [Dt At ]


| {z } | {z }
aB aT

+ −qwall Al + SV (112)
| {z }
Su

With the following coefficients:

ap = aL + aR + aT + aB − S p
aL = 0 aR = Dr Ar aB = Db Ab aT = Dt At
Sp = 0 Su = −qwall Al + SV (113)

Using summation notation (from the previous chapter), the finite volume discretisation is
identical to the 1D discretisation from the previous chapter.
X
ap TP = aN TN + Su
N
!
X kN AN kN AN
ap = |n̂| aN = |n̂| Su = SV − qw Aw
N |dP N | |dP N |
Once again it should be remembered that when using the summation notation aN = 0 for
the boundary faces and the summation for aP does not include the boundary faces.

Summary of Coefficients
The tables below summarise the coefficients for each of the boundary and interior cells in the
mesh when Dirichlet and Neumann boundary conditions are applied.

Dirichlet Boundary Condition (2D)

aL aR aB aT Sp Su
Interior DL AL DR AR DB AB DT A T 0 SV
Boundary (L) 0 DR AR DB AB DT A T −2DL AL Twall (2DL AL ) + SV
Boundary (R) DL AL 0 DB AB DT A T −2DR AR Twall (2DR AR ) + SV
Boundary (B) DL AL DR AR 0 DT AT −2DB AB Twall (2DB AB ) + SV
Boundary (T) DL AL DR AR DT AT 0 −2DT AT Twall (2DT AT ) + SV

Dr. Aidan Wimshurst, Fluid Mechanics 101 30


2 TRANSPORT EQUATIONS IN 2D

Right Cell

Bottom Cell

Figure 15: The boundary cell at the top-left of the domain with temperature TP at its
centroid. The top and left walls are at fixed temperatures of Twall, l and Twall, t

Neumann Boundary Condition (2D)

aL aR aB aT Sp Su
Interior DL AL DR AR DB AB DT AT 0 SV
Boundary (L) 0 DR AR DB AB DT AT 0 −qwall Al + SV
Boundary (R) DL AL 0 DB AB DT AT 0 −qwall Ar + SV
Boundary (B) DL AL DR AR 0 DT AT 0 −qwall AB + SV
Boundary (T) DL AL DR AR DT A T 0 0 −qwall AT + SV

The summation notation can also be summarised in a table. Following the previous
chapter, this table gives the contribution of each face to the cell total:

Summation Notation

Face Type aP aN Su
kN AN kN AN
Interior |n̂| |n̂| 0
|dP N | |dP N | !
kw Aw kw Aw
Dirichlet |n̂| 0 Tw |n̂|
|dLP |/2 |dLP |/2

Neumann 0 0 −qwall Aw

It should be emphasised once again that with the summation notation, the contribution
of the volumetric source term (SV ) also needs to be included in the total for Su .

Dr. Aidan Wimshurst, Fluid Mechanics 101 31


2 TRANSPORT EQUATIONS IN 2D

Cells with Multiple Boundary Faces


For 2D and 3D meshes, some boundary cells may have more than 1 boundary face. Further-
more, the boundary conditions on these boundary faces may be different. Figure 15 shows an
example cell with 2 boundary faces. For this cell, the finite volume discretisation is:
! ! ! !
∂T ∂T ∂T ∂T
0 = kA − kA + kA − kA + SV (114)
∂x r
∂x l
∂y t
∂y b

The right and bottom faces are connected to interior cells. Hence, central differencing can
be used to simplify the heat flux through these faces.
! !
TR − TP ∂T ∂T TP − TB
0 = kr Ar − kA + kA − kb A b + SV (115)
dP R ∂x l
∂x t
dBP
Introduce the diffusive flux per unit D = k/d, as normal.
! !
∂T ∂T
0 = Dr Ar (TR − TP ) − kA + kA − Db Ab (TP − TB ) + SV (116)
∂x l
∂x t

If the boundary faces are at fixed temperatures of Twall, l on the left and Twall, t on the top,
then central differencing can also be used on the boundary faces.
0 = Dr Ar (TR −TP )−2Dl Al (TP −Twall, l )+2Dt At (Twall, t −TP )−Db Ab (TP −TB )+SV (117)
Rearrange and collect the temperatures at the cell centroids (TP , TR , TT ).
TP [0 + Dr Ar + Db Ab + 0 + 2Dl Al + 2Dt At ] = TL [0] + TR [Dr Ar ]
+ TB [Db Ab ] + TT [0] + SV
+ Twall, l (2Dl Al ) + Twall, t (2Dt At ) (118)
The equation is in standard form:
ap = aL + aR + aT + aB − Sp (119)
With the following coefficients:
aL = 0 aR =Dr Ar aB = Db Ab aT = 0
Sp = −2Dl Al − 2Dt At Su = SV + Twall, 1 (2Dl Al ) + Twall, 2 (2Dt At ) (120)
Hence, when a cell has multiple boundary faces the contribution of those faces to ap = 0.
These faces then add their contribution to Sp and Su instead.
When using summation notation, additional summation symbols are used in the definition
of ap and Su to emphasise that additional contributions are added for each boundary face M
that the cell has. Otherwise the equations are identical.
X
ap TP = aN TN + Su
N
! !
X kN AN X kw Aw kN AN
ap = |n̂| + |n̂| aN = |n̂|
N |dP N | M |dLP |/2 |dP N |
!
X kw Aw
Su = SV + Twall |n̂| (121)
M |dLP |/2
Cells with multiple boundary faces will be considered further in the example problem in this
chapter.

Dr. Aidan Wimshurst, Fluid Mechanics 101 32


2 TRANSPORT EQUATIONS IN 2D

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

Figure 16: Cell numbering scheme for a 4x4 mesh. The mesh stencil around cell 10 is
highlighted.

Assembling the Matrices


When applying the finite volume method in 2D and 3D, a cell numbering scheme must be
adopted to ensure that the correct cells are connected together. Figure 16 shows an example
numbering scheme for a mesh with 16 cells (4 x 4). For each cell in the mesh, it useful to
visualise a stencil of 4 cells that surround the cell under consideration (also shown in Figure
16). This stencil allows us to identify the neighbouring cells more easily. As shown in the
previous course, an algebraic equation is written for each cell in the mesh individually. For the
mesh in Figure 16, the algebraic equations are:

ap1 T1 = ar2 T2 + ab5 T5 + Su1


ap2 T2 = al1 T1 + ar3 T3 + ab6 T6 + Su2
ap3 T3 = al2 T2 + ar4 T4 + ab7 T7 + Su3
ap4 T4 = al3 T3 + ab8 T8 + Su4
ap5 T5 = at1 T1 + ar6 T6 + ab9 T9 + Su5
ap6 T6 = al2 T2 + at5 T5 + ar7 T7 + ab10 T10 + Su6
ap7 T7 = al3 T3 + at6 T6 + ar8 T8 + ab11 T11 + Su7
ap8 T8 = al4 T4 + at7 T7 + ab12 T12 + Su8
ap9 T9 = ar5 T5 + at10 T10 + ab13 T13 + Su9
ap10 T10 = al6 T6 + ar9 T9 + at11 T11 + ab14 T14 + Su10
ap11 T11 = al7 T7 + ar10 T10 + at12 T12 + ab15 T15 + Su11
ap12 T12 = al8 T8 + at11 T11 + ab16 T16 + Su12
ap13 T13 = at9 T9 + ar14 T14 + Su13
ap14 T14 = al10 T10 + at13 T13 + ar15 T15 + Su14
ap15 T15 = al11 T11 + at14 T14 + ar16 T16 + Su15
ap16 T16 = al12 T12 + at15 T15 + Su16 (122)

Dr. Aidan Wimshurst, Fluid Mechanics 101 33


2 TRANSPORT EQUATIONS IN 2D

Width = 4m Top

Left Right

Bottom
Length = 4m

Figure 17: Example geometry used for heat diffusion in a 2D plate.

As before, the equations are then arranged into matrix form.


ap1 −ar2 0 0 −ab5 0 0 0 0 0 0 0 0 0 0 0
 
−a a −a 0 −ab6 0
 l1 p1 r3 0 0 0 0 0 0 0 0 0 0  
 0 −al2 ap3 −ar4 0 0 −a 0 0 0 0 0 0 0 0 0
 
 b7 

 0
 0 −al3 ap4 −ar5 0 0 −ab8 0 0 0 0 0 0 0 0  
−at1 0 0 −a l4 ap5 −ar6 0 0 −a 0 0 0 0 0 0 0
 
b9 
 
 0 −at2 0 0 −a a
l5 p6 −a r7 0 0 −a b10 0 0 0 0 0 0 
 
 0

0 −at3 0 0 −al6 ap7 −ar8 0 0 −ab11 0 0 0 0 0  
 0 0 0 −a 0 0 −a a −a 0 0 −a 0 0 0 0
 
t4 l7 p8 r9 b12 
A= 
 0
 0 0 0 −at5 0 0 −al8 ap9 −ar10 0 0 −ab13 0 0 0  
 0 0 0 0 0 −at6 0 0 −al9 ap10 −ar11 0 0 −ab14 0 0 
 
 
 0
 0 0 0 0 0 −at7 0 0 −al10 ap11 −ar12 0 0 −ab15 0  
 0

0 0 0 0 0 0 −at8 0 0 −al11 ap12 −ar13 0 0 −ab16  
−a −a −a
 
 0 0 0 0 0 0 0 0 t9 0 0 a
l12 p13 r14 0 0 
 
 0
 0 0 0 0 0 0 0 0 −at10 0 0 −al13 ap14 −ar15 0  
 0 0 0 0 0 0 0 0 0 0 −at11 0 0 −al14 ap15 −ar16 
 

0 0 0 0 0 0 0 0 0 0 0 −at12 0 0 −al15 ap16

T = [T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 ...

... T12 T13 T14 T15 T16 ]T (123)

B = [Su1 Su2 Su3 Su4 Su5 Su6 Su7 Su8 Su9 Su10 Su11 ...

... Su12 Su13 Su14 Su15 Su16 ]T (124)


In the same manner as the 1D flow case, the A matrix has a diagonal banded structure.
However, rather than having 2 off-diagonal bands (representing the left and right faces of the
cell), the matrix now has 4 bands. The additional bands represent the connectivity to the top
and bottom cells.

Example Problem - Heat Diffusion in a 2D Plate


Consider steady-state diffusion of heat in a 2D plate, as shown in Figure 17. The plate has a
length of 4m, a width of 4m, a thickness of 0.1m and a thermal conductivity of 100 W/mK.

Dr. Aidan Wimshurst, Fluid Mechanics 101 34


2 TRANSPORT EQUATIONS IN 2D

4m

4m
1m
Cross-Sectional
Area of Cell 0.1m
1m
Figure 18: A diagram to show the dimensions of a cell in the mesh. The cross-sectional
area that is used to calculate the heat fluxes in the x direction is highlighted in red and the
cross-sectional area that is used to calculate the heat fluxes in the y direction is highlighted
in green.

The temperature on the sides of the plate are fixed at 100◦ C, 150◦ C, 200◦ C and 250◦ C on the
left, bottom, right and top faces respectively. There is a constant heat source of 1000 W/m3
in the plate. The temperature field in the plate is governed by the 2D steady-state diffusion
equation. ! !
∂ ∂T ∂ ∂T
k + k +S =0 (125)
∂x ∂x ∂y ∂y

Step 1: Divide the Geometry into a Mesh


For the example in Figure 17, divide the geometry into a mesh of 16 quadrilateral cells (4
cells in each direction). These cells have equal length and equal width. The length of each
cell (Lcell ) is given by:
L 4
Lcell = = = 1m (126)
N 4
Because the cells are uniformly distributed and have equal size, the distance between cell
centroids d is equivalent to the length of the cells. Hence:

dLP = dP R = dBP = dP T = d = 1m (127)

As shown in Figure 18, the cross-sectional area of all of the cells (in the x and y directions)
is:
A = 1.0 ∗ 0.1 = 0.1m2 (128)

Step 2: Assign Material Properties


The thermal conductivity k and the cross-sectional area A are the same for every cell in the
mesh. Hence, the parameter DA is given by:
kA 100 ∗ 0.1
DA = = = 10 [W/K] (129)
d 1
The heat source in each cell is given by:

SV = SLcell W t = 1000 ∗ 1 ∗ 1 ∗ 0.1 = 100 [W] (130)

Dr. Aidan Wimshurst, Fluid Mechanics 101 35


2 TRANSPORT EQUATIONS IN 2D

Step 3: Calculate Matrix Coefficients


Now calculate the coefficients required to assemble the matrices. The most straightforward
way is to fill in the table of coefficients:

Cell aL aR ab at Sp Su ap
1 0 10 10 0 -40 7100 60
2 10 10 10 0 -20 5100 50
3 10 10 10 0 -20 5100 50
4 10 0 10 0 -40 9100 60
5 0 10 10 10 -20 2100 50
6 10 10 10 10 0 100 40
7 10 10 10 10 0 100 40
8 10 0 10 10 -20 4100 50
9 0 10 10 10 -20 2100 50
10 10 10 10 10 0 100 40
11 10 10 10 10 0 100 40
12 10 0 10 10 -20 4100 50
13 0 10 0 10 -40 5100 60
14 10 10 0 10 -20 3100 50
15 10 10 0 10 -20 3100 50
16 10 0 0 10 -40 7100 60

Alternatively, the summation notation summary table can be filled in (noting that an
additional source SV = 100W is required in each cell):

Face Type aP aN Su
Interior 10 10 0
Dirichlet (Left) 20 0 2000
Dirichlet (Bottom) 20 0 3000
Dirichlet (Right) 20 0 4000
Dirichlet (Top) 20 0 5000

Dr. Aidan Wimshurst, Fluid Mechanics 101 36


2 TRANSPORT EQUATIONS IN 2D

Step 4: Assemble the Matrices


Assign the coefficients to their correct location in the matrix.

60 −10 0 0 −10 0 0 0 0 0 0 0 0 0 0 0
 
−10 50 −10 0 0 −10 0 0 0 0 0 0 0 0 0 0 
 
 0 −10 50 −10 0 0 −10 0 0 0 0 0 0 0 0 0
 

 
 0
 0 −10 60 0 0 0 −10 0 0 0 0 0 0 0 0 

−10 0 0 0 50 −10 0 0 −10 0 0 0 0 0 0 0
 

 
 0 −10 0 0 −10 40 −10 0 0 −10 0 0 0 0 0 0 
 
 0

0 −10 0 0 −10 40 −10 0 0 −10 0 0 0 0 0  
 0 0 0 −10 0 0 −10 50 0 0 0 −10 0 0 0 0 
 
A=
  (131)
 0 0 0 0 −10 0 0 0 50 −10 0 0 −10 0 0 0  
 0 0 0 0 0 −10 0 0 −10 40 −10 0 0 −10 0 0
 

 
 0
 0 0 0 0 0 −10 0 0 −10 40 −10 0 0 −10 0  
 0

0 0 0 0 0 0 −10 0 0 −10 50 0 0 0 −10 
0 0 0 0 0 0 0 −10 0 0 0 60 −10 0 0 
 
 0
 
 0
 0 0 0 0 0 0 0 0 −10 0 0 −10 50 −10 0  
 0 0 0 0 0 0 0 0 0 0 −10 0 0 −10 50 −10
 

0 0 0 0 0 0 0 0 0 0 0 −10 0 0 −10 60

T = [T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 ...

... T12 T13 T14 T15 T16 ]T (132)

B = [7100 5100 5100 9100 2100 100 100 4100 2100 100 100 ...

... 4100 5100 3100 3100 7100]T (133)

Step 5: Solve the Equations


Now that the matrices have been assembled, the matrix equation can solved with an appro-
priate iterative method. As with the previous course, different algorithms to solve the matrix
equation AT = B will not be considered and the default algorithms used by Excel and Python
will be used instead.

Run the Example Problem Yourself!


Now, open either the Excel spreadsheets or the Python source code and solve the problem
yourself.

Excel solve2DDiffusionEquation.xlsx

Python solve2DDiffusionEquation.py

Dr. Aidan Wimshurst, Fluid Mechanics 101 37


2 TRANSPORT EQUATIONS IN 2D

(a) (b)

Figure 19: Temperature variation across the 2D plate with (a) a coarse mesh and (b) a
fine mesh.

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

Figure 20: A diagram to show the centroids numbering scheme used in the mesh. The
centroids are shown as dark blue circles, the boundary nodes as red circles and the interior
nodes as white circles.

Results
Figure 19 shows the temperature variation across the plate with (a) a coarse mesh and (b) a
fine mesh. To plot the temperature variation as a contour plot, it is more convenient to plot
the temperature at the mesh nodes rather than the mesh centroids. As shown in Figure 20,
this is because the boundary temperatures are specified at the nodes (shown in red) and these
would be missed if a contour plot was generated from the mesh centroids (shown in blue).
The CFD solution is computed at the cell centroids. Hence, the interior nodal values
(shown in white in Figure 20) have to be computed by interpolating between the centroid
values (shown in blue). This interpolation has already been carried out in the Excel spreadsheet
and the python source code for you.

Heat Balancing
Now that a CFD solution has been computed, a heat balance can be written for every cell in
the mesh. In the same manner as the previous chapter, the sum of the heat fluxes into the

Dr. Aidan Wimshurst, Fluid Mechanics 101 38


2 TRANSPORT EQUATIONS IN 2D

cell and the heat generated in the cell must be equal to zero for energy to be conserved.
TR − TP TP − TL
   
0 = kr Ar nx + kl Al nx
dP R dLP
TT − TP TP − TB
   
+ kt At ny + kb Ab ny + SV (134)
dP T dBP
From Fourier’s Law, the heat conduction across each face is given by:
TP − TL TR − TP
   
Ql = −kl Al nx Qr = −kr Ar nx
dLP dP R
TP − TB TT − TP
   
Qb = −kb Ab ny Qt = −kt At ny (135)
dBP dP T
The negative sign is required to ensure that the heat flows in the opposite direction to the
temperature gradient and the unit normal vectors ensure that positive heat flues are out of
the cell. By substituting Fourier’s Law (equation 135) into the finite volume discretisation
(equation 134), the heat balance for each cell can be written in concise form as:
−Qr − Ql − Qt − Qb + SV = 0 (136)
X
(−Q) + SV = 0 (137)
N
The error in the heat flux balance for 2D quadrilateral cells can therefore be written as:
Error = −Qr − Ql − Qt − Qb + SV (138)
The table below summarises the heat balance for every cell in the mesh. The heat fluxes
across the boundaries of the plate are highlighted in blue.

Cell Heat Flux Balance Table

Cell Ql [W] Qr [W] Qt [W] Qb [W] SV [W] Error


1 1575.0 -427.3 -1425.0 377.3 100 0
2 427.3 -109.2 -570.4 352.3 100 0
3 109.2 74.4 -351.9 268.3 100 0
4 -74.4 499.4 -500.6 175.6 100 0
5 820.4 -452.3 -377.3 109.2 100 0
6 452.3 -193.3 -352.3 193.3 100 0
7 193.3 -18.3 -268.3 193.3 100 0
8 18.3 148.1 -175.6 109.2 100 0
9 601.9 -368.3 -109.2 -24.4 100 0
10 368.3 -193.3 -193.3 118.3 100 0
11 192.3 -102.3 -193.3 202.3 100 0
12 102.3 -70.4 -109.2 177.3 100 0
13 650.6 -225.6 24.4 -349.4 100 0
14 225.6 -109.2 -118.3 101.9 100 0
15 109.2 -127.3 -202.3 320.4 100 0
16 127.3 -425.0 -177.3. 575.0 100 0

Dr. Aidan Wimshurst, Fluid Mechanics 101 39


2 TRANSPORT EQUATIONS IN 2D

The cell heat flux balance table can also be used to calculate the total heat flux out of
each of the faces of the plate (across all the boundaries). By summing the heat flux out of
each of the boundary faces (highlighted in blue in the table above):

Heat Flux Summary Table

Boundary Heat Flux Out [W] Total [W]


Left 1575.0 + 820.4 + 601.9 + 650.6 3647.9
Right 499.4 + 148.1 -70.4 -425.0 152.1
Bottom -349.4 + 101.9 +320.4 +575.0 647.9
Top -1425 -570.4 - 351.9 - 500.6 -2847.9
Total 1600

Once again positive heat fluxes indicate heat travelling out of the plate across the boundary,
while negative heat fluxes indicate heat travelling into the plate. As the coldest face, the left
face of the plate (100◦ C) experiences the largest heat flux out of the plate. Conversely, the
top face of the plate experiences a negative heat flux as heat is drawn into the plate by
the hot boundary temperature (250◦ C). The total of these heat fluxes (1600W) balances the
total heat generated in the plate (1600W), so energy is conserved. As the mesh is refined,
the same total heat flux (1600W) is conserved. However, the temperature distribution in the
plate and the heat flux across each of the individual cells changes as a result of the mesh
refinement.

Dr. Aidan Wimshurst, Fluid Mechanics 101 40


Chapter 3
Wall Functions
3 WALL FUNCTIONS

3 Wall Functions
In the second order finite volume method, the flow variables (temperature, velocity, pressure
etc.) vary linearly across the cell. Hence, when there are steep gradients in the flow variables,
many cells are required to resolve the profiles with sufficient accuracy. As shown in Figure 21,
the gradients are particularly steep close to the wall. This is due to the boundary layer that
develops on a solid surface in contact with the flow. In order to resolve the steep gradients
near the wall accurately, many thin cells are required normal to the wall. The gradients across
the cell that is immediately adjacent to the wall are particularly important, as the gradients
across this cell determine the wall shear stress and the wall heat flux. In general, the wall
shear stress τw and the wall heat flux qw are given by Newton’s Law of Viscosity and Fourier’s
Law of Heat Conduction:

τw ∂U qw ∂T
= −ν = −α (139)
ρ ∂y y=0 ρcp ∂y y=0

where ρ is the fluid density, ν is the kinematic viscosity of the fluid, α is the thermal diffusivity
of the fluid, U is the velocity component parallel with the wall, T is the temperature and y
is the direction normal to the wall. As the profile is non-linear (the gradient changes with
distance from the wall), the gradient is evaluated at the wall (y = 0). The minus sign is
required because the wall shear stress acts in the opposite direction to the velocity profile and
heat flux is in the opposite direction to the temperature gradient (high temperature to low
temperature).
When generating a mesh for CFD simulations, a fine mesh should be used with many thin
cells normal to the wall. If the mesh is sufficiently fine, then the piecewise linear variation that
is computed by the CFD code has a sufficient number of nodes to accurately reproduce the
real flow profile normal to the wall. However, for some flow simulations it is not possible to use
many thin cells normal to the wall, as this would lead to a high cell count (and sometimes poor
cell quality). For these flow scenarios, the cell adjacent to the wall is too large to accurately
reproduce the flow profile. As shown in Figure 22, the velocity and temperature gradients
at the wall (∂U/∂y and ∂T /∂y) will be incorrect if the cell is too large. This will lead to
inaccuracies in the wall shear stress and wall heat flux (equation 139), unless the CFD code
is corrected appropriately. The focus of this Chapter is the method used to correct the flow
at the wall when the cells adjacent to the wall are too large.

Background Theory
In order to compute the correct wall shear stress, the product of the near wall kinematic
viscosity and the velocity gradient at the wall must be correct.

τw ∂U
= −ν = −Kinematic Viscosity × Velocity Gradient at the Wall (140)
ρ ∂y y=0

Hence, even though the gradient at the wall (∂U/∂y) is incorrect, if the near wall kinematic
viscosity (ν) is modified appropriately, then the wall shear stress will be correct. This approach
of modifying the near wall kinematic viscosity and the near wall thermal diffusivity is used by
the majority of modern CFD codes to correct the solution when the cells are too large.

Dr. Aidan Wimshurst, Fluid Mechanics 101 42


3 WALL FUNCTIONS

(a) Real Profile (b) Mesh (c) Piecewise Linear

Figure 21: A diagram to show the approximation of a real flow profile (velocity or
temperature) by a finite volume mesh. The finite volume method uses a piecewise linear
approximation of the real profile.

Gradient
Error

(a) Thin Cells (b) Large Cells

Figure 22: A diagram to show the difference in the piecewise linear approximation of the
near wall velocity or temperature profile when (a) thin and (b) large cells are used. The
gradient at the wall is incorrect when large cells are used.

Figure 23: A diagram to show the linear variation of velocity and temperature across the
wall adjacent cell in the mesh.

The velocity and temperature variation across the cell are always linear. Hence, as shown
in Figure 23, the wall shear stress and wall heat flux computed by the CFD code are:
!
Up Tp − Tw
τw = −ρνw qw = −ρcp αw (141)
yp yp
where yp is the distance from the wall to the wall adjacent cell centroid, Up is the velocity
at the cell centroid, Tp is the temperature at the cell centroid and Tw is the temperature of

Dr. Aidan Wimshurst, Fluid Mechanics 101 43


3 WALL FUNCTIONS

(a) (b)

Figure 24: Experimental measurements of (a) the velocity profile and (b) the temperature
profile normal to the wall in a turbulent flow of air over a flat plate.

the wall. The kinematic viscosity νw and the thermal diffusivity αw are now denoted with a
subscript w and will be described as the near wall kinematic viscosity (νw ) and the near wall
thermal diffusivity (αw ). The change in notation is to emphasise that these quantities have
been modified. The modification is required to ensure that the product of these quantities
and the (incorrect) velocity and temperature gradients produces the correct wall shear stress
and wall heat flux. The modification to the near wall kinematic viscosity and the near wall
thermal diffusivity is called a wall function, as the modification is only carried out in the cells
that are adjacent to the wall.
At this stage it should be emphasised that a wall function is a modification to νw and
αw in the wall adjacent cell. The wall function is not a modification to the velocity and
temperature profiles (despite sometimes being called a velocity or temperature wall function
in the literature) because the variation across the cell in a CFD code is always linear. The
modifications to αw and νw may result in a change in the velocity and temperature solution
fields, but the velocity and temperature in the wall adjacent cell are not set directly by a wall
function.

Wall Functions for νw and αw


In order to propose wall functions for νw and αw , the real variation of velocity and temper-
ature between the cell centroid and the wall is required first. These are the actual velocity
and temperature profiles that we are trying to model and are non-linear. Figure 24 shows
the real variation of velocity and temperature normal to the wall, which were extracted from
experimental measurements of fully developed turbulent flow between 2 parallel plates. Fur-
ther experimental measurements found this profile to be relatively universal (independent of
Reynolds number and streamwise pressure gradient) close to the wall. Hence, the profile is
often called ’The Universal Law of the Wall’. Mathematically, the experimental data in
Figure 24 can be reasonably approximated by the following function:

y + y + < 11.25
U+ = (142)
 1 log (Ey + ) y + > 11.25
κ

Dr. Aidan Wimshurst, Fluid Mechanics 101 44


3 WALL FUNCTIONS

(a) (b)

11.25

Figure 25: Experimental measurements of (a) the velocity profile and (b) the temperature
profile normal to the wall in a turbulent flow of air. The light blue and light green lines show
the mathematical functions that are fitted to the data for y + < yL+ and y + > yL+ respectively.

where κ = 0.4187 and E = 9.793 are empirical constants that were fitted to the data. As
shown in Figure 25, these profiles are less accurate at reproducing the experimental data when
5 < y + < 30 (the buffer region). Hence, it is normally recommended to ensure that y + < 5
or y + > 30 for the final solution to be accurate.
The two profiles intersect where:
1  
y+ = log Ey + (143)
κ
1  
y+ − log Ey + = 0 −→ f (y + ) = 0 (144)
κ
Substituting in the empirical coefficients E = 9.7983 and κ = 0.4187 and solving for y + with
a root-finding algorithm (like the bisection method or Newton-Raphson method) results in an
intersection point of y + = 11.25. This process of root finding will be demonstrated later in
the example problem. A similar mathematical function can also be fitted to the temperature
profile. 
+
P r y + y + < yL+
T =   (145)
P rt 1 log (Ey + ) + P
κ
y + > yL+
where P r = ν/α is the molecular Prandtl number, P rt is the turbulent Prandtl number (0.85)
and P is an empirical function of P r and P rt .
" 3/4 #
Pr h i
P = 9.24 −1 1 + 0.28e−0.007P r/P rt (146)
P rt
The reason for the differences between the velocity and temperature wall functions is that
(unlike the velocity profile) the dimensionless temperature profile is different for different
fluids. The difference is captured by the molecular Prandtl number P r. For water and air for
example, the molecular Prandtl numbers are:
P r = ν/α
Air 0.71
Water 5.68

Dr. Aidan Wimshurst, Fluid Mechanics 101 45


3 WALL FUNCTIONS

Air

Water

Figure 26: A diagram to shown the differences in the temperature profiles for water and air.

A value of P r < 1 indicates that thermal energy diffuses into the flow faster than momentum.
This means that the thermal boundary layer is thinner than the velocity boundary layer when
P r < 1. A consequence of the temperature profile being different for different fluids is that
the intersection between the 2 profiles does not occur at 11.25 (as it does for the velocity
profile). The intersection point yL+ can be determined by equating the profiles in equation
145.
1
   
P r y + = P rt log Ey + + P (147)
κ
1
   
+ +
P r y − P rt log Ey + P = 0 −→ f (y + ) = 0 (148)
κ
Substitute in the values of P r for the fluid of interest. Then solve the non-linear equation
for y + using a root-finding algorithm (this process will be demonstrated later in the example
problem). This is the intersection point of the two curves (yL+ ) and is different for different
fluids.
Pr yL+
Air 0.71 7.1
Water 5.68 11.8
Figure 26 compares the temperature profiles for water and air. Unlike the velocity profile
(which is the same for water and air), the profiles are different and have a different intersection
point. This difference in the profiles will also be reflected in the wall function for αw . Once
again it should be emphasised that the mathematical functions for velocity and temperature are
not applied directly in the CFD code. The equations are actually used to derive equations for
the near wall kinematic viscosity νw and the near wall thermal diffusivity αw . This derivation
will be demonstrated in the next section. It is these wall functions for νw and αw that are
actually applied in the CFD code.

y + and y ?
The velocity and temperature profiles in equations 142 and 145 are expressed in dimensionless
wall units.
U ρuτ y (Tw − Tp )ρcp uτ
U+ = y+ = T+ = (149)
uτ µ qw

Dr. Aidan Wimshurst, Fluid Mechanics 101 46


3 WALL FUNCTIONS

Figure 27: A schematic diagram of the experimental set up that was used to derive the
velocity profiles normal to the wall.

The reason for using dimensionless units is so that the profiles are universal and can be
applied to any flow scenario (flow over an aerofoil, flow in a pipe, flow over a flat plate etc.),
as long as we are close to the wall. This is a reasonable theory, as the flow close to the wall
at small scales should be universal, regardless of the freestream flow and the overall shape of
the geometry.
However, to define these dimensionless groups, appropriate choices of velocity scale (uτ )
and length scale (y) are required. Since the flow is close to the wall, the appropriate length
scale y is the distance normal to the wall. For the velocity scale, it would not be appropriate
to use the free-stream velocity (U∞ ), as the flow is close to the wall where viscous effects are
dominant and the velocity is much lower than the freestream velocity. However, the velocity
at the wall itself is zero due to the no-slip condition, so this cannot be used as a velocity scale
either. The original approach in the experiments was to chose a velocity scale based on the
(square-root of the) wall shear stress. This velocity scale (uτ ) is called the friction-velocity.
s
|τw |
uτ = [m/s] (150)
ρ
However, the problem with using a friction velocity based on the wall shear stress is that
the wall shear stress is zero at separation points. This would result in a friction velocity of 0,
which would create difficulties for the CFD code. An alternative is to use a friction velocity
based on the turbulent kinetic energy k (which would have been more difficult to attain in
the experiments). q
1/2
uτ = Cµ k Cµ = 0.09 (151)
A dimensionless velocity scale based on the turbulent kinetic energy is denoted as y ? rather
than y + by CFD codes.
U ρuτ y (Tw − Tp )ρcp uτ
q
? ? ? 1/2
U = y = T = uτ = Cµ k (152)
uτ µ qw
In most scenarios, y + and y ? are almost identical and either can be used. However, the
majority of modern CFD codes prefer to use y ? in their calculations.

Deriving a Wall Function for νw


We now have a mathematical model for the velocity profile normal to the wall:

y + y + < 11.25
U+ = (153)
 1 log (Ey + ) y + > 11.25
κ

Dr. Aidan Wimshurst, Fluid Mechanics 101 47


3 WALL FUNCTIONS

Replace the dimensionless variables with the actual variables (U + = U/uτ and y + = ρuτ y/µ):
U ρuτ y
= y + < 11.25
uτ µ
!
U 1 ρuτ y
= log E y + > 11.25 (154)
uτ κ µ
The trick to calculating the wall shear stress τw from these profiles is to write:
U U uτ
= 2 (155)
uτ uτ
q
Then recall that uτ = |τw |/ρ and therefore u2τ = −τw /ρ
U U uτ U ρuτ
= 2 =− (156)
uτ uτ τw
The velocity profile then becomes:
U ρuτ ρuτ y
− = y + < 11.25
τw µ
!
U ρuτ 1 ρuτ y
− = log E y + > 11.25 (157)
τw κ µ
Rearrange for the wall shear stress (τw ):
U
τw = −µ y + < 11.25
y
U ρuτ
τw = − 1   y + > 11.25 (158)
κ
log E ρuµτ y
This equation gives the real wall shear stress that is exhibited by a turbulent velocity profile
over a flat plate. In a CFD code, the velocity profile between the wall adjacent cell centroid
and the wall is always linear. As shown in Figure 23, the velocity at the cell centroid is Up
and the cell is a height yp normal to the wall. Hence, the wall shear stress in the CFD code
is always:
∂U Up
τw = −ρν = −ρνw (159)
∂y y=0 yp
To ensure that the CFD code always computes the correct wall shear stress, equate equation
159 with equation 158 (noting that the velocity and wall normal distance in equation 158 are
now evalauted at the cell centroid, U = Up and y = yp ).
Up Up
−ρνw = −ρν y + < 11.25
yp yp
Up Up ρuτ
−ρνw =−1 
ρu y
 y + > 11.25 (160)
yp log E µ τ p
κ

Rearrange for νw .
νw = ν y + < 11.25
uτ y p
νw =   y + > 11.25 (161)
1
κ
log E ρuµτ yp

Dr. Aidan Wimshurst, Fluid Mechanics 101 48


3 WALL FUNCTIONS

Figure 28: The variation of near wall kinematic viscosity νw with y +

(a) (b)

Figure 29: A diagram to shown the difference in wall treatment when (a) y + < 11.25 and
(b) y + > 11.25

Make a final substitution (y + = yp uτ /ν) to simplify the equation:



ν


!
y + < 11.25
νw = + (162)
y
ν

1 y + > 11.25
log (Ey + )

κ

Equation 162 is the wall function for the near wall kinematic viscosity νw and is plotted
in Figure 28. Physically, the equation states that if the wall adjacent cell is thin enough
(y + < 11.25), then the near wall kinematic viscosity is set equal to the molecular viscosity
of the fluid (ν). This will result in the correct wall shear stress as the true velocity profile is
linear. However, if the cell is large (y + > 11.25), then the CFD code assumes that the velocity
profile between the wall adjacent cell centroid and the wall is linear. This is not correct, as
the real velocity profile is non-linear. However, if the near wall kinematic viscosity is increased
using equation 162, the the product of the near wall kinematic viscosity and the (incorrect)
velocity gradient will yield the correct wall shear stress.
τw
= −Near Wall Kinematic Viscosity × Velocoity Gradient (163)
ρ
Figure 29 shows a diagram to illustrate this process. The astute reader will notice that

Dr. Aidan Wimshurst, Fluid Mechanics 101 49


3 WALL FUNCTIONS

Water
Air

Figure 30: The variation of the near wall thermal diffusivity αw with y + for air and water.

equation 162 can be written concisely as:


" #
y+
νw = ν ∗ (164)
f (y + )

where f (y + ) is given by equation 153. Hence, if a new function for U + is proposed (replacing
equation 142), then the wall function for νw can be deduced directly from the above equation.
It should also be noted that y ? can be used in place of y + in the wall function for near
wall kinematic viscosity.

ν

 y ? < 11.25
y?
!
νw = (165)
ν

1 y ? > 11.25
log (Ey ? )

κ

The majority of CFD codes (ANSYS Fluent, ANSYS CFX, Star CCM+) use the y ? formulation
instead of y + . OpenFOAM offers the choice of both: nutUWallFunction (for y + ) and
nutkWallFunction (for y ? ).

Wall Function for αw


The wall function for the near wall thermal diffusivity (αw ) takes a similar form to νw :



α y + < yL+
  
αw =   P r y+ (166)
α
 
1
 y + > yL+
 P rt κ
log (Ey + ) +P

For brevity, the derivation will not be provided here, as it follows an identical process to
the wall function for νw in the previous section. The wall function for αw is shown in Figure
30 for air and water. In the same manner as νw , for y + < yL+ , αw takes the value of the
molecular thermal diffusivity α. For y + > yL+ , the thermal diffusivity is increased, to ensure
that the product of the near wall thermal diffusivity and the temperature gradient gives the
correct wall heat flux. Notice (in Figure 30) that air and water have different values of yL+

Dr. Aidan Wimshurst, Fluid Mechanics 101 50


3 WALL FUNCTIONS

Wall Function Here

1 2 3 4 5

Boundary Cells

Figure 31: An example problem to demonstrate 1D heat diffusion in a bar. A wall function
is applied at the right hand end (where the temperature is fixed).

and the rate of increase of αw with y + is greater for water than air. In general, the shape of
the wall function will be different for every fluid, depending on P r. The wall function for νw
however, is universal for all fluids.
Now that the wall functions for νw and αw have been presented, the remainder of the
chapter will demonstrate how the wall functions are incorporated into CFD codes. This
demonstration will be carried through an example problem.

Example Problem: Heat Diffusion in a Bar


Consider 1D steady-state diffusion of heat in a bar, as shown in Figure 31. The left end of
the bar has a fixed heat flux (qwall ) of 100 W/m2 , while the right end of the bar is at a fixed
temperature of (TB ) 200◦ C. There is a constant heat source (S) of 1000 W/m3 applied to
the bar. The bar has a density of 8000 kg/m3 and a specific heat capacity of 500 J/kg K.
For ease of comparison, this example problem has the same geometry, mesh and boundary
conditions as the previous chapter. However, unlike the previous chapter, a wall function for
the thermal diffusivity αw will be applied at the right hand end (where the fixed temperature
is applied). To evaluate the wall function, the material is assumed to have a Prandtl number
(P r) of 0.71 and the right boundary cell has a y + = 30.

Step 1: Divide the Geometry into a Mesh


For the example in Figure 31, divide the geometry into a mesh of 5 cells of equal length. The
length of each cell (Lcell ) is given by:
L 5
Lcell = = = 1m (167)
N 5
Because the cells are uniformly distributed and have equal size, the distance between cell
centroids d is equivalent to the length of the cells. Hence:

dLP = dP R = d = 1m (168)

Step 2: Evaluate the Wall Function


Before the material properties can be assigned, the wall function needs to be evaluated. As the
wall function for αw is being applied (equation 166), the first stage is to evaluate the empirical

Dr. Aidan Wimshurst, Fluid Mechanics 101 51


3 WALL FUNCTIONS

function P . For a molecular Prandtl number of 0.71 and a turbulent Prandtl number of 0.85,
the function P evaluates as:
" 3/4 #
Pr h i
P = 9.24 −1 1 + 0.28e−0.007P r/P rt = −1.491 (169)
P rt

Now the intersection point between the two sections of the wall function (yL+ ) needs to be
calculated. This requires the solution of the following non-linear equation for y + (equation
148):
1
   
+ +
P r y − P rt log Ey + P = 0 (170)
κ
This non-linear equation can be solved with any root finding algorithm (Bisection, Newton-
Raphson etc.). The Newton-Raphson method gives rapid convergence and will be used here.
To use the Newton-Raphson method, define:
1
   
+
f = P r y − P rt log Ey + + P (171)
κ
df P rt
+
= Pr − + (172)
dy κy
The Newton-Raphson iteration proceeds by evaluating:

+ f
yi+1 = yi+ − (173)
df /dy +

Starting from an initial guess (y0+ ) of 11.0, the Newton-Raphson iteration gives:

Iteration yi+ +
yi+1
1 11.000 11.806
2 11.806 11.796
3 11.796 11.796

Hence, the solution of the Newton Raphson procedure gives yL+ = 11.796 when P r = 0.71.
Now that yL+ has been evaluated, αw can be calculated (using equation 166).



α y + < yL+
  
αw =   P r y+ (174)
α
 
1
 y + > yL+
 P rt κ
log (Ey + ) + P

In this example, y + = 30. Hence, αw /α = 2.074 and the near wall thermal diffusivity will be
approximately double the thermal diffusivity of the interior cells.

Step 2: Assign Material Properties


The wall function is applied to the molecular thermal diffusivity α. The molecular thermal
diffusivity is defined as:
k
α= (175)
ρcp

Dr. Aidan Wimshurst, Fluid Mechanics 101 52


3 WALL FUNCTIONS

Wall Function Here

Figure 32: Thermal conductivity of each of the faces in the mesh when a wall function is
applied to the right end of the bar.

where k is the thermal conductivity, ρ is the material density and cp is the specific heat
capacity. For the example problem considered here:
k 100
α= = = 2.5 × 10−5 [m2 /s] (176)
ρcp 8000 ∗ 500
This is the thermal diffusivity for all the interior cells and interior faces in the mesh. For the
right boundary face, the thermal diffusivity is modified by the wall function:
αw
= 2.074 αw = 5.185 × 10−5 [m2 /s] (177)
α
As the thermal diffusivity of the right boundary face is now αw , then the thermal conductivity
of the face kw is also modified.

kw = ρcp αw = 8000 ∗ 500 ∗ 5.185 × 10−5 = 207.4 [W/mK] (178)

It follows that the thermal conductivity of all the faces in the mesh is constant (100 W/mK),
except for the right boundary face, where k modified by the wall function. The variation of
thermal conductivity across the mesh is shown in Figure 32. For the interior cells in the mesh,
the diffusive heat flux across the cell faces DA is given by:
kA 100 ∗ 0.1
DA = = = 10 [W/K] (179)
d 1
For the right boundary cell, the diffusive heat flux is evaluated using the modified thermal
conductivity (kw ).
kw A 200 ∗ 0.1
DA = = = 20.74 [W/K] (180)
d 1
The heat source in each cell is not affected by the wall function. It is given by:

SV = SALcell = 1000 ∗ 0.1 ∗ 1 = 100 [W] (181)

Step 3: Calculate the Matrix Coefficients


The matrix coefficients for 1D heat diffusion in a bar with fixed temperature (Dirichlet)
boundary conditions at the left end and fixed heat flux (Neumann) boundary conditions at
the right end are:

Dr. Aidan Wimshurst, Fluid Mechanics 101 53


3 WALL FUNCTIONS

Matrix Coefficients

aL aR aP Sp Su
Boundary (L) 0 DR AR al + ar − Sp 0 −qA AL + SV
Interior DL AL DR AR al + ar − Sp 0 SV
Boundary (R) DL AL 0 al + ar − S P −2D R AR TB (2D R AR ) + SV

However, as a wall function is applied to the right face of the right boundary cell, the coef-
ficient DR (highlighted in red in the table above) is modified by the wall function. The other
coefficients remain unchanged by the wall function. Filling in the table with the calculated
coefficients:

Matrix Coefficients

aL aR aP Sp Su
Boundary (L) 0 10 10 0 90
Interior 10 10 20 0 100
Boundary (R) 10 0 51.5 -41.5 8395.9

It is clear that the wall function enters the matrix equations through the diagonal coefficient
ap and the source term Su of the cell that contains the boundary face. The coefficients in
the other cells remain unchanged.
Using summation notation, the wall function modifies the face contribution of the right
boundary face through kw . No other changes are made to the face contributions of the other
faces.

Summation Notation

Face Type aP aN Su
Interior 10 10 0
Neumann (Left) 0 0 -10
Dirichlet (Right, No Wall Function) 20 0 4000
Dirichlet (Right, Wall Function) 41.5 0 8295.9

Dr. Aidan Wimshurst, Fluid Mechanics 101 54


3 WALL FUNCTIONS

Step 4: Assemble and Solve the Matrices


As a reminder, the matrices are populated in the following manner:
    
ap1 −ar1 0 0 0 T1 Su1
−al2 a −a 0 0  T2  Su2 
    
 p2 r2    
 0
 −al3 ap3 −ar3 0  T3  = Su3 
    (182)

 0 0 −a l4 a p4 −a r4  T4 
 
Su4 
 
0 0 0 −al5 ap5 T5 Su5
Filling in the known coefficients from the table above:
    
10 −10 0 0 0 T1 90
−10 20 −10 0 0  T2   100 
    
    
 0
 −10 20 −10 0  T3  =  100 
    (183)
 0

0 −10 20 −10  T4   100 
  

0 0 0 −10 51.5 T5 8395.9
For the case when a wall function is not applied, DR AR = kA/d = 10 W/mK and the
matrices reduce back to the same matrices from the previous chapter.
    
10 −10 0 0 0 T1 90
−10 20 −10 0 0  T2   100 
    
    
 0
 −10 20 −10 0 
 T3  =  100 
    (184)
 0

0 −10 20 −10 T4   100 
  

0 0 0 −10 30 T5 4100
Hence, the effect of the wall function is localised to the cell where the wall function is applied.

Run the Example Problem Yourself!


Now, open either the Excel spreadsheets or the Python source code and solve the problem for
yourself.

Excel wallFunction.xlsx

Python wallFunction.py

Examine the calculation of the coefficients, the assembly of the matrices and run the code.
A fixed value of y + = 30 has been set initially. Try changing the value of y + and observe the
changes in the solution. Note that in a real CFD code, y + changes automatically in response
to changes in the mesh. In this problem, we are specifying the value of y + directly instead,
so that we can observe the changes in solution for a fixed mesh. Hence, the solution is not
strictly accurate, but is useful for demonstration purposes.

Results
Figure 33 shows the temperature variation along the bar, for different values of y + on the
right boundary face. Notice that the temperature of the right boundary face is fixed at

Dr. Aidan Wimshurst, Fluid Mechanics 101 55


3 WALL FUNCTIONS

350
325
300

T [◦ C]
275
y+ = 5
250
y + = 30
225 y + = 100
200
0 1 2 3 4 5
x [m]

Figure 33: Temperature variation along the 1D bar with different values of y + on the right
boundary face.

200◦ C. However, the temperature of the wall adjacent cell centroid (T5 ) is modified by the
wall function. This results in a change in shape of the entire temperature profile.
The temperature of the wall adjacent cell centroid (T5 ) is not modified because the wall
function changes its temperature directly. The temperature of the cell is modified because
the wall function modifies the thermal conductivity of the right face of this cell from 100
W/mK to 207.4 W/mK. In order to maintain the same heat heat flux from the wall (qw ), the
temperature gradient (dT /dx) is reduced to counterbalance the increase in kw . The table
below summarises the heat flux balance for every cell in the mesh for a y + of (a) 5 and (b)
30. It is clear that the heat flux through the faces of each of the cells remains unchanged by
the wall function, but the temperature profile does change (see Figure 33).

Dr. Aidan Wimshurst, Fluid Mechanics 101 56


3 WALL FUNCTIONS

Heat Flux Balance


(a) y + = 5

Cell Ql [W] Qr [W] SV [W] Error


1 10 90 100 0
2 -90 190 100 0
3 -190 290 100 0
4 -290 390 100 0
5 -390 490 100 0

Heat flux out of the bar = 490 + 10 = 500W


Heat generated in the bar = 100 + 100 + 100 + 100 + 100 = 500W

(b) y + = 30

Cell Ql [W] Qr [W] SV [W] Error


1 10 90 100 0
2 -90 190 100 0
3 -190 290 100 0
4 -290 390 100 0
5 -390 490 100 0

Heat flux out of the bar = 490 + 10 = 500W


Heat generated in the bar = 100 + 100 + 100 + 100 + 100 = 500W

As the heat flux from the left end of the bar is fixed by the boundary condition (10W)
and 500W is generated in the bar, 490W must pass out of the bar at the right end. Hence,
as the wall function modifies αw , the temperature gradient at the wall changes, so that the
heat flux remains the same (490W).

Dr. Aidan Wimshurst, Fluid Mechanics 101 57

You might also like