Fluid Mechanics 101: Fundamentals Course 3
Fluid Mechanics 101: Fundamentals Course 3
Fundamentals Course 3
Foreward 4
Unstructured Meshes 6
Mesh Quality 38
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.
Foreward
In Chapter 1 of this course, the unstructured approach to CFD codes is explained in detail.
This requires the nodes, faces and cells in the mesh to be treated as seperate entities and
requires the CFD codes that were created in Part 1 and Part 2 to be completely rewritten.
To finish the Chapter, the example problem from Part 2 of this course is revisited and solved
using an unstructured approach, rather than a structured approach. The solution generated
with the unstructured approach is shown to be identical to the structured approach.
The majority of real CFD codes contain a variety of cell shapes and sizes. Some of these cells
may be of poor quality, which can lead to numerical errors and even divergence of the CFD
solver in some cases. To help the user, CFD codes and mesh generators use a variety of
quality metrics to help identify the bad cells. However it is often not clear what these metrics
actually mean and how they are calculated. In Chapter 2 of this course, the main quality
metrics are introduced and explained in detail. The interactive exercise then allows these
metrics to be observed as the mesh changes.
I am really excited to bring you Part 3 of 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 and 2, 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.
0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 1 0
0 0 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 1 0
0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1
1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1
1 0 0 0 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 1 0
1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1
0 1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1
1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1
0 1 1 1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1
0 0 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 1 0
0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1
1 1 1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1
5
Chapter 1
Unstructured Meshes
Figure 2: Cells, faces and nodes are treated as seperate entities in unstructured CFD codes.
For simplicity, the convection term and the temporal derivative will not be considered and the equation
will be solved in 2D rather than 3D.
In the previous course, the cell neighbours were referred to as ’left’, ’right’, ’top’ and ’bottom’, as
the mesh was structured and all cells had 4 neighbours which were aligned with the coordinate axis.
It is not possible to use this approach with an unstructured formulation, as it cannot be specified
explicitly how many neighbours each cell has and which direction they will be in. The approach
needs to be more general. In this Chapter, an alternative formulation of the discretised heat diffusion
equation will be presented, which is applicable to all unstructured meshes.
Start with the vector form of the heat diffusion equation:
0 = ∇ · (k∇T ) + S (1)
where T is the static temperature, k is the thermal conductivity and S is a heat source per unit
volume (with units of [W/m3 ]). Note that ∇· is the divergence operator, which can be written in 2D
Cartesian coordinates (x, y) as: !
∂ ∂
∇= , (2)
∂x ∂y
The first step in the finite volume method is to integrate the equation over a finite-sized control
volume (cell) with volume V . Z
0= [∇ · (k∇T ) + S] dV (3)
V
Separate the integral into two separate integrals: one containing the diffusion term and the other
containing the source term. This is permissible as integration and addition are commutative operations
Figure 3: An example of the linear variation of the source term across a control volume.
Figure 4: A diagram to show the physical significance of the divergence theorem applied to the
vector field B. The accumulation of B in the volume equals the flux of B across the faces of the
volume.
In the finite volume method, all quantities vary linearly across the cell. As shown in Figure 3, the
integral of the source term across the cell volume can therefore be replaced by the value at the cell
centroid (Sp ), multiplied by the volume of the cell (Vp ).
Z
[S] dV = Sp Vp (5)
V
Z
0= [∇ · (k∇T )] dV + Sp Vp (6)
V
In this course, the subscript p will be used to refer specifically to the value at the cell centroid, to
distinguish the term from other locations in the mesh (such as the value at the face centre).
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:
Z Z
(∇ · B) dV = (B · n̂) dA (7)
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. Physically, the divergence theorem states that the rate of accumulation of a
quantity B inside a control volume must be equal to the flux of B across the surface of the volume,
regardless of what the quantity B is. A diagram to illustrate the physical meaning of the divergence
theorem is shown in Figure 4.
To apply the divergence theorem to the heat diffusion equation, let B = k∇T . The diffusion
term can then be simplified using the divergence theorem:
Z
0= (k∇T · n̂) dA + Sp Vp (8)
A
This form of the heat diffusion equation is general for any volume, regardless of its shape. However,
CFD meshes are constructed from cells which have a finite number of flat faces (they are not smooth
continuous surfaces). The surface integral can therefore be split up into the surface integral over
each of the cell faces (regardless of how many faces the cell has).
X Z
0= (k∇T · n̂) dA + Sp Vp (9)
Faces A
This formulation is still general and can be applied to any type of unstructured mesh, as long as the
cells in the mesh have a finite number of flat faces.
In the finite volume method, the flow quantities all vary linearly across the cell faces, as shown
in Figure 5. The integral across the face can therefore be reduced to the value at the centre of the
face (a constant value). Z
X
0= [(kf (∇T )f · n̂f )] dA + Sp Vp (10)
Faces A
The subscript f has been used here to emphasise that these quantities are evaluated at the face
centre. This should avoid confusion with the quantities at the cell centroid, which are given the
subscript p. As all of the quantities have now been moved outside the surface integral, the integral
just evaluates to the area of the face, Af .
X
0= [kf Af ((∇T )f · n̂f )] + Sp Vp (11)
Faces
Equation 11 is the final form of the discretised heat diffusion equation. Unlike the formulation adopted
in the previous course, this formulation is not limited to a particular cell geometry (squares, triangles
or polygons) and it can therefore be applied to unstructured and structured meshes. Note that for
a structured mesh of 2D quadrilaterals, the equation reduces back to the equation adopted in the
previous course:
! ! ! !
∂T ∂T ∂T ∂T
0 = kA − kA + kA − kA + Sp Vp (12)
∂x Right
∂x Left
∂y Top
∂y Bottom
Hence, equation 11 is actually the more generalised form of the discretised form of the heat diffusion
equation considered in the previous course.
Equation 11 may appear confusing at first, due to the number of terms and the subscript notation.
To help understand this equation better, recall that the heat flux (Q) is given by Fourier’s Law:
Q = −kA∇T (13)
where Q is the vector heat flux. The negative sign is required because heat flows in the direction
opposite to the temperature gradient ∇T (from hot to cold). Substituting Fourier’s Law into the
Figure 6: An example 2D cell with 5 faces (a pentagon). The temperature gradient (∇T )f ,
thermal conductivity (kf ) and the unit normal vector (n̂f ) are required at the face centre to
evaluate the heat flux across each face. Note that the temperature gradient is not necessarily
parallel with the unit normal vector.
X h i
Qf · n̂f = SP VP (15)
Faces
Physically the discretised form of the heat diffusion equation therefore means that the sum of the
heat fluxes across all of the faces of the cell must be equal to the sources of heat inside the cell.
Hence, the discretised form of the heat diffusion equation is actually an expression of conservation
of energy. The dot product is required to capture the component of the heat flux (Q) that passes
out of the cell across each face, as the temperature gradient does not necessarily align with the
unit normal vector (which always points out of the cell). Figure 6 shows a diagram to illustrate the
dot product of the temperature gradient and the unit normal vector. Before a CFD solution can
be constructed for the discretised heat diffusion equation (equation 11), the temperature gradient
(∇T )f at the face centre must be expressed in terms of the temperatures at the centroids of the
surrounding cells (TP ). Slightly different methods are used on the interior faces and boundary faces
in the mesh. These methods will now be presented, before illustrating the entire process with an
example problem at the end of the Chapter.
Interior Faces
At this stage, it is useful to think about cell faces specifically. Cell faces can either be interior faces
or boundary faces. Interior faces are connected to a cell on both sides, while boundary faces are
connected to a cell on a single side. Figure 7 shows an example interior face that is connected to a
triangular cell on each side. One of these cells shall be referred to as the owner (P ) and the other
cell as the neighbour (N ). It does not matter which cell is selected as the owner and which one as
the neighbour, as long as each interior face is assigned an owner cell and a neighbour cell. As shown
in Figure 8, there is a vector dP N that connects the owner cell centroid (P ) and the neighbour cell
centroid (N ) across interior faces in the mesh. This vector may not necessarily be parallel with the
unit normal vector (n̂f ) and is essential in the analysis that follows.
As a reminder, we currently have the discretised form of the heat diffusion equation (equation
11): X
0= [kf Af ((∇T )f · n̂f )] + Sp Vp (16)
Faces
Interior Face
Figure 7: A example interior face that is connected to an owner cell and a neighbour cell.
Neighbour Cell
Owner Cell
Centroid
Face Centre
Shared Face
Figure 8: An example triangular cell which is connected to a rectangular cell across an interior
face. The cell centroids are connected by a vector dP N that is not necessarily parallel with the unit
normal vector n̂f .
and need to express the dot product of the temperature gradient and the unit normal vector ((∇T )f ·
n̂f ) in terms of the temperatures at the owner and neighbour cell centroids (TP and TN ). Start by
decomposing the unit normal vector into a component n̂1 which is parallel with dP N and a residual
component which is left over (n̂2 ).
n̂f = n̂1 + n̂2 (17)
A schematic diagram of this decomposition is shown in Figure 9. Returning to the dot product of
the temperature gradient and the unit normal vector we can write:
(∇T )f · n̂f = (∇T )f · n̂1 + (∇T )f · n̂2 (18)
The vector n̂1 is parallel with dP N . Therefore, the first term can be simplified:
TN − TP
(∇T )f · n̂1 = |n̂1 | (19)
|dP N |
This simplification is valid because the temperature gradient along a straight line is:
∆T Change in Temperature
∇T ∼ = (20)
∆x Distance
and this gradient is parallel with n̂1 , so we can just multiply by the magnitude of n̂1 . Returning to
the dot product of the temperature gradient and n̂f :
TN − TP
(∇T )f · n̂f = |n̂1 | + (∇T )f · n̂2 (21)
|dP N |
Substitute this equation into the finite volume discretisation of the heat diffusion equation (equation
11): " !#
X TN − TP X
0= kf Af |n̂1 | + [kf Af ((∇T )f · n̂2 )] +Sp Vp (22)
Faces |dP N | Faces
| {z }
Non Orthogonal Term
Centroid
Face Centre
Figure 10: An example of two rectangular cells which are connected across an interior face. All of
the internal angles are 90◦ . The cell centroids are connected by a vector dP N that is parallel with
the unit normal vector n̂f .
The second summation is referred to as the non-orthogonal term and is required on meshes where
the vector dP N is not parallel with the unit normal vector n̂f (n̂2 6= 0). In this Chapter, we will limit
our consideration to unstructured meshes made up of perfect squares and rectangles only. For these
meshes n̂2 = 0. Hence:
:0
" !#
X TN − TP X
0= kf Af |n̂1 | + [kf Af((∇T
) f · n̂2 + Sp Vp
)] (23)
|dP N |
Faces Faces
" !#
X TN − TP
0= kf Af |n̂1 | + Sp Vp (24)
Faces |dP N |
Split up the fraction (so that TP and TN are separate):
" # " #
X TN X TP
0= kf Af |n̂1 | − kf Af |n̂2 | + Sp Vp (25)
Faces |dP N | Faces |dP N |
The temperature at the centroid of the owner cell (Tp ) is the same for all of the faces. Hence, it can
be brought outside the fraction:
" # " #
X kf Af X kf Af
Tp |n̂1 | = TN |n̂1 | + Sp Vp (26)
Faces |dP N | Faces |dP N |
This form may seem complicated at first glance. However, if we consider the example cell in Figure
11 with three faces, then we can easily write the expression out in its full form as an example:
" ! ! !#
k1 A1 k2 A2 k3 A3
Tp |n̂1,1 | + |n̂1,2 | + |n̂1,3 | =
|dP N,1 | |dP N,2 | |dP N,3 |
Face 1
! ! !
k1 A1 k2 A2 k3 A3
|n̂1,1 | TN,1 + |n̂1,2 | TN,2 + |n̂1,3 | TN,3 + Sp Vp (27)
|dP N,1 | |dP N,2 | |dP N,3 |
All of the terms in equation 26 are known, with the exception of the temperature at the owner
cell centroid (Tp ) and the neighbouring cell centroids (TN,1 , TN,2 , TN,3 ). It is common in the CFD
literature to write equation 26 in concise form as:
X
ap Tp = (aN TN ) + Sp Vp (28)
Faces
or: X
ap Tp − (aN TN ) = Sp Vp (29)
Faces
AT = B (30)
with the following coefficients:
X kf Af kf Af
ap = |n̂1 | aN = |n̂1 | (31)
Faces |dP N | |dP N |
When writing an unstructured CFD code, the equations above show that the process of calculating
the matrix coefficients (ap and aN ) now involves looping over the faces in the mesh. This is different
to how structured CFD codes are written, where specific cell neighbours are referred to (e.g top,
bottom, left and right). There is no restriction on the shape of the cell or the number of faces it has.
Hence, this form of the discretised heat equation can be applied to any unstructured mesh, along as
the cells have a finite number of faces.
Later in this chapter, an example problem will be used to fully demonstrate the process of calcu-
lating the matrix coefficients and assembling the matrices for unstructured meshes. However, before
this example problem can be considered, the boundary faces in the mesh need to be considered, as
they do not contain a vector dP N and need different treatment.
Boundary Faces
Boundary faces require a different formulation of the discretised heat diffusion equation to interior
faces because boundary faces are only connected to a single cell (the owner cell) on one side. They
are not connected to a neighbour cell and therefore do not have a distance dP N associated with
them. Boundary faces will either have a Dirichlet (fixed value) or Neumann (fixed gradient) condition
applied to them. These conditions were introduced in Part 2 of this course. The treatment of Dirichlet
and Neumann conditions will be revisited again here, because their treatment is slightly different for
unstructured meshes.
Figure 12: An example quadrilateral cell with one boundary face. dP F is the vector from the cell
centroid to the face centre, y is the perpendicular distance from the boundary face to the cell
centroid and n̂f is the unit normal vector pointing out of the domain.
Notice that the distance |dP N | has been replaced with |y|, which is the magnitude of the perpendicular
distance to the wall, as shown in Figure 12. The reason for this change is that the boundary
temperature is constant across the face, unlike interior faces where the temperature variation is
linear.
The perpendicular distance (y) can be calculated by first calculating the vector that connects the
cell centre to the face centre dP F .
dP F = xf − xP (34)
Now the perpendicular component can be calculated by taking the dot product with the unit normal
vector (n̂f ):
y = n̂f (dP F · n̂f ) (35)
For Neumann boundary conditions, the user specifies a heat flux per unit area qwall on the boundary
face, rather than a fixed temperature Twall . Note that qwall has units of W/m2 . For these boundary
faces, the heat flux out of the boundary cell is:
Returning to the finite volume discretisation of the heat equation for interior cells (equation 26):
" #
X TN − TP
0= kf Af |n̂1 | + Sp Vp (37)
Interior |dP N |
Faces
This equation is valid for interior cells only (cells which only contain interior faces). If the cell also
contains boundary faces, then the heat flux out of the cell across these boundary faces is also required.
Following the same procedure as before, split up the fractions so that TN , TP and Twall are treated
as separate terms.
" # " #
X TN X TP
0= kf Af |n̂1 | − kf Af |n̂1 | + (40)
Interior |dP N | Interior |dP N |
Faces Faces
" # " #
X Twall X TP X
kwall Awall − kwall Awall + [qwall Awall ] + Sp Vp (41)
Dirichlet |y| Dirichlet |y| Neumann
Faces Faces Faces
While this equation may seem complicated, it can still be written in concise form:
X
ap Tp = (aN TN ) + S (44)
Interior
Faces
Equation 42 is identical to the equation 26 (which was derived for interior faces only), with the
exception of the additional terms for the Dirichlet and Neumann boundary faces. The procedure to
assemble the equations is also identical: loop over the faces in the mesh and then add contributions
to the terms in the above equation, depending on whether the face is an interior face or a boundary
face.
Regardless of the complexity of the above formulation, it should always be remembered that the
equation represents conservation of energy in discrete form. Each of the terms represents either a
heat flux out the cell or a volumetric heat source within the cell. At all times, the units of the terms
can be checked and should evaluate to [W].
In the next section, an example problem will be considered to illustrate how the above formulation
is applied to solve the 2D heat equation on an unstructured mesh.
Figure 13: An overview of the algorithm used to solve transport equations with an unstructured
finite volume mesh.
General Algorithm
It is now possible to put together a general algorithm for how the 2D heat diffusion equation can be
solved on an unstructured mesh. An overview of the key stages in the general algorithm is shown
in Figure 13. Each of these stages will be demonstrated in the example problem and expanded on
in more detail in the following sections. Stages 1, 2, 3 and 4 (in Figure 13) are usually carried out
by the meshing software. The mesh is then passed to the CFD solver and stages 5, 6, 7 and 8 are
calculated by the CFD solver itself.
The nodes are straightforward, as they only require x, y and z coordinates to fully define them.
However, the faces and cells require many more quantities (face centre, face area, unit normal vector,
volume etc.) to be calculated in order to fully define them. The methods used to calculate these
quantities will be presented in the following sections.
2 3
Figure 14: An example of the face centre calculation for a polyhedral cell
Face Centre
The face centre is the most straightforward quantity to calculate. It is calculated as the arithmetic
average of the nodes that make up the face.
1 X
xf = xNode (47)
N Nodes
This calculation is valid for all polyhedral cells, as long as the nodes that make up the face lie in on
a flat plane. Figure 14 shows an example cell where the face centre is calculated on one of the faces.
Face Area
For 2D cells, the face area (Af ) can be calculated from the magnitude of the vector that connects
the two nodes that make up the face.
Af = |x2 − x1 | (48)
This calculation is illustrated in Figure 15. For 3D cells, it is more complicated to compute the
face area, as the face may not be a regular polygon. It could have N faces and may be highly
skewed. Therefore, simple formulas for calculating the areas of regular polygons are not appropriate.
An alternative approach to computing the face area will be presented later, when the cell volume is
computed.
Figure 16: Normal vector generation on the face of (a) a 3D cell and (b) a 2D cell.
Centroid
Face Centre
Figure 17: Examples of (a) an outwards facing unit normal vector and (b) an inwards facing unit
normal vector. The vector c connects the cell centroid with the face centre.
Figure 16 (a) shows an example of the normal vector generation for a face on a 3D cell. For 2D
cells, the calculation of the unit normal vector is more straightforward, as the face is defined by a
line between 2 nodes. As shown in Figure 16 (b), this 2D vector a can be rotated by 90 degrees
(becoming the normal vector) with the following formula:
a = (ax , ay ) (50)
nf
nf = (−ay , ax ) n̂f = (51)
|nf |
When constructing the mesh, the normal vectors should always point out of the cell that they belong
to (the owner cell P ). So when constructing the mesh, it should be checked that the normal vectors
are pointing out of the owner cells. As shown in Figure 17, this checking procedure can be carried
out by taking the dot product of the vector xf − xc with the unit normal vector. The vector xf − xc
represents the vector from the cell centroid to the face centre. If the dot product is positive, the
unit normal vector is pointing out of the cell. Conversely, if the dot product is negative then the unit
normal vector is pointing into the cell and must be reversed.
Recall that vectors can be reversed (or rotated by 180◦ ) by multiplying all components by -1.
Figure 18: Examples of (a) Regular Polyhedra and (b) Irregular Polyhedra
Cell Volume
The cell volume is not straightforward to calculate, as the cells may be skewed, have a large number
of faces or have faces with different areas. Therefore, (for unstructured meshes) a general approach
is needed to compute the cell volume. This approach needs to be appropriate for irregular polyhedra
(see Figure 18) and skewed cells.
To ensure that the approach is general and works for any unstructured mesh, an equation for
the cell volume will be derived for an N sided irregular polyhedra (Figure 18 (b)). As the formula is
appropriate for an N sided irregular polyhedra, it can be applied to all cells in the unstructured mesh,
regardless of their shape. To derive this formula, start with the divergence theorem in its general
form (equation 7 from earlier in this Chapter):
Z Z
(∇ · B) dV = (B · n̂) dA (54)
V A
Recall that this formula is valid for any vector field B. The trick to calculate the volume of the cell
with this formula is to let:
1
B = (x, y, z) (55)
3
We can evaluate the divergence of this field directly:
∂Bx ∂By ∂Bz 1
∇·B = + + = (1 + 1 + 1) = 1 (56)
∂x ∂y ∂z 3
By substituting this expression into the left-hand side of the divergence theorem, the left hand side
becomes the volume of the cell.
Z Z
(∇ · B) dV = (B · n̂) dA (57)
V A
Z Z
(1) dV = (B · n̂) dA (58)
V A
Z
Vp = (B · n̂) dA (59)
A
The divergence theorem has now become an equation for the volume of the cell! However, the vector
field B has now been specified. Hence, B also has to be substituted into the right hand side of this
equation. Z
1
Vp = (x, y, z) · n̂ dA (60)
A 3
The right hand side of this equation can be best understood using Figure 19. At every location on
the surface, the coordinate of the point on the surface (x, y, z) is multiplied by the local unit normal
vector (n̂). This process is repeated (integrated) over the entire surface of the cell to calculate the
volume. This integral is computationally expensive to carry out. Hence, it will be simplified to reduce
the computational cost.
Figure 19: The product of the surface coordinate (x, y, z) and the unit normal vector (n̂) are
integrated over the surface of the cell.
Figure 20: The integral across the face is equivalent to taking the face centre value multiplied by
the face area.
To simplify the integral, first note that the cell has a finite number of faces N . Hence, the integral
over the surface of the entire cell can be split into the surface integral over each of the faces of the
cell individually:
X Z 1
Vp = (x, y, z) · n̂ dA (61)
Faces A 3
Recall that the flow quantities all vary linearly across the faces of the cell. Hence, the integral over
the face is equivalent to the value at the face centre multiplied by the area of the face. This can
be best understood visually, using Figure 20. Hence, the integral over the face of the cell can be
replaced with the value at the centre of the face. The subscript f will be used to denote the value
at the centre of the face:
X 1
Vp = ((xf , yf , zf ) · n̂f ) Af (62)
Faces 3
Notice that the general coordinates x, y and z are now evaluated locally at the centre of the face
only (xf , yf and zf ). Likewise, the unit normal vector (n̂f ) is now only evaluated at the centre of the
face, rather than continuously along the face. Hence, the dot product is now only evaluated locally
at the centre of the face. With this simplification, the formula for the volume of the cell can be
written concisely as the dot product of the face centre coordinate and the unit normal vector at the
centre of the face:
X 1
Vp = (xf · n̂f )Af (63)
Faces 3
This formula is valid for any 3D polyhedral cell, regardless of the number of faces and whether the
cell is skewed or not.
When evaluating the formula it should be emphasised that the coordinates of the centre of the
face (xf = (xf , yf , zf )) are evaluated relative to the centroid of the cell and are not global
coordinates. This is to ensure that the dot product actually represents the flux out of the cell, as is
Figure 21: The cell centroid can be computed from either the nodal coordinates or the face centre
coordinates
required by the divergence theorem. Hence, the formula should actually be written (more correctly)
as:
X 1
Vp = ((xf − xc ) · n̂f )Af (64)
Faces 3
Following the same approach as used for the 3D cell, the volume of the cell in 2D is:
X 1
Vp,2D = ((xf − xc ) · n̂f )Af (66)
Faces 2
This formula is used in the example code later in this chapter to calculate the area of the cells that
make up the 2D unstructured mesh.
Cell Centroid
The cell centroid can be calculated by either taking the arithmetic average of all of the nodal coordi-
nates that make up the cell, or the arithmetic average of the face centre coordinates. This method
is applicable to both 2D cells and 3D cells.
1 X 1 X
xCentroid = xFace xCentroid = xNode (67)
N Faces N Nodes
As the face centre coordinates where calculated from the nodes, either method of calculating the
cell centroid will produce the same result. Figure 21 shows an example 2D cell to illustrate the two
methods that can be used to calculate the cell centroid.
Face 4
Face 2
Face 6
Cell 1 Cell 2
0
0 2 4
Figure 22: Two example cells that will be used to illustrate the cell construction process.
Notice that all of the faces are boundary faces (they are only connected to a single cell), except
for face 2, which is an interior face. Face 2 is connected to both cell 1 and cell 2. For face 2, its
owner cell has been selected as cell 1 and its neighbour cell as face 2. This means that (later on when
the matrices are calculated) the unit normal vector points out of cell 1 and into cell 2. As explained
in the previous section, it does not matter which cell is selected as the owner and the neighbour cell,
as long as the vector points out of the owner cell and into the neighbour cell.
Now that the face centres and unit normal vectors have been computed for all the faces, the
volume of each cell can be computed. Once the cell volumes have been computed, the cells are fully
defined and a CFD solution can be computed.
To calculate the volume of the cells in Figure 22, the cells are considered one at a time, in isolation
from the rest of the mesh. This means that the unit normal vectors will all be pointing out of the
cell, when its volume is being calculated. Hence, when Cell 2 is considered, the unit normal vector
for Face 2 will be reversed (as Face 2 belongs to Cell 1). Recall that the volume of a 2D cell can be
computed using equation 66:
X 1
Vp,2D = ((xf − xc ) · n̂f )Af (70)
Faces 2
Using the values in the table above, the volume of Cell 1 is:
1 1 1 1
Vp,2D = (0 + 0.5)2 + (1 + 0)1 + (0 + 0.5)2 + (1 + 0)1 = 2 (71)
2 2 2 2
and the volume of Cell 2 is:
1 1 1 1
Vp = (0 + 0.5)2 + (1 + 0)1 + (0 + 0.5)2 + (1 + 0)1 = 2 (72)
2 2 2 2
Each cell has a volume of 2, which can be checked by inspection.
This method may appear unnecessarily complicated for such simple cells. However, it should be
remembered that this method is universal and can also be applied to more complicated cells, like
skewed cells and irregular polyhedra, where simple methods cannot.
4m
(a) Geometry (b) Boundary Conditions
0 1 2 3 4
0 1 2 3
5 6 7 8 9 4 5 8 6 7 0 1 2 3
9
10 11 12
10 11 12 13 14 13 14 15 16 17 4 5 6 7
18 19 20 21
15 16 17 18 19 22 23 24 25 26 8 9 10 11
27 28 29 30
20 21 22 23 24 31 32 33 34 35 12 13 14 15
36 37 38 39
(c) Nodes (d) Faces (e) Cells
Figure 23: A summary of the geometry, mesh and boundary conditions for the example problem.
the geometry that was used in the Part 2 of this course. However, the mesh is now treated as an
unstructured mesh, rather than a structured mesh. This means that the nodes, faces and cells are
treated as independent units.
The plate has a thickness of 0.1m, a width of 4m, a height of 4m, and a thermal conductivity
of 100 W/mK. The walls of the plate are held at fixed temperatures of 100◦ C, 150◦ C, 200◦ C and
250◦ C on the left, bottom, right and top sides respectively. There is a volumetric heat source of 1000
W/m3 in the plate.
As you proceed through the following sections where the solution procedure is described, follow
along with either the python source code or the Excel sheets provided.
unstructuredMesh.py unstructuredMesh.xls
Either the python or Excel approach can be used to solve this problem. However, it should be
noted that real CFD codes use an object-oriented programming approach. Hence, the python code
is preferred in this instance.
Mesh Generation
The first stage in the solution process is to assemble the mesh. Meshes can be generated using a
variety of techniques (block-structured, Delaunay triangulation, Octree etc). In this course, a manual
approach will be adopted for simplicity.
Start by assembling the nodes as shown in Figure 23 (c). The numbering scheme used to identify
the nodes (along with their coordinates) is shown in the table below.
Figure 24: A diagram to highlight the interior faces and Dirichlet boundary faces in the mesh.
Nodes
For this example problem, the nodes have a regular pattern. This is to make it easier to follow
and recreate but is not essential for unstructured meshes.
Now that the nodes have been created, the faces can be constructed from the nodes. Each face
needs to know which nodes it was constructed from and whether it is an interior face, a Dirichlet
boundary face or a Neumann boundary face. Figure 24 shows a diagram to highlight which faces are
interior faces, which faces are Dirichlet and which faces are Neumann faces in the mesh. The interior
faces have an owner cell and a neighbour cells, while the Dirichlet and Neumann faces only have an
owner cell. Hence, interior faces are actually two-sided faces, while the Dirichlet and Neumann faces
are single-sided faces.
Having constructed the faces from the nodes, the properties of the faces can be calculated. This
includes: the face centre (xf ), the face area (Af ) and the unit normal vector (n̂f ). The face centres
are calculated by arithmetic averaging the nodes that they were constructed from (equation 47). As
the mesh is 2D and each face only has 2 nodes:
1 X 1
xf = xNode −→ xf = (x1 + x2 ) (73)
N Nodes 2
The face area can be computed using equation 48. This is the same method that was used for the
example problem in the previous section (the 2D rectangles).
Af = |x2 − x1 | (74)
As the mesh in this example is 2D, the unit normal vector for each face is calculated using equation
51. More specifically, the vector that connects the two nodes that make up the face (a) is rotated
by 90 degrees.
n
n = (−ay , ax ) n̂f = (75)
|n|
After creating the unit normal vectors, it must be checked that the unit normal vectors are all pointing
out of the cells that they belong to, to ensure that the cell volumes are computed correctly. The check
on the unit normal vector direction is carried out by taking the dot product of the unit normal vector
(n̂f ) and the vector that connects the face centre to the cell centroid (xf − xc ) (using equation 52).
Figure 25: Diagrams to show the connecting vector dP N and perpendicular vector y that are
needed for interior and boundary faces respectively.
If the unit normal vector is pointing out of the cell, then the dot product will be positive. Conversely,
if the unit normal vector is pointing into the cell, then the dot product will be negative and the unit
normal vector must be reversed (by multiplying it by -1). This process of checking the unit normal
vector can be examined in the python code and Excel sheets.
Unlike the previous example problem (where a CFD solution was not computed), the vector dP N
that connects the cell centroids across the interior faces in the mesh, also needs to be computed.
As shown in Figure 25, the connecting vector is the vector from the owner cell centroid (xP ) to the
neighbour cell centroid (xN ) across the face of interest.
dP N = xP − xN (77)
Boundary faces do not have a neighbour cell. Hence, a connecting vector is not calculated for these
faces. However, boundary faces need to know the perpendicular distance from the cell centroid to
the wall (y) instead. This vector is also shown in Figure 25. To calculate the perpendicular distance
to the wall, start with the vector between the cell centroid and the boundary face centre (dP F ):
dP F = xf − xP (78)
The connecting vector (dP N ) and the perpendicular vector (y) are calculated for every face in the
mesh and are shown in the table below. Note that interior faces do not have a perpendicular distance
vector y, while boundary faces do not have a connecting vector dP N .
The nodes and faces have now been assembled and are fully defined. The cells can now be
constructed from the faces. To start constructing the cells, the cell centroids are calculated by
arithmetic averaging either the face centres or the nodes that make up the cell (equation 67):
1 X 1 X
xP = xf or xP = xNode (80)
N Faces N Nodes
As the mesh is constructed from all quadrilateral cells in this example, the equation becomes:
1 1
xP = (xf 1 + xf 2 + xf 3 + xf 4 ) or xP = (xn1 + xn2 + xn3 + xn4 ) (81)
4 4
In addition to the cell centroid, the cell volume has to be calculated. The cell volume is calculated
using equation 66
X 1
Vp,2D = ((xf − xc ) · n̂f )Af (82)
Faces 2
The cell volume calculation is carried out by looping over the faces that make up each cell and adding
their contribution to the cell volume. This process can be examined in the python code and the
Excel sheets.
The table below shows the cell centroid (xP ) and volume of the cell (VP ) for all cells in the mesh.
Now that the nodes, faces and cells are all fully defined, the meshing process is complete. The
generated mesh can now be passed to the CFD software (such as ANSYS Fluent, OpenFOAM, Star
CCM and ANSYS CFX), where the matrices are assembled and the equations solved.
Matrix Coefficients
The first stage in the solution process is to compute the matrix coefficients (aP , aN and S), so that
the matrices can be assembled and the CFD equations solved. As a reminder, the finite volume
discretisation of the heat diffusion equation is:
X
ap Tp = (aN TN ) + S (83)
Interior
Faces
Next loop over the cells in the mesh. For each of the cells, add up the contributions of each of
the faces that makes up the cell. The table below summarises each of the cells and the faces that it
is constructed from:
Cells
4 Cell 0 5 4 5 6 7
9 8 9 10 11
12 13 14 15
Figure 26: A diagram to highlight Cell 0 in the mesh. Cell 0 is constructed from faces 9, 5, 0 and
4.
As an example of this process, consider Cell 0, which is located in the top left hand corner of
the mesh, as shown in Figure 26. Cell 0 is constructed from faces 9, 5, 0 and 4. Faces 9 and 5 are
interior faces, while faces 0 and 4 are Dirichlet boundary faces. Hence, the coefficient ap for Cell 0
has a contribution from faces 9, 5, 0 and 4. By using the table of face contributions, ap for Cell 0 is:
ap = 10 + 10 + 20 + 20 = 60 (89)
which is in agreement with the table above. As a reminder, ap is the diagonal coefficient of the A
matrix and will appear on the diagonal of row 0.
The source term for Cell 0 (S) also has contributions from faces 9, 5, 0 and 4:
In addition to the face contributions to S, the volumetric heat source contribution (SP Vp ) is also
required. As a reminder:
" #
X kwall Awall X
S = Sp V p + Twall + [qwall Awall ] (91)
| {z } Dirichlet |y| Neumann
Volumetric Faces Faces
S is the coefficient of the left-hand side (B) vector that is associated with cell 0. This process of
assembling the coefficients is carried out for all cells in the mesh. The resulting coefficients ap , aN
and S are summarised in the table above.
While this method of assembling the coefficients for the matrices may appear unnecessarily com-
plicated, the unstructured approach is completely general and does not restrict the user to a type
of cell or mesh structure. For example, if the cells in the mesh had five faces, then each cell would
receive five contributions towards the coefficients ap , aN and S instead of four (as in this example).
AT = B (96)
where A is a square matrix of coefficients, T is the vector of temperatures at the cell centroids and
B is the vector of source terms.
For the example problem considered here, the mesh has 16 cells. Therefore, the A, T and B
matrices are:
ap0 −an1 0 0 −an4 0 0 0 0 0 0 0 0 0 0 0
−a
n0 ap1 −an2 0 0 −an5 0 0 0 0 0 0 0 0 0 0
0 −an1 ap2 −an3 0 0 −a 0 0 0 0 0 0 0 0 0
n6
0
0 −an2 ap3 −an4 0 0 −an7 0 0 0 0 0 0 0 0
−an0 0 0 −an3 ap4 −an5 0 0 −an8 0 0 0 0 0 0 0
0 −an1 0 0 −an4 ap5 −an6 0 0 −an9 0 0 0 0 0 0
0
0 −an2 0 0 −an5 ap6 −an7 0 0 −an10 0 0 0 0 0
0 0 0 −a 0 0 −a a −a 0 0 −a 0 0 0 0
n3 n6 p7 n8 n11
A=
0 0 0 0 −an4 0 0 −an7 ap8 −an9 0 0 −an12 0 0 0
0 0 0 0 0 −an5 0 0 −an8 ap9 −an10 0 0 −an13 0 0
0
0 0 0 0 0 −an6 0 0 −an9 ap10 −an11 0 0 −an14 0
0
0 0 0 0 0 0 −an7 0 0 −an10 ap11 −an12 0 0 −an15
−a −a −a
0 0 0 0 0 0 0 0 n8 0 0 a
n11 p12 n13 0 0
0
0 0 0 0 0 0 0 0 −an9 0 0 −an12 ap13 −an14 0
0 0 0 0 0 0 0 0 0 0 −an10 0 0 −an13 ap14 −an15
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 ...
Results
Figure 27 shows the temperature variation across the plate computed with the unstructured mesh
approach. Notice that the computed temperature field is identical to the computed temperature field
in the Part 2 of this course, as the mesh and boundary conditions are identical. The only aspect
that has changed is the method used to assemble the equations, as the mesh has been treated as an
unstructured mesh rather than a structured mesh.
To plot the temperature variation as a contour plot, it is more convenient to plot the temperature
at the mesh nodes (Figure 27 (a)) rather than the cell centroids (Figure 27 (b)). As shown in
Figure 28, this is because the boundary temperatures are specified at the nodes (shown in green) and
these would be missed if a contour plot was generated from the cell centroids (shown in blue).
Temperature [C]
Temperature [C]
(a) Nodal Temperatures (b) Centroid Temperatures
Figure 27: Temperature variation across the 2D plate. The centroids are shown as blue circles, the
interior nodes as white circles and the boundary nodes as green circles.
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Figure 28: A diagram to show the centroid numbering scheme used in the mesh. The centroids
are shown as dark blue circles, the boundary nodes as green circles and the interior nodes as white
circles.
4 5
Figure 29: An example of the calculation of the temperature of the top left node (Node 6, shown
in white) by arithmetic averaging the temperature of the surrounding cell centroids.
Figure 29 shows an example of this calculation for the top left interior node in the mesh (Node 6).
The temperature of this node is the average of the temperatures at the four centroids that surround
it:
1 X 1
TNode = Tp −→ TNode = (T0 + T1 + T4 + T5 ) (103)
N Cells 4
However, for the majority of unstructured meshes, the nodes are not equally distant from the centroids
that surround them. For these meshes, arithmetic averaging would lead to an incorrect calculation
of the nodal temperatures, as the temperatures must vary linearly across the cell. Figure 30 shows
an example of a node in an unstructured mesh that is not equally distant from the centroids that
surround it.
In order to compute the correct nodal temperatures for these meshes, weighted averaging must
be used instead. With weighted averaging, the contribution of each centroid to the nodal value is
weighted (multiplied) by 1/|d|, where d is the vector distance of the node from the centroid (shown
in Figure 30). The cells which are closer to the node have a smaller distance and therefore have a
larger weighting than cells which are further away.
The formula for the nodal temperature using weighted averaging is:
!
P 1
Cells Tp
|d|
TNode = ! (104)
P 1
Cells
|d|
1 2
3
5
4
Figure 30: An example node which is surrounded by 5 cells. Cells 1 and 5 are further away from
the node than cells 2, 3 and 4 and so weighted averaging must be used.
where the summation is carried out on the cell centroids that surround that particular node. This
summation might appear complicated. However, it is actually quite simple. For the example in Figure
30, the node is surrounded by five centroids. Hence the temperature of the node is:
T1 T2 T3 T4 T5
d
+ d2
+ d3
+ d4
+ d5
TNode = 1 (105)
1 1 1 1 1
d1
+ d2
+ d3
+ d4
+ d5
Weighted averaging is used in both the python code and Excel sheets to calculate the nodal
temperatures that are used in the contour plots.
Closing Remarks
The unstructured mesh used in this Chapter only contains square cells with perfect quality. However,
the majority of real meshes in CFD have skewed cells with poor quality. These cells reduce the
accuracy of the simulation and can sometimes even lead to divergence of the CFD flow solver. In the
next Chapter, a variety of mesh metrics will be introduced that can be used to assess the quality of
real CFD meshes.
Quardilaterals
Triangles
Prisms
Figure 31: An example of a mesh that contains cells with a variety of shapes.
Figure 32: Some example cells that can be processed by CFD codes.
Higher Quality
Figure 33: An example of a mesh that contains triangular cells with different shapes.
Longest Side
Aspect Ratio =
Shortest Side
Aspect Ratio =
Figure 34: The aspect ratio of a regular quadrilateral is the ratio of the longest and shortest side
lengths
cells that are as close to perfect squares and perfect (equilateral) triangles as possible. This is because
skewed cells reduce the accuracy of the solution and in some cases can even lead to divergence of
the solver itself. To improve the shape of the cells, it is useful to have quantitative metrics that can
be used to assess how close the cells are to perfect squares/triangles. When generating the mesh,
the user can use these metrics to assess the quality of the cells and seek to improve them as much
as possible.
CFD codes and mesh generators have a variety of metrics that can be used to assess the quality
of cells in the mesh. All of these metrics have their utility. However, it is often not clear which metric
is most important for the user to optimise. In this Chapter, the main cell quality metrics will be
presented and it will be demonstrated how these metrics affect the CFD solution process. The table
below summarises the main quality metrics that will assessed in this Chapter.
Aspect Ratio
Jacobian Determinant
Non-Orthogonality
Equiangle Skewness
Aspect Ratio =
Figure 35: An example of how the cell aspect ratio is calculated for a pentagon using the approach
adopted by ANSYS Fluent.
Aspect Ratio
For regular quadrilaterals (where all the sides are at 90◦ to eachother), the aspect ratio is straight-
forward to calculate. As shown in Figure 34, the aspect ratio is the ratio of the length of the longest
and shortest sides. An aspect ratio of 1 indicates a perfect square.
Longest Side L
Aspect Ratio = = (107)
Shortest Side S
However, for skewed quadrilaterals (where the sides are not all at 90◦ to eachother) and for other types
of cell, it is not clear how the aspect ratio should be defined. Therefore, different mesh generators
and CFD codes use different definitions of aspect ratio. Regardless of the aspect ratio definition
adopted, it is desirable for solver stability to have aspect ratios as close to 1 as possible. This is
because cells with a high aspect ratio have faces with much larger areas than the others. These faces
have a much larger face flux contribution than the other faces. To demonstrate this point, refer to
the heat diffusion equation from Chapter 1.
0 = ∇ · (k∇T ) + S (108)
The summation occurs over all of the faces of the cell. If one cell has a much larger area (Af ) than
the other faces of the cell, then this face dominates the contribution from the other faces. This can
lead to instability in the system of equations if the aspect ratios are too large.
Aspect Ratio =
Figure 36: An example of the aspect ratio calculation for a perfect square, using the method
adopted by ANSYS Fluent.
Longest Side
Aspect Ratio =
Shortest Side
Aspect Ratio =
Figure 37: An example of how the cell aspect ratio is calculated by OpenFOAM for 2D faces
It should be noted that for a perfect square, this method does not compute an aspect ratio of 1. As
shown in Figure 36, the length of the diagonal (the distance from the centroid to the corner node)
is greater than the side length (the distance from the centroid to the face centre) and therefore the
computed aspect ratio is greater than 1.
√
0.5 2
Aspect Ratio (Square) = = 1.414 (113)
0.5
Despite this difference, this method is completely general and can be applied to skewed cells and
cells with any number of faces. Therefore, the slight difference in the aspect ratio calculation is not
critically important.
Minimum
Figure 38: An example of the bounding boxes that are constructed around some 3D cells in order
to calculate the cell aspect ratio.
Once the bounding box has been constructed, the aspect ratio is computed with the following
formula:
Largest Area
Aspect Ratio = (115)
Smallest Area
where the areas are the areas of the faces of the bounding box. With this approach, the aspect ratio
of skewed cells and cells with any number of sides can all be calculated using the same approach. It
is also relatively simple to implement in a CFD code or mesh generator.
Jacobian Determinant
In a CFD mesh, it needs to be ensured that none of the cells are inverted. An inverted cell has one
or more of its nodes collapsed inwards towards the centre of the cell. This results in an internal angle
greater than 180◦ . Figure 39 shows a comparison of a regular pentagon and a pentagon where one
of the faces is inverted.
The Jacobian Determinant (often shortened to ’Determinant’ or ’Determinant 2x2x2 ’) is a check
of whether any of the cell faces are inverted. As the cells have multiple faces, the mesh generator
computes the Jacobian Determinant for each of the faces in turn and then reports the lowest value
(which corresponds with the worst face). Jacobian Determinant values less than 0 indicate that the
cell has 1 or more inverted faces, while a Jacobian Determinant value greater than 0 indicates that
none of the faces are inverted.
It is generally recommended that all of the cells in the mesh have a Jacobian Determinant greater
than 0.2. However, CFD codes can often still solve successfully with Jacobian Determinant values
as low as 0.1. Some mesh generators offer the option of calculating the ’Determinant 2x2x2 ’ or the
’Determinant 3x3x3 ’. These options are included because mesh generators can create finite element
meshes, as well as finite volume meshes. The finite volume meshes used in CFD codes only have
nodes at the corners of the cells. An example of a finite volume CFD cell is shown in Figure 40 (a).
Finite volume cells are linear because the flow quantities vary linearly between the nodes and across
the cells.
Finite element meshes can use higher-order elements, where the faces of the element contain
extra nodes. An example of a higher-order finite element is shown in Figure 40 (b). The extra node
-1
Figure 39: A comparison of a regular pentagon, a skewed pentagon and a pentagon with an
inverted face
Flow
Quantity Extra
Nodes
Cell
Figure 40: A comparison of a linear CFD cell and a higher-order finite element.
allows the quantity to vary non-linearly across the element, increasing the accuracy of the solution.
However, because of the additional node, the Jacobian Determinant calculation is slightly different.
The Jacobian Determinant calculation for higher-order elements is referred to as the Determinant
3x3x3 (where the 3 refers to the number of nodes along the face) rather than the Determinant 2x2x2.
Linear finite volume cells that are used in CFD codes do not contain additional nodes along the
faces. Therefore, the Determinant 2x2x2 and Determinant 3x3x3 calculations will produce the same
result. As the Determinant 2x2x2 is quicker to compute, this quantity is usually preferable when
constructing CFD meshes.
Details of how the Jacobian Determinant is computed will not be provided in this course, as
an extensive background of the finite element method is required. A general understanding of the
meaning of the Jacobian Determinant and how it is applied should be sufficient for the user to
generate high quality CFD meshes, without understanding the details of the calculation.
Shared Face
Figure 41: An example of a triangular cell which is connected to a rectangular cell across a shared
face. The cell centroids are connected by a vector dP N that is not necessarily parallel with the face
unit normal vector n̂f .
Centroid
Face Centre
Figure 42: An example of two rectangular cells which are connected across a shared face. All of
the internal angles are 90◦ . The cell centroids are connected by a vector dP N that is parallel with
the unit normal vector n̂f .
Non-Orthogonality
The main metric which directly affects the stability of the CFD solution itself is face non-orthogonality.
To help understand how non-orthogonality arises, Figure 41 shows an example of a quadrilateral cell
and a triangular cell which are connected by a shared face. The unit normal vector at the face centre
is n̂f and the vector that connects the centroids of the cells is dP N . Unless the two cells are perfect
quadrilaterals, the unit normal vector (n̂f ) and the centroid-to-centroid vector (dP N ) will not be
parallel with eachother. The angle between these two vectors is the face non-orthogonality angle
θface . It can be calculated by rearranging the formula for the dot product:
Centroid
Face Centre
Shared Face
Figure 43: An example of a triangular cell which is connected to a rectangular cell across a shared
face. The cell centroid is connected to the face centre by a vector dP F , which is highlighted in
green.
Neighbour Cell
Shared Face
Centroid
Face Centre
Owner Cell
Figure 44: An example of a triangular cell which is connected to a rectangular cell across a shared
face. The vector dP N and the unit normal vector n̂f are parallel, even though the shared face is
highly skewed.
Some CFD codes and mesh generators express the cell non-orthogonality as non-orthogonality
quality (θquality ), by normalising the computed values by 90◦ .
Non-Orthogonal Correctors
Non-orthogonality directly affects the stability of the CFD solution because of the finite volume
discretisation of the diffusion term. To observe how non-orthogonality affects the diffusion term,
refer back to the heat diffusion equation from Chapter 1.
0 = ∇ · (k∇T ) + S (121)
In this equation, k is the thermal conductivity, T is the temperature and S represents any volumetric
sources of heat that may be present. As shown in Chapter 1, the finite volume discretisation of the
heat diffusion equation is: X
0= [kf Af ((∇T )f · n̂f )] + Sp Vp (122)
Faces
where kf is the thermal conductivity at the face centre, (∇T )f is the temperature gradient at the
face centre, Sp is the volumetric heat source at the cell centroid, Vp is the volume of the cell and
n̂f is the unit normal vector at the face centre pointing out of the cell. The summation is carried
out over all of the faces of the cell and represents the flux of heat out of the cell across each of its
faces. It is balanced by any sources of heat inside the cell (Sp Vp ) and is therefore an expression of
conservation of energy.
As shown in Chapter 1, the dot product of the temperature gradient at the face centre and the
unit normal vector can be written as:
TN − TP
(∇T )f · n̂f = |n̂f | (123)
|dP N |
only if the vectors dP N and n̂f are parallel with each other (if the face non-orthogonality θface = 0◦ ).
For the majority of meshes, these vectors are not parallel with each other (θface > 0◦ ). Hence, this
approach cannot be used. For non-orthogonal meshes (where θface > 0◦ ), the unit normal vector is
decomposed into 2 components n̂1 and n̂2 :
where n̂1 is parallel with the vector between the cell centroids (dP N ) and n̂2 is the residual component
from the decomposition. A diagram to illustrate this decomposition is shown in Figure 45. Substitute
the decomposition into the finite volume discretisation:
X
0= [kf Af ((∇T )f · n̂f )] + Sp Vp (125)
Faces
X X
0= [kf Af ((∇T )f · n̂1 )] + [kf Af ((∇T )f · n̂2 )] + SP VP (126)
Faces Faces
In Chapter 1, the analysis was limited to meshes made up of perfect squares and rectangles where
n̂2 = 0.
:0
" #
X TN − TP X
0= kf Af |n̂1 | + )f · n̂2 )] + SP VP
[kf Af((∇T
(129)
Faces |dP N | Faces
However for the majority of real meshes, θface > 0, n̂2 6= 0 and the second summation term cannot
be neglected. Because (∇T )f and n̂2 are not parallel, they cannot be rewritten in terms of TN and
TP . Instead, the second summation is evaluated explicitly (directly) using the temperature gradient
computed in the previous iteration of the CFD solver. This term is called the non-orthogonal
corrector. Physically, the non-orthogonal term is lagged (delayed) one iteration behind the orthogonal
term and can lead to divergence if it is too large.
It should be emphasised that once the CFD simulation has converged, the temperature gradient
in the current iteration will be the same as the previous iteration. Hence, the decomposition of the
unit normal vector into components n̂1 and n̂2 will not affect the accuracy of the final solution.
However, the decomposition does affect the stability of the CFD simulation, as it converges.
Returning to the finite volume discretisation of the heat equation:
" #
X TN − TP X
0= kf Af |n̂1 | + [kf Af ((∇T )f · n̂2 )] + SP VP (130)
Faces |dP N | Faces
As the face non-orthogonality (θface ) increases, n̂1 decreases and n̂2 increases. Hence, the summation
over the faces gets smaller and the non-orthogonal source term gets larger. This reduces the stability
of the equations as large source terms contribute to instability. Hence, it is desirable to have θface as
small as possible, so that n̂1 is large and n̂2 is as small as possible. This reduces the strength of the
source term and increases the stability of the equations.
Equiangle Skewness
Equiangle skewness is a useful metric used by mesh generators to indicate cells which are likely to
have poor non-orthogonality. It is relatively quick and straightforward to evaluate. The equiangle
skewness for a face is the departure of the face shape from a perfect (regular) polygon with the same
number of sides as the face. As shown in Figure 46, the equiangle skewness for a triangular face (with
3 sides) is the departure of the corner angles from a perfect triangle (60◦ ). For a quadrilateral (with
4 sides), the equiangle skewness is the departure of the corner angles from a perfect quadrilateral
(90◦ ).
To quantify this departure from a regular polygon (perfect shape), start by defining the equilateral
angle θe as:
60◦ Triangle
◦
θe = 90 Quadrialteral (131)
◦
180 (N − 2)
N-Sided Face
N
Figure 47: An example of the equiangle skewness calculation for three triangular faces with
internal angles of 60◦ , 90◦ and 120◦ .
The equilateral angle can be thought of as the ideal angle of each of the face corners required to
create a perfect (regular) polygon. Any depature from this ideal angle will result in a skewed cell.
Now that the equilateral (ideal) angle has been defined, the equiangle skewness eface for a face is:
" #
θmax − θe θe − θmin
eface = max , (132)
180◦ − θe θe
where θmin and θmax are the maximum and minimum corner angles on the face. This equation is
general and can be applied to any N sided face. Figure 47 shows three example triangles (3 sides)
with different internal angles to illustrate this calculation process.
The equiangle skewness is based on the worst angle of the face. A perfect triangular or quadrilat-
eral face will result in an equiangle skewness of 0. A corner angle less than 0◦ or greater than 180◦
indicates that the face is inverted and will result in a equiangle skewness greater than 1.
Once the equiangle skewness has been calculated for all faces in the mesh, the equiangle skewness
for each cell is taken as the highest equiangle skewness for all the faces that make up the cell.
ecell = max (eface, 1 , eface, 2 , eface, 1 , ...eface, N ) (133)
In general, when constructing the mesh, the user should aim for equiangle skewness as low as possible.
ANSYS Fluent recommends that all cells in the mesh should have an equiangle skewness less than
0.95. Any cells with an equiangle skewness greater than 1 have inverted faces and will cause the CFD
solver to fail. Hence, these faces must be corrected before a solution can be attempted.
In all cases the ideal mesh is generated from perfect squares and equilateral triangles. Therefore,
the user should attempt to construct the mesh so that the cells are as close to perfect squares and
equilateral triangles as possible.
Example Problem
For the example problem in this Chapter, consider the two quadrilateral elements shown in Figure 48.
These elements will be used to demonstrate and investigate the mesh quality metrics introduced in
this Chapter. The quadrilaterals are constructed from 6 nodes and share 1 face. The location of each
of the 6 nodes are variable. By manipulating the location of the nodes, the shape of the elements
will change, allowing the mesh quality metrics to be investigated.
Now open up either the python source code or the Excel spreadsheets provided.
meshQuality.py meshQuality.xls
Try manipulating the coordinates of the various nodes and observe the changes in the mesh quality
metrics. In all cases, perfect rectangles lead to the best mesh quality metrics. In the next section,
three specific example shapes will be used to demonstrate the changes in the mesh quality metrics
that occur when the nodes are moved around.
Cell 0 Cell 1
0 1 4
Figure 48: The geometry of the example problem for Chapter 2. Two rectangular cells are
constructed from 6 nodes, which are labelled 0 to 5 in the diagram
Results
Figure 49: A diagram to show the mesh configurations investigated in the example problem by
moving node 2 in the lateral direction
Figure 49 shows the three example meshes that will be analysed using the python code and Excel
spreadsheets in this Chapter. These meshes were generated by moving node 2 (the middle node on
the top row) in the lateral direction towards node 5. The table below shows the results of the quality
metrics for Cell 0 (the left cell) and Cell 1 (the right cell), as the node 2 is moved in the lateral
direction.
As node 2 is moved in the lateral direction, both cells (Cell 0 and Cell 1) become more skewed.
This is reflected in the equiangle skewness (es ), face non-orthogonality angle (θface ) and the cell
non-orthogonality quality (θcell ), which are all worse for mesh 3 than mesh 2 and mesh 1. This simple
investigation is an excellent example to show that low quality (skewed) cells are reflected in all of
the main quality metrics. Therefore, when constructing the mesh as a user, it does not really matter
which metric is used to identify poor quality cells in the mesh, as long as these cells are improved
before they are sent to the CFD solver.
As node 2 is moved in the lateral direction, the aspect ratio of Cell 1 increases significantly
because the length of the top side of the cell reduces. However, the aspect ratio of Cell 0 is relatively
unaffected by the movement of node 2. Therefore, this simple investigation shows that to identify
skewed faces and cells, it is more convenient to use the equiangle skewness and non-orthogonality
metrics, as all of these metrics get worse as the cell is skewed. The aspect ratio metric is more useful
to assess the thin cells that are often used in inflation layers (prism layers) near the walls of CFD
geometries.
FluidMechanics101
FluidMechanics101
Aidan Wimshurst
Aidan Wimshurst
1 0 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0