Está en la página 1de 16

1. A thin plate is initially at a uniform temperature of 2000C.

At a certain time t=0, the


temperature of the east side of the plate is reduced to 00C. The other surface is insulated.
Calculate transient temperature distribution of the slab using
i) Explicit method
ii) Fully implicit method
iii) Crank-Nicolson method
Compare your results with analytical solution of Versteeg- Example 8.1 at 1) time = 40 s 2)
time =80 s 3) time =120 s. Select the proper time step size for the calculations. Also
compare results at time = 40 s using various time steps. Plate thickness L = 2 cm, thermal
conductivity K =10 W/m and c =10 x 106 J/m3K.
Solution:

display('Enter length,no.of control volume');


l=input('');n=input('');x=l/n;
display('Enter density,specific heat and thermal conductivity ');
r=input('');h=input('');k=input('');
ti=input('Enter initial temperature of slab');
display('Enter total time and time interval:');
time=input('');dt=input('');t=dt;
e=k/x; w=k/x;Apo=(r*h*x)/dt;
for i=2:1:n+1
Told(i)=ti;
end
Told(1)=Told(2);
Told(n+2)=input('Enter temperature at right end:');
p=input('Press 1 for explicit,2 for implicit,3 for Crank-Nicolson method:');
switch (p)
case 1
while t<time
for i=2:1:n+1
if(i==2)
ae(i)=e;aw(i)=2*w;ap(i)=Apo;
elseif(i==n+1)
ae(i)=2*e;aw(i)=w;ap(i)=Apo;
else
ae(i)=e;aw(i)=w;ap(i)=Apo;
end
end
for i=2:1:n+1
Tnew(i)=(aw(i)*Told(i-1)+ae(i)*Told(i+1)+(ap(i)-aw(i)-ae(i))*Told(i))/ap(i);
end
Tnew(1)=Tnew(2);Tnew(n+2)=Told(n+2);
Told=Tnew;
t=t+dt;
end

case 2
while t<time
b(1)=0;d(1)=-1;a(1)=1;c(1)=0;
b(n+2)=0;d(n+2)=1;a(n+2)=0;c(n+2)=Told(n+2);
for i=2:1:n+1
if(i==2)
b(i)=-2*e;a(i)=-1*w;d(i)=Apo+2*e+w;c(i)=Apo*Told(i);
elseif(i==n+1)
b(i)=-1*e;a(i)=-2*w;d(i)=Apo+e+2*w;c(i)=Apo*Told(i);
else
b(i)=-1*e;a(i)=-1*w;d(i)=Apo+e+w;c(i)=Apo*Told(i);
end
end
Tnew=tdma(b,a,d,c,n);
Told=Tnew;
t=t+dt;
end
case 3
while t<time
b(1)=0;d(1)=-1;a(1)=1;c(1)=0;
b(n+2)=0;d(n+2)=1;a(n+2)=0;c(n+2)=Told(n+2);
for i=2:1:n+1
if(i==2)
b(i)=-w;a(i)=-.5*e;d(i)=Apo+w+.5*e;
c(i)=w*Told(i-1)+.5*e*Told(i+1)+(Apo-w-.5*e)*Told(i);
elseif(i==n+1)
b(i)=-.5*w;a(i)=-e;d(i)=Apo+e+.5*w;
c(i)=.5*w*Told(i-1)+e*Told(i+1)+(Apo-e-.5*w)*Told(i);
else
b(i)=-.5*w;a(i)=-.5*e;d(i)=Apo+.5*e+.5*w;
c(i)=.5*w*Told(i-1)+.5*e*Told(i+1)+(Apo-.5*e-.5*w)*Told(i);
end
end
Tnew=tdma(b,a,d,c,n);
Told=Tnew;
t=t+dt;
end
end
q(1)=0;q(2)=x/2;q(n+2)=l;q(n+1)=l-x/2;
for i=3:1:n
q(i)=q(i-1)+x;
end
display(q);display(Tnew);
plot(q,Tnew);

Output:

2. Consider a two-dimensional rectangular plate of dimension L = 1 m in the x direction


and H= 2 m in the y direction. The plate material has constant thermal conductivity. The
steadystate temperature distribution within this plate is to be determined for the following
imposed boundary conditions: (i) y = 0, T = 100oC, (ii) x = 0, T = 0oC, (iii) y = H, T = 0oC,
and (iv) x = L, T = 0oC. Choose a uniform grid size of 0.05 m in both directions. Solve
the problem using the point-by-point Gauss-Seidel iterative method. Experiment with the
initial guess and comment on the number of iterations required for convergence in each
case. Clearly explain your convergence criterion for the iterations and how it is
implemented. Plot the temperature contours as the output.
Solution:
display('Enter length in x and y direction:');
L1=input('');L2=input('');
display('Enter length of control volume in x and y direction:');
x=input('');y=input('');
p=L1/x; q=L2/y;
k=input('Enter thermal conductivity of slab:');
display('Enter temperature at west,east,north,south faces:');
Tw=input('');Te=input('');Tn=input('');Ts=input('');
for i=2:1:p+1
for j=2:1:q+1
if(i==2)
if(j==2)
aw(i,j)=-2*k/x;ae(i,j)=-k/x;as(i,j)=-2*k/y;an(i,j)=-k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
elseif(j==q+1)
aw(i,j)=-2*k/x;ae(i,j)=-k/x;as(i,j)=-k/y;an(i,j)=-2*k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
else
aw(i,j)=-2*k/x;ae(i,j)=-k/x;as(i,j)=-k/y;an(i,j)=-k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
end
elseif(i==p+1)
if(j==2)
aw(i,j)=-k/x;ae(i,j)=-2*k/x;as(i,j)=-2*k/y;an(i,j)=-k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
elseif(j==q+1)
aw(i,j)=-k/x;ae(i,j)=-2*k/x;as(i,j)=-k/y;an(i,j)=-2*k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
else
aw(i,j)=-k/x;ae(i,j)=-2*k/x;as(i,j)=-k/y;an(i,j)=-k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
end
else
if(j==2) aw(i,j)=-k/x;ae(i,j)=-k/x;as(i,j)=-2*k/y;an(i,j)=-k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
elseif(j==q+1)

aw(i,j)=-k/x;ae(i,j)=-k/x;as(i,j)=-k/y;an(i,j)=-2*k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
else
aw(i,j)=-k/x;ae(i,j)=-k/x;as(i,j)=-k/y;an(i,j)=-k/y;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));
end
end
end
end
for j=2:1:q+1
aw(1,j)=0;ae(1,j)=0;as(1,j)=0;an(1,j)=0;ap(1,j)=1;Told(1,j)=Tw;
aw(p+2,j)=0;ae(p+2,j)=0;as(p+2,j)=0;an(p+2,j)=0;ap(p+2,j)=1;Told(p+2,j)=Te;
end
for i=2:1:p+1
aw(i,1)=0;ae(i,1)=0;as(i,1)=0;an(i,1)=0;ap(i,1)=1;Told(i,1)=Ts;
aw(i,q+2)=0;ae(i,q+2)=0;as(i,q+2)=0;an(i,q+2)=0;ap(i,q+2)=1;Told(i,q+2)=Tn;
end
zz=input('Enter initial value of temperature to be assumed:');
for i=2:1:p+1
for i=2:1:q+1
Told(i,j)=zz;
end
end
rms=1;g=0;
while rms>.001
for i=1:1:p+2
for j=1:1:q+2
if(i==1 || i==p+2) Tnew(i,j)=Told(i,j);
elseif(j==1 || j==q+2) Tnew(i,j)=Told(i,j);
else
Tnew(i,j)=(-aw(i,j)*Tnew(i-1,j)-as(i,j)*Tnew(i,j-1)-an(i,j)*Told(i,j+1)ae(i,j)*Told(i+1,j))/ap(i,j);
end
end
end
resi=0;
for i=1:1:p+2
for j=1:1:q+2
resi=resi+(Tnew(i,j)-Told(i,j))*(Tnew(i,j)-Told(i,j));
end
end
rms=sqrt(resi/((p+2)*(q+2)));
Told=Tnew;
g=g+1;
end
display(Tnew);display(g);

Output:

Analytical solution:

display('Display H,L,x,y:');
h=input('');l=input('');x=input('');y=input('');
t1=input('Enter input temperature:');
sum=0;
p=l/x;q=h/y;
for i=1:1:p+2
for j=1:1:q+2
if(i==1) m(i,j)=0;
elseif(i==2) m(i,j)=x/2;
elseif(i==p+1) m(i,j)=l-x/2;
elseif(i==p+2) m(i,j)=l;
else m(i,j)=m(i-1,j)+x;
end
end
end
for i=1:1:p+2
for j=1:1:q+2
if(j==1) n(i,j)=0;
elseif(j==2) n(i,j)=y/2;
elseif(j==q+1) n(i,j)=h-y/2;
elseif(j==q+2) n(i,j)=h;
else n(i,j)=n(i,j-1)+y;
end
end
end
for i=1:1:p+2
for j=1:1:q+2
Tnewana(i,j)=analytical(h,l,m(i,j),n(i,j),t1);
end
end
display(Tnewana);
Function:
function T= analytical(h,l,x,y,t1)
sum=0;
for i=1:1:100
sum=sum+(1-(-1)^i)*sinh(i*pi*(h-y)/l)*sin(i*pi*x/l)/(i*pi*sinh(i*pi*h/l));
end
T=2*t1*sum;
end

Output:

5. West boundary of a plate of 1 m x 1 m thickness is maintained at constant temperature of


1000C. East boundary receives a steady heat flux of 10 kW/m 2. South boundary is insulated.
North boundary is exposed to atmosphere. Atmospheric temperature is 300C. Thermal
conductivity of plate material = 63.9 W/m-k. Convective heat transfer coefficient (for north
boundary) is 100 W/m2. Taking uniform grid of x = y =0.05 m, calculate steady state
temperature distribution in the plate using a program.
Solution:

display('Enter Length,Height:');
l=input('');h=input('');
display('Enter length of control volume in x and y direction:');
dx=input('');dy=input('');
m=l/dx;n=h/dy;
Twest=input('Enter temperature at west end:');
q=input('Enter heat input at east end:');
hn=input('Enter heat transfer coefficient at north end:');
k=input('Enter thermal conductivity of block:');
tamb=input('Enter atmosphearic temperature:');
w=k/dx;s=k/dy;
for i=1:1:n+2
for j=1:1:m+2
if (i==1)
aw(i,j)=0;ae(i,j)=0;an(i,j)=0;as(i,j)=-2*s;ap(i,j)=2*s+hn;b(i,j)=hn*tamb;
elseif (i==2)
if(j==1)
aw(i,j)=0;ae(i,j)=0;an(i,j)=0;as(i,j)=0;
ap(i,j)=1;b(i,j)=Twest;
elseif(j==2)
aw(i,j)=-2*w;an(i,j)=-2*s;as(i,j)=-s;ae(i,j)=-w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
elseif(j==n+1)
aw(i,j)=-w;an(i,j)=-2*s;as(i,j)=-s;ae(i,j)=-2*w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
elseif(j==n+2)
aw(i,j)=-2*w;ae(i,j)=0;an(i,j)=0;as(i,j)=0;
ap(i,j)=2*w;b(i,j)=q;
else
aw(i,j)=-w;an(i,j)=-2*s;as(i,j)=-s;ae(i,j)=-w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
end
elseif(i==n+1)
if(j==1)
aw(i,j)=0;ae(i,j)=0;an(i,j)=0;as(i,j)=0;
ap(i,j)=1;b(i,j)=Twest;
elseif(j==2)

aw(i,j)=-2*w;an(i,j)=-s;as(i,j)=-2*s;ae(i,j)=-w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
elseif(j==m+1)
aw(i,j)=-w;an(i,j)=-s;as(i,j)=-2*s;ae(i,j)=-2*w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
elseif(j==m+2)
aw(i,j)=-2*w;ae(i,j)=0;an(i,j)=0;as(i,j)=0;
ap(i,j)=2*w;b(i,j)=q;
else
aw(i,j)=-w;an(i,j)=-s;as(i,j)=-2*s;ae(i,j)=-w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
end
elseif(i==n+2)
aw(i,j)=0;an(i,j)=-1;as(i,j)=0;ae(i,j)=0;ap(i,j)=1;b(i,j)=0;
else
if(j==1)
aw(i,j)=0;ae(i,j)=0;an(i,j)=0;as(i,j)=0;
ap(i,j)=1;b(i,j)=Twest;
elseif(j==2)
aw(i,j)=-2*w;an(i,j)=-s;as(i,j)=-s;ae(i,j)=-w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
elseif(j==n+1)
aw(i,j)=-w;an(i,j)=-s;as(i,j)=-s;ae(i,j)=-2*w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
elseif(j==n+2)
aw(i,j)=-2*w;ae(i,j)=0;an(i,j)=0;as(i,j)=0;
ap(i,j)=2*w;b(i,j)=q;
else
aw(i,j)=-w;an(i,j)=-s;as(i,j)=-s;ae(i,j)=-w;
ap(i,j)=-(aw(i,j)+ae(i,j)+an(i,j)+as(i,j));b(i,j)=0;
end
end
end
end
for i=1:1:n+2
for j=1:1:m+2
Told(i,j)=0;
end
end
rms=1;
while rms>.001
for i=1:1:n+2
Tnew(i,1:m+2)=TDMA(aw,ae,an,as,ap,b,i,m,n,Told);
end
residual=0;

for i=1:1:n+2
for j=1:1:m+2
residual=residual+(Tnew(i,j)-Told(i,j))*(Tnew(i,j)-Told(i,j));
end
end
rms=sqrt(residual/((m+2)*(n+2)));
Told=Tnew;
end
TDMA FUNCTION:

function Tnew=TDMA(aw,ae,an,as,ap,b,i,m,n,Told)
e=aw(i,:);f=ap(i,:);g=ae(i,:);c=b(i,:);
if (i==1)
for j=1:1:m+2
r(j)=-as(i,j)*Told(i+1,j)+c(j);
end
elseif (i==n+2)
for j=1:1:m+2
r(j)=-an(i,j)*Told(i-1,j)+c(j);
end
else
for j=1:1:m+2
r(j)=-an(i,j)*Told(i-1,j)-as(i,j)*Told(i+1,j)+c(j);
end
end
d1(1)=f(1); r1(1)=r(1);
for j=2:1:m+2
d1(j)=f(j)-e(j)*g(j-1)/d1(j-1);
r1(j)=r(j)-e(j)*r1(j-1)/d1(j-1);
end
Tnew(m+2)=r1(m+2)/d1(m+2);
for j=m+1:-1:1
Tnew(j)=(r1(j)-g(j)*Tnew(j+1))/d1(j);
end

También podría gustarte