0% found this document useful (0 votes)
97 views

Flow Around A Cylinder

Uploaded by

Hiếu Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Flow Around A Cylinder

Uploaded by

Hiếu Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

Flow Around a Cylinder

Lecture Notes for

Jeffrey R. Chasnov
The Hong Kong University of Science and Technology
Department of Mathematics
Clear Water Bay, Kowloon
Hong Kong

Copyright © 2022 by Jeffrey Robert Chasnov

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

View the Deep Dive video Flow Around a Cylinder on YouTube

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

3 Geometry of the flow 7

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

9 Finite difference method 21

10 Iteration equations 23

11 Free-stream boundary conditions 25

12 Cylinder boundary conditions 27

13 Summary of the boundary conditions 31

14 Matlab program (steady) (Part A) 33

15 Matlab program (steady) (Part B) 35

III Unsteady Flows 37

16 Periodic boundary conditions 39

17 Finite difference equations 41

18 Stream-function computation 43

19 Stream-function boundary conditions 45

iv
v CONTENTS

20 Vorticity computation 47

21 Matlab program (unsteady) (Part A) 49

22 Matlab program (unsteady) (Part B) 51

Problem solutions and Matlab learner templates 53


Week I

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

View this lecture on YouTube

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

𝑢 = u( x, y, z)𝑖 + v( x, y, z)𝑗 + w( x, y, z)𝑘,

where the three components also depend on the time t. The continuity equation expands to

∂u ∂v ∂w
+ + = 0;
∂x ∂y ∂z

and the Navier-Stokes equation expands into the three-component equations


 2
∂ u ∂2 u ∂2 u
  
∂u ∂u ∂u ∂u 1 ∂p
+ u +v +w =− +ν + + ,
∂t ∂x ∂y ∂z ρ ∂x ∂x2 ∂y2 ∂z2
 2
∂2 v ∂2 v
  
∂v ∂v ∂v ∂v 1 ∂p ∂ v
+ u +v +w =− +ν + + ,
∂t ∂x ∂y ∂z ρ ∂y ∂x2 ∂y2 ∂z2
 2
∂ w ∂2 w ∂2 w
  
∂w ∂w ∂w ∂w 1 ∂p
+ u +v +w =− +ν + 2 + 2 .
∂t ∂x ∂y ∂z ρ ∂z ∂x2 ∂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

Problems for Lecture 1


1. Plane Couette flow consists of an incompressible fluid flowing between two infinite plates separated
by a distance d. The lower plate is stationary, and the upper plate is moving to the right with velocity
U. The pressure p is constant. Choose a coordinate system so that the 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)𝑖.

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.

Solutions to the Problems


Lecture 2 | Vorticity equation

View this lecture on YouTube

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

And because the curl of a gradient is zero,

∇ × {−∇p/ρ} = 0.

To simplify the curl of the convection term, one writes


 
1
∇ × {(𝑢 · ∇)𝑢} = ∇ × ∇(𝑢2 ) + 𝜔 × 𝑢 = ∇ × (𝜔 × 𝑢) ;
2

and the vorticity equation becomes

∂𝜔
+ ∇ × (𝜔 × 𝑢) = ν∇2 𝜔.
∂t

An alternative form expands the convection term to obtain

∂𝜔
+ (𝑢 · ∇)𝜔 = (𝜔 · ∇)𝑢 + ν∇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

Problems for Lecture 2


1. Prove the following equalities:

a) ∇ × {(𝑢 · ∇)𝑢} = ∇ × (𝜔 × 𝑢);

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

Solutions to the Problems


Lecture 3 | Geometry of the flow

View this lecture on YouTube

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

Problems for Lecture 3


1. In the cross-sectional plane, express the cylinder boundary in Cartesian and polar coordinates.
Express the free-stream velocity in polar coordinates.

Solutions to the Problems


Lecture 4 | Two-dimensional flow

View this lecture on YouTube

The vorticity equation is given by

∂𝜔
+ (𝑢 · ∇)𝜔 = (𝜔 · ∇)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

𝑢 = ur (r, θ )r̂ + uθ (r, θ )θ̂,

where the components of the velocity may also depend on time.


In polar coordinates, the vorticity field becomes
 
1 ∂ ∂ur
𝜔 = ∇×𝑢 = (ruθ ) − 𝑘,
r ∂r ∂θ

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

Problems for Lecture 4


1. With
𝜔 = ω ( x, y)𝑘, 𝑢 = u( x, y)𝑖 + v( x, y)𝑗,

show by direct calculation that


 
∂ω ∂ω
∇ × (𝜔 × 𝑢) = u +v 𝑘.
∂x ∂y

2. Define the scalar vorticity in Cartesian coordinates.

3. Write the scalar vorticity equation in Cartesian coordinates.

Solutions to the Problems


Lecture 5 | Stream function

View this lecture on YouTube

The incompressibility condition in polar coordinates is given by


 
1 ∂ ∂u
∇·𝑢 = (rur ) + θ = 0.
r ∂r ∂θ

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 ∂θ

which is simply the equation


∇2 ψ = − ω

in polar coordinates.

11
WEEK I. GOVERNING EQUATIONS 12

Problems for Lecture 5


1. Define the stream function in Cartesian coordinates.

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 𝐴.

Solutions to the Problems


Lecture 6 | Streamlines

View this lecture on YouTube

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

0 = 𝑢 × d𝑟 = (ur r̂ + uθ θ̂ ) × (drr̂ + rdθ θ̂ ) = (−uθ dr + rur dθ ))𝑘.

But since the stream function ψ is defined by

∂ψ ∂ψ
rur = , uθ = − ,
∂θ ∂r

we have determined that  


∂ψ ∂ψ
0= dr + dθ 𝑘 = dψ𝑘,
∂r ∂θ
or dψ = 0 along streamlines. The streamlines are therefore curves of constant ψ, and a plot of the
contour lines of the stream function thus provides us an excellent visual representation of a steady
two-dimensional flow.

13
WEEK I. GOVERNING EQUATIONS 14

Problems for Lecture 6


1. Use Cartesian coordinates to show that the stream function is constant along streamlines.

Solutions to the Problems


Lecture 7 | Reynolds number

View this lecture on YouTube

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 ∂θ

where ∇2 is the two-dimensional Laplacian in polar coordinates.


We now consider flow past an infinite circular cylinder of radius R, with free-stream velocity
𝑢 = U𝑖. The units of our problem are time t and length l, and [ R] = l, [U ] = lt−1 , and the various
terms in the equations have units
   
∂ ∂
= t −1 , = l −1 , [∇2 ] = l −2 , [ ν ] = l 2 t −1
∂t ∂r
[ ψ ] = l 2 t −1 , [ ω ] = t −1 .

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

Problems for Lecture 7


1. From the nondimensional equations for the stream function and the scalar vorticity, determine a
single equation for the stream function when Re = 0.

Solutions to the Problems


Lecture 8 | Log-polar coordinates

View this lecture on YouTube

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.

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ξ .

The Laplacian in these log-polar coordinates then becomes

∂2
   
21 ∂ ∂
∇ = 2 r r + 2
r ∂r ∂r ∂θ
 2 2 
∂ ∂
= e−2ξ + 2 ;
∂ξ 2 ∂θ

and the governing equations become

∂2 ψ ∂2 ψ
 
+ 2 = −e2ξ ω,
∂ξ 2 ∂θ
∂2 ω ∂2 ω
   
∂ω ∂ψ ∂ω ∂ψ ∂ω 2 −2ξ
+ e−2ξ − = e + .
∂t ∂θ ∂ξ ∂ξ ∂θ Re ∂ξ 2 ∂θ 2

17
WEEK I. GOVERNING EQUATIONS 18

Problems for Lecture 8


1. Determine the governing equations for a steady flow in log-polar coordinates. Try to write the
equations as neatly as possible.

Solutions to the Problems


Week II

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

View this lecture on YouTube

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,

u( x, −y) = u( x, y), v( x, −y) = −v( x, y).

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

Problems for Lecture 9


1. An even function of x satisfies f (− x ) = f ( x ). An odd function of x satisfies f (− x ) = − f ( x ). Prove
the following symmetry theorems:

a) If f ( x ) is an even function of x, then f 0 ( x ) is an odd function of x.

b) If f ( x ) is an odd function of x, then f 0 ( x ) is an even function of x.

Solutions to the Problems


Lecture 10 | Iteration equations

View this lecture on YouTube

The governing equations for a steady flow field may be written as

∂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

εkψ+1 = max ψi,j


k +1 k
− ψi,j , εkω+1 = max ωi,j
k +1 k
− ωi,j .
i,j i,j

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

Problems for Lecture 10


1. Derive the SOR finite difference equations for

a) the stream function equation,


∂2 ψ ∂2 ψ
 
− + 2 = e2ξ ω;
∂ξ 2 ∂θ

b) the scalar vorticity equation,

∂2 ω ∂2 ω
   
Re ∂ψ ∂ω ∂ψ ∂ω
− 2
+ 2 = − .
∂ξ ∂θ 2 ∂ξ ∂θ ∂θ ∂ξ

Solutions to the Problems


Lecture 11 | Free-stream boundary
conditions

View this lecture on YouTube

The dimensionless free-stream velocity field is given by 𝑢 = 𝑖, which in polar coordinates is

ˆ
u = cos θr̂ − sin θ 𝜃.

Since rur = ∂ψ/∂θ and uθ = −∂ψ/∂r, the stream function satisfies the free-stream conditions

∂ψ ∂ψ
= r cos θ, = sin θ.
∂θ ∂r

The solution of these equations can be seen to be

ψ(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

Problems for Lecture 11


1. Instead of assuming the scalar vorticity to be zero in the free stream, that is,

ωn,j = 0,

another option is to take the normal derivative to be zero, that is,

∂ω
= 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 .

Solutions to the Problems


Lecture 12 | Cylinder boundary
conditions

View this lecture on YouTube

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 ∂θ

and on the cylinder ξ = 0 and ψ is independent of θ so that

∂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

8ψ2,j − ψ3,j = −2h2 ω1,j + O(h4 );

27
WEEK II. STEADY FLOWS 28

and the boundary condition on the vorticity, accurate to second-order, is given by

1
ω1,j = (ψ3,j − 8ψ2,j ).
2h2
29 LECTURE 12. CYLINDER BOUNDARY CONDITIONS

Problems for Lecture 12


1. The cylinder boundary condition on the scalar vorticity may be rewritten in terms of the stream
function as
∂2 ψ 1
= (8ψ2,j − ψ3,j ).
∂ξ 2 (1,j) 2h2

This boundary condition was derived using

∂ψ
ψ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.

Solutions to the Problems


Lecture 13 | Summary of the boundary
conditions

View this lecture on YouTube

We collect all the boundary conditions and summarize them here:

ξ = 0, 0≤θ≤π: ψ1,j = 0, ω1,j = (ψ3,j − 8ψ2,j )/2h2 ;


ξ = ξ max , 0≤θ≤π: ψn,j = eξ n sin θ j , ωn,j = 0;
θ = 0, 0 ≤ ξ ≤ ξ max : ψi,1 = 0, ωi,1 = 0;
θ = π, 0 ≤ ξ ≤ ξ max : ψi,m = 0, ωi,m = 0.

31
WEEK II. STEADY FLOWS 32

Problems for Lecture 13


1. Consider a grid with n and m gridpoints in the ξ and θ directions, respectively. Suppose the SOR
iteration begins with the flow fields ψ = ω = 0 everywhere except on the free-stream boundary, where

ψn,j = eξ n sin θ j .

How many SOR iterations does it take for ω to obtain its first nonzero value?

Solutions to the Problems


Lecture 14 | Matlab program (steady)
(Part A)

View this lecture on YouTube

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,

function [psi, omega] = flow_around_cylinder_steady

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

Problems for Lecture 14


1. Using the SOR method, compute the steady solution for the stream function and scalar vorticity
when Re = 10.

Solutions to the Problems


Lecture 15 | Matlab program (steady)
(Part B)

View this lecture on YouTube

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)

The structure of the graphics code is as follows:


1. Define the ξ-θ grid.
2. Define the x-y grid.
3. Construct interpolation points.
4. Interpolate the values of psi onto the Cartesian grid.
5. Scale the interpolated values of psi for a better plot.
6. Set the color map.
7. Plot the color contours.
8. Set the contour line values.
9. Plot the contour lines.
10. Draw a black circle to represent the cylinder.
11. Beautify the plot.

35
WEEK II. STEADY FLOWS 36

Problems for Lecture 15


1. Study the graphics code and try to understand it. You may need to Google some unfamiliar Matlab
functions.

Solutions to the Problems


Week III

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

View this lecture on YouTube

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

The polar angle is now discretized as

θ j = ( j − 2)h, j = 1, 2, . . . , m,

and since θm = 2π, we have h = 2π/(m − 2).


The first and last grid points are duplicates of the (m − 1) and second internal grid points and are
called ghost points. Periodic boundary conditions then requires for these ghost points

ψi,1 = ψi,m−1 , ωi,1 = ωi,m−1 ; ψi,m = ψi,2 , ωi,m = ωi,2 .

39
WEEK III. UNSTEADY FLOWS 40

Problems for Lecture 16


1. Our implementation of periodic boundary conditions in the polar angle uses two extra ghost points:
one point below the x-axis and one point on the x-axis. It is equally fine to implement periodic
boundary conditions with one point above the x-axis and one point on the x-axis, as shown in the
figure below.

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?

Solutions to the Problems


Lecture 17 | Finite difference equations

View this lecture on YouTube

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

4ψi,j − ψi+1,j − ψi−1,j − ψi,j+1 − ψi,j−1 = h2 e2ξ i ωi,j ,

and the vorticity equation becomes

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

Problems for Lecture 17


1. Derive the finite difference equation for the scalar vorticity from the time-dependent vorticity equa-
tion,
2e−2ξ ∂2 ω ∂2 ω
   
∂ω −2ξ ∂ψ ∂ω ∂ψ ∂ω
= + +e − .
∂t Re ∂ξ 2 ∂θ 2 ∂ξ ∂θ ∂θ ∂ξ

Solutions to the Problems


Lecture 18 | Stream-function
computation

View this lecture on YouTube

The discrete stream-function equation is given by

4ψi,j − ψi+1,j − ψi−1,j − ψi,j+1 − ψi,j−1 = h2 e2ξ i ωi,j .

We define the right-hand side of this equation as

ω̃i,j = h2 e2ξ i ωi,j ,

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

4ψk − ψk+1 − ψk−1 − ψk+n − ψk−n = ω̃k .

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

Problems for Lecture 18


1. Consider the calculation of ω̃k in Matlab, where

ω̃i,j = h2 e2ξ i ωi,j ,

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.

Solutions to the Problems


Lecture 19 | Stream-function boundary
conditions

View this lecture on YouTube

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

Problems for Lecture 19


1. Construct the nine-by-nine matrix equation for the stream function on the three-by-three grid shown
below, where the k indexing is labeled. Note that only grid point five is an internal point.

7 8 9

4 5 6

1 2 3

Solutions to the Problems


Lecture 20 | Vorticity computation

View this lecture on YouTube

The discrete scalar vorticity equation at interior grid points is given by

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

Problems for Lecture 20


1. In an efficiently written Matlab program, often one line of code takes up most of the computational
time. In the unsteady flow problem, it will certainly be the call to ode23.m. But within the function
that defines the time derivative of the vorticity field, which line of code do you think will require most
of the computational time?

Solutions to the Problems


Lecture 21 | Matlab program (unsteady)
(Part A)

View this lecture on YouTube

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

Problems for Lecture 21


1. Using ode23.m, compute the unsteady solution for the scalar vorticity when Re = 60.

Solutions to the Problems


Lecture 22 | Matlab program (unsteady)
(Part B)

View this lecture on YouTube

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');

where k is the loop variable, for instance.


The separate graphics program then reads in the fields one-by-one, and plots the vorticity using
the Matlab function imagesc. To initialize the movie file, we use
writerObj = VideoWriter('movie.mp4','MPEG-4');
writerObj.Quality = 100;
writerObj.FrameRate=24;
open(writerObj);

To capture movie frames and save them into a movie file, we use the commands
frame=getframe(gcf);
writeVideo(writerObj,frame);

Finally, we conclude the program with the command


close(writerObj);

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

Problems for Lecture 22


1. Study the graphics code that creates the movie file and try to understand what it does.

Solutions to the Problems


Problem solutions and
Matlab learner templates

53
55 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES

Solutions to the Problems for Lecture 1

1. The first component of the Navier-Stokes equation reduces to

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

2. The first component of the Navier-Stokes equation reduces to

1 dp d2 u
− + ν 2 = 0.
ρ dx dy

Using dp/dx = − G leads to


d2 u G
2
=− ,
dy νρ
which can be solved using the no-slip boundary conditions u(0) = u(d) = 0. We find

Gd2  y   y
𝑢= 1− 𝑖.
2νρ d d

3. The first component of the Navier-Stokes equation becomes

∂2 u ∂2 u
 
1 dp
− +ν + 2 = 0.
ρ dx ∂y2 ∂z

Using dp/dx = − G leads to


∂2 u ∂2 u G
+ 2 =− .
∂y2 ∂z νρ
p
We use polar coordinates in the y-z plane. With r = y2 + z2 , and the Laplacian written in polar
coordinates, the differential equation for u = u(r ) then becomes
 
d du Gr
r =− ,
dr dr νρ

with no-slip boundary condition u( R) = 0. The first integration from 0 to r yields

du Gr2
r =− ;
dr 2νρ

and after division by r, the second integration from r to R yields

GR2
  r 2 
u (r ) = 1− ,
4νρ R

so that
GR2 y2 + z2
 
𝑢= 1− 𝑖.
4νρ R2
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 56

Solutions to the Problems for Lecture 2

1.

a) We prove that ∇ × {(𝑢 · ∇)𝑢} = ∇ × (𝜔 × 𝑢) . To begin, we first prove the identity

1
𝑢 × (∇ × 𝑢) = ∇(𝑢 · 𝑢) − (𝑢 · ∇)𝑢.
2

Proof proceeds by considering the ith component of the left-hand side:

∂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
∇ × (𝜔 × 𝑢) = (𝑢 · ∇)𝜔 − (𝜔 · ∇)𝑢,

using the vector identity

∇ × (𝑢 × 𝑣 ) = 𝑢(∇ · 𝑣 ) − 𝑣 (∇ · 𝑢) + (𝑣 · ∇)𝑢 − (𝑢 · ∇)𝑣.

We have

∇ × (𝜔 × 𝑢) = 𝜔 (∇ · 𝑢) − 𝑢(∇ · 𝜔 ) + (𝑢 · ∇)𝜔 − (𝜔 · ∇)𝑢 (vector identity)


= (𝑢 · ∇)𝜔 − (𝜔 · ∇). (∇ · 𝑢 = 0, ∇ · 𝜔 = 0)
57 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES

Solutions to the Problems for Lecture 3

1. The cylinder boundary in Cartesian coordinates is given by

x 2 + y2 = R2 ,

and in polar coordinates is given by


r = R.

The free stream velocity in Cartesian coordinates is given by

𝑢 f = U𝑖,

and in polar coordinates is given by

𝑢 f = U (cos θ r̂ − sin θ θ̂ ).

Solutions to the Problems for Lecture 4

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

The scalar vorticity is then defined as


∂v ∂u
ω= − .
∂x ∂y

3. In Cartesian coordinates, the two-dimensional scalar vorticity equation is written as

∂2 ω ∂2 ω
 
∂ω ∂ω ∂ω
+u +v =ν + .
∂t ∂x ∂y ∂x2 ∂y2
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 58

Solutions to the Problems for Lecture 5

1. The two-dimensional incompressibility condition in Cartesian coordinates is given by

∂u ∂v
+ = 0.
∂x ∂y

The appropriate definition of the stream function ψ = ψ( x, y) that satisfies this condition is

∂ψ ∂ψ
u= , v=− .
∂y ∂x

2. The scalar vorticity in Cartesian coordinates is given by

∂v ∂u
ω= − .
∂x ∂y

Using the definition of the stream function, we have

∂2 ψ ∂2 ψ
 
ω=− + 2
∂x2 ∂y

3. Since ∇ · 𝑢 = 0 we can write 𝑢 = ∇ × 𝐴, where 𝐴 is called a vector potential. In two dimensions,


we have
𝑖 𝑗 𝑘  
∂A3 ∂A3 ∂A2 ∂A1
u𝑖 + v𝑗 = ∂/∂x ∂/∂y 0 = 𝑖− 𝑗+ − 𝑘.
∂y ∂x ∂x ∂y
A1 A2 A3

Therefore,
∂A3 ∂A3
u= , v=− ,
∂y ∂x
and the stream function can be identified as the third component of the vector potential 𝐴.

Solutions to the Problems for Lecture 6

1. In Cartesian coordinates, d𝑟 = dx𝑖 + dy𝑗, and with the velocity field parallel to d𝑟, we have

0 = 𝑢 × d𝑟 = (u𝑖 + v𝑗 ) × (dx𝑖 + dy𝑗 ) = (−vdx + udy)𝑘.

But since the stream function ψ is defined by

∂ψ ∂ψ
u= , v=− ,
∂y ∂x

we have determined that  


∂ψ ∂ψ
0= dx + dy 𝑘 = dψ𝑘,
∂x ∂y
or that the stream function is constant along streamlines.
59 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES

Solutions to the Problems for Lecture 7

1. The nondimensional vorticity equation can be written as


  
2Re ∂ω 1 ∂ψ ∂ω ∂ψ ∂ω
∇ ω= + − ;
2 ∂t r ∂θ ∂r ∂r ∂θ

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.

Solutions to the Problems for Lecture 8

1. The time-dependent governing equations are given by

∂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 ∂θ ∂ξ ∂ξ ∂θ

Solutions to the Problems for Lecture 9

1.

a) Suppose f ( x ) is an even function of x so that f (− x ) = f ( x ). Then using the definition of the


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 ).

b) Suppose f ( x ) is an odd function of x so that f (− x ) = − f ( x ). Then using the definition of the


PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 60

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 ).

Solutions to the Problems for Lecture 10

1.

a) The stream function equation is given by

∂2 ψ ∂2 ψ
 
− + 2 = e2ξ ω.
∂ξ 2 ∂θ

The second-order finite difference approximation to the second partial derivatives yields

ψi+1,j − 2ψi,j + ψi−1,j ψi,j+1 − 2ψi,j + ψi,j−1


 
− 2
+ = e2ξ i ωi,j
h h2

We multiply by h2 and collect terms to obtain

4ψi,j − ψi+1,j − ψi−1,j − ψi,j+1 − ψi,j−1 = h2 e2ξ i ωi,j

To construct the SOR method, we rewrite this equation as

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

b) The scalar vorticity equation is given by

∂2 ω ∂2 ω
   
Re ∂ψ ∂ω ∂ψ ∂ω
− 2
+ 2 = − .
∂ξ ∂θ 2 ∂ξ ∂θ ∂θ ∂ξ

Second-order finite difference approximations for the first- and second-derivatives yields

ωi+1,j − 2ωi,j + ωi−1,j ωi,j+1 − 2ωi,j + ωi,j−1


 
− +
h2 h2
ψi+1,j − ψi−1,j ωi,j+1 − ωi,j−1 ψi,j+1 − ψi,j−1 ωi+1,j − ωi−1,j
     
Re
= − .
2 2h 2h 2h 2h
61 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES

Multiplying by h2 and collecting terms yields

4ωi,j − ωi+1,j − ωi−1,j − ωi,j+1 − ωi,j−1


Re     
= ψi+1,j − ψi−1,j ωi,j+1 − ωi,j−1 − ψi,j+1 − ψi,j−1 ωi+1,j − ωi−1,j
8

For notational clarity, we define


   
f i,j = ψi+1,j − ψi−1,j ωi,j+1 − ωi,j−1 − ψi,j+1 − ψi,j−1 ωi+1,j − ωi−1,j .

We then rewrite the equation as


 
1 Re
ωi,j = ωi,j + ωi+1,j + ωi−1,j + ωi,j+1 + ωi,j−1 − 4ωi,j + f .
4 8 i,j

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 .

Solutions to the Problems for Lecture 11

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 ).

The boundary condition on ωn,j is therefore

4ωn−1,j − ωn−2,j
ωn,j = .
3

Solutions to the Problems for Lecture 12

1. Near the cylinder surface, we assume that

ψ(ξ ) = 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)

Solutions to the Problems for Lecture 13

1. The SOR iteration formulas are

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 .

The iterations start with ψ and ω everywhere zero except for

ψn,j = eξ n sin θ j , for j = 1 to m.

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:

ω1,j = (ψ3,j − 8ψ2,j )/2h2 ,

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

Solutions to the Problems for Lecture 14

1. Complete your solution in the Matlab Grader using the Learner Template:

function [psi, omega] = flow_around_cylinder_steady


Re=10;
%%%%% define the grid %%%%%
n=101; m=101; % number of grid points
N=n-1; M=m-1; % number of grid intervals
h=pi/M; % grid spacing based on theta variable
xi=(0:N)*h; theta=(0:M)*h; % xi and theta variables on the grid
%%%%% Initialize the flow fields %%%%%
psi=zeros(n,m);
omega=zeros(n,m);
psi(n,:)=... % Write the free-stream boundary condition here
%%%%% Set relax params, tol, extra variables %%%%%
r_psi=1.8; r_omega=0.9; % relaxation parameters
delta=1.e-08; % error tolerance
error=2*delta; % initialize error variable
%%%%% Add any additional variable definitions here %%%%%
...
...
%%%%% Main SOR Loop %%%%%
while (error > delta)
psi_old = psi; omega_old = omega;
for i=2:n-1
for j=2:m-1
psi(i,j)=... % Write the psi equation here
end
end
error_psi=max(abs(psi(:)-psi_old(:)));
omega(1,:)=... % Write the boundary condition here
for i=2:n-1
for j=2:m-1
omega(i,j)=... % Write the omega equation here
end
end
error_omega=max(abs(omega(:)-omega_old(:)));
error=max(error_psi, error_omega);
end
plot_Re10(psi);
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 64

Solutions to the Problems for Lecture 15

1. Here is a copy of the graphics code.


function plot_Re10(psi)
Re=10;
%%%%% xi-theta grid %%%%%
n=size(psi,1); m=size(psi,2);
N=n-1; M=m-1;
h=pi/M; % grid spacing
xi=(0:N)*h; theta=(0:M)*h;
[XI, THETA] = meshgrid(xi,theta);
%%%%%% x-y grid %%%%%
nx=640; ny=480/2; % number of pixels in x and half of y
xmin=-1.5; xmax=2.5; ymax=(xmax-xmin)*ny/nx; ymin=-ymax;
x=linspace(xmin,xmax,nx+1); y=linspace(0,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 %%%%%
psi_xy=interp2(XI,THETA,psi',xi_i,theta_i);
%%%%% set psi to zero inside cylinder %%%%%
psi_xy(xi_i<0)=0;
%%%%% scale contour levels %%%%%
%%%%% negative values have same range as positive values %%%%%
psi_min=min(psi_xy(:));
psi_max=max(psi_xy(:));
psi_xy(psi_xy<0)=psi_xy(psi_xy<0)/abs(psi_min);
psi_xy(psi_xy>0)=psi_xy(psi_xy>0)/abs(psi_max);
%%%%% set colormap for contours %%%%%
levels=linspace(-1,1,1000);
cmap=flipud(jet(length(levels)));
colormap(cmap);
%%%%% plot color contours %%%%%
imagesc(x,y,psi_xy); hold on;
imagesc(x,-y,-psi_xy); % negative values of y
%%%%% plot contour lines %%%%%
v=[-0.9:0.2:-0.1,0,0.0005,0.001,0.002:0.004:0.01,0.02:0.04:0.9];
contour(X,Y,psi_xy,v,'LineColor','k');
contour(X,-Y,-psi_xy,-v,'LineColor','k');
%%%%% 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),...
['Re = ', num2str(Re,'%3.0f')],'FontSize',22,'Color','k');
65 PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES

Solutions to the Problems for Lecture 16

1. Periodic boundary conditions requires for the end points

ψi,1 = ψi,m−1 , ωi,1 = ωi,m−1 ; ψi,m = ψi,2 , ωi,m = ωi,2 .

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π.

Solutions to the Problems for Lecture 17

1. The scalar vorticity equation is given by

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 ωi+1,j − 2ωi,j + ωi−1,j ωi,j+1 − 2ωi,j + ωi,j−1


   
= + +
dt Re h2 h2
ψi+1,j − ψi−1,j ωi,j+1 − ωi,j−1 ψi,j+1 − ψi,j−1 ωi+1,j − ωi−1,j
     
−2ξ i
e − .
2h 2h 2h 2h

Collecting terms 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

Solutions to the Problems for Lecture 18

1. One straightforward implementation that uses two for loops is

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

Solutions to the Problems for Lecture 19

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.

Solutions to the Problems for Lecture 20

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

Solutions to the Problems for Lecture 21

1. Complete your solution in the Matlab Grader using the Learner Template:

function omega = flow_around_cylinder_unsteady


Re=60;
%%%%% define the grid %%%%%
n=101; m=202; % number of grid points
N=n-1; M=m-2; % number of grid intervals: 2 ghost points, theta=-h,2*pi
h=2*pi/M; % grid spacing based on theta variable
xi=(0:N)*h; theta=(-1:M)*h; % xi and theta variables on the grid
%%%%% time-stepping parameters %%%%%
t_start=0; t_end=0.5; % vortex street starts at around t=900
tspan=[t_start t_end];
%%%%% Initialize vorticity field %%%%%
omega=zeros(n,m);
%%%%% Construct the matrix A for psi equation %%%%%

%%%%% Find the LU decomposition %%%%%


[L,U]=lu(A); clear A;
%%%%% Compute any time-independent constants %%%%%

%%%%% advance solution using ode23 %%%%%


options=odeset('RelTol', 1.e-03);
omega=omega(2:n-1,2:m-1); % strip boundary values for ode23
omega=omega(:); % make a column vector
[t,omega]=ode23...
(@(t,omega)omega_eq(omega,L,U, (additional arguments),...
tspan, omega, options);
%%%%% expand omega to include boundaries %%%%%
temp=zeros(n,m);
temp(2:n-1,2:m-1)=reshape(omega(end,:),n-2,m-2);
omega=temp; clear temp;
%%%%% compute stream function (needed for omega boundary values) %%%%%

%%%%% set omega boundary conditions %%%%%

%%%%% plot scalar vorticity field %%%%%


plot_Re60(omega,t_end);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function d_omega_dt=omega_eq(omega,L,U,%additional arguments)
%%%%% expand omega to include boundary points %%%%%
temp=zeros(n,m);
index1=2:n-1; index2=2:m-1;
temp(index1,index2)=reshape(omega,n-2,m-2);
omega=temp; clear temp;
%%%%% compute stream function %%%%%

%%%%% compute derivatives of omega %%%%%

end
PROBLEM SOLUTIONS AND MATLAB LEARNER TEMPLATES 68

Here is a copy of the code plot_Re60.m.

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);

%construct interpolation points


xi_i=0.5*log(X.^2+Y.^2);
theta_i=wrapTo2Pi(atan2(Y,X));

omega_xy=interp2(XI,THETA,omega',xi_i,theta_i);

%inside circle
omega_xy(xi_i<0)=0;

%set colormap for contours


levels=linspace(-1,1,1000);
v=[levels(1) levels(end)];
cmap=jet(length(levels));
cmap=flipud(cmap);
colormap(cmap);

%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]);

%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

Solutions to the Problems for Lecture 22

1. Here is a copy of the graphics code.

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);

You might also like