Flow Around A Cylinder
Flow Around A Cylinder
Jeffrey R. Chasnov
The Hong Kong University of Science and Technology
Department of Mathematics
Clear Water Bay, Kowloon
Hong Kong
This work is licensed under the Creative Commons Attribution 3.0 Hong Kong License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/hk/ or send a letter to Creative Commons, 171 Second
Street, Suite 300, San Francisco, California, 94105, USA.
Preface
These are my lecture notes for Mathematics for Engineers: The Capstone Course. Students will learn
how to solve for the steady and unsteady two-dimensional flow around an infinite cylinder. Before
students take this course, they should have some basic knowledge of single-variable calculus, vector
calculus, differential equations, matrix algebra and numerical methods. Students should also be able
to program in Matlab.
I have divided these notes into chapters called Lectures, with each Lecture corresponding to a
video on Coursera. I have also uploaded all my Coursera videos to YouTube, and links are placed at
the top of each Lecture.
The course is divided into three weeks. The first week introduces the Navier-Stokes equations and
defines the flow geometry. The second week details the numerical methods we use to compute steady
flow solutions. And the third week details the methods we use to compute unsteady flow solutions
and the Kármán vortex street.
After every Lecture of Week One, there are problems to solve. There are problems in Week Two
and Week Three also, but these weeks culminate in a substantial Matlab program to write. Solutions
to the problems and Learner Templates for the Matlab programs can be found in the Appendix.
Jeffrey R. Chasnov
Hong Kong
Feb 2022
Contents
I Governing Equations 1
1 Navier-Stokes equations 3
2 Vorticity equation 5
4 Two-dimensional flow 9
5 Stream function 11
6 Streamlines 13
7 Reynolds number 15
8 Log-polar coordinates 17
II Steady Flows 19
10 Iteration equations 23
18 Stream-function computation 43
iv
v CONTENTS
20 Vorticity computation 47
Governing Equations
In this week’s lectures, we introduce the Navier-Stokes equations and the flow around an infinite circular cylinder.
Our flow field will be two dimensional and we write the Navier-Stokes equations using a scalar vorticity and
stream function. To take advantage of the circular symmetry, we formulate the equations in polar coordinates. A
further simplification of the Laplacian operator is made by defining log-polar coordinates.
1
Lecture 1 | Navier-Stokes equations
For an incompressible fluid, the continuity and Navier-Stokes equations are written in vector nota-
tion as
∂𝑢 1
∇ · 𝑢 = 0, + (𝑢 · ∇)𝑢 = − ∇p + ν∇2 𝑢.
∂t ρ
The first equation states that the velocity field is a divergence-free (or solenoidal) vector field. It is
an expression of the incompressibility condition—that the density of the fluid is everywhere constant.
The second equation expresses Newton’s law F = ma applied to a fluid, and its derivation is usually
presented in a first course on Fluid Mechanics.
Some students may have trouble deciphering the compact vector notation. To illustrate how to
unpack these equations, we use Cartesian coordinates and write
where the three components also depend on the time t. The continuity equation expands to
∂u ∂v ∂w
+ + = 0;
∂x ∂y ∂z
The goal of our capstone course is to solve numerically a two-dimensional version of these equations
for the flow around a cylinder.
3
WEEK I. GOVERNING EQUATIONS 4
2. Channel flow, or Poiseuille flow, consists of an incompressible fluid flowing between two infinite
plates separated by a distance d, but with both plates stationary. Here, the fluid flows between the two
plates in the direction of a constant pressure gradient. Choose a coordinate system so that the fluid
flow is in the x-direction and the y-axis is perpendicular to the two plates. Find the solution for the
velocity field of the form 𝑢( x, y, z) = u(y)𝑖, with p = p( x ), dp/dx = − G and G is a positive constant.
3. Pipe flow consists of an incompressible fluid flowing through a pipe of circular cross-section radius
R, with a constant pressure gradient along the pipe length. Choose a coordinate system so that the
pressure gradient is in the x-direction and the y- and z-axes are perpendicular to the sides of the pipe.
Find the solution for the velocity field of the form 𝑢 = u(y, z)𝑖, with p = p( x ), dp/dx = − G and G is
a positive constant. Use polar coordinates.
The equation for the vorticity, 𝜔 = ∇ × 𝑢, may be found by taking the curl of the Navier-Stokes
equation; that is
∂𝑢 1
∇× + (𝑢 · ∇)𝑢 = ∇ × − ∇p + ν∇2 𝑢 .
∂t ρ
Examining each term, we have
∂𝑢 ∂ ∂𝜔 n o
∇× = (∇ × 𝑢) = and ∇ × ν∇2 𝑢 = ν∇2 (∇ × 𝑢) = ν∇2 𝜔.
∂t ∂t ∂t
∇ × {−∇p/ρ} = 0.
∂𝜔
+ ∇ × (𝜔 × 𝑢) = ν∇2 𝜔.
∂t
∂𝜔
+ (𝑢 · ∇)𝜔 = (𝜔 · ∇)𝑢 + ν∇2 𝜔.
∂t
Compared to the Navier-Stokes equation for 𝑢, there is an extra term on the right-hand side of this
equation, (𝜔 · ∇)𝑢. This term is called the vortex stretching term and is often used to explain the
energy cascade in three-dimensional turbulence.
5
WEEK I. GOVERNING EQUATIONS 6
b) ∇ × (𝜔 × 𝑢) = (𝑢 · ∇)𝜔 − (𝜔 · ∇)𝑢.
You can use the facts that the curl of a gradient and the divergence of a curl are equal to zero, and the
general vector identity
You will also need to use 𝜔 = ∇ × 𝑢 and ∇ · 𝑢 = 0. However, you will need to prove that
1
𝑢 × (∇ × 𝑢) = ∇(𝑢 · 𝑢) − (𝑢 · ∇)𝑢.
2
We consider flow around an infinite cylinder with cross-sectional radius R. We define our x-y coordi-
nates to lie in the cross-sectional plane, and orient the axes so that the free-stream velocity, 𝑢 f = U𝑖,
is in the x-direction. The geometry of the flow in the plane is shown in the figure below.
For the nonturbulent flows considered here, we assume that the velocity field vectors lie in the x-y
plane and have no z-component, and that the flow field is independent of the z coordinate. And for
steady flows only, we assume that the flow field in the bottom half of the plane (y < 0) is a mirror
image of the flow field in the top half of the plane (y > 0). That is, with velocity field given by
𝑢 = u( x, y)𝑖 + v( x, y)𝑗, we assume u( x, −y) = u( x, y) and v( x, −y) = −v( x, y).
7
WEEK I. GOVERNING EQUATIONS 8
∂𝜔
+ (𝑢 · ∇)𝜔 = (𝜔 · ∇)u + ν∇2 𝜔,
∂t
where 𝜔 = ∇ × 𝑢. For nonturbulent flow past an infinite cylinder, one expects that the velocity field
will lie in the cross-sectional plane of the cylinder and be independent of the z coordinate.
To best model the boundary conditions on the cylinder, we will use polar coordinates and write
and has only a single component in the z-axis direction. We can then define a scalar vorticity field by
1 ∂ ∂ur
ω= (ruθ ) − .
r ∂r ∂θ
And since
∂𝑢
(𝜔 · ∇)𝑢 = ω = 0,
∂z
and
∂2
∂ 1 ∂ 1 ∂ ∂
∇ = r̂ + θ̂ , ∇2 = r r + ,
∂r r ∂θ r2 ∂r ∂r ∂θ 2
the vorticity vector equation in polar coordinates becomes the scalar equation
∂2 ω
∂ω ∂ω 1 ∂ω ν ∂ ∂ω
+ ur + uθ = 2 r r + .
∂t ∂r r ∂θ r ∂r ∂r ∂θ 2
9
WEEK I. GOVERNING EQUATIONS 10
To automatically satisfy this condition, we make use of the equality of mixed partials and define a
stream function ψ by
∂ψ ∂ψ
rur = , uθ = − .
∂θ ∂r
The definition of the scalar vorticity then becomes
1 ∂ ∂ur
ω= (ruθ ) −
r ∂r ∂θ
∂2 ψ
1 ∂ ∂ψ
=− 2 r r + 2 ,
r ∂r ∂r ∂θ
in polar coordinates.
11
WEEK I. GOVERNING EQUATIONS 12
2. Using Cartesian coordinates, write the scalar vorticity in terms of the stream function.
3. In general, a solenoidal vector field 𝑢 that satisfies ∇ · 𝑢 = 0 admits a vector potential 𝐴 such that
𝑢 = ∇ × 𝐴. Using Cartesian coordinates in two dimensions, show that the stream function can be
identified as the third component of a vector potential 𝐴.
The streamlines in a steady flow show the direction of fluid motion. A streamline is everywhere
tangent to the velocity field of the flow (see figure).
With infinitesimal vector displacement d𝑟 = drr̂ + rdθ θ̂ along a streamline, and with the velocity field
parallel to d𝑟 so that their cross-product is zero, we have
∂ψ ∂ψ
rur = , uθ = − ,
∂θ ∂r
13
WEEK I. GOVERNING EQUATIONS 14
The governing equations for a two-dimensional flow in terms of the stream function and scalar vortic-
ity field are given by
∂ω 1 ∂ψ ∂ω ∂ψ ∂ω
∇2 ψ = −ω, + − = ν∇2 ω,
∂t r ∂θ ∂r ∂r ∂θ
If we nondimensionalize using R and U, the net result is the replacement of the viscosity ν by a
dimensionless grouping of parameters, that is,
ν
ν→ .
UR
It is standard here to define the Reynolds number Re in terms of the diameter of the cylinder instead
of the radius, so that with
2UR
Re = ,
ν
the nondimensional governing equations (with all variables now dimensionless) become
∂ω 1 ∂ψ ∂ω ∂ψ ∂ω 2 2
∇2 ψ = −ω, + − = ∇ ω.
∂t r ∂θ ∂r ∂r ∂θ Re
15
WEEK I. GOVERNING EQUATIONS 16
The recurring factor r∂/∂r in the polar coordinate Laplacian is awkward to discretize and we look
for a change of variables r = r (ξ ), where
∂ ∂
r = .
∂r ∂ξ
Now,
∂ dr ∂
= ,
∂ξ dξ ∂r
so that we require
dr
= r.
dξ
This simple differential equation can be solved if we take as our boundary condition ξ = 0 when r = 1,
corresponding to points lying on the boundary of the circular cylinder. The solution of the differential
equation is therefore given by
r = eξ .
∂2
21 ∂ ∂
∇ = 2 r r + 2
r ∂r ∂r ∂θ
2 2
∂ ∂
= e−2ξ + 2 ;
∂ξ 2 ∂θ
∂2 ψ ∂2 ψ
+ 2 = −e2ξ ω,
∂ξ 2 ∂θ
∂2 ω ∂2 ω
∂ω ∂ψ ∂ω ∂ψ ∂ω 2 −2ξ
+ e−2ξ − = e + .
∂t ∂θ ∂ξ ∂ξ ∂θ Re ∂ξ 2 ∂θ 2
17
WEEK I. GOVERNING EQUATIONS 18
Steady Flows
In this week’s lectures, we show how to solve the stream function and scalar vorticity equations to obtain steady
solutions. These steady solutions for the fields do not depend on time. We discretize the equations using a
second-order finite difference method and the SOR iteration method. Low Reynolds number iterations can be
initialized with zero flow fields except for the free-stream condition on the stream function. We derive a key
boundary condition for the scalar vorticity on the cylinder.
For the computational project, students will compute and plot the stream function for Re = 10. Experiments
have shown that the steady solutions are stable for Re < 46. The steady solutions still exist for higher Reynolds
numbers, but they are unstable and not observed in Nature.
19
Lecture 9 | Finite difference method
A finite difference approximation requires a grid in (ξ, θ ) space. With velocity field 𝑢 = u( x, y)𝑖 +
v( x, y)𝑗, we assume that u is even in y and v is odd; that is,
If a function is even in a variable, then its partial derivative in that variable is odd, and vice-a-versa.
Since u = ∂ψ/∂y and ω = ∂v/∂x − ∂u/∂y, both the stream function and scalar vorticity must be odd
in y:
ψ( x, −y) = −ψ( x, y), ω ( x, −y) = −ω ( x, y).
We need then define a grid only for the upper half of the x-y plane, and take as our boundary
conditions at y = 0 the values ψ = ω = 0.
In log-polar coordinates, we can then define our grid as 0 ≤ ξ ≤ ξ max and 0 ≤ θ ≤ π, and our
computational domain forms a rectangle without any holes. The sides of this rectangle correspond to
the cylinder boundary (ξ = 0), the free stream (ξ = ξ max ), the midline behind the cylinder (θ = 0), and
the midline in front of the cylinder (θ = π).
We discretize the computational domain using square grid cells, and write
ξ i = (i − 1)h, i = 1, 2, . . . , n; θ j = ( j − 1)h, j = 1, 2, . . . , m,
where n and m are the number of grid points (including boundary points) in the ξ and θ directions,
and h is the side length of a grid cell. Because 0 ≤ θ ≤ π, the value of h must satisfy h = π/(m − 1),
and the maximum value of ξ is given by ξ max = (n − 1)π/(m − 1). The radius of the computational
domain is therefore given by eξ max , which is to be compared to a cylinder radius of one. The choice
n = m yields eξ max ≈ 23, and this will be large enough for the relatively low Reynolds number solutions
we seek here.
21
WEEK II. STEADY FLOWS 22
∂2 ψ ∂2 ψ ∂2 ω ∂2 ω
2ξ Re ∂ψ ∂ω ∂ψ ∂ω
− + 2 = e ω, − + = − .
∂ξ 2 ∂θ ∂ξ 2 ∂θ 2 2 ∂ξ ∂θ ∂θ ∂ξ
We define ψi,j = ψ(ξ i , θ j ) and ωi,j = ω (ξ i , θ j ) and use second-order centered difference approximations
for all the derivatives. Application of the SOR method (Numerical Methods for Engineers, Lecture 66)
results in the equations
k +1 k rψ k
ψi,j = (1 − rψ )ψi,j + ψi+1,j + ψik−1,j + ψi,j
k
+1 + ψ k
i,j−1 + h 2 2ξ i k
e ω i,j ,
4
k +1 k rω Re k
ωi,j = (1 − rω )ωi,j + ωik+1,j + ωik−1,j + ωi,j
k
+1 + ω k
i,j−1 + f ,
4 8 i,j
where
k
f i,j = ψik+1,j − ψik−1,j ωi,j
k k k k
+1 − ωi,j−1 − ψi,j+1 − ψi,j−1 ωik+1,j − ωik−1,j .
Because these equations are nonlinear, iterations can easily become unstable. To maintain stability,
the relaxation parameters, rψ and rω , may need to be less than one. Numerical experimentation may
be necessary to obtain the best trade-off between computationally stability and computational speed.
In addition, solutions at higher Reynolds numbers are best initialized by solutions at slightly lower
Reynolds numbers.
The convergence of the iterations need to be monitored. We define
Iterations can be stopped when the values of εkψ+1 and εkω+1 are less than some pre-defined error
tolerance, say 10−8 .
23
WEEK II. STEADY FLOWS 24
∂2 ω ∂2 ω
Re ∂ψ ∂ω ∂ψ ∂ω
− 2
+ 2 = − .
∂ξ ∂θ 2 ∂ξ ∂θ ∂θ ∂ξ
ˆ
u = cos θr̂ − sin θ 𝜃.
Since rur = ∂ψ/∂θ and uθ = −∂ψ/∂r, the stream function satisfies the free-stream conditions
∂ψ ∂ψ
= r cos θ, = sin θ.
∂θ ∂r
ψ(r, θ ) = r sin θ,
which also satisfies our boundary conditions ψ = 0 when θ = 0 and π. On our log-polar coordinate
grid, then, the free-stream boundary condition at ξ = ξ n is given by
ψn,j = eξ n sin θ j .
The free-stream flow field has zero vorticity, and the simplest, effective boundary condition on the
scalar vorticity is
ωn,j = 0.
25
WEEK II. STEADY FLOWS 26
ωn,j = 0,
∂ω
= 0.
∂ξ (n,j)
From second-order Taylor series expansions of ωn−1,j and ωn−2,j , derive the corresponding boundary
condition on ωn,j .
Boundary conditions on the cylinder are determined from the no-penetration condition, ur = 0, and
no-slip condition, uθ = 0. And since rur = ∂ψ/∂θ and uθ = −∂ψ/∂r, the stream function is constant
and its normal derivative is zero. Since we know ψ = 0 at y = 0, the cylinder boundary conditions are
∂ψ
ψ1,j = 0, = 0.
∂ξ (1,j)
The normal derivative boundary condition on the stream function will become a boundary condition
on the vorticity. The scalar vorticity everywhere satisfies
∂2 ψ ∂2 ψ
−2ξ
ω = −e + 2 ,
∂ξ 2 ∂θ
∂2 ψ
ω1,j = − .
∂ξ 2 (1,j)
To obtain a boundary condition on the vorticity, we Taylor series expand the stream function one and
two grid points away from the cylinder surface:
∂ψ 1 ∂2 ψ 1 ∂3 ψ
ψ2,j = ψ1,j + h + h2 + h3 + O( h4 ),
∂ξ (1,j) 2 ∂ξ 2 (1,j) 6 ∂ξ 3 (1,j)
∂ψ ∂2 ψ 4 ∂3 ψ
ψ3,j = ψ1,j + 2h + 2h2 + h3 + O( h4 ).
∂ξ (1,j) ∂ξ 2 (1,j) 3 ∂ξ 3 (1,j)
Since the stream function and its normal derivative are zero on the cylinder surface, these Taylor series
expansions reduce to
1 1 ∂3 ψ 4 ∂3 ψ
ψ2,j = − h2 ω1,j + h3 + O( h4 ), ψ3,j = −2h2 ω1,j + h3 + O( h4 ).
2 6 ∂ξ 3 (1,j) 3 ∂ξ 3 (1,j)
After multiplying the first equation by eight and subtracting the second equation, we obtain
27
WEEK II. STEADY FLOWS 28
1
ω1,j = (ψ3,j − 8ψ2,j ).
2h2
29 LECTURE 12. CYLINDER BOUNDARY CONDITIONS
∂ψ
ψ1,j = 0, = 0.
∂ξ (1,j)
A stream function that is quadratic in ξ near the cylinder surface satisfies the above two conditions.
Use it to test the validity of the derived boundary condition.
31
WEEK II. STEADY FLOWS 32
ψn,j = eξ n sin θ j .
How many SOR iterations does it take for ω to obtain its first nonzero value?
Successful Matlab programs will (1) calculate the stream function and scalar vorticity for the two-
dimensional steady flow around a cylinder (simulation code), and; (2) visualize the solution (graphics
code). We will provide students with a skeleton of the simulation code, and a finished graphics code.
The solution for Re = 10 will be graded and students can perform additional calculations at other
Reynolds numbers, if they so desire.
We have written the simulation code as a function, with the stream function psi and scalar vorticity
omega as outputs, that is,
To make the calculation fast, we use only 101 grid points in both the ξ and θ directions (1012 = 10,201
total grid points). The iteration is to be stopped when the absolute value of the change in omega or
psi after one iteration is less than the error tolerance delta=1.e-08 at every grid point.
The structure of the simulation code is as follows:
1. Define the grid.
2. Initialize the flow fields, including the free-stream boundary condition.
3. Set the relaxation parameters, error tolerance and any extra variables.
4. Perform the main SOR iteration loop:
(a) Loop over all the grid points of the psi equation;
(b) Set the omega boundary condition on the cylinder;
(c) Loop over all the grid points of the omega equation;
(d) Test for convergence of the fields, and continue the iteration or end the loop.
5. Plot the contours of the stream function.
33
WEEK II. STEADY FLOWS 34
The graphics code that we provide plots the stream function for Re = 10. The stream function com-
putation is on a grid in log-polar coordinates and the stream function needs to be plotted in Cartesian
coordinates. Apart from the graphics itself, we will need to interpolate the psi values on the ξ-θ grid
onto an x-y grid.
We make use of the Matlab functions meshgrid.m and interp2.m to interpolate the stream func-
tion onto the Cartesian grid points xi_i and theta_i. The Cartesian grid is created using meshgrid.m
and is given by the two arrays X and Y. The interpolation points in the ξ-θ space are given by
xi_i=0.5*log(X.^2+Y.^2);
theta_i=wrapTo2Pi(atan2(Y,X));
The graphics code is written as a function with stream function psi as input, that is,
function plot_Re10(psi)
35
WEEK II. STEADY FLOWS 36
Unsteady Flows
In this week’s lectures, we will solve for a time-dependent stream function and scalar vorticity. Our goal is to
simulate the famous Kármán street, where periodic vortices are shed from the top and bottom of the cylinder.
Applying periodic boundary conditions in the polar angle θ, we use a second-order finite difference method to
discretize the equations in space. The stream-function equation is a system of linear equations and can be solved
by a direct method using the Matlab backslash operator. To increase the speed of the computation, we make use
of the LU decomposition. The time integration of the vorticity equation is performed using the Matlab function
ode23.m.
For the computational project, students will flesh out the skeleton of a code that time-advances the vorticity field.
Experiments have shown that the steady solution becomes unstable for Re < 46 and we ask students to perform
a calculation at Re = 60. After building a program that passes the Matlab Grader, students can then write code
to create a movie file of the Kármán street.
37
Lecture 16 | Periodic boundary
conditions
In the unsteady flow, vortices are shed above and below the cylinder. We will need to solve for
the flow over the entire range of the polar angle, 0 ≤ θ < 2π.
We implement periodic boundary conditions. Let m be the total number of grid points in the θ
angle. We define the first grid point to be one grid cell below zero, and the last grid point to be 2π
(see figure).
grid points
2, m
1, m-1
θ j = ( j − 2)h, j = 1, 2, . . . , m,
39
WEEK III. UNSTEADY FLOWS 40
grid points
2, m
1, m-1
Write down the two appropriate periodic boundary conditions for the first and last grid points. What
is the difference between this implementation and the one in lecture?
If we know the vorticity ω at time t, we can solve a Poisson equation for the stream function,
∂2 ψ ∂2 ψ
− + 2 = e2ξ ω.
∂ξ 2 ∂θ
Then with both the stream function and vorticity known at time t, we can time integrate the vorticity
equation,
2e−2ξ ∂2 ω ∂2 ω
∂ω ∂ψ ∂ω ∂ψ ∂ω
= + + e−2ξ − .
∂t Re ∂ξ 2 ∂θ 2 ∂ξ ∂θ ∂θ ∂ξ
We discretize the spatial derivatives as before, using a second-order finite difference scheme. The
stream-function equation is
dωi,j 2e−2ξ i
= 2 ωi+1,j + ωi−1,j + ωi,j+1 + ωi,j−1 − 4ωi,j
dt h Re
e−2ξ i
+ 2
ψi+1,j − ψi−1,j ωi,j+1 − ωi,j−1 − ψi,j+1 − ψi,j−1 ωi+1,j − ωi−1,j .
4h
In the next few lectures, we discuss how to solve these two coupled equations.
41
WEEK III. UNSTEADY FLOWS 42
and apply natural ordering [Numerical Methods for Engineers, Lecture 63] to map (i, j) → k = i +
( j − 1)n. The stream-function equation transforms to
This is a matrix equation Aψ = b, where each value of k corresponds to a row of the matrix A. The
matrix A has dimension mn-by-mn and has five diagonal bands: a four on the main diagonal, and a
negative one on one and n above and below the main diagonal. These diagonal bands extend only
over the rows in which k indexes an interior point of the domain.
When k indexes a boundary point, however, the discrete stream function equation no longer ap-
plies and the corresponding rows of the matrix A and right-hand side b are modified to enforce the
boundary conditions. We discuss the boundary conditions in the next lecture.
43
WEEK III. UNSTEADY FLOWS 44
the dimension of ω is n-by-m, and we have applied natural ordering to map (i, j) → k = i + ( j − 1)n.
Map the mathematical variables above into the following Matlab variables: omega_tilde, h, xi,
omega, n, m. Write the Matlab code that computes the mn sized vector omega_tilde given that all the
other variables have previously been defined.
We want to solve the matrix equation Aψ = b and consider now the rows of A corresponding to
points on the boundaries of the computational domain. The values of k on the boundaries are shown
in the figure below, where we borrow the colon notation from Matlab. We label the four sides: bottom
(B), top (T), left (L) and right (R). On (L) where ξ = 0, we have ψ1,j = 0; and on (R) where ξ = ξ n ,
we have the free-stream condition ψn,j = eξ n sin θ j . These boundary conditions are implemented by
replacing the kth row of A by the corresponding kth row of the mn × mn identity matrix, and setting
the right-hand side row element either to zero or to the free-stream condition.
Periodic boundary conditions are implemented on (B) and (T). On (B), we implement ψi,1 −
ψi,m−1 = 0. That is, in rows k = 1:n of the matrix A, we place the difference of two rows of the
identity matrix: rows 1:n minus rows 1 + (m − 2)n:(m − 1)n. The corresponding row elements in b
are set to zero. On (T), we implement ψi,m − ψi,2 = 0. That is, in rows k = 1 + (m − 1)n:mn of the
matrix A, we place the difference of two rows of the identity matrix: rows 1 + (m − 1)n:mn minus
rows (1 + n):2n. And again the corresponding row elements in b are set to zero.
45
WEEK III. UNSTEADY FLOWS 46
7 8 9
4 5 6
1 2 3
dωi,j 2e−2ξ i
= 2 ωi+1,j + ωi−1,j + ωi,j+1 + ωi,j−1 − 4ωi,j
dt h Re
e−2ξ i
+ 2
ψi+1,j − ψi−1,j ωi,j+1 − ωi,j−1 − ψi,j+1 − ψi,j−1 ωi+1,j − ωi−1,j
4h
This equation is a system of (n − 2)(m − 2) first-order differential equations. The stream function and
scalar vorticity are assumed to be known at time t, and this system of equations is integrated to solve
for the scalar vorticity at time t + ∆t.
Although we are solving only for the scalar vorticity at the interior points, the right-hand side
requires the values of the stream function and scalar vorticity at the boundaries. Our matrix equation
for the stream function already includes boundary conditions, and the boundary conditions on the
scalar vorticity are
ψ3,j − 8ψ2,j
ω1,j = , ωn,j = 0, ωi,1 = ωi,m−1 ωi,m = ωi,2 .
2h2
To integrate the system of first-order differential equations, a Matlab ode solver can be used. We have
timed the solvers ode45.m, ode23.m and ode113.m using the default error tolerance RelTol = 1.e-3,
and the most commonly used solver, ode45.m, appears to require about 50% more derivative evalua-
tions than the other two solvers. We have therefore chosen to use ode23.m in our program.
47
WEEK III. UNSTEADY FLOWS 48
To compute the Kármán vortex street, one can first compute a time series of the scalar vorticity in
the unsteady flow regime, and second, create images of the vorticity field and add them to a movie
file. For the assessment, we will only ask students to fill out the skeleton of a code to time-advance
the vorticity field. Students, on their own, can create a time series of fields and produce a movie of the
Kármán street, as explained in the next Lecture.
The code template we give students uses 101 grid points in the ξ direction and 202 grid points in
the θ direction. Dimensionless time is to be advanced to only t = 0.5, and the resulting vorticity field
will be graded. We found that a near steady flow field develops by t = 50, after which a growing
instability can be seen visually near t = 900, with a fully formed Kármán street at t = 1100.
The structure of the simulation code for the assessment is as follows:
1. Define the grid and time-stepping parameters.
2. Initialize the flow fields, including the free-stream boundary condition.
3. Construct the matrix A for the ψ equation and compute A = LU.
4. Compute and save time-independent factors.
5. Advance the vorticity field using ode23.m.
6. Compute the stream function and obtain the vorticity boundary values.
9. Plot the vorticity field.
The function called by ode23.m has the following structure:
1. Compute the stream function.
2. Set the boundary conditions on the vorticity field.
3. Compute the time-derivative of the vorticity.
49
WEEK III. UNSTEADY FLOWS 50
After you have a code that computes a time-dependent vorticity field, you might want to create a
movie file of the Kármán vortex street. One could add movie frames on the fly as you compute the
fields. But since most of the computational time is spent computing the fields, and often we need to
tweak the graphics, a better solution is to write a time series of fields into .mat files. These fields can
then be loaded into another program that creates the movie file.
To write the .mat files, we define a file name such as
output_file='.\fields\Re_60_';
where we choose to write the fields into a subdirectory of our current working directory. We then loop
over the call to ode23.m, advance the vorticity field over a fixed time interval, and save each computed
vorticity field to disk using the Matlab function call
save([output_file,num2str(k),'.mat'],'omega');
To capture movie frames and save them into a movie file, we use the commands
frame=getframe(gcf);
writeVideo(writerObj,frame);
I will provide you a copy of my graphics code, but feel free to modify it to suit your desired outcome
and taste.
51
WEEK III. UNSTEADY FLOWS 52
53
55 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES
d2 u
ν = 0.
dy2
The boundary conditions on the plates are u(0) = 0 and u(d) = U . We find u(y) = Uy/d, so that
Uy
𝑢= 𝑖.
d
1 dp d2 u
− + ν 2 = 0.
ρ dx dy
Gd2 y y
𝑢= 1− 𝑖.
2νρ d d
∂2 u ∂2 u
1 dp
− +ν + 2 = 0.
ρ dx ∂y2 ∂z
du Gr2
r =− ;
dr 2νρ
GR2
r 2
u (r ) = 1− ,
4νρ R
so that
GR2 y2 + z2
𝑢= 1− 𝑖.
4νρ R2
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 56
1.
1
𝑢 × (∇ × 𝑢) = ∇(𝑢 · 𝑢) − (𝑢 · ∇)𝑢.
2
∂um
[𝑢 × (∇ × 𝑢)]i = eijk u j eklm (curl in component notation)
∂xl
∂um
= ekij eklm u j (eijk = ekij )
∂xl
∂um
= (δil δjm − δim δjl )u j (ekij eklm = δil δjm − δim δjl )
∂xl
∂u j ∂u
= uj − uj i (δij A j = Ai )
∂xi ∂x j
1 ∂ ∂u
= (u j u j ) − u j i
2 ∂xi ∂x j
1
= ∇(𝑢 · 𝑢) − [(𝑢 · ∇)𝑢]i . (back to vector notation)
2 i
Therefore,
1
(𝑢 · ∇)𝑢 = ∇(𝑢 · 𝑢) − 𝑢 × (∇ × 𝑢),
2
and
1
∇ × (𝑢 · ∇)𝑢 = ∇ × ∇(𝑢 · 𝑢) − 𝑢 × (∇ × 𝑢)
2
1
= ∇ × (∇(𝑢 · 𝑢)) − ∇ × (𝑢 × (∇ × 𝑢)) (distribution law for curl)
2
= −∇ × (𝑢 × (∇ × 𝑢)) (curl of a gradient equals zero)
= −∇ × (𝑢 × 𝜔 ) (∇ × 𝑢 = 𝜔)
= ∇ × (𝜔 × 𝑢). (𝑢 × 𝜔 = −𝜔 × 𝑢)
b) We prove that
∇ × (𝜔 × 𝑢) = (𝑢 · ∇)𝜔 − (𝜔 · ∇)𝑢,
We have
x 2 + y2 = R2 ,
𝑢 f = U𝑖,
𝑢 f = U (cos θ r̂ − sin θ θ̂ ).
1. We have
𝑖 𝑗 𝑘
𝜔×𝑢 = 0 0 ω = −vω𝑖 + uω𝑗,
u v 0
and
𝑖 𝑗 𝑘
∂ ∂
∇ × (𝜔 × 𝑢) = ∂/∂x ∂/∂y 0 = (uω ) + (vω ) 𝑘
∂x ∂y
−vω uω 0
∂u ∂v ∂ω ∂ω
= + ω+ u +v 𝑘
∂x ∂y ∂x ∂y
∂ω ∂ω
= u +v 𝑘.
∂x ∂y
2.
𝑖 𝑗 𝑘
∂v ∂u
𝜔 = ∇ × 𝑢 = ∂/∂x ∂/∂y 0 = − 𝑘.
∂x ∂y
u v 0
∂2 ω ∂2 ω
∂ω ∂ω ∂ω
+u +v =ν + .
∂t ∂x ∂y ∂x2 ∂y2
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 58
∂u ∂v
+ = 0.
∂x ∂y
The appropriate definition of the stream function ψ = ψ( x, y) that satisfies this condition is
∂ψ ∂ψ
u= , v=− .
∂y ∂x
∂v ∂u
ω= − .
∂x ∂y
∂2 ψ ∂2 ψ
ω=− + 2
∂x2 ∂y
Therefore,
∂A3 ∂A3
u= , v=− ,
∂y ∂x
and the stream function can be identified as the third component of the vector potential 𝐴.
1. In Cartesian coordinates, d𝑟 = dx𝑖 + dy𝑗, and with the velocity field parallel to d𝑟, we have
∂ψ ∂ψ
u= , v=− ,
∂y ∂x
and if we set Re = 0, we obtain the Laplace equation ∇2 ω = 0. Since ∇2 ψ = −ω, taking the Laplacian
of both sides results in the biharmonic equation, usually written as
∇4 ψ = 0.
The attempt to solve this equation for the flow around an infinite circular cylinder leads to Stokes’
paradox.
∂2 ψ ∂2 ψ
+ 2 = −e2ξ ω,
∂ξ 2 ∂θ
∂2 ω ∂2 ω
∂ω ∂ψ ∂ω ∂ψ ∂ω 2 −2ξ
+ e−2ξ − = e + .
∂t ∂θ ∂ξ ∂ξ ∂θ Re ∂ξ 2 ∂θ 2
In a steady flow, we have ∂ω/∂t = 0. The governing equations can then be written neatly as
∂2 ψ ∂2 ψ ∂2 ω ∂2 ω
Re ∂ψ ∂ω ∂ψ ∂ω
+ 2 = −e2ξ ω, + = − .
∂ξ 2 ∂θ ∂ξ 2 ∂θ 2 2 ∂θ ∂ξ ∂ξ ∂θ
1.
f (− x + h) − f (− x )
f 0 (− x ) = lim
h →0 h
f ( x − h) − f ( x )
= lim
h →0 h
f ( x ) − f ( x − h)
= − lim
h →0 h
= − f 0 ( x ).
derivative
f (− x + h) − f (− x )
f 0 (− x ) = lim
h →0 h
− f ( x − h) + f ( x )
= lim
h →0 h
f ( x ) − f ( x − h)
= lim
h →0 h
= f 0 ( x ).
1.
∂2 ψ ∂2 ψ
− + 2 = e2ξ ω.
∂ξ 2 ∂θ
The second-order finite difference approximation to the second partial derivatives yields
1
ψi,j = ψi,j + ψi+1,j + ψi−1,j + ψi,j+1 + ψi,j−1 − 4ψi,j + h2 e2ξ i ωi,j .
4
We make the left-hand side the (k + 1)-th iteration and the right-hand side the k-th iteration, and
we adjust the correction to ψi,j by a relaxation factor rψ . The result becomes
k +1 k rψ k
ψi,j = ψi,j + ψi+1,j + ψik−1,j + ψi,j
k
+
k k 2 2ξ i k
1 + ψi,j−1 − 4ψi,j + h e ωi,j
4
k rψ k
= (1 − rψ )ψi,j + ψi+1,j + ψik−1,j + ψi,j
k
+1 + ψ k
i,j−1 + h 2 2ξ i k
e ω i,j .
4
∂2 ω ∂2 ω
Re ∂ψ ∂ω ∂ψ ∂ω
− 2
+ 2 = − .
∂ξ ∂θ 2 ∂ξ ∂θ ∂θ ∂ξ
Second-order finite difference approximations for the first- and second-derivatives yields
Again, we make the left-hand side the (k + 1)-th iteration and the right-hand side the k-th itera-
tion, and we adjust the correction to ωi,j by a relaxation factor rω . The result becomes
k +1 k rω Re k
ωi,j = ωi,j + ωik+1,j + ωik−1,j k
+ ωi,j +1
k
+ ωi,j
+ f−1
k
− 4ωi,j
4 8 i,j
k rω k k k k Re k
= (1 − rω )ωi,j + ωi+1,j + ωi−1,j + ωi,j+1 + ωi,j−1 + f ,
4 8 i,j
with
k
f i,j = ψik+1,j − ψik−1,j ωi,j
k
+1 − ω k
i,j−1 − ψ k
i,j+1 − ψ k
i,j−1 ω k
i +1,j − ω k
i −1,j .
1. We Taylor series expand the scalar vorticity one and two grid points inside the free-stream boundary.
That is,
∂ω h2 ∂2 ω
ωn−1,j = ωn,j − h + + O( h3 )
∂ξ (n,j) 2 ∂ξ 2 (n,j)
∂ω 2
(2h) ∂2 ω
ωn−2,j = ωn,j − 2h + + O( h3 ).
∂ξ (n,j) 2 ∂ξ 2 (n,j)
We assume that the first derivative terms are zero and multiply the first equation by four and subtract
the second equation to find
4ωn−1,j − ωn−2,j = 3ωn,j + O(h3 ).
4ωn−1,j − ωn−2,j
ωn,j = .
3
ψ(ξ ) = aξ 2 .
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 62
Then
∂2 ψ
= 2a, ψ2,j = ah2 , ψ3,j = 4ah2 ,
∂ξ 2 (1,j)
and
1 1 ∂2 ψ
2
(8ψ2,j − ψ3,j ) = 2 (8ah2 − 4ah2 ) = 2a = .
2h 2h ∂ξ 2 (1,j)
k +1 k rψ k
ψi,j = (1 − rψ )ψi,j + ψi+1,j + ψik−1,j + ψi,j
k
+1 + ψ k
i,j−1 + h 2 2ξ i k
e ω i,j ,
4
k +1 k rω Re k
ωi,j = (1 − rω )ωi,j + ωik+1,j + ωik−1,j + ωi,j
k
+1 + ω k
i,j−1 + f ,
4 8 i,j
where
f ijk = ψik+1,j − ψik−1,j ωi,j
k k k k
+1 − ωi,j−1 − ψi,j+1 − ψi,j−1 ωik+1,j − ωik−1,j .
Note that every term in the iteration equation for the scalar vorticity ω k+1 is proportional to ω k .
Therefore, ω k can only become nonzero through the boundary condition on the cylinder:
and ω will first become nonzero after ψ3,j becomes nonzero. In the iteration equation for the stream
k +1
function ψi,j , there is a term ψik+1,j so that the nonzero boundary condition at i = n propagates
downward in i with each iteration until it finally reaches i = 3. This will take n − 3 iterations of the
SOR equations.
Considerations such as this are useful when debugging code and monitoring how the fields develop
with each iteration.
63 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES
1. Complete your solution in the Matlab Grader using the Learner Template:
The boundary conditions are the same as the implementation in the lecture, but the values of θ are
now shifted by one grid point, starting at zero rather than −h and ending at 2π + h rather than at 2π.
2e−2ξ ∂2 ω ∂2 ω
∂ω −2ξ ∂ψ ∂ω ∂ψ ∂ω
= + +e − .
∂t Re ∂ξ 2 ∂θ 2 ∂ξ ∂θ ∂θ ∂ξ
Second-order finite difference approximations for the first- and second-derivatives yields
dωi,j 2e−2ξ i
= 2 ωi+1,j + ωi−1,j + ωi,j+1 + ωi,j−1 − 4ωi,j +
dt h Re
e−2ξ i
2
ψi+1,j − ψi−1,j ωi,j+1 − ωi,j−1 − ψi,j+1 − ψi,j−1 ωi+1,j − ωi−1,j .
4h
omega_tilde=zeros(n,m);
for j=1:m
for i=1:n
omega_tilde(i,j}=h^2*exp(2*xi(i))*omega(i,j);
end
end
omega_tilde = omega_tilde(:);
An implementation that doesn’t use for loops could use the Matlab repmat.m function to duplicate
xi across m columns, and may be written as
omega_tilde=h^2*repmat(exp(2*xi(:)),1,m).*omega;
omega_tilde=omega_tilde(:);
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 66
1. Only the fifth row satisfies the Poisson equation, being the only internal grid point. Rows one
to three and rows seven to nine obey periodic boundary conditions, row four satisfies the cylinder
boundary condition ψ4 = 0 and row six satisfies the free-stream condition ψ6 = eξ 3 sin θ2 .
Φ1
1 0 0 −1 0 0 0 0 0 0
0 1 0 0 −1 0 0 0 0 Φ2 0
Φ3
0
0 1 0 0 −1 0 0 0 0
0 0 0 1 0 0 0 0 0 Φ4 0
0 Φ5 = h e ω2,2
0 −1 0 −1 4 −1 0 −1 2 2ξ 2
0 0 0 0 0 1 0 0 0 Φ6 eξ 3 sin θ2
Φ7
0
0 0 −1 0 0 1 0 0 0
0 0 0 0 −1 0 0 1 0 Φ8 0
0 0 0 0 0 −1 0 0 1 Φ9 0
With only three grid points in θ, all the θ values are actually located at the same point (equivalent
to θ = 0)! Nevertheless, this result can be used to debug your construction of the matrix for the
stream-function equation.
1. We have found that the line of code that solves the stream-function equation Aψ = b using the
backslash operator takes almost 90% of the computational time. Replacing A by LU, where the LU
decomposition need only be done once, saves substantial computational time.
67 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES
1. Complete your solution in the Matlab Grader using the Learner Template:
end
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 68
function plot_Re60(omega,t_plot)
% Plot vorticity for Re = 60 from flow_past_circle_unsteady
Re=60;
% xi-theta grid
n=size(omega,1); m=size(omega,2);
N=n-1; M=m-2;
h=2*pi/M; %grid spacing
xi=(0:N)*h; theta=(-1:M)*h; %xi and theta variables on the grid
[XI, THETA] = meshgrid(xi,theta);
% x-y grid
nx=640; ny=480; %number of pixels in x and y
xmin=-1.5; xmax=10; ymax=((xmax-xmin)/2)*ny/nx; ymin=-ymax;
x=linspace(xmin,xmax,nx+1); y=linspace(ymin,ymax,ny+1);
[X,Y]=meshgrid(x,y);
omega_xy=interp2(XI,THETA,omega',xi_i,theta_i);
%inside circle
omega_xy(xi_i<0)=0;
%color contours
imagesc(x,y,omega_xy,v); hold on;
%neaten plot
set(gca,'YDir','normal');
axis([xmin xmax ymin ymax]); set(gcf,'color','w'); axis equal; axis off;
text(xmin+0.75*(xmax-xmin),ymin+0.08*(ymax-ymin),...
['t = ', num2str(t_plot,'%3.1f')],'FontSize',22,'Color','k');
69 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES
function plot_Re60_movie
Re=60;
%%%%% Initialize movie file %%%%%
writerObj = VideoWriter('movie.mp4','MPEG-4');
writerObj.Quality = 100;
writerObj.FrameRate=24;
open(writerObj);
input_file='.\fields\Re_60_';
%%%%% Loop over fields to construct plot and put in movie file %%%%%
nfields=1000;
for ij=1:nfields
load([input_file num2str(ij)],'omega');
%%%%% xi-theta grid %%%%%
n=size(omega,1); m=size(omega,2);
N=n-1; M=m-2;
h=2*pi/M; %grid spacing
xi=(0:N)*h; theta=(-1:M)*h;
[XI, THETA] = meshgrid(xi,theta);
%%%%%% x-y grid %%%%%
nx=640; ny=480; % number of pixels in x and y
xmin=-1.5; xmax=20; ymax=((xmax-xmin)/2)*ny/nx; ymin=-ymax;
x=linspace(xmin,xmax,nx+1); y=linspace(ymin,ymax,ny+1);
[X,Y]=meshgrid(x,y);
%%%%% construct interpolation points %%%%%
xi_i=0.5*log(X.^2+Y.^2);
theta_i=wrapTo2Pi(atan2(Y,X));
%%%%% interpolate %%%%%
omega_xy=interp2(XI,THETA,omega',xi_i,theta_i);
%%%%% set omega to zero inside cylinder %%%%%
omega_xy(xi_i<0)=0;
%%%%% set colormap for contours %%%%%
levels=linspace(-1,1,1000);
v=[levels(1) levels(end)];
cmap=flipud(jet(length(levels)));
colormap(cmap);
%%%%% plot color contours %%%%%
imagesc(x,y,omega_xy,v); hold on;
%%%%% draw black circle for cylinder %%%%%
t=linspace(0,2*pi, 1000);
a=cos(t); b=sin(t);
fill(a,b,[0 0 0]);
%%%%% beautify plot %%%%%
set(gca,'YDir','normal');
axis([xmin xmax ymin ymax]); set(gcf,'color','w'); axis equal; axis off;
text(xmin+0.75*(xmax-xmin),ymin+0.08*(ymax-ymin),...
['t = ', num2str(ij,'%3.0f')],'FontSize',22,'Color','k');
%%%%% add frame to movie file %%%%%
frame=getframe(gcf);
writeVideo(writerObj,frame);
close;
fprintf('%g\n',ij)
end
close(writerObj);