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

5/16/21 9:02 PM G:\ASHIM\Mtech Class\2...\CFD_Assignment.

m 1 of 5

% CFD Lab Assignment


% Name : Ashim Jyoti Nath
% Scholar No : 2026406
% Subject code : ME 5407
clear all
clc

% Given

L=1; % Domain length (m)


R=1; % Density (Kg/m^3)
V=0.1; % Diffusion Coefficient (Kg/m.s)
% for case 1, case 2, case 3 velocities are U1, U2 & U3 respectively
% Given
U1=0.1; % (m/s)
U2=2.5; % (m/s)
U3=2.5; % (m/s)
T0=1;
TL=0;
F1=(R*U1); % mass flux 1
F2=(R*U2); % mass flux 2
F3=(R*U3); % mass flux 3

% Grid Generation for case 1 and case 2 :

n=5;
dx=L/n;
D= V/dx;
x(1)=dx/2;
for i=2:n
x(i)=x(i-1)+dx;
end
xF=[0,x,1];

% Calculation Of Coefficients aW,aE,aP,sU,sP for all three cases


% Case 1

for i=1:n
if i==1
aE1(i)=(D-(F1/2));
aW1(i)=0;
sU1(i)=(F1+(2*D))*T0;
sP1(i)= -((2*D)+F1);
elseif i==n
aE1(i)=0;
aW1(i)=(D+(F1/2));
sU1(i)=((2*D)-F1)*TL;
sP1(i)=(F1-(2*D));
else
aE1(i)=(D-(F1/2));
aW1(i)=(D+(F1/2));
5/16/21 9:02 PM G:\ASHIM\Mtech Class\2...\CFD_Assignment.m 2 of 5

sU1(i)=0;
sP1(i)=0;
end
aP1(i)=aW1(i)+aE1(i)-sP1(i);
end

% Calling subroutine For TDMA calculation :

[T1]= TDMA_1(aE1,aW1,aP1,sU1,n)
T1F=[T0,T1,TL]

% Case 2

for i=1:n
if i==1
aE2(i)=(D-(F2/2));
aW2(i)=0;
sU2(i)=(F2+(2*D))*T0;
sP2(i)= -((2*D)+F2);
elseif i==n
aE2(i)=0;
aW2(i)=(D+(F2/2));
sU2(i)=((2*D)-F2)*TL;
sP2(i)=(F2-(2*D));
else
aE2(i)=(D-(F2/2));
aW2(i)=(D+(F2/2));
sU2(i)=0;
sP2(i)=0;
end
aP2(i)=aW2(i)+aE2(i)-sP2(i);
end

% Calling subroutine For TDMA calculation :

[T2]= TDMA_2(aE2,aW2,aP2,sU2,n)
T2F=[T0,T2,TL]

% Case 3
% Generation of grid for third case using FVM :

nn=19;
dx2=L/nn;
D= V/dx2;
X(1)=dx2/2;
for i=2:nn
X(i)=X(i-1)+dx2;
end
XF=[0,X,1];

for i=1:nn
5/16/21 9:02 PM G:\ASHIM\Mtech Class\2...\CFD_Assignment.m 3 of 5

if i==1
aE3(i)=(D-(F3/2));
aW3(i)=0;
sU3(i)=(F3+(2*D))*T0;
sP3(i)= -((2*D)+F3);
elseif i==nn
aE3(i)=0;
aW3(i)=(D+(F3/2));
sU3(i)=((2*D)-F3)*TL;
sP3(i)=(F3-(2*D));
else
aE3(i)=(D-(F3/2));
aW3(i)=(D+(F3/2));
sU3(i)=0;
sP3(i)=0;
end
aP3(i)=aW3(i)+aE3(i)-sP3(i);
end

% Calling subroutine For TDMA calculation :

[T3]= TDMA_3(aE3,aW3,aP3,sU3,nn)
T3F=[T0,T3,TL]

% Comparision of results with given expression

% Case 1

for i=1:n
T1P(i)=T0+((TL-T0)*((exp((R*U1*x(i))/V)-1)/(exp((R*U1*L)/V)-1)))
end
T1PF=[T0,T1P,TL]

% Case 2

for i=1:n
T2P(i)=T0+((TL-T0)*((exp((R*U2*x(i))/V)-1)/(exp((R*U2*L)/V)-1)))
end
T2PF=[T0,T1P,TL]

% Case 3

for i=1:nn
T3P(i)=T0+((TL-T0)*((exp((R*U3*X(i))/V)-1)/(exp((R*U3*L)/V)-1)))
end
T3PF=[T0,T3P,TL]

% PLots

% Case 1
5/16/21 9:02 PM G:\ASHIM\Mtech Class\2...\CFD_Assignment.m 4 of 5

figure(1)
plot(xF,T1F,'-r','linewidth',3)
hold on
plot(xF,T1PF,'-k','linewidth',3)
hold off
ylabel('T')
xlabel('X')
legend('ANALYTICAL SOLUTION 1','NUMARICAL SOLUTION 1')
title('Comparision Of Results For Case 1')
figure(1)

% Case 2

figure(2)
plot(xF,T2PF,'.-b','linewidth',3)
hold on
plot(xF,T2F,'.-m','linewidth',3)
hold off
ylabel('T')
xlabel('X')
legend('ANALYTICAL SOLUTION 2','NUMARICAL SOLUTION 2')
title('Comparision Of Results For Case 2')

% case 3

figure(3)
plot(XF,T3PF,'-g','linewidth',3)
hold on
plot(XF,T3F,'-r','linewidth',3)
hold off
ylabel('T')
xlabel('X')
legend('ANALYTICAL SOLUTION 3','NUMARICAL SOLUTION 3')
title('Comparision Of Results Case 3')

% Error calculation

% Case 1

[E1]=T1PF-T1F; % difference between numerical results and analytical results


[PE1]=(E1./T1PF).*100; % Percentage Error
[PE1F]=PE1'

% Case 2

[E2]=T2PF-T2F;% difference between numerical results and analytical results


[PE2]=(E2./T2PF).*100;%Percentage Error
[PE2F]=PE2'

% Case 3
5/16/21 9:02 PM G:\ASHIM\Mtech Class\2...\CFD_Assignment.m 5 of 5

[E3]=T3PF-T3F;% difference between numerical results and analytical results


[PE3]=(E3./T3PF).*100;%Percentage Error
[PE3F]=PE3'

% Error plots :

figure(4)
plot(xF,PE1,'-b','linewidth',2)
hold on
plot(xF,PE2,'-y','linewidth',3)
hold on
plot(XF,PE3,'-k','linewidth',1)
hold off
title('Error Plot')
ylabel('Percentage Error')
xlabel('Value of X(i)')
legend('Case 1','Case 2','Case 3')

You might also like