You are on page 1of 6

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Written in MATLAB R2015b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MECH 4805
% Group 2
% Term Paper 1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear
colorVec = hsv(12);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%States:
% Select the desired geometry
% 0 for rectangular fin constant x section
% 1 for triangular fin
% 2 for Ben's custom fin
% 3 for GROUP 2's custom fin
% 4 for GROUP 2's custom fin (Improved)

Xsection = 1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Variables
convergenceCriteria = 0.1; %convergence criteria in percent
k = 237;   %thermal conductivity W/mK
L = 0.03;  %Length m (height)
t = 0.002; %t­i­ckness m
W = 0.1; %depth into page m
Tamb = 20; %degC
Tbase = 80; %degC
h = 100; %range of convection coefficients
n = 5; %number of nodes
x=1;
xtest = 2;
j=2;
tTip = 0.0001;

%%%Graph variables
xLower  =100;
yLower  =100;
xWidth  =1000;
yHeight =700;

%percent difference variables
percentdiff(1:5,1)=2;
percentdiff(1:5,2)=1;
MaxPdiff = max(percentdiff(:,2));

while (MaxPdiff > convergenceCriteria)

dx = L/n; %distance between nodes

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (Xsection == 0)
% Rectangular constant crossection
thicknessBase(1:n+1,1) = t;
%P(1:n,1) = 2*W + 2*t(1,1);  % Perimeter m
A(1:n,1) = t*W;  % Cross­sectional area m^s

As(1:n,1)=2*thicknessBase(1:n,1)*dx+2*W*dx;
Atip = thicknessBase(n+1,1)*W;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif (Xsection == 1)
%Triangular fin no constant crossection

theta = atan(0.5*t/L);
thicknessBase(1,1) = t;

for(i=1:1:n)
thicknessBase(i+1,1) = 2*((L­(i*dx))*tan(theta));
end

A = thicknessBase*W;            % Cross­sectional area m^s   t as a function
of
Atip = thicknessBase(n+1,1)*W;

for i=1:n
%Surface Area of full fin = Triangle sides + rectangle top/bottom =
2*(B*H)/2 + 2*hyp*W
%Area dx section = full fin ­ fin @ (L­i*dx)
As(i,1) = ((thicknessBase(i,1)*(L­(i­1)*dx))
+2*(0.5*thicknessBase(i,1)/sin(theta))*W)­...
((thicknessBase(i+1,1)*(L­i*dx))
+2*(0.5*thicknessBase(i+1,1)/sin(theta))*W);

end

elseif (Xsection == 2)
%Hyberbolic plate fin geometry
for(i=1:1:n)
thicknessBase(i,1) = 2*(cosh(0.09483*(1­(dx*(i­1))/L))­(1­tTip/2));
end

A = thicknessBase*W;            % Cross­sectional area m^s   t as a
function of
Atip = tTip*W;
thicknessBase(n+1,1) = tTip;
for i=1:n
trem = 0.5*(thicknessBase(i,1) ­ thicknessBase(i+1));
hyp = dx/(cos(atan(trem/dx)));
As(i,1) = 2*hyp*W + (thicknessBase(i+1,1)+thicknessBase(i,1))*dx;

end

elseif (Xsection == 3)
%Group 2 Custom Plate fin geometry
for(i=1:1:n+1)
thicknessBase(i,1) = 2*( ­867170785.415039*(dx*(i­1))^6 +
77907452.337196*(dx*(i­1))^5 ...
­ 2580442.078543*(dx*(i­1))^4 + 37856.100304*(dx*(i­1))^3 ­
224.378307*(dx*(i­1))^2 ...
+ 0.254748*(dx*(i­1)) + 0.001508);
end

A = thicknessBase*W;            % Cross­sectional area m^s   t as a
function of
Atip = thicknessBase(n+1,1)*W;

for i=1:n
trem = 0.5*(thicknessBase(i,1) ­ thicknessBase(i+1));
hyp = dx/(cos(atan(trem/dx)));
As(i,1) = 2*hyp*W + (thicknessBase(i+1,1)+thicknessBase(i,1))*dx;

end

elseif (Xsection == 4)
%Group 2 Custom Plate fin geometry (improved)
for(i=1:1:n+1)
thicknessBase(i,1) =2*(­232167180.082397*(dx*(i­1))^6 +
20351609.103310*(dx*(i­1))^5 ...
­ 649368.263497*(dx*(i­1))^4 + 8940.737022*(dx*(i­1))^3 ­
47.060870*(dx*(i­1))^2 ...
+ 0.011325*(dx*(i­1)) + 0.001501);
end

A = thicknessBase*W;            % Cross­sectional area m^s   t as a
function of
Atip = thicknessBase(n+1,1)*W;

for i=1:n
trem = 0.5*(thicknessBase(i,1) ­ thicknessBase(i+1));
hyp = dx/(cos(atan(trem/dx)));
As(i,1) = 2*hyp*W + (thicknessBase(i+1,1)+thicknessBase(i,1))*dx;

end
end

T(1:n,x) = finiteVolume(Tbase, Tamb, h, k, dx, n, A, As, Atip);
Ttest(1:n,xtest) = T(1:n,x);

%total surface area check
AsTotal(x,1) = sum(As') + Atip;
if x == 1
figure('pos',[xLower yLower xWidth yHeight])
end
hold on

PlotTemps(1:n+2,x) = [Tbase; T(1:n,x); T(n,x);];
% %Make list of x points
Points = (dx/2):dx:(L­(dx/2));
PlotX(1:n+2,x) = [0; Points'; L];

%plot(Points', T)
grid on
subplot(2,1,1)
plot(PlotX(1:n+2,x),PlotTemps(1:n+2,x),'Color',colorVec(x,:),'LineWidth',2)
set(gca,'Fontsize',18);
xlabel('Distance (m)', 'Fontsize', 16)
ylabel('Temperature °C', 'Fontsize', 16)

ThetaB(1:n,x) = T(1:n,x)­Tamb;
q(1:n,x)=h*As.*ThetaB(1:n,x);
Qtotal(1,x)=sum(q(1:n,x));
nf(1,x) = Qtotal(1,x)*(1/(h*AsTotal(1,1)*(Tbase­Tamb)));
%percentdiff(x,1) = (abs(T_tip(1,j­1)­T_tip(1,j)))/(T_tip(1,j­1)*100);

%xtest starts at 2

if x>1
for (z=1:1:5)
percentdiff(z,xtest) = (abs(Ttest(z*2^(x­2),xtest­1)­ ...
Ttest(z*2^(x­1),xtest))/Ttest(z*2^(x­2),xtest­1)*100);
end
end

MeanPdiff = mean(percentdiff);

MaxPdiff = max(percentdiff(:,xtest));

j=j+1;
T_tip(1,j) = T(n,x);
nodes(1,x) = n;
n=2*n +1;
x=x+1;
xtest=xtest+1;
end

legendCell = cellstr(num2str(nodes', 'n=%­d'));
legend(legendCell,'Location','Northeast')

hold off

subplot(2,1,2)
hold on
grid on
dxDiff = L/5;
PointsDiff = (dxDiff/2):dxDiff:(L­(dxDiff/2));

NodesLength = size(nodes);
NodesLength = NodesLength(2);
nodes1 = nodes(1,2:NodesLength);

for i=1:NodesLength­1

legendCell1(i,1) = cellstr([num2str(nodes(1,i), 'n = %­d')
num2str(nodes1(1,i), '­%­d')]);

end
xlabeldiff(2:NodesLength) = legendCell1;
xlabeldiff(1) = cellstr(' ');
xlabeldiff(NodesLength+1) = cellstr(' ');

for loop = 1:1:NodesLength­1
plot(PointsDiff',percentdiff(:,loop+2),'Color',colorVec(loop,:),'LineWidth',2)
end

set(gca,'Fontsize',18);
xlabel('Distance (m)', 'Fontsize', 16);
ylabel('Percent Difference (%)', 'Fontsize', 16);
legend(legendCell1,'Location','Northwest');
% legendCell1(1,1);

figure('pos',[xLower yLower xWidth yHeight])
grid on
plot(nodes(4:end),MeanPdiff(5:end),'Color',colorVec(1,:),'LineWidth',2);

set(gca,'XtickLabel',xlabeldiff,'Fontsize',10)
set(gca,'Fontsize',16);
xlabel('Nodes', 'Fontsize', 16)
ylabel('Percent Difference (%)', 'Fontsize', 16)

% legendCell1 = cellstr(num2str(nodes', 'n=%­d ­',nodes1', 'n=%d'));
% legend(legendCell1,'Location','Northeast')

set(gca,'Fontsize',18);
xlabel('Nodes', 'Fontsize', 16)
ylabel('Percent Difference (%)', 'Fontsize', 16)
hold off

figure('pos',[xLower yLower xWidth yHeight])
n=nodes(1,x­1);
x=1;

for h = [10,50,100]

Tfinal(1:n,x) = finiteVolume(Tbase, Tamb, h, k, dx, n, A, As, Atip);

hold on

PlotTemps(1:n+2,x) = [Tbase; Tfinal(1:n,x); Tfinal(n,x);];
% %Make list of x points
Points = (dx/2):dx:(L­(dx/2));
PlotX(1:n+2,x) = [0; Points'; L];
grid on

plot(PlotX(1:n+2,x),PlotTemps(1:n+2,x),'Color',colorVec(x,:),'LineWidth',2)
set(gca,'Fontsize',18);
xlabel('Distance (m)', 'Fontsize', 16)
ylabel('Temperature °C', 'Fontsize', 16)

ThetaBfinal(1:n,x) = Tfinal(1:n,x)­Tamb;
qfinal(1:n,x)=h*As.*ThetaBfinal(1:n,x);
Qtotalfinal(1,x)=sum(qfinal(1:n,x));
nftotal(1,x) = Qtotalfinal(1,x)/(h*AsTotal(1,1)*(Tbase­Tamb));

heattransfercoeff(1,x) = h;

x=x+1;

end

legendCell2 = cellstr(num2str(heattransfercoeff', 'h=%­d'));
legend(legendCell2,'Location','Best');

hold off

figure('pos',[xLower yLower xWidth yHeight])
plot(heattransfercoeff, nftotal,'LineWidth',2)
set(gca,'Fontsize',18);
xlabel('heat transfer coefficient (W/m^2 K)', 'Fontsize', 16)
ylabel('Efficiency', 'Fontsize', 16)