Computational Fluid Dynamics

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

COMPUTATIONAL FLUID

DYNAMICS
THERMAL ENGINEERING

RAMESHKUMAR R
222TH015

DEPARTMENT OF MECHANICAL ENGINEERING (M.TECH)


NATIONAL INSTITUTE OF TECHNOLOGY, KARNATAKA
SURATHKAL, MANGALORE-575025
ASSIGNMENT: 9
LID DRIVEN CAVITY
Question:
By developing a code perform numerical simulations for a square lid driven
cavity for Re=100, 400 and 1000.

1) Perform validation for the three Re by comparing with the results of Ghia et
al. Present the validation in graphical (plot) form.

2) Plot velocity contours for the three cases.

3) Plot streamlines patterns for the three cases to capture the recirculation zones.

4) Plot steady state plot

5) Note down the CPU time, time required for steady state.
Matlab code:
clear all
clc

%inputs:
m=129;
n=m; %uniform grid size
dx=1/(m);
dy=1/(n);
r=dx/dy;
dt=1;
w=1.75;
x=((1:m)-1)*dx;
y=1-((1:n)-1)*dy;
%Reynold's Number:
for R=1:3
tic
if R==1
re=100
end
if R==2
re=400
end
if R==3
re=1000
end

%Array declaration:
uo=zeros(m+1,n+1);
un=zeros(m+1,n+1);
vo=zeros(m+1,n+1);
vn=zeros(m+1,n+1);
po=zeros(m+1,n+1);
pn=zeros(m+1,n+1);
u=zeros(m+2,n+2);
f=zeros(m+1,n+1);
g=zeros(m+1,n+1);

%Boundary Conditions:
%LEFT:
for j=2:n
uo(1,j)=0;
end
for j=2:n-1
vo(1,j)=-vo(2,j);
end

%RIGHT:
for j=2:m
uo(m,j)=0;
end
for j=2:n-1
vo(m+1,j)=-vo(m,j);
end

%BOTTOM:
for i=2:m-1
uo(i,1)=-uo(i,2);
end
for i=2:m
vo(i,1)=0;
end

%TOP:
for i=2:m-1
uo(i,n+1)=2-uo(i,n);
end
for i=2:m
vo(i,n)=0;
end

%TIME LOOP:
for t=0:dt:1000
%F(i,j) calculation:
for i=2:m-1
for j=2:n
ue=(uo(i,j)+uo(i+1,j))/2;
uw=(uo(i,j)+uo(i-1,j))/2;
un=(uo(i,j)+uo(i,j+1))/2;
us=(uo(i,j)+uo(i,j-1))/2;
vn=(vo(i,j)+vo(i+1,j))/2;
vs=(vo(i,j-1)+vo(i+1,j-1))/2;
dudx = (uo(i+1,j) - 2*uo(i,j) + uo(i-1,j))/dx^2;
dudy = (uo(i,j+1)- 2*uo(i,j) + uo(i,j-1))/dy^2;
f(i,j)= -((ue^2)-(uw^2))/dx - ((un*vn)-(us*vs))/dy +
((1/re)*(dudx+dudy));
end
end

%G(i,j) calculation:
for i=2:m
for j=2:n-1
ue=(uo(i,j)+uo(i,j+1))/2;
uw=(uo(i-1,j)+uo(i-1,j+1))/2;
ve=(vo(i,j)+vo(i+1,j))/2;
vw=(vo(i,j)+vo(i-1,j))/2;
vn=(vo(i,j)+vo(i,j+1))/2;
vs=(vo(i,j)+vo(i,j-1))/2;
dvdx = (vo(i+1,j) - 2*vo(i,j) + vo(i-1,j))/dx^2;
dvdy = (vo(i,j+1)- 2*vo(i,j) + vo(i,j-1))/dy^2;
g(i,j)= -((vn^2)-(vs^2))/dy - ((ue*ve)-(uw*vw))/dx +
((1/re)*(dvdx+dvdy));
end
end

%PRESSURE TERMS:
for itrp=0:10000
for i=2:m
for j=2:n
aw=1;
ae=1;
an=1;
as=1;
if i==2
aw=0;
end
if i==m
ae=0;
end
if j==2
as=0;
end
if j==n
an=0;
end
ap=-(aw+ae+an+as);
h(i,j)=(dx^2)*(((f(i,j)-f(i-1,j))/dx)+(g(i,j)-
g(i,j-1))/dy);
pn(i,j)=(w/ap)*(h(i,j)-(aw*pn(i-
1,j)+ae*pn(i+1,j)+as*pn(i,j-1)+an*pn(i,j+1)))+(1-w)*po(i,j);
end
end
err=max(max(abs(pn-po)));
po=pn;
if err<1e-6
break
end
end

%u_velocity:
for i=2:m-1
for j=2:n
un(i,j)=uo(i,j)+(dt*f(i,j))-((dt/dx).*(pn(i+1,j)-
pn(i,j)));
end
end
for i=2:m
for j=2:n-1
vn(i,j)=vo(i,j)+(dt*g(i,j))-((dt/dy).*(pn(i,j+1)-
pn(i,j)));
end
end
MAX_ERROR=1e-9;
U_e=max(max(abs(un-uo)));
V_e=max(max((abs(vn-vo))));
uo=un;
vo=vn;
if max(U_e,V_e)<1e-9
fprintf("TIME TAKEN TO COOL DOWN\n")
disp(t);
break
end
end
uu=rot90(un);
vv=rot90(vn);
pp=rot90(pn);

%AVERAGING:
for i=1:m
for j=1:m
u(i,j)=(uu(i,j)+uu(i,j+1)+uu(i+1,j)+uu(i+1,j+1))/4;
v(i,j)=(vv(i,j)+vv(i,j+1)+vv(i+1,j)+vv(i+1,j+1))/4;
p(i,j)=(pp(i,j)+pp(i,j+1)+pp(i+1,j)+pp(i+1,j+1))/4;
end
end

%plots:
%velocity contours:
figure
contourf(x,y,u,30);
colorbar;
title(' U VELOCITY CONTOUR FOR REYNOLDS NUMBER =
',re,13,'FontWeight','bold')
xlabel('X','FontSize',13,'FontWeight','bold')
ylabel('Y','FontSize',13,'FontWeight','bold')
figure
contourf(x,y,v,30);
colorbar
title(' U VELOCITY CONTOUR FOR REYNOLDS NUMBER =
',re,13,'FontWeight','bold')
xlabel('X','FontSize',13,'FontWeight','bold')
ylabel('Y','FontSize',13,'FontWeight','bold')

%Streamline:
figure
streamslice(x,y,u,v)
title(' STREAMLINES FOR REYNOLDS NUMBER =
',re,13,'FontWeight','bold')
xlabel('X','FontSize',13,'FontWeight','bold')
ylabel('Y','FontSize',13,'FontWeight','bold')

%Validation with Ghia Values


figure
u_g=u(:,((m+1)/2));
plot(u_g,y,'linewidth',1.2)
hold on
if Re==100
ughia100=[0 -0.03717 -0.04192 -0.04775 -0.06434 -0.10150 -
0.15662 -0.21090 -0.20581 -0.13641 0.00332 0.23151 0.68717 0.73722
0.78871 0.84123 1];
yghia100=[0 0.0547 0.0625 0.0703 0.1016 0.1719 0.2813 0.4531
0.5 0.6172 0.7344 0.8516 0.9531 0.9609 0.9688 0.9766 1];
plot(ughia100,yghia100,'*g');
end
if Re==400
ughia400=[0 -0.08186 -0.09266 -0.10338 -0.14612 -0.24299 -
0.32726 -0.17119 -0.11477 -0.02135 0.16256 0.29093 0.55892 0.61756
0.68439 0.75837 1];
yghia400=[0 0.0547 0.0625 0.0703 0.1016 0.1719 0.2813 0.4531
0.5 0.6172 0.7344 0.8516 0.9531 0.9609 0.9688 0.9766 1];
plot(ughia400,yghia400,'*b');
end
if Re==1000
ughia1000=[0 -0.18109 -0.20196 -0.22220 -0.29730 -0.38289 -
0.27805 -0.10648 -0.06080 -0.05702 0.18719 0.33304 0.466604 0.51117
0.57492 0.65928 0];
yghia1000=[0 0.0547 0.0625 0.0703 0.1016 0.1719 0.2813
0.4531 0.5 0.6172 0.7344 0.8516 0.9531 0.9609 0.9688 0.9766 1];
plot(ughia1000,yghia1000,'*r');
end
title('VALIDATION OF U VELOCITY WITH GHIA VALUES FOR REYNOLDS
NUMBER',re,13,'FontWeight','bold')
xlabel('U' ,'FontSize',13,'FontWeight','bold')
ylabel('Y','FontSize',13,'FontWeight','bold')
legend('NUMERICAL SOLUTION','GHIA VALUES')
hold off
figure
v_g=v(((n+1)/2),:);
plot(x,v_g,'linewidth',1.2);
hold on
if Re==100
vghia100=[0 0.09233 0.10091 0.10890 0.12317 0.16077 0.17507
0.17527 0.05454 -0.24533 -0.22445 -0.16914 -0.10313 -0.08864 -
0.07391 -0.05906 0];
xghia100=[0 0.0625 0.0703 0.0781 0.0938 0.1563 0.2266 0.2344
0.5 0.8047 0.8594 0.9063 0.9453 0.9531 0.9609 0.9688 1];
plot(xghia100,vghia100,'*g');
end
if Re==400
vghia400=[0 0.18360 0.19713 0.20920 0.22965 0.28124 0.30203
0.30174 0.05186 -0.38598 -0.44993 -0.23827 -0.22847 -0.19254 -
0.15663 -0.12146 0];
xghia400=[0 0.0625 0.0703 0.0781 0.0938 0.1563 0.2266 0.2344
0.5 0.8047 0.8594 0.9063 0.9453 0.9531 0.9609 0.9688 1];
plot(xghia400,vghia400,'*r');
end
if Re==1000
vghia1000=[0 0.27485 0.29012 0.30353 0.32627 0.37095 0.33075
0.32235 0.02526 -0.31966 -0.42665 -0.51550 -0.39188 -0.33714 -
0.27669 -0.21338 0];
xghia1000=[0 0.0625 0.0703 0.0781 0.0938 0.1563 0.2266
0.2344 0.5 0.8047 0.8594 0.9063 0.9453 0.9531 0.9609 0.9688 1];
plot(xghia1000,vghia1000,'*b');
end
title('VALIDATION OF V VELOCITY WITH GHIA VALUES FOR REYNOLDS
NUMBER',Re,13,'FontWeight','bold')
ylabel('V','FontSize',13,'FontWeight','bold')
xlabel('Y','FontSize',13,'FontWeight','bold')
legend('NUMERICAL SOLUTION','GHIA VALUES')
hold off
end

OUTPUT OF THE CODE:


REYNOLD'S NUMBER 100

TIME TAKEN TO COOL DOWN


20.6200

Elapsed time is 173.319278 seconds.

REYNOLD'S NUMBER 400

TIME TAKEN TO COOL DOWN


46.0340

Elapsed time is 287.316320 seconds.

REYNOLD'S NUMBER 1000

TIME TAKEN TO COOL DOWN


60.6260

Elapsed time is 370.833522 seconds.


Velocity Contours and Streamline plot of Different Reynolds number:

1. For Re=100:
2. For Re=400:
3. For Re=1000:
VALIDATION WITH GHIA et al. Values:
• Plots were obtained by plotting the benchmark values of Ghia et al. and
the mid values obtained from the numerical solving.

1. For Re=100:
Validation of U Velocity:
Validation of V velocity:

2. For Re=400;
Validation of U Velocity:
Validation of V velocity:

3. For Re=1000;
Validation of U velocity:
Validation of V velocity:

INFERENCE:
• The mid values of the two dimensional velocity matrix are obtained
and compared with the benchmark problem of Ghia et al.
• Most of the values in the scatter plot are aligned on the line obtained by
the plot of velocity of both u and v.
• By observing the velocity contours of Re=100, a primary vortex was
observed on the centre of the plot and two secondary vortices are found
which are very small when compared to the primary vortex.
• The secondary vortex have increased in size with the increase in the
Reynolds number.
• The streamline plot gives a clear view of the vortices growth and
expansion.
• The time taken to cooldown is tabulated.
REYNOLDS TIME TAKEN TO ITERATION TIME
NUMBER COOL DOWN (Seconds)
(seconds)

100 20.62 173.3192


400 46.034 287.316
1000 60.026 370.835

You might also like