Computational Fluid Dynamics
Computational Fluid Dynamics
Computational
Fluid Dynamics
CFD
Fluid (gas and liquid) flows are governed by partial differential equations which represent
conservation laws for the mass, momentum, and energy. Computational Fluid Dynamics (CFD) is
the art of replacing such PDE systems by a set of algebraic equations which can be solved using
digital computers.
These equations along with the conservation of energy equation form a set of
coupled, nonlinear partial differential equations. It is not possible to solve these
equations analytically for most engineering problems.
Applications of CFD
CFD is useful in a wide variety of applications and here we note a few to give you
an idea of its use in industry. The simulations shown below have been performed
using the FLUENT software.
CFD can be used to simulate the flow over a vehicle. For instance, it can be used
to study the interaction of propellers or rotors with the aircraft fuselage. The
following figure shows the prediction of the pressure field induced by the
interaction of the rotor with a helicopter fuselage in forward flight. Rotors and
propellers can be represented with models of varying complexity.
2
The temperature distribution obtained from a CFD analysis of a mixing manifold is
shown below. This mixing manifold is part of the passenger cabin ventilation
system on the Boeing 767. The CFD analysis showed the effectiveness of a simpler
manifold design without the need for field testing.
x1 x𝑖 xN
x=0 x=1
Grid point
Coupled PDEs + boundary
Coupled algebraic equations. In
Conditions in continuous discrete variables
variables
In a CFD solution, one would directly solve for the relevant flow variables only at
the grid points. The values at other locations are determined by interpolating the
values at the grid points.
The governing partial differential equations and boundary conditions are defined
in terms of the continuous variables p, V etc. One can approximate these in the
discrete domain in terms of the discrete variables 𝑝𝑖 , 𝑉𝑖 etc. The discrete system is
a large set of coupled, algebraic equations in the discrete variables. Setting up the
discrete system and solving it (which is a matrix inversion problem) involves a very
large number of repetitive calculations, a task we humans palm over to the digital
computer.
This idea can be extended to any general problem domain. The following figure
shows the grid used for solving the flow over an airfoil. We’ll take a closer look at
this airfoil grid soon while discussing the finite-volume method.
4
Discretization Using the Finite-Difference Method
To keep the details simple, we will illustrate the fundamental ideas underlying CFD
by applying them to the following simple 1D equation:
𝑑𝑢
+ 𝑢𝑚 = 0; 0 ≤ 𝑥 ≤ 1; 𝑢(0) = 1
𝑑𝑥
We’ll first consider the case where m = 1 when the equation is linear. We’ll later
consider the m = 2 case when the equation is nonlinear.
This grid has four equally-spaced grid points with ∆x being the spacing between
successive points. Since the governing equation is valid at any grid point, we have
𝑑𝑢
( ) + 𝑢𝑖 = 0
𝑑𝑥 𝑖
Where the subscript “i” represents the value at grid point 𝑥𝑖 . In order to get an
expression for (du/dx)𝑖 in terms of u at the grid points, we expand 𝑢𝑖−1 in a
Taylor’s series:
𝑑𝑢
𝑢𝑖−1 = 𝑢𝑖 − ∆𝑥 ( ) + 𝑂(∆𝑥 2 )
𝑑𝑥 𝑖
Rearranging gives
𝑑𝑢 𝑢𝑖 − 𝑢𝑖−1
( ) = + 𝑂(∆𝑥)
𝑑𝑥 𝑖 ∆𝑥
The error in (du/dx) due to the neglected terms in the Taylor’s series is called the
truncation error. Since the truncation error above is O(∆x), this discrete
representation is termed first order accurate.
5
Using (3) in (2) and excluding higher-order terms in the Taylor’s series, we get the
following discrete equation:
𝑢𝑖 − 𝑢𝑖−1
+ 𝑢𝑖 = 0
∆𝑥
Note that we have gone from a differential equation to an algebraic equation!
This method of deriving the discrete equation using Taylor’s series expansions is
called the finite-difference method. However, most commercial CFD codes use the
finite-volume or finite-element methods which are better suited for modeling flow
past complex geometries.
For example, the FLUENT code uses the finite-volume method whereas ANSYS uses
the finite-element method. We’ll briefly indicate the philosophy of the finite-
Fundamentals of Computational Fluid Dynamics
volume method next but will keep using the finite-difference approach to illustrate
the underlying concepts which are very similar between the different approaches
with the finite-difference method being easiest to understand.
∫ 𝑉 · 𝑛ˆ 𝑑𝑆 = 0
The integration is over the surface S of the control volume and nˆ is the outward
normal at the surface. Physically, this equation means that the net volume flow
into the control volume is zero.
6
The velocity at face i is taken to be 𝑉𝑖 = 𝑢𝑖 ˆ𝑖 + 𝑣𝑖 ˆ𝑗. Applying the mass
conservation equation (5) to the control volume defined by the cell gives
−𝑢1 ∆𝑦 − 𝑣2 ∆𝑥 + 𝑢3 ∆𝑦 + 𝑣4 ∆𝑥 = 0
This is the discrete form of the continuity equation for the cell. It is equivalent to
summing up the net mass flow into the control volume and setting it to zero. So it
ensures that the net mass flow into the cell is zero i.e. that mass is conserved for
the cell. Usually, though not always, the values at the cell centers are solved for
directly by inverting the discrete system. The face values u1, v2, etc. are obtained
by suitably interpolating the cell-center values at adjacent cells.
Similarly, one can obtain discrete equations for the conservation of momentum
Look back at the airfoil grid. When you are using FLUENT, it’s useful to remind
yourself that the code is finding a solution such that mass, momentum, energy and
other relevant quantities are being conserved for each cell. Also, the code directly
solves for values of the flow variables at the cell centers; values at other locations
are obtained by suitable interpolation.
− 𝑢𝑖−1 + (1 + ∆𝑥)𝑢𝑖 = 0
Applying this equation to the 1D grid shown earlier at grid points i = 2, 3, 4 gives
− 𝑢1 + (1 + ∆𝑥)𝑢2 = 0 (i = 2) 7
− 𝑢2 + (1 + ∆𝑥)𝑢3 = 0 (i = 3)
− 𝑢3 + (1 + ∆𝑥)𝑢4 = 0 (i = 4)
The discrete equation cannot be applied at the left boundary (i=1) since 𝑢𝑖−1is not
defined here. Instead, we use the boundary condition to get
𝑢1 = 1
Equations (6)-(9) form a system of four simultaneous algebraic equations in the
four unknowns 𝑢1 ,𝑢2 , 𝑢3 and 𝑢4 . It’s convenient to write this system in matrix
form:
Fundamentals of Computational Fluid Dynamics
In a general situation, one would apply the discrete equations to the grid points
(or cells in the finite-volume method) in the interior of the domain. For grid points
(or cells) at or near the boundary, one would apply a combination of the discrete
equations and boundary conditions. In the end, one would obtain a system of
simultaneous algebraic equations with the number of equations being equal to the
number of independent discrete variables. The process is essentially the same as
for the model equation above with the details being much more complex.
FLUENT, like other commercial CFD codes, offers a variety of boundary condition
options such as velocity inlet, pressure inlet, pressure outlet, etc. It is very
important that you specify the proper boundary conditions in order to have a well-
defined problem. Also, read through the documentation for a boundary condition
option to understand what it does before you use it (it might not be doing what
you expect). A single wrong boundary condition can give you a totally wrong result.
Grid Convergence
While developing the finite-difference approximation for the 1D example, we saw
that the truncation error in our discrete system is O(∆x). So one expects that as
the number of grid points is increased and ∆x is reduced, the error in the numerical 9
solution would decrease and the agreement between the numerical and exact
solutions would get better.
Let’s consider the effect of increasing the number of grid points N on the numerical
solution of the 1D problem. We’ll consider N = 8 and N = 16 in addition to the N =
4 case solved previously. We repeat the above assembly and solution steps on
each of these additional grids. The resulting discrete system was solved using
MATLAB. The following figure compares the results obtained on the three grids
with the exact solution. As expected, the numerical error decreases as the number
of grid points is increased.
Fundamentals of Computational Fluid Dynamics
When the numerical solutions obtained on different grids agree to within a level
of tolerance specified by the user, they are referred to as “grid converged”
solutions. The concept of grid convergence applies to the finite-volume approach
also where the numerical solution, if correct, becomes independent of the grid as
the cell size is reduced. It is very important that you investigate the effect of grid
resolution on the solution in every CFD problem you solve. Never trust a CFD
solution unless you have convinced yourself that the solution is grid converged to
an acceptance level of tolerance (which would be problem dependent).
The strategy that is adopted to deal with nonlinearity is to linearize the equations
about a guess value of the solution and to iterate until the guess agrees with the
∆𝑢𝑖 = 𝑢𝑖 − 𝑢𝑔𝑖
Assuming that ∆𝑢𝑖 ≪ 𝑢𝑔𝑖 , we can neglect the ∆𝑢𝑖 2 term to get
Thus,
𝑢𝑖 2 ≅ 2𝑢𝑔𝑖 𝑢𝑖 −𝑢𝑔𝑖 2
𝑢𝑖 − 𝑢𝑖−1
+ 2𝑢𝑔𝑖 𝑢𝑖 −𝑢𝑔𝑖 2 = 0
∆𝑥
The superscript indicates the iteration level. We continue the iterations until they
converge. We’ll defer the discussion on how to evaluate convergence until a little
later.
Fundamentals of Computational Fluid Dynamics
This is essentially the process used in CFD codes to linearize the nonlinear terms
in the conservations equations, with the details varying depending on the code.
The important points to remember are that the linearization is performed about a
guess and that it is necessary to iterate through successive approximations until
the iterations converge.
We saw that we need to perform iterations to deal with the nonlinear terms in the
governing equations. We next discuss another factor that makes it necessary to
carry out iterations in practical CFD problems.
Verify that the discrete equation system resulting from the finite-difference
approximation (12) on our four-point grid is
In a practical problem, one would usually have thousands to millions of grid points
or cells so that each dimension of the above matrix would be of the order of a
million (with most of the elements being zeroes). Inverting such a matrix directly
would take a prohibitively large amount of memory. So instead, the matrix is
Since we are using the guess values at neighboring points, we are effectively
obtaining only an approximate solution for the matrix inversion in (13) during each
iteration but in the process have greatly reduced the memory required for the
Iterative Convergence
Recall that as 𝑢𝑔 → u, the linearization and matrix inversion errors tends to zero.
So we continue the iteration process until some selected measure of the
difference between 𝑢𝑔 and u, referred to as the residual, is “small enough”. We
13
could, for instance, define the residual R as the RMS value of the difference
between u and 𝑢𝑔 on the grid:
It’s useful to scale this residual with the average value of u in the domain. An
unscaled residual of, say, 0.01 would be relatively small if the average value of u
in the domain is 5000 but would be relatively large if the average value is 0.1.
Scaling ensures that the residual is a relative rather than an absolute measure.
Scaling the above residual by dividing by the average value of u gives
Fundamentals of Computational Fluid Dynamics
For the nonlinear 1D example, we’ll take the initial guess at all grid points to be
equal to the value at the left boundary i.e. 𝑢𝑔 (1) = 1. In each iteration, we
update 𝑢𝑔 , sweep from right to left on the grid updating, in turn, u4, u3 and u2
using (14) and calculate the residual using (15). We’ll terminate the iterations
when the residual falls below 10−9 (which is referred to as the convergence
criterion). Take a few minutes to implement this procedure in MATLAB which will
help you gain some familiarity with the mechanics of the implementation. The
variation of the residual with iterations obtained from MATLAB is shown below.
Note that logarithmic scale is used for the ordinate. The iterative process
converges to a level smaller than 10−9 in just 6 iterations. In more complex
problems, a lot more iterations would be necessary for achieving convergence.
14
The solution after 2, 4 and 6 iterations and the exact solution are shown below. It
can easily be verified that the exact solution is given by
1
𝑢𝑒𝑥𝑎𝑐𝑡 =
𝑥+1
The solutions for iterations 4 and 6 are indistinguishable on the graph. This is
another indication that the solution has converged. The converged solution
doesn’t agree well with the exact solution because we are using a coarse grid for
which the truncation error is relatively large. The iterative convergence error,
which is of order 10−9 , is swamped out by the truncation error of order10−1 . So
driving the residual down to 10−9 when the truncation error is of order 10−1 is a
Different codes use slightly different definitions for the residual. Read the
documentation to understand how the residual is calculated.
In the FLUENT code, residuals are reported for each conservation equation. 15
A discrete conservation equation at any cell can be written in the form LHS
= 0. For any iteration, if one uses the current solution to compute the LHS,
it won’t be exactly equal to zero, with the deviation from zero being a
measure of how far one is from achieving convergence. So FLUENT
calculates the residual as the (scaled) mean of the absolute value of the
LHS over all cells.
The convergence criterion you choose for each conservation equation is
problem- and code-dependent. It’s a good idea to start with the default
values in the code. One may then have to tweak these values.
Numerical Stability
In our previous 1D example, the iterations converged very rapidly with the residual
falling below the convergence criterion of 10−9in just 6 iterations. In more
complex problems, the iterations converge more slowly and in some instances,
Fundamentals of Computational Fluid Dynamics
may even diverge. One would like to know a priori the conditions under which a
given numerical scheme converges. This is determined by performing a stability
analysis of the numerical scheme. A numerical method is referred to as being
stable when the iterative process converges and as being unstable when it
diverges. It is not possible to carry out an exact stability analysis for the Euler or
Navier-Stokes equations. But a stability analysis of simpler, model equations
provides useful insight and approximate conditions for stability. A common
strategy used in CFD codes for steady problems is to solve the unsteady equations
and match the solution in time until it converges to a steady state. A stability
analysis is usually performed in the context of time-marching.
16
Where c is the wave speed. One possible way to discretize this equation at grid point
i and time-level n is
The crucial thing to note here is that the spatial derivative is evaluated at the n−1 time-
level. Solving for u𝑖 𝑛 gives
This is an explicit expression i.e. the value of u𝑖 𝑛 at any grid point can be calculated
Where C is called the Courant number. This condition is referred to as the Courant-
Friedrichs-Lewy or CFL condition. While a detailed derivation of the CFL condition
through stability analysis is outside the scope of the current discussion, it can see that
the coefficient of u𝑖 𝑛−1 in (17) changes sign depending on whether C > 1 or C < 1
leading to very different behavior in the two cases. The CFL condition places a rather
severe limitation on ∆tmax .
In this case, we can’t update u𝑖 𝑛 at each grid point independently. We instead need
to solve a system of algebraic equations in order to calculate the values at all grid
points simultaneously. It can be shown that this scheme is unconditionally stable for
the wave equation so that the numerical errors will be damped out irrespective of
how large the time-step is.
The stability limits discussed above apply specifically to the wave equation. In general, 17
explicit schemes applied to the Euler or Navier-Stokes equations have the same
restriction that the Courant number needs to be less than or equal to one. Implicit
schemes are not unconditionally stable for the Euler or Navier-Stokes equations since
the nonlinearities in the governing equations often limit stability. However, they allow
a much larger Courant number than explicit schemes. The specific value of the
maximum allowable Courant number is problem dependent.
CFD codes will allow you to set the Courant number (which is also referred to
as the CFL number) when using time-stepping. Taking larger time-steps leads
to faster convergence to the steady state, so it is advantageous to set the
Courant number as large as possible, within the limits of stability, for steady
problems.
You may find that a lower Courant number is required during startup when
Fundamentals of Computational Fluid Dynamics
changes in the solution are highly nonlinear but it can be increased as the
solution progresses.
Turbulence Modeling
There are two radically different states of flows that are easily identified and
distinguished: laminar flow and turbulent flow. Laminar flows are characterized by
smoothly varying velocity fields in space and time in which individual “laminate”
(sheets) move past one another without generating cross currents. These flows
arise when the fluid viscosity is sufficiently large to damp out any perturbations to
the flow that may occur due to boundary imperfections or other irregularities.
These flows occur at low-to-moderate values of the Reynolds number. In contrast,
turbulent flows are characterized by large, nearly random fluctuations in velocity
and pressure in both space and time. These fluctuations arise from instabilities
that grow until nonlinear interactions cause them to break down into finer and
finer whirls that eventually are dissipated (into heat) by the action of viscosity.
Turbulent flows occur in the opposite limit of high Reynolds numbers.
A typical time history of the flow variable u at a fixed point in space is shown in
Fig. 1(a). The dashed line through the curve indicates the “average” velocity. We
can define three types of averages:
Time average
Volume average
Ensemble average
18
Fundamentals of Computational Fluid Dynamics
Figure 1: Example of a time history of a component of a fluctuating velocity at a
point in a turbulent flow. (a) Shows the velocity, (b) shows the fluctuating
component of velocity u’ ≡ u − u and (c) shows the square of the fluctuating
velocity. Dashed lines in (a) and (c) indicate the time averages.
The most mathematically general average is the ensemble average, in which you
repeat a given experiment a large number of times and average the quantity of
interest (say velocity) at the same position and time in each experiment. For
practical reasons, this is rarely done. Instead, a time or volume average (or
combination of the two) is made with the assumption that they are equivalent to
the ensemble average. For the sake of this discussion, let us define the time
average for a stationary flow1 as
19
The deviation of the velocity from the mean value is called the fluctuation and is
usually defined as
much more complicated in this regime. The approaches to solving the flow
equations for a turbulent flow field can be roughly divided into two classes. Direct
numerical simulations (DNS) use the speed of modern computers to numerically
integrate the Navier Stokes equations, resolving all of the spatial and temporal
fluctuations, without resorting to modeling. In essence, the solution procedure is
the same as for laminar flow, except the numeric must contend with resolving all
of the fluctuations in the velocity and pressure. DNS remains limited to very simple
geometries (e.g., channel flows, jets and boundary layers) and is extremely
expensive to run.2 The alternative to DNS found in most CFD packages (including
FLUENT) is to solve the Reynolds Averaged Navier Stokes (RANS) equations. RANS
equations govern the mean velocity and pressure. Because these quantities vary
smoothly in space and time, they are much easier to solve; however, as will be
shown below, they require modeling to “close” the equations and these models
introduce significant error into the calculation.
20
The kinematic viscosity ν=µ/ρ. The quantity u’ v’, known as the Reynolds stress, is
a higher order moment that must be modeled in terms of the known (i.e., u(y) and
its derivatives). This is referred to as the “closure” approximation. The quality of
the modeling of this term will determine the reliability of the computations.
Summary
CFD is a method to numerically calculate heat transfer and fluid flow.
Currently, its main application is as an engineering method, to provide data
that is complementary to theoretical and experimental data. This is mainly
the domain of commercially available codes and in-house codes at large
companies.
CFD can also be used for purely scientific studies, e.g. into the
fundamentals of turbulence. This is more common in academic institutions
and government research laboratories. Codes are usually developed to
specifically study a certain problem.
References
Milne-Thomson, L.M. (1973). Theoretical Aerodynamics. Dover
Publications
Richardson, L. F.; Chapman, S. (1965). Weather prediction by numerical
process. Dover Publications 21
Hunt (1997). "Lewis Fry Richardson and his contributions to mathematics,
meteorology, and models of conflict". Annual Review of Fluid Mechanics