fluid mechanics kundu cohen 6th edition solutions sm ch (6)

34
1 Chapter 6 Excercises Problem 1 Show, by Taylor expansion, that d 3 f dx 3 f j+2 - 2f j+1 +2f j-1 - f j-2 x 3 . What is order of this approximation? Solution Expand around x j : f j+1 = f j + ∂f ∂x Δx + 2 f ∂x 2 Δx 2 2 + 3 f ∂x 3 Δx 3 6 + 4 f ∂x 4 Δx 4 24 + Ox 5 ) (1) f j-1 = f j - ∂f ∂x Δx + 2 f ∂x 2 Δx 2 2 - 3 f ∂x 3 Δx 3 6 + 4 f ∂x 4 Δx 4 24 + Ox 5 ) (2) f j+2 = f j + ∂f ∂x x + 2 f ∂x 2 x 2 2 + 3 f ∂x 3 x 3 6 + 4 f ∂x 4 (2Δx) 4 24 + Ox 5 ) (3) f j-2 = f j - ∂f ∂x x + 2 f ∂x 2 x 2 2 - 3 f ∂x 3 x 3 6 + 4 f ∂x 4 (2Δx) 4 24 + Ox 5 ) (4) Subtract equation (2) from equation (1): f j+1 - f j-1 = ∂f ∂x x + 3 f ∂x 3 Δx 3 3 + Ox 5 ) (5) and equation (4) from equation (3) f j+2 - f j-2 = ∂f ∂x x + 3 f ∂x 3 x 3 3 + Ox 5 ). (6) Multiplying equation (5) by 2 and subtracting it from equation (6) yields f j+2 - 2f l+1 +2f j-1 - f j-2 = 3 f ∂x 3 x 3 3 + Ox 5 ), (7) which can be rearranged to give d 3 f dx 3 = f j+2 - 2f j+1 +2f j-1 - f j-2 x 3 + Ox 2 ). Thus, this is a second order approximation to the third derivative.

Upload: manoj-c

Post on 14-Apr-2017

2.506 views

Category:

Engineering


849 download

TRANSCRIPT

Page 1: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

1

Chapter 6 Excercises

Problem 1Show, by Taylor expansion, that

d3f

dx3≈ fj+2 − 2fj+1 + 2fj−1 − fj−2

2∆x3.

What is order of this approximation?

SolutionExpand around xj :

fj+1 = fj +∂f

∂x∆x+

∂2f

∂x2

∆x2

2+∂3f

∂x3

∆x3

6+∂4f

∂x4

∆x4

24+O(∆x5) (1)

fj−1 = fj −∂f

∂x∆x+

∂2f

∂x2

∆x2

2− ∂3f

∂x3

∆x3

6+∂4f

∂x4

∆x4

24+O(∆x5) (2)

fj+2 = fj +∂f

∂x2∆x+

∂2f

∂x2

4∆x2

2+∂3f

∂x3

8∆x3

6+∂4f

∂x4

(2∆x)4

24+O(∆x5) (3)

fj−2 = fj −∂f

∂x2∆x+

∂2f

∂x2

4∆x2

2− ∂3f

∂x3

8∆x3

6+∂4f

∂x4

(2∆x)4

24+O(∆x5) (4)

Subtract equation (2) from equation (1):

fj+1 − fj−1 =∂f

∂x2∆x+

∂3f

∂x3

∆x3

3+O(∆x5) (5)

and equation (4) from equation (3)

fj+2 − fj−2 =∂f

∂x4∆x+

∂3f

∂x3

8∆x3

3+O(∆x5). (6)

Multiplying equation (5) by 2 and subtracting it from equation (6) yields

fj+2 − 2fl+1 + 2fj−1 − fj−2 =∂3f

∂x3

6∆x3

3+O(∆x5), (7)

which can be rearranged to give

d3f

dx3=fj+2 − 2fj+1 + 2fj−1 − fj−2

2∆x3+O(∆x2).

Thus, this is a second order approximation to the third derivative.

Page 2: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

2

Problem 2Consider the following “backward in time” approximation for the diffusion equa-tion:

fn+1j = fnj +

∆tD

∆x2

(fn+1j+1 + fn+1

j−1 − 2fn+1j

)(a) Determine the accuracy of this scheme.(b) Find its stability properties by von Neumann’s method. How does it comparewith the forward in time, centered in space approximation considered earlier?

SolutionExpand around fn+1

j

fnj = fn+1j − ∂f

∂t∆t+

∂2f

∂t2∆t2

2+O(∆t3)

fn+1j+1 = fn+1

j +∂f

∂x∆x+

∂2f

∂x2

∆x2

2+∂3f

∂x3

∆x3

6+O(∆x4)

fn+1j−1 = fn+1

j − ∂f

∂x∆x+

∂2f

∂x2

∆x2

2− ∂3f

∂x3

∆x3

6+O(∆x4)

Substituting into:

fn+1j = fnj +

∆tD

∆x2

(fn+1j+1 + fn+1

j−1 − 2fn+1j

)and rearranging the terms gives:

∂f

∂t−D∂

2f

∂x2=∂2f

∂t2∆t

2+∂4f

∂t4D∆x2

12+O(∆t2,∆x4). (1)

The right hand side is the error, so the accuracy is O(∆t,∆x2).To find stability, write fnj = εneikxj and substitute into the equation given

in the problem statement, using that eik(xj±∆x) = eikxje±ik∆x. The result is

εn+1 = εn + (∆tD

∆x2)εn+1(eik∆x − 2 + e−ik∆x),

or

εn+1

εn=

1

1− (cos k∆x− 1)2(∆tD/∆x2)=

1

1 + 4(∆tD/∆x2) sin2 k∆x2

.

Thus, we always have ∣∣∣εn+1

εn

∣∣∣ ≤ 1,

and the scheme is unconditionally stable.

Page 3: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

3

Problem 3Approximate the linear advection equation

∂f

∂t+ U

∂f

∂x= 0 U > 0

by the backward in time method from problem 2. Use the standard secondorder centered difference approximation for the spatial derivative.(a) Write down the finite difference equation.(b) Write down the modified equation(c) Find the accuracy of the scheme(d) Use the von Neuman’s method to determine the stability of the scheme.

Solution(a) The scheme is:

fn+1j − fnj

∆t+ U

fn+1j−1 − f

n+1j−1

2∆x= 0

(b) First expand around fn+1j :

fnj = fn+1j − ∂f

∂t∆t+

∂2f

∂t2∆t2

2+O(∆t3)

Rearrange to get

fn+1j − fnj

∆t=∂f

∂t− ∂2f

∂t2∆t

2+O(∆t2)

Then expand

fn+1j+1 = fn+1

j +∂f

∂x∆x+

∂2f

∂x2

∆x2

2+∂3f

∂x3

∆x3

6+O(∆x4)

fn+1j−1 = fn+1

j − ∂f

∂x∆x+

∂2f

∂x2

∆x2

2− ∂3f

∂x3

∆x3

6+O(∆x4)

subtract and divide by 2∆x to get:

fn+1j+1 − f

n+1j−1

2∆x=∂f

∂x+∂3f

∂t3∆x2

6+O(∆x4)

The modified equation is therefore

∂f

∂t+ U

∂f

∂x=∂2f

∂t2∆t

2− U ∂

3f

∂x3

∆x2

6

(c) From the modified equation the error is O(∆t,∆x2)(d) Substituting fnj = εneikxj into the discrete equation and using that eik(xj±∆x) =

eikxje±ik∆x, we get

εn+1 − εn

∆t= εn+1 U

2∆x(eik∆x − e−ik∆x) ⇒ εn+1

εn− 1 +

εn+1

εni∆tU

∆xi sin k∆x = 0

⇒ εn+1

εn=

1

1 + i∆tU∆x i sin k∆x

Page 4: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

4

Thus, the method is unconditionally stable since∣∣∣ εn+1

εn

∣∣∣ ≤ 1.

Page 5: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

5

Problem 4Consider the following finite difference approximation to the diffusion equation:

fn+1j = fnj + 2

∆tD

∆x2

(fnj+1 − fn+1

j − fn−1j + fnj−1

).

This is the so-called Dufort-Frankel scheme, where the time integration is the”Leapfrog” method, and the spatial derivative is the usual center differenceapproximation, except that we have replaced fnj by (1/2)(fn+1

j +fn−1j ) . Derive

the modified equation and determine the accuracy of the scheme. Are there anysurprises?

SolutionWriting

fn+1j = fnj +

∂f

∂t∆t+

∂2f

∂t2∆t2

2+∂3f

∂t3∆t3

6+∂4f

∂t4∆t4

24+O(∆t5)

fn−1j = fnj −

∂f

∂t∆t+

∂2f

∂t2∆t2

2− ∂3f

∂t3∆t3

6+∂4f

∂t4∆t4

24+O(∆t5)

fnj+1 = fnj +∂f

∂x∆x+

∂2f

∂x2

∆x2

2+∂3f

∂x3

∆x3

6+∂4f

∂x4

∆x4

24+O(∆x5)

fnj−1 = fnj −∂f

∂x∆x+

∂2f

∂x2

∆x2

2− ∂3f

∂x3

∆x3

6+∂4f

∂x4

∆x4

24+O(∆x5)

and substituting into the finite difference equation gives

∂f

∂t−D∂

2f

∂x2=∂4f

∂t4D∆x2

12− ∂3f

∂t3∆t

6− ∂2f

∂t2D∆t2

∆x2+O(∆t3,∆x3)

The accuracy is O(∆t2,∆x2, ∆t2

∆x2 ). Notice the ∆t2

∆x2 term, which must go to zeroas ∆x → 0 and ∆t → 0 for the results to converge. This, the scheme is onlyconditionally consistent.

Page 6: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

6

Problem 5The following finite difference approximation is given

fn+1j =

1

2(fnj+1 + fnj−1)− ∆tU

2∆x

(fnj+1 − fnj−1

)(a) Write down the modified equation(b) What equation is being approximated?(c) Determine the accuracy of the scheme(d) Use the von Neuman’s method to examine under which conditions thisscheme is stable.

Solution(a) Start by expanding

fn+1j = fnj +

∂f

∂t∆t+

∂2f

∂t2∆t2

2+O(∆t3)

fnj+1 = fnj +∂f

∂x∆x+

∂2f

∂x2

∆x2

2+∂3f

∂x3

∆x3

6+O(∆x4)

fnj−1 = fnj −∂f

∂x∆x+

∂2f

∂x2

∆x2

2− ∂3f

∂x3

∆x3

6+O(∆x4)

Substitute to get

fnj +∂f

∂t∆t+

∂2f

∂t2∆t2

2=

1

2(2fnj +

∂2f

∂x2∆x2)− U∆t

2∆x

(∂f∂x

2∆x+∂3f

∂x3

∆x3

3

)Or:

∂f

∂t+ U

∂f

∂x= −∂

2f

∂t2∆t

2+∂2f

∂x2

∆x2

2∆t− ∂3f

∂x3

U∆x2

6

(b) The equation being approximated is

∂f

∂t+ U

∂f

∂x= 0

(c) The accuracy is O(∆t, ∆x2

∆t ,∆x2). If ∆x ∼ ∆t, then ∆x2/∆t ∼ ∆x and the

method is first order in time and space.(d) To determine the stability, we substitute fnj = εneikxj into the discrete

equation and use that eik(xj±∆x) = eikxje±ik∆x, giving:

εn+1 = εn1

2(eik∆x + e−ik∆x)− εnU∆t

2∆x(eik∆x − e−ik∆x).

Rearrangeεn+1

εn= cos k∆x− U∆t

hi sin k∆x.

Page 7: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

7

The absolute value is∣∣∣εn+1

εn

∣∣∣2 = cos2 k∆x+(U∆t

∆x

)2

sin2 k∆x.

So the scheme is stable ifU∆t

∆x≤ 1.

Page 8: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

8

Problem 6Consider the equation

∂f

∂t= g(f),

and the second-order predictor-corrector method:

f∗j = fnj + ∆tg(fn)

fn+1j = fnj +

∆t

2(g(fn) + g(f∗)).

Show that this method can also be written as:

f∗j = fnj + ∆tg(fn)

f∗∗j = f∗j + ∆tg(f∗)

fn+1j = (1/2)(fn + f∗∗).

That is, you simply take two explicit Euler steps and then average the solutionat the beginning of the time step and the end. This makes it particularly simpleto extend a first order explicit time integration scheme to second order.

SolutionThe first equations in each formulation are the same. To show that the secondtwo equations in the second formulation are the same as the final equation ofthe first formulation, substitute the second and first equation into the third one:

fn+1j =

1

2(fnj + f∗∗j )

fn+1j =

1

2(fnj + f∗j + ∆tg(f∗j ))

fn+1j =

1

2(fnj + fnj + ∆tg(fnj ) + ∆tg(f∗j )

fn+1j = fnj +

1

2(∆tg(fnj ) + ∆tg(f∗j ))

Page 9: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

9

Problem 7Modify the code used to solve the one-dimensional linear advection equation(Code 1) to solve the Burgers equation:

∂f

∂t+

∂x

(f2

2

)= D

∂2f

∂x2

using the same initial conditions. What happens? Refine the grid. How doesthe solution change if we add a constant (say 1) to the initial conditions?

SolutionThe modified code is:

% one-dimensional NONLINEAR advection-diffusion

% by the FTCS scheme

N=21; nstep=10; L=2.0; dt=0.05;D=0.05; k=1;

dx=L/(N-1); for j=1:N, x(j)=dx*(j-1);end

f=zeros(N,1); fo=zeros(N,1); time=0.0;

for j=1:N, f(j)=0.5*sin(2*pi*k*x(j)); end;

for m=1:nstep, m, time

plot(x,f,’linewidt’,2); axis([0 L -1.5, 1.5]); pause

fo=f;

for j=2:N-1

f(j)=fo(j)-(0.25*dt/dx)*((fo(j+1)+fo(j))^2-...

(fo(j)+fo(j-1))^2)+...

D*(dt/dx^2)*(fo(j+1)-2*fo(j)+fo(j-1));

end;

f(N)=fo(N)-(0.25*dt/dx)*((fo(2)+fo(N))^2-...

(fo(N)+fo(N-1))^2)+...

D*(dt/dx^2)*(fo(2)-2*fo(N)+fo(N-1));

f(1)=f(N);

time=time+dt;

end;

Page 10: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

10

0 0.5 1 1.5 2-1.5

-1

-0.5

0

0.5

1

1.5

Running the code for for three different resolutions N = 21, 41, 81 with dt =0.05, 0.025, 0.0125 up to time 0.25 (for 5, 10, 20) steps, produces the figure above.Even for the coarsest resolution, the solution is essentially fully converged, sowe have used thicker lines for the low resolution results, since otherwise thosewould not be visible.

For the second part of the problem, replace the initial conditions by

for j=1:N, f(j)=1.0+0.5*sin(2*pi*k*x(j)); end;

Taking dt=0.0125, gives a solution that travels to the right.

Page 11: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

11

Problem 8Modify the code used to solve the two-dimensional linear advection equation(Code 2) to simulate the advection of an initially square blob with f = 1 diag-onally across a square domain by setting u = v = 1. The dimension of the blobis 0.2× 0.2 and it is initially located near the origin. Refine the grid and showthat the solution converges by comparing the results before the blob flows outof the domain.

SolutionThe modified code is:

% Two-dimensional unsteady diffusion by the FTCS scheme

Nx=32;Ny=32;nstep=20;D=0.025;Lx=2.0;Ly=2.0;

dx=Lx/(Nx-1); dy=Ly/(Ny-1); dt=0.02;

f=zeros(Nx,Ny);fo=zeros(Nx,Ny);time=0.0;

for i=1:Nx,for j=1:Ny,x(i,j)=dx*(i-1);y(i,j)=dy*(j-1);end,end;

u=1.0; v=1.0; x0=0.2;y0=0.2;

for i=2:Nx-1, for j=2:Ny-1

if x(i,j)>x0-0.5*0.2 & x(i,j)<x0+0.5*0.2 &...

y(i,j)>y0-0.5*0.2 & y(i,j)<y0+0.5*0.2

f(i,j)=1.0;

end;end;end

for l=1:nstep,l,time

hold off;mesh(x,y,f); axis([0 Lx 0 Ly -0.5 1.5]);pause

fo=f;

for i=2:Nx-1, for j=2:Ny-1

f(i,j)=fo(i,j)-(0.5*dt*u/dx)*(fo(i+1,j)-fo(i-1,j))-...

(0.5*dt*v/dy)*(fo(i,j+1)-fo(i,j-1))+...

D*dt*( ((fo(i+1,j)-2*fo(i,j)+fo(i-1,j))/dx^2)...

+((fo(i,j+1)-2*fo(i,j)+fo(i,j-1))/dy^2) );

end,end

for i=1:Nx, f(i,1)=f(i,2);end;

for j=1:Ny,f(1,j)=f(2,j);f(Nx,j)=f(Nx-1,j);end;

time=time+dt;

end;

The code is best run interactively by advancing one step at a time andpressing a key to go to the next step. The figure shows the initial condition ona 32× 32 grid and the solution at time 0.5 on the 32× 32 grid and an 128× 128grid. As we run the code further, the solution quickly dampens out. Try loverD and finer grids.

Page 12: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

12

21.5

10.5

00

0.5

1

1.5

1.5

-0.5

0

0.5

1

2

The initial condition on a 32× 32 grid.

21.5

10.5

00

0.5

1

1.5

1.5

1

0.5

0

-0.52

21.5

10.5

00

0.5

1

1.5

1

-0.5

0

0.5

1.5

2

The solution at time 0.5 on the 32× 32 grid and an 128× 128 grid.

Page 13: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

13

Problem 9Derive a second order expression for the boundary vorticity by writing thestream function at j = 2 and j = 3 as a Taylor series expansion around the valueat the wall (j = 1). How does the expression compare with equation (6.67).

SolutionThe derivation is essentially the same as in the text. The stream function, onemesh block away, can be expressed using a Taylor series expansion around theboundary point:

ψi,2 = ψi,1 +∂ψi,1∂y

∆y +∂2ψi,1∂y2

∆y2

2+∂3ψi,1∂y3

∆y3

6+O(∆y4).

Similarly, two mesh blocks away, we have

ψi,3 = ψi,1 +∂ψi,1∂y

2∆y +∂2ψi,1∂y2

(2∆y)2

2+∂3ψi,1∂y3

(2∆y)3

6+O(∆y4).

Multiplying the first equation by 23 = 8, and subtracting it from the secondone, using that ∂ψi,1/∂y = Uwall and that ωwall = −∂2ψi,1/∂y

2 gives:

ψi,3 − 8ψi,2 = −7ψi,1 − 6∆yUwall + 2ωwall∆y2 +O(∆y4),

which can be solved for the wall vorticity

ωwall =

(7ψi,1 + ψi,3 − 8ψi,2

)1

2∆y2+ Uwall

3

∆y+O(∆y2).

This is similar to the first order condition (equation 6.67)

ωwall =

(ψi,1 − ψi,2

)2

∆y2+ Uwall

2

∆y+O(∆y)

but involves ψi,3 as well as ψi,2.

Page 14: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

14

Problem 10Modify the vorticity-stream function code used to simulate the two-dimensionaldriven cavity problem (Code 3) to simulate the flow in a rectangular 2 × 1channel with periodic boundaries. Set the value of the vorticity and the streamfunction at the top and bottom to zero. As initial conditions place two circularblobs with radius r = 0.25 and ω = 10 on the centerline of the channel at y = 0.5and x = 0.6 and x = 1.4. Refine the grid to ensure that the solution converges.Describe the evolution of the flow as the viscosity is decreased.

SolutionThe code, modified as specified in the problem is listed below. Notice thatthe viscosity here is 0.01 and that we accommodate the periodic boundaryconditions by extending the grid one grid line in the x-direction. Thus, thegrid spacing is given by h = 2.0/(Nx− 2), rather than h = 2.0/(Nx− 1). Here,the 2 is the length of the domain in the x-direction.

% Problem 10 Modified Vorticity-Stream Function Code

Nx=34; Ny=17; MaxStep=200; Visc=0.01; dt=0.005; time=0.0;

MaxIt=100; Beta=1.5; MaxErr=0.001; % parameters for SOR

sf=zeros(Nx,Ny); vt=zeros(Nx,Ny); vto=zeros(Nx,Ny);

x=zeros(Nx,Ny); y=zeros(Nx,Ny); h=2.0/(Nx-2);

for i=1:Nx,for j=1:Ny,x(i,j)=h*(i-1);y(i,j)=h*(j-1);end,end;

for i=1:Nx,for j=1:Ny,

if(sqrt((x(i,j)-0.6)^2+(y(i,j)-0.5)^2)<0.25); vt(i,j)=10;end;

if(sqrt((x(i,j)-1.4)^2+(y(i,j)-0.5)^2)<0.25); vt(i,j)=10;end;

end;end

for istep=1:MaxStep, % Time loop

for iter=1:MaxIt, % solve for the stream function

vto=sf; % by SOR iteration

for i=2:Nx-1; for j=2:Ny-1

sf(i,j)=0.25*Beta*(sf(i+1,j)+sf(i-1,j)...

+sf(i,j+1)+sf(i,j-1)+h*h*vt(i,j))+(1.0-Beta)*sf(i,j);

end; end;

sf(1,2:Ny-1)=sf(Nx-1,2:Ny-1); sf(Nx,2:Ny-1)=sf(2,2:Ny-1);

Err=0.0; for i=1:Nx; for j=1:Ny, % check error

Err=Err+abs(vto(i,j)-sf(i,j)); end; end;

if Err <= MaxErr, break, end % stop if converged

end;

vto=vt;

for i=2:Nx-1; for j=2:Ny-1

vt(i,j)=vt(i,j)+dt*(-0.25*((sf(i,j+1)-sf(i,j-1))*...

Page 15: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

15

(vto(i+1,j)-vto(i-1,j))-(sf(i+1,j)-sf(i-1,j))*...

(vto(i,j+1)-vto(i,j-1)))/(h*h)...

+Visc*(vto(i+1,j)+vto(i-1,j)+vto(i,j+1)+...

vto(i,j-1)-4.0*vto(i,j))/(h^2) );

end; end;

vt(1,2:Ny-1)=vt(Nx-1,2:Ny-1); vt(Nx,2:Ny-1)=vt(2,2:Ny-1);

time=time+dt

subplot(211),contour(x,y,vt,40),axis(’equal’);axis([0 2 0 1]);

subplot(212),contour(x,y,sf),axis(’equal’);axis([0 2 0 1]);

pause(0.01)

end;

0 0.5 1 1.5 20

0.2

0.4

0.6

0.8

1

0 0.5 1 1.5 20

0.2

0.4

0.6

0.8

1

The vorticity and the streamfunction at time 1 are plotted in the figure, showingthat the vorticity patches are in the process of merging. The grid here is verycoarse, for the viscosity used.

Page 16: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

16

Problem 11Derive the discrete pressure equation for a corner point. How does it comparewith the equation for an interior point, (6.91) and a point next to a straightboundary (6.96)?

SolutionStart with the continuity equation for the cell in the lower left corner. For thecontrol volume around the pressure node p(2, 2), it is

un+1i+1/2,j − Ub,j

∆x+vn+1i,j+1/2 − Vi,b

∆y= 0. (1)

Since the velocities for the left and the bottom boundary are known, we onlysubstitute the equations for the correction velocities for the two unknown veloc-ities, through the top and right edge. Thus, the pressure equation for the cellin the bottom left corner is:

pi+1,j − pi,j∆x2

+pi,j+1 − pi,j

∆y2

∆t

(u∗i+1/2,j − Ub,j∆x

+v∗i,j+1/2 − Vi,b

∆y

). (2)

Page 17: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

17

Problem 12Modify the velocity-pressure code used to simulate the two-dimensional drivencavity problem (Code 4) to simulate the mixing of a jet of fast fluid with slowerfluid. Change the size of the domain to 3 and specify an inflow velocity of 1 inthe middle third of the left boundary and an inflow velocity of 0.25 for the restof the boundary. For the right boundary specify a uniform outflow velocity of0.5. Keep other parameters the same. Refine the grid and check the convergenceof the solution.

SolutionThe main change is in the boundary conditions. On the left boundary wespecify the inflow by setting u(1, 2 : Ny + 1) to different values depending onwhether the grid point is in the jet or not. In general we would specify “gentle”outflow boundary conditions that allowed the flow to leave the domain as freelyas possible. Here, however, we take a simpler approach and specify the outflowvelocity, u(Nx + 1, 2 : Ny + 1) = 0.5. Notice that in this approach the totalinflow must be equal to the total outflow. For the tangent velocity, we take allwalls to be stationary and full-slip. We do not check weather the the pressurehas converged (as we really should do). This leads to a slight “sloshing” in thebeginning and we have increased the maximum iterations to 500 for the pressureto reduce this.

% Starting Jet by the MAC Method

Nx=3*33; Ny=33; Lx=3; Ly=1; MaxStep=500; Visc=0.01; rho=1.0;

MaxIt=500; Beta=1.5; MaxErr=0.001; % parameters for SOR

dx=Lx/Nx;dy=Ly/Ny; un=0;us=0;ve=0;vw=0;time=0.0; dt=0.02;

u=zeros(Nx+1,Ny+2);v=zeros(Nx+2,Ny+1);p=zeros(Nx+2,Ny+2);

ut=zeros(Nx+1,Ny+2);vt=zeros(Nx+2,Ny+1);c=zeros(Nx+2,Ny+2)+1;

c=zeros(Nx+1,Ny+2)+1/(2/dx^2+2/dy^2);

c(2,3:Ny)=1/(1/dx^2+2/dy^2); c(Nx+1,3:Ny)=1/(1/dx^2+2/dy^2);

c(3:Nx,2)=1/(1/dx^2+2/dy^2); c(3:Nx,Ny+1)=1/(1/dx^2+2/dy^2);

c(2,2)=1/(1/dx^2+1/dy^2); c(2,Ny+1)=1/(1/dx^2+1/dy^2);

c(Nx+1,2)=1/(1/dx^2+1/dy^2); c(Nx+1,Ny+1)=1/(1/dx^2+1/dy^2);

Ny1=12; Ny2=23;

u(1,2:Ny+1)=0.25; u(1,Ny1:Ny2)=1.0;

u(Nx+1,2:Ny+1)=0.5;

ut=u;

for is=1:MaxStep % Impose full-slip boundaries

u(1:Nx+1,1)=u(1:Nx+1,2);u(1:Nx+1,Ny+2)=u(1:Nx+1,Ny+1);

v(1,1:Ny+1)=v(2,1:Ny+1);v(Nx+2,1:Ny+1)=v(Nx+1,1:Ny+1);

for i=2:Nx,for j=2:Ny+1 % temporary u-velocity

Page 18: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

18

ut(i,j)=u(i,j)+dt*(-0.25*(...

( (u(i+1,j)+u(i,j))^2-(u(i,j)+u(i-1,j))^2 )/dx+...

( (u(i,j+1)+u(i,j))*(v(i+1,j)+v(i,j))-...

(u(i,j)+u(i,j-1))*(v(i+1,j-1)+v(i,j-1)) )/dy )+...

Visc*((u(i+1,j)+u(i-1,j)-2*u(i,j))/dx^2+...

(u(i,j+1)+u(i,j-1)-2*u(i,j))/dy^2));

end,end

for i=2:Nx+1,for j=2:Ny % temporary v-velocity

vt(i,j)=v(i,j)+dt*(-0.25*(...

( (u(i,j+1)+u(i,j))*(v(i+1,j)+v(i,j))-...

(u(i-1,j+1)+u(i-1,j))*(v(i,j)+v(i-1,j)) )/dx+...

( (v(i,j+1)+v(i,j))^2-(v(i,j)+v(i,j-1))^2 )/dy )+...

Visc*((v(i+1,j)+v(i-1,j)-2*v(i,j))/dx^2+...

(v(i,j+1)+v(i,j-1)-2*v(i,j))/dy^2));

end,end

for it=1:MaxIt % solve for pressure

for i=2:Nx+1,for j=2:Ny+1

p(i,j)=Beta*c(i,j)*...

( (p(i+1,j)+p(i-1,j))/dx^2+...

(p(i,j+1)+p(i,j-1))/dy^2 -...

(rho/dt)*( (ut(i,j)-ut(i-1,j))/dx+...

(vt(i,j)-vt(i,j-1))/dy ) )+...

(1-Beta)*p(i,j);

end,end

end

% correct the velocity

u(2:Nx,2:Ny+1)=...

ut(2:Nx,2:Ny+1)-...

(dt/dx)*(p(3:Nx+1,2:Ny+1)-p(2:Nx,2:Ny+1));

v(2:Nx+1,2:Ny)=...

vt(2:Nx+1,2:Ny)-...

(dt/dy)*(p(2:Nx+1,3:Ny+1)-p(2:Nx+1,2:Ny));

time=time+dt % plot the results

uu(1:Nx+1,1:Ny+1)=0.5*(u(1:Nx+1,2:Ny+2)+u(1:Nx+1,1:Ny+1));

vv(1:Nx+1,1:Ny+1)=0.5*(v(2:Nx+2,1:Ny+1)+v(1:Nx+1,1:Ny+1));

w(1:Nx+1,1:Ny+1)=(u(1:Nx+1,2:Ny+2)-u(1:Nx+1,1:Ny+1)-...

v(2:Nx+2,1:Ny+1)+v(1:Nx+1,1:Ny+1))/(2*dx);

hold off,quiver(flipud(rot90(uu)),flipud(rot90(vv)),’r’);

hold on;contour(flipud(rot90(w)),100),axis equal,

plot(20+10*uu(20,1:Ny+1),[1:Ny+1],’k’);

plot([20,20],[1,Ny],’k’);

Page 19: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

19

plot(60+10*uu(60,1:Ny+1),[1:Ny+1],’k’);

plot([60,60],[1,Ny],’k’); pause(0.01)

end

Notice that here we plot the velocity and the vorticity without finding thephysical location of the grid points and instead simply used that the grid isuniform. This does, however, require us to manipulate the field slightly, sincefor 2D plots, Matlab treats the first variable as the vertical one and the secondone as the horizontal one, instead of the other way around as we have assumed.To convert the data to the convention used here, we rotate the field and thenflip it. If we specify the location of the grid points, this is not needed, for 2Dflow. However, see problem 13 for the same issue with 3D plots.

10 20 30 40 50 60 70 80 90 100

5

10

15

20

25

30

The velocity and the vorticity field at nearly steady state. In addition to plottingthe velocity vectors and the vorticity, we plot the horizontal velocity along twovertical lines (at Nx = 20, and Nx = 60. The velocity is multiplied by 10).

Page 20: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

20

Problem 13Extend the velocity-pressure code used to simulate the two-dimensional drivencavity problem (Code 4) to three-dimensions. Assume that the third dimensionis unity (as the current dimensions) and take the velocity of the top wall andthe material properties to be the same. Compute the flow on a 93 and 173

grids and compare the results by plotting the velocities along lines through thecenter of the domain. How do the velocities in the center compare with thetwo-dimensional results?

SolutionThe extension of the code to three-dimensional flow is relatively straight forward.Everything just becomes longer. The biggest difference between 2D and 3D isthat plotting the results becomes more of a challenge. Here we solve the pressureequation using a fixed number of iterations so it may not be fully converged atthe early stages.

% Driven Cavity by the MAC Method---3D

Nx=16;Ny=16;Nz=16;Lx=1;Ly=1;Lz=1;MaxStep=50;visc=0.1;rho=1.0;

MaxIt=100; Beta=1.5; MaxErr=0.001; % parameters for SOR

dx=Lx/Nx;dy=Ly/Ny; dz=Lz/Nz; time=0.0; dt=0.002;

u=zeros(Nx+1,Ny+2,Nz+2); v=zeros(Nx+2,Ny+1,Nz+2);

w=zeros(Nx+2,Ny+2,Nz+1); p=zeros(Nx+2,Ny+2,Nz+2);

ut=zeros(Nx+1,Ny+2,Nz+2); vt=zeros(Nx+2,Ny+1,Nz+2);

wt=zeros(Nx+2,Ny+2,Nz+1);

c=zeros(Nx+2,Ny+2,Ny+2)+1/(2/dx^2+2/dy^2+2/dz^2);

c(2,3:Ny,3:Nz)=1/(1/dx^2+2/dy^2+2/dz^2);

c(Nx+1,3:Ny,3:Nz)=1/(1/dx^2+2/dy^2+2/dz^2);

c(3:Nx,2,3:Nz)=1/(2/dx^2+1/dy^2+2/dz^2);

c(3:Nx,Ny+1,3:Nz)=1/(2/dx^2+1/dy^2+2/dz^2);

c(3:Nx,3:Ny,2)=1/(2/dx^2+2/dy^2+1/dz^2);

c(3:Nx,3:Ny,Nz+1)=1/(2/dx^2+2/dy^2+1/dz^2);

c(2,2,2) =1/(1/dx^2+1/dy^2+1/dz^2);

c(Nx+1,2,2)=1/(1/dx^2+1/dy^2+1/dz^2);

c(2,Ny+1,2) =1/(1/dx^2+1/dy^2+1/dz^2);

c(Nx+1,Ny+1,2)=1/(1/dx^2+1/dy^2+1/dz^2);

c(2,2,Nz+1) =1/(1/dx^2+1/dy^2+1/dz^2);

c(Nx+1,2,Nz+1)=1/(1/dx^2+1/dy^2+1/dz^2);

c(2,Ny+1,Nz+1)=1/(1/dx^2+1/dy^2+1/dz^2);

c(Nx+1,Ny+1,Nz+1)=1/(1/dx^2+1/dy^2+1/dz^2);

for is=1:MaxStep

Page 21: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

21

u(1:Nx+1,1:Ny+1,1)=-u(1:Nx+1,1:Ny+1,2);

u(1:Nx+1,1:Nz+1,Nz+2)=-u(1:Nx+1,1:Nz+1,Nz+1);

v(1:Nx+1,1:Ny+1,1)=-v(1:Nx+1,1:Ny+1,2);

v(1:Nx+1,1:Nz+1,Nz+2)=-v(1:Nx+1,1:Nz+1,Nz+1);

u(1:Nx+1,1,1:Nz+1)=-u(1:Nx+1,2,1:Nz+1);

u(1:Nx+1,Ny+2,1:Nz+1)=2-u(1:Nx+1,Ny+1,1:Nz+1);

w(1:Nx+1,1,1:Nz+1)=-w(1:Nx+1,2,1:Nz+1);

w(1:Nx+1,Ny+2,1:Nz+1)=-w(1:Nx+1,Ny+1,1:Nz+1);

v(1,1:Ny+1,1:Nz+1)=-v(2,1:Ny+1,1:Nz+1);

v(Nx+2,1:Ny+1,1:Nz+1)=-v(Nx+1,1:Ny+1,1:Nz+1);

w(1,1:Ny+1,1:Nz+1)=-w(2,1:Ny+1,1:Nz+1);

w(Nx+2,1:Ny+1,1:Nz+1)=-w(Nx+1,1:Ny+1,1:Nz+1);

ut=u;vt=v;wt=w;

for i=2:Nx,for j=2:Ny+1,for k=2:Nz+1 % temp. u-velocity

ut(i,j,k)=u(i,j,k)+dt*(-0.25*(...

( (u(i+1,j,k)+u(i,j,k))^2-(u(i,j,k)+u(i-1,j,k))^2)/dx+...

( (u(i,j+1,k)+u(i,j,k))*(v(i+1,j,k)+v(i,j,k))-...

(u(i,j,k)+u(i,j-1,k))*(v(i+1,j-1,k)+v(i,j-1,k)))/dy +...

( (u(i,j,k+1)+u(i,j,k))*(w(i+1,j,k)+w(i,j,k))-...

(u(i,j,k)+u(i,j,k-1))*(w(i+1,j,k-1)+w(i,j,k-1)))/dz)+...

visc*((u(i+1,j,k)+u(i-1,j,k)-2*u(i,j,k))/dx^2+...

(u(i,j+1,k)+u(i,j-1,k)-2*u(i,j,k))/dy^2+...

(u(i,j,k+1)+u(i,j,k-1)-2*u(i,j,k))/dz^2) );

end,end,end

for i=2:Nx+1,for j=2:Ny,for k=2:Nz+1 % temp. v-velocity

vt(i,j,k)=v(i,j,k)+dt*(-0.25*(...

( (u(i,j+1,k)+u(i,j,k))*(v(i+1,j,k)+v(i,j,k))-...

(u(i-1,j+1,k)+u(i-1,j,k))*(v(i,j,k)+v(i-1,j,k)))/dx+...

( (v(i,j+1,k)+v(i,j,k))^2-(v(i,j,k)+v(i,j-1,k))^2)/dy+...

( (v(i,j,k+1)+v(i,j,k))*(w(i,j+1,k)+w(i,j,k))-...

(v(i,j,k)+v(i,j,k-1))*(w(i,j+1,k-1)+w(i,j,k-1)))/dz )+...

visc*((v(i+1,j,k)+v(i-1,j,k)-2*v(i,j,k))/dx^2+...

(v(i,j+1,k)+v(i,j-1,k)-2*v(i,j,k))/dy^2+...

(v(i,j,k+1)+v(i,j,k-1)-2*v(i,j,k))/dz^2) );

end,end,end

for i=2:Nx+1,for j=2:Ny+1,for k=2:Nz % temp. w-velocity

wt(i,j,k)=w(i,j,k)+dt*(-0.25*(...

( (w(i+1,j,k)+w(i,j,k))*(u(i,j,k+1)+u(i,j,k))-...

(w(i,j,k)+w(i-1,j,k))*(u(i-1,j,k+1)+u(i-1,j,k)) )/dx+...

Page 22: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

22

( (w(i,j+1,k)+w(i,j,k))*(v(i,j,k+1)+v(i,j,k))-...

(w(i,j,k)+w(i,j-1,k))*(v(i,j-1,k+1)+v(i,j-1,k)) )/dy+...

((w(i,j,k+1)+w(i,j,k))^2-(w(i,j,k)+w(i,j,k-1))^2 )/dz)+...

visc*((w(i+1,j,k)+w(i-1,j,k)-2*w(i,j,k))/dx^2+...

(w(i,j+1,k)+w(i,j-1,k)-2*w(i,j,k))/dy^2+...

(w(i,j,k+1)+w(i,j,k-1)-2*w(i,j,k))/dz^2) );

end,end,end

for it=1:MaxIt % solve for pressure

for i=2:Nx+1,for j=2:Ny+1, for k=2:Ny+1

p(i,j,k)=Beta*c(i,j,k)*...

( (p(i+1,j,k)+p(i-1,j,k))/dx^2+...

(p(i,j+1,k)+p(i,j-1,k))/dy^2+...

(p(i,j,k+1)+p(i,j,k-1))/dz^2 -...

(rho/dt)*( (ut(i,j,k)-ut(i-1,j,k))/dx+...

(vt(i,j,k)-vt(i,j-1,k))/dy+...

(wt(i,j,k)-wt(i,j,k-1))/dz) )+(1-Beta)*p(i,j,k);

end,end,end

end

% correct the velocity

u(2:Nx,2:Ny+1,2:Nz+1)=ut(2:Nx,2:Ny+1,2:Nz+1)-...

(dt/dx)*(p(3:Nx+1,2:Ny+1,2:Nz+1)-p(2:Nx,2:Ny+1,2:Nz+1));

v(2:Nx+1,2:Ny,2:Nz+1)=vt(2:Nx+1,2:Ny,2:Nz+1)-...

(dt/dy)*(p(2:Nx+1,3:Ny+1,2:Nz+1)-p(2:Nx+1,2:Ny,2:Nz+1));

w(2:Nx+1,2:Ny+1,2:Nz)= wt(2:Nx+1,2:Ny+1,2:Nz)-...

(dt/dz)*(p(2:Nx+1,2:Ny+1,3:Nz+1)-p(2:Nx+1,2:Ny+1,2:Nz));

time=time+dt % plot the results

Nzh=Nz/2;

uu(1:Nx+1,1:Ny+1)=0.5*(u(1:Nx+1,2:Ny+2,Nzh)+...

u(1:Nx+1,1:Ny+1,Nzh));

vv(1:Nx+1,1:Ny+1)=0.5*(v(2:Nx+2,1:Ny+1,Nzh)+...

v(1:Nx+1,1:Ny+1,Nzh));

p2d(1:Nx+1,1:Ny+1)= p(2:Nx+2,2:Ny+2,Nzh);

hold off,quiver(flipud(rot90(uu)),flipud(rot90(vv)),’r’);

hold on;contour(flipud(rot90(p2d)),20),axis equal;

axis([1 Nx 1 Ny]); pause(0.01)

end

% ---------- Plot the final results ---------------------

[X,Y,Z]=ndgrid(0.5*dx:dx:1-0.5*dx, 0.5*dy:dy:1-0.5*dy,...

0.5*dz:dz:1-0.5*dz);

quiver3(X,Y,Z,u3(2:Nx+1,2:Ny+1,2:Nz+1),...

v3(2:Nx+1,2:Ny+1,2:Nz+1),w3(2:Nx+1,2:Ny+1,2:Nz+1))

Page 23: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

23

hold on; [X,Y,Z]=meshgrid(0.5*dx:dx:1-0.5*dx,...

0.5*dy:dy:1-0.5*dy, 0.5*dz:dz:1-0.5*dz);

slice(X,Y,Z,flipud(rot90(p(2:Nx+1,2:Ny+1,2:Nz+1))),...

0.5, 0.5,[0.25 0.75])

xlabel(’x’); ylabel(’y’); zlabel(’z’); axis([0 1 0 1 0 1])

We show three figures for the results. The first one shows the velocity and thevorticity in a plane cutting through the middle of the domain for a 173 grid.When the code is run, this figure is plotted at every step and shows how theflow evolves. The second shows a 3D view of the velocity and the pressurein slices through the domain. Notice that we have used different functions toprovide the location of the grid points, for the different plotting functions andwe needed to flip and rotated the pressure field. In general it would be betterto use more advanced plotting to examine the results, particularly if the flowwas more complicated.

2 4 6 8 10 12 14 16

2

4

6

8

10

12

14

16

The velocity and the vorticity in a plane cutting through the middle of thedomain.

Page 24: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

24

10.8

0.60.4

x0.2

000.2

y

0.40.6

0.8

0.8

0

0.2

0.4

1

0.6

1

z

The velocity plotted using the Matlab function quiver3 and the pressure invarious planes cutting though the domain, using the Matlab function slice.

-0.2 0 0.2 0.4 0.6 0.8 1 1.20

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

The velocity plotted along the centerline of the cavity for two different resolu-tions

Page 25: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

25

Problem 14Derive equation (6.121),

gyfx − gxfy =1

J(gηfξ − gξfη).

SolutionUse that

fx =1

J(fξyη − fηyξ); and fy =

1

J(fηxξ − fξxη),

where J = xξyη − xηyξ, and substitute into the left hand side:

gyfx − gxfy =1

J2

((fξyη − fηyξ)(gηxξ − gξxη)

)−(

(fηxξ − fξxη)(gξyη − gηyξ))

=1

J2

(fξgηyηxξ−fξgξyηxη−fηgηyξxξ+fηgξyξxη−fξgηyηxξ+fξgξyηxη−fηgηyξxξ−fξgηyξxη

)=

1

J2

(fξgη(yηxξ − yξxη) + fηgξ(yξxη − yηxξ)

)=

1

J2(yηxξ − yξxη)

(fξgη − fηgξ

)=

1

J

(fξgη − fηgξ)

)

Page 26: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

26

Problem 15Show that the equations for the first derivatives in the mapped coordinates(equations 6.111) can be written in the so-called conservative form:

fx =1

J((fyη)ξ − (fyξ)η) and fy =

1

J((fxξ)η − (fxη)ξ)

Solution

fx =1

J(fξyη− fηyξ) =

1

J

((fyη)ξ− fyηξ− (fyξ)η + fyξη

)=

1

J((fyη)ξ− (fyξ)η)

fy =1

J(fηxξ−fξxη) =

1

J

((fxξ)η−fxξη−(fxη)ξ+fxηξ

)=

1

J((fxξ)η−(fxη)ξ)

Since yηξ = yξη and xξη = xηξ.

Page 27: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

27

Problem 16Derive equation (6.120),

∇2ξ =1

J3

(q1(xηyξξ − yηxξξ)− 2q2(xηyξη − yηxξη) + q3(xηyηη − yηxηη)

).

Take f = ξ and use that ξη = 0 and so on.

SolutionThe equation listed is actually (6.119) and we will derive that one. The deriva-tion of (6.120) is similar. We start with

fx =1

J((fyη)ξ − (fyξ)η) where J = xξyη − xηyξ.

If f = ξ then

ξx =1

J((ξyη)ξ − (ξyξ)η) =

yηJ,

since ξη = 0 and ξξ = 1. Hence

ξxx =(ξx)x

=1

J

[(yηJ

)ξyη −

(yηJ

)ηyξ

].

Similarly

ξyy =(ξy)y

=1

J

[(−xηJ

)ηxξ −

(−xηJ

)ξxη

].

Adding them together

∇2ξ = ξxx + ξyy =1

J

[(yηJ

)ξyη −

(yηJ

)ηyξ

]+

1

J

[(−xηJ

)ηxξ +

(xηJ

)ξxη

].

Expanding the terms

∇2ξ =1

J

[(yηJ

)ξyη −

(yηJ

)ηyξ −

(xηJ

)ηxξ +

(xηJ

)ξxη

]=

1

J

[yηξJyη −

y2η

J2Jξ −

yηηJyξ +

yηyξJ2

Jη −xηηJxξ +

xηxξJ2

Jη +xηξJxη −

x2η

J2Jξ

]=

1

J3

[Jyηξyη − y2

ηJξ − Jyηηyξ + yηyξJη − Jxηηxξ + xηxξJη + Jxηξxη − x2ηJξ

]=

1

J3

[(yηξyη − yηηyξ − xηηxξ + xηξxη)J − (y2

η + x2η)Jξ + (yηyξ + xηxξ)Jη

]

Page 28: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

28

Now use that J = xξyη − xηyξ to get

Jξ = xξξyη + xξyηξ − xηξyξ − xηyξξJη = xξηyη + xξyηη − xηηyξ − xηyξη

Then

∇2ξ =

1

J3

[xξyη(yηξyη − yηηyξ − xηηxξ + xηξxη)− xηyξ(yηξyη − yηηyξ − xηηxξ + xηξxη)

−(x2η + y2

η)(xξξyη + xξyηξ − xηξyξ − xηyξξ) +

(xξxη + yξyη)(xξηyη + xξyηη − xηηyξ − xηyξη)

]=

1

J3

[xξy

2ηyηξ − xξyηyξyηη − x2

ξyηxηη + xξyηxηxηξ

−xηyξyηyηξ + xηy2ξyηη + xηyξxξxηη − x2

ηyξxηξ

−x2ηyηxξξ − x2

ηxξyηξ + x2ηyξxηξ + x2

ηxηyξξ

−y2ηyηxξξ − y2

ηxξyηξ + y2ηyξxηξ + y2

ηxηyξξ +

xξxηyηxξη + x2ξxηyηη − xξxηyξxηη − xξx2

ηyξη +

yξy2ηxξη + yξyηxξyηη − y2

ξyηxηη − yξyηxηyξη

].

The red terms cancel and grouping the surviving terms we have:

∇2ξ =1

J3

[(x2η + y2

η)(xηyξξ − yηxξξ)

−2(xξxη + yξyη)(xηyηξ − yηxηξ) + (x2ξ + y2

ξ )(xηyηη − yηxηη)

]

=1

J3

[q1(xηyξξ − yηxξξ)− 2q2(xηyηξ − yηxηξ) + q3(xηyηη − yηxηη)

].

where

q1 = x2η + y2

η, q2 = xξxη + yξyη, q3 = x2ξ + y2

ξ

Page 29: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

29

Problem 17Derive numerical approximations for the velocity-pressure equations for a map-ping where the grid lines are straight and orthogonal, but unevenly spaced.That is, x = x(ξ) and y = y(η) only. Assume that ∆ξ = ∆η = 1. How do theseequations compare with (6.85), (6.88), (6.89), (6.90), and (6.91)?

SolutionThe various relationships simplify to q1 = y2

η; q2 = 0; q3 = x2ξ ; and J = xξyη.

The velocities are therefore

u =1

J

(Uxξ

)=

1

xξyη

(Uxξ

)=U

v =1

J

(V yη

)=

1

xξyη

(V yη

)=V

xξ.

The continuity equation is

∂U

∂ξ+∂V

∂η= 0 ⇒ yη

∂u

∂ξ+ xξ

∂v

∂η= 0 ⇒ 1

∂u

∂ξ+

1

∂v

∂η= 0.

Using that ∆ξ = ∆η = 1 we approximate the derivative between the grid pointsas

yη ≈yj+1 − yj

1= ∆yj+1/2 and xξ ≈

xi+1 − xi1

= ∆xi+1/2.

Defining ∆yj = 12 (∆yj+1/2 + ∆yj−1/2) and ∆xi = 1

2 (∆xi+1/2 + ∆xi−1/2), thecontinuity equation becomes

ui+1/2 + ui−1/2

∆xi+vj+1/2 + vj−1/2

∆yj= 0.

Similarly, the u-momentum equation becomes

∂u

∂t+

1

∂u2

∂ξ+

1

∂vu

∂η= − 1

∂p

∂ξ+ ν[ 1

∂ξ

(uξxξ

)+

1

∂η

(uηyη

)].

The discrete version is

un+1i+1/2,j − u

ni+1/2,j

∆t+

(u2)ni+1,j − (u2)ni,j∆xi+1/2

+(uv)ni+1/2,j+1/2 − (uv)ni+1/2,j−1/2

∆yj=

−pi+1,j − pi,j∆xi+1/2

+ ν[ 1

∆xi+1/2

(uni+3/2,j − uni+1/2,j

∆xi+1−uni+1/2,j − u

ni−1/2,j

∆xi+1

)+

1

∆yj

(uni+1/2,j+1 − uni+1/2,j

∆yj+1/2−uni+1/2,j − u

ni+1/2,j−1

∆yj−1/2

)].

Similarly, the v-momentum equation is

∂v

∂t+

1

∂uv

∂ξ+

1

∂v2

∂η= − 1

∂p

∂η+ ν[ 1

∂ξ

( vξxξ

)+

1

∂η

(vηyη

)].

Page 30: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

30

The discrete version is

vn+1i,j+1/2 − v

ni,j+1/2

∆t+

(uv)ni+1,j+1/2 − (uv)ni,j+1/2

∆xi+1/2+

(v2)ni,j+1 − (v2)ni,j∆yj

=

−pi,j+1 − pi,j∆yj+1/2

+ ν[ 1

∆xi

(vni+1,j+1/2 − vni,j+1/2

∆xi+1/2−vni,j+1/2 − v

ni−1,j+1/2

∆xi−1/2

)+

1

∆yj+1/2

(vni,j+3/2 − vni,j+1/2

∆yj+1−vni,j+1/2 − v

ni,j−1/2

∆yj

)].

The velocities in the advection terms are found by averaging as for the regulargrid. This equation can be solved by the same projection method described inthe book for uniform grids and solved in the same way.

The main observation is that these equations look just like those for theregular grid, except we divide by the local ∆x and ∆y. Notice that generallywe specify either ∆xi or ∆xi+1/2 and then find the intermediate points byaveraging. Same for ∆yj and ∆yj+1/2.

Page 31: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

31

Problem 18When the velocity is high and diffusion is small, the linear advection-diffusionequation can exhibit boundary layer behavior. Assume that you want to solve(6.11) in a domain given by 0 ≤ x ≤ 1, that U > 0, and that the boundaryconditions are f(0) = 0 and f(1) = 1. The velocity U is high and the diffusionD is small so we expect a boundary layer near x = 1.(a) Sketch the solution for high U and low D.(b) Propose a mapping function that will cluster the grid points near the x=1boundary.(c) Write the equation in the mapped coordinates.

Solution(a) This is the problem studied in section 6.2.6 and shown in figure 6.9. Herewe assume that we are solving the unsteady problem but at steady state thesolution looks like:

0 0.5 1 1.5 20

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

(b): A function like ξ = x2 will cluster the points near the x = 1 part of thedomain.

(c) Start with the advection-diffusion equation

∂f

∂t+ U

∂f

∂x= D

∂2f

∂x2.

The derivatives transform as∂f

∂x=

1

∂f

∂ξ

and

∂2f

∂x2=

∂x

(∂f

∂x

)=

1

∂ξ

(1

∂f

∂ξ

).

Substituting into the advection-diffusion equation gives us:

∂f

∂t+ U

1

∂f

∂ξ= D

1

∂ξ

( 1

∂f

∂ξ

)

Page 32: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

32

In an actual implementation we usually take ∆ξ = 1 so (xξ)j ≈ ∆xj . Thus, thediscrete equation is:

fn+1j − fnj

∆t+ U

fnj+1 − fnj−1

2∆xj= D

1

∆xj

(fnj+1 − fnj∆xj+1/2

−fnj − fnj−1

∆xj−1/2

)

where xj+1/2 = 0.5(xj +xj+1) and so on, and we have assumed a forward Eulertime discretization.

Page 33: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

33

Problem 19Derive equation (6.141).

SolutionStart with equation (6.140) and insert (6.133) and (6.134):

F̂n

j+1/2 = F+(fnj ) + F−(fnj+1) =

max(unj , 0)

ρρuρe

nj

+

0p+

(pu)+

nj

+ min(unj+1, 0)

ρρuρe

nj+1

+

0p−

(pu)−

nj+1

.

Then use that max(u, 0) = 0.5(u+|u|) and min(u, 0) = 0.5(u−|u|) and equations(6.135) and (6.134) to get

F̂nj+1/2 =1

2(unj + |unj |)

ρρuρe

nj

+

012pnj (1 +Mn

j )12pnj (unj + cnj )

nj

+

1

2(unj+1 − |unj+1|)

ρρuρe

nj+1

+

012pnj+1(1−Mn

j+1)pnj (unj+1 − cnj+1)

nj+1

.

Rearranging yields

F̂nj+1/2 =1

2

( ρuρu2 + pρeu+ pu

nj

+

ρuρu2 + pρeu+ pu

nj+1

)

−1

2

(|unj+1|

ρnj+1

ρnj+1unj+1

ρnj+1enj+1

− |unj | ρnjρnj u

nj

ρnj enj

)− 1

2

( 0pnj+1M

nj+1

pnj+1cnj+1

− 0pnjM

nj

pnj cnj

),or

F̂nj+1/2 =1

2

(F(fnj+1) + F(fnj )

)− 1

2

(|unj+1|

ρnj+1

ρnj+1unj+1

ρnj+1enj+1

− |unj | ρnjρnj u

nj

ρnj enj

)

−1

2

( 0pnj+1M

nj+1

pnj+1cnj+1

− 0pnjM

nj

pnj cnj

)

Page 34: Fluid Mechanics Kundu Cohen 6th edition solutions Sm ch (6)

34

Problem 20Propose a numerical scheme to solve for the unsteady flow over a rectangularcube in an unbounded domain. The Reynolds number is relatively low, 500-1000. Identify the key issues that must be addressed and propose a solution.Limit your discussion to one page and do NOT write down the detailed nu-merical approximations, but state clearly what kind of spatial and temporaldiscretization you would use.

SolutionThe key issues and how those control the design of the numerical scheme arelisted below:

• Since the Reynolds number is relatively low, it is safe to assume that theflow is laminar so no turbulence model is needed.

• Since we are dealing with a cube, we can use rectangular structured gridwhere the cube boundaries are aligned with grid lines and impose bound-ary conditions at the cube surface in the same way we do at a solid exteriorwall. Alternatively, we could use immersed boundaries.

• The simplest way to deal with the unbounded domain is to use stretchedgrid, extend it very far from the cube to make the domain very large, andprescribe inflow at the front, full slip at the side boundaries and outflowin the back. Since the flow is three dimensional, the effect of the cube isgoing to be weak far away, except in the wake behind the cube.

• Since the flow is unsteady, we can use the explicit projection methoddescribed in the text.