CFD Chapter 1
CFD Chapter 1
In this chapter we will introduce the numerical solution to an ordinary differential equation (ODE). While some
differential equations, like many of those you saw in 18.03, have analytical solutions, there are many interesting ODEs
that do not have analytical solutions. For those problems without analytical solutions we will use numerical methods
to approximate the solution.
1 Self-Assessment
Before reading this chapter, you may wish to review...
solutions of first-order ODEs [18.03 Lecture 3: Video]
Taylor series expansions [18.01 Lecture 38: Video]
Matlab plotting basics [Matlab plotting documentation]
After reading this chapter you should be able to...
describe the general form for a first-order scalar ordinary differential equation
represent a continuous solution as a set of discrete points
adequately communicate using the shorthand notation
write Taylor series expansions for un+1 , un1 , and un+2 about un
describe the forward Euler method to a friend
2 First-order ODEs
Many interesting physical phenomena can be modeled by a first-order ODE of the form
where u(t) is the time-dependent state of the system, ut = du/dt is the time-derivative of the state, f (u(t)) is the
forcing function depending on the state, u0 is the initial condition, and 0 < t < T indicates that we want to solve
the problem forward in time until time t = T . We will begin by considering scalar problems where u(t) R (a real
number), but in Chapter 6 we will extend to the vector-valued case where u(t) Rd is a d-dimensional state vector.
Lets consider an example.
Example 1. Consider transient heat transfer associated to convective heating or cooling (Unified Propulsion 18.3). The
first law states that the heat into the object is given by the product V cTt where is the density, V is the volume, and c
is the specific heat. Let h be the heat transfer coefficient and A be the surface area of the body, then the time evolution
of temperature is given by
1
2
Ah(T T ) = V cTt .
Let u(t) be the non-dimensional temperature difference (T T )/(Ti T ) where T (t) is the time-dependent temper-
ature in the body (assumed constant throughout, i.e., small Biot number), T is the surrounding ambient temperature,
and Ti is the initial temperature of the body at time t = 0. Then the governing equation is
ut = u
hA
where = . The initial condition is u(0) = 1.
V c
Exercise 1. Write down the analytical solution to the initial value problem of Example 1 and plot it in Matlab
for the values h = 2, A = 4, = 10, V = 9, and c = 1. What is the value of u(2)?
3 Discretization
When you plot the solution in Matlab, you are likely creating two vectors: one corresponding to points in time t =
[t0 ,t1 , . . . ,tN ] and another corresponding to the solution u(t) = [u(t0 ), u(t1 ), . . . , u(tN )] at those points in time. This
process of representing a continuous function by a finite set of numbers is referred to as discretization. The main idea
is illustrated in Figure 1. Instead of representing the function continuously, we represent it as a finite set of ordered
pairs (tn , u(tn )).
0.8
0.6
0.4
solution u(t)
0.2
0.2
0.4
0.6
0 1 2 3 4 5 6 7 8 9 10
time t
Fig. 1 Numerical solutions are represented as a finite set of ordered pairs (blue dots) representing the discretization of a continuous
function.
3
When we solve mathematical problems on a computer, it will always be necessary to discretize them. For the initial
value problems of the form (1), we will begin with the initial condition u0 at time t = 0 and solve forward in time.
First we select a time step t > 0 representing the length of the interval between any two adjacent time points tn and
tn+1 . Although it is not necessary to choose a constant t for the entire simulation, this is the approach we will take
for this course. (You should be aware that state of the art numerical simulation codes adaptively select the time step,
e.g., based on an estimate of the error.) Our numerical solution will then involve computing an approximation to the
solution u(tn ) using information up to (and sometimes including, see implicit methods in Chapter 9) time step n.
4 Notation
Lets establish some convenient shorthand notation. In what follows we will place time indices as superscripts. For
example, the discrete time point at t = 0 will be indicated by t 0 . Analogously, one time step later, we will have
t 1 = t 0 + t, then t 2 = t 1 + t = t 0 + 2 t, and so on. Therefore, if t 0 = 0, at time step n, we have t = t n . Similarly, we
will refer to the solution at time step n as un = u(t n ). It is understood that these superscripts indicate time step and are
not exponents. Since our numerical solution will rarely be exact, we will introduce vn as the numerical approximation
to the solution un at time t n . Thus, our numerical solution will be a set of ordered pairs (t n , vn ) that (we hope) closely
approximate the analytical solution u(t).
It will also be necessary for us to refer to time derivatives of the solution. For example, we indicate the first time
derivative of the solution at time step n as utn = ut (t n ). For higher derivatives we add more subscripts; for example,
d2u
uttn = 2 , (2)
dt t n
that is, the second time derivative evaluated at t n . The notation is summarized in Table 4.
Thought Experiment Suppose we wish to solve the general initial value problem
ut = f (u,t), u0 = 0. (3)
Assume that t > 0 is given. Devise a method to approximate u1 ; what information can get you from u0 to u1 and how
might you use it?
5 Forward Euler
We will conclude this chapter by introducing our first numerical method for the solution of ODEs. The forward Euler
method approximates the solution at time step n + 1 using the approximation at the previous time step vn and the
forcing function f (vn ,t n ) at time step n. Suppose we have solved numerically the ODE up through time step n. That
is, we have chosen t, we were given v0 = u0 , and we subsequently obtained approximations v1 , v2 , . . . , vn . It is now
our task to obtain an approximation vn+1 for the solution un+1 at time step n + 1.
4
Recall that utn = ut (t n ) and since the governing equation (1) is ut = f (u,t), this means that utn = f (un ,t n ). Substituting
into (5) we find
un+1 un + t f (un ,t n ). (6)
In practice, we do not know un (except for when n = 0) but instead we have an approximation vn of it by the time
we reach time step n. We have arrived at the forward Euler method:
with initial condition v0 = u0 . We begin with the given initial condition and iteratively solve for the subsequent numer-
ical solution at each time step, first obtaining v1 using v0 and f (v0 , 0), then calculating v2 based on v1 and f (v1 ,t 1 ),
and so on.
Video demonstration of the forward Euler method
ut = 2u, u0 = 1. (8)
Although this problem has an analytical solution, we demonstrate here the numerical solution using the forward Euler
method. Grab the M ATLAB script
and run it to see for yourself how the forward Euler method works.
Exercise 2. Consider the equation and initial condition in Example 2. Using t = 0.01, calculate by hand v2
using the forward Euler method. Which solution below most accurately reflects your answer?
(a) v2 = 0.9604
(b) v2 = 0.0099
(c) v2 = 0.9800
(d) v2 = 1.0098
In the next chapter we will discuss convergence of numerical schemes. The following exercise serves as a preview
for that discussion.
5
Exercise 3. In this exercise you will modify the code provided in Example 2 to observe the behavior of the error
in our numerical solution as you change the time step t. Implement the forward Euler method for the problem
in Example 2 (or modify the provided code), and compute the error between the numerical solution and the exact
solution at time t = 1 for time steps t = 0.005, t = 0.01, and t = 0.02. Do you notice any pattern in the
results?
(a) errors approximately double when the timestep is doubled
(b) errors decrease as timestep decreases
(c) (a) and (b)
(d) none of the above