2D Heat Conduction Equation
1) Transient Heat Conduction Analysis using Jacobi method (Implicit)
%Transient state analysis using jacobi method implicitly
clear all
close all
clc
%Inputs
nx=10;
ny=nx;
L=1;
x=linspace(0,L,nx);
dx=x(2)-x(1);
y=linspace(0,L,ny);
dy=y(2)-y(1);
dt=10;
alpha=1.4e-5;
nt=2000;
t=nt*dt;
%Values of k1 and k2 and constant
k1=(alpha*dt)/(dx)^2;
k2=(alpha*dt)/(dy)^2;
term1=1+2*k1+2*k2;
%Temperature matrix
T=293*ones(nx,ny);
%Boundary Conditions
T(:,1)=400;
T(1,:)=900;
T(:,end)=800;
T(end,:)=600;
%Error and tolerance values
error=9e9;
tol=1e-4;
%Assigning Told value
T_old=T;
T_p=T;
iterative_solver=1;
%Jacobi Method
jacobi_iter=1;
for k=1:nt
while (error > tol)
for i=2:nx-1
for j=2:ny-1
Tr=T_old(i+1,j);
Tl=T_old(i-1,j);
Tt=T_old(i,j+1);
Tb=T_old(i,j-1);
T(i,j)=(T_p(i,j)+k1*(Tr+Tl)+k2*(Tt+Tb))/term1;
end
end
error_n=max(abs(T_old-T));
error=max(error_n);
T_old=T;
jacobi_iter=jacobi_iter+1;
end
T_p=T;
error=9e9;
colormap(jet)
contourf(x,y,T)
title_text=sprintf(\'Iteration Number=%d\',jacobi_iter);
title(title_text)
colorbar
pause(0.003)
end
2) Transient Heat Conduction Analysis using Gauss Seidel method (Implicit)
%Transient state analysis using gauss seidel method implicitly
clear all
close all
clc
%Inputs
nx=10;
ny=nx;
L=1;
x=linspace(0,L,nx);
dx=x(2)-x(1);
y=linspace(0,L,ny);
dy=y(2)-y(1);
dt=10;
alpha=1.4e-5;
nt=2000;
%Values of k1 and k2 and constant
k1=(alpha*dt)/(dx)^2;
k2=(alpha*dt)/(dy)^2;
term1=1+2*k1+2*k2;
%Temperature matrix
T=293*ones(nx,ny);
%Boundary Conditions
T(:,1)=400;
T(1,:)=900;
T(:,end)=800;
T(end,:)=600;
%Error and tolerance values
error=9e9;
tol=1e-4;
%Assigning Told value
T_old=T;
T_p=T;
iterative_solver=1;
%Gauss Seidel Method
if iterative_solver==1
gs_iter=1;
for k=1:nt
while (error > tol)
for i=2:nx-1
for j=2:ny-1
Tr=T_old(i+1,j);
Tl=T(i-1,j);
Tt=T_old(i,j+1);
Tb=T(i,j-1);
T(i,j)=(T_p(i,j)+k1*(Tr+Tl)+k2*(Tt+Tb))/term1;
end
end
error_n=max(abs(T_old-T));
error=max(error_n);
T_old=T;
gs_iter=gs_iter+1;
end
T_p=T;
error=9e9;
colormap(jet)
contourf(x,y,T)
title_text=sprintf(\'Iteration Number=%d\',gs_iter);
title(title_text)
colorbar
pause(0.003)
end
end
3) Transient Heat Conduction Analysis using SOR method (Implicit)
%Transient state analysis using SOR method implicitly
clear all
close all
clc
%Inputs
nx=10;
ny=nx;
L=1;
x=linspace(0,L,nx);
dx=x(2)-x(1);
y=linspace(0,L,ny);
dy=y(2)-y(1);
dt=10;
alpha=1.4e-5;
w=1.2;
nt=2000;
%Values of k1 and k2 and constant
k1=(alpha*dt)/(dx)^2;
k2=(alpha*dt)/(dy)^2;
term1=1+2*k1+2*k2;
%Temperature matrix
T=293*ones(nx,ny);
%Boundary Conditions
T(:,1)=400;
T(1,:)=900;
T(:,end)=800;
T(end,:)=600;
%Error and tolerance values
error=9e9;
tol=1e-4;
%Assigning Told value
T_old=T;
T_p=T;
iterative_solver=1;
%SOR Method
if iterative_solver==1
SOR_iter=1;
for k=1:nt
while (error > tol)
for i=2:nx-1
for j=2:ny-1
Tr=T_old(i+1,j);
Tl=T(i-1,j);
Tt=T_old(i,j+1);
Tb=T(i,j-1);
T(i,j)=((T_p(i,j)))*(1-w)+(w*(T_p(i,j)+k1*(Tr+Tl)+k2*(Tt+Tb)))/term1;
end
end
error_n=max(abs(T_old-T));
error=max(error_n);
T_old=T;
SOR_iter=SOR_iter+1;
end
T_p=T;
error=9e9;
colormap(jet)
contourf(x,y,T)
title_text=sprintf(\'Iteration Number=%d\',SOR_iter);
title(title_text)
colorbar
pause(0.003)
end
end
4) Transient State Analysis using explicit scheme
%Transient state analysis explicitly
clear all
close all
clc
%Inputs
nx=10;
ny=nx;
L=1;
x=linspace(0,L,nx);
dx=x(2)-x(1);
y=linspace(0,L,ny);
dy=y(2)-y(1);
dt=10;
alpha=1.4e-5;
nt=2000;
%Values of k1 and k2 and constant
k1=(alpha*dt)/(dx)^2;
k2=(alpha*dt)/(dy)^2;
term1=1-2*k1-2*k2;
cfl=(k1+k2)/2;
%Temperature matrix
T=293*ones(nx,ny);
%Boundary Conditions
T(:,1)=400;
T(1,:)=900;
T(:,end)=800;
T(end,:)=600;
%Assigning Told value
T_p=T;
%Time Loop
iter=1;
for k=1:nt
%Space Loop
for i=2:nx-1
for j=2:ny-1
Tr=T(i+1,j);
Tl=T(i-1,j);
Tt=T(i,j+1);
Tb=T(i,j-1);
T(i,j)=((T_p(i,j)*term1)+k1*(Tr+Tl)+k2*(Tt+Tb));
end
end
T_p=T;
colormap(jet)
contourf(x,y,T)
title_text=sprintf(\'Iteration No=%d\',iter);
title(title_text)
colorbar
pause(0.003)
iter=iter+1;
end
5) Steady State Analysis
%Steady state analysis of 2d heat conduction
clear all
close all
clc
%Inputs
nx=10;
ny=nx;
L=1;
x=linspace(0,L,nx);
dx=x(2)-x(1);
y=linspace(0,L,ny);
dy=y(2)-y(1);
%Creating temperature matrix
T=ones(nx,ny);
%Boundary conditions
T(:,1)=400;
T(end,:)=600;
T(:,end)=800;
T(1,:)=900;
error=9e9;
tol=1e-4;
%Space Loop
T_old=T;
while (error>tol)
for i=2:nx-1
for j=2:ny-1
Tr=T(i+1,j);
Tl=T(i-1,j);
Tt=T(i,j+1);
Tb=T(i,j-1);
T(i,j)=(Tr+Tl+Tb+Tt)/4;
end
end
colormap(jet)
contourf(x,y,T)
title(\'Steady State Heat Conduction\')
pause(0.003)
colorbar
T_old=T;
end
Explanation
1) The number of iterations required for transient state analysis by implicit scheme for jacobi,gauss siedel and SOR method are 7263,6732 and 6655 respectively
2) Comparitively less number of iteration are required for SOR then gauss siedel and jacobi
3) In implicit scheme the solution remains stable for all values of timestep(dt)
4) Explicit method gives us direct answer as the values on RHS are known,so no iterative solver is needed
5) Explicit solution remains stable for paticular range of timestep(dt)