Professional Documents
Culture Documents
Computational Fluid Dynamics
Computational Fluid Dynamics
Computational Fluid Dynamics
DYNAMICS
THERMAL ENGINEERING
RAMESHKUMAR R
222TH015
1) Perform validation for the three Re by comparing with the results of Ghia et
al. Present the validation in graphical (plot) form.
3) Plot streamlines patterns for the three cases to capture the recirculation zones.
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')
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)