Computational Fluid Dynamics Fundamentals Course 2
Computational Fluid Dynamics Fundamentals Course 2
Computational Fluid Dynamics Fundamentals Course 2
Fundamentals Course 2
Table of Contents
Foreward 4
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
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.
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
∂ (ρ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
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
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
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 ).
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
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).
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
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.
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.
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
(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)
ap Tp = aL TL + aR TR + Su (48)
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 .
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
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):
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.
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.
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
(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.
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)
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.
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):
Face Type aP aN Su
Interior 10 10 0
Dirichlet (Left) 20 0 2000
Dirichlet (Right) 20 0 4000
Neumann (Left) 0 0 -10
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.
(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
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:
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
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:
The table below summarises the heat balance for each cell in the mesh:
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):
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)
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
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
Top 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.
Manipulate the equation slightly (add a zero to the TP bracket) to express in standard form.
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)
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.
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:
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.
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).
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:
TP [0 + Dr Ar + Db Ab + Dt At + 0] = TL [0] + TR [Dr Ar ]
+ TB [Db Ab ] + TT [Dt At ]
− qwall Al + SV (111)
+ −qwall Al + SV (112)
| {z }
Su
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.
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
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
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 .
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.
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.
Width = 4m Top
Left Right
Bottom
Length = 4m
B = [Su1 Su2 Su3 Su4 Su5 Su6 Su7 Su8 Su9 Su10 Su11 ...
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
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)
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
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
B = [7100 5100 5100 9100 2100 100 100 4100 2100 100 100 ...
Excel solve2DDiffusionEquation.xlsx
Python solve2DDiffusionEquation.py
(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
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.
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):
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.
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.
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
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
(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.
(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
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
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.
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
(a) (b)
Figure 29: A diagram to shown the difference in wall treatment when (a) y + < 11.25 and
(b) y + > 11.25
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
Water
Air
Figure 30: The variation of the near wall thermal diffusivity αw with y + for air and water.
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 ? ).
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+
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.
dLP = dP R = d = 1m (168)
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.
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.
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:
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
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
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).
(b) y + = 30
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).