Week 5.1 - Mid term project - Solving the steady and unsteady 2D heat conduction problem
Steady state analysis & Transient State Analysis
Solve the 2D heat conduction equation by using the point iterative techniques that were taught in the class. The Boundary conditions for the problem are as follows;
Top Boundary = 600 K
Bottom Boundary = 900 K
Left Boundary = 400 K
Right Boundary = 800 K
1. Jacobi
clear all
close all
clc
nx=10;
ny=10;
T=ones(nx,ny);
TL=400;
TR=800;
TT=600;
TB=900;
T(:,1)=TL;
T(:,ny)=TR;
T(1,:)=TT;
T(nx,:)=TB;
T(1,1)=0.5*(T(2,1)+T(1,2));
T(nx,1)=0.5*(T(nx-1,1)+T(nx,2));
T(nx,ny)=0.5*(T(nx-1,ny)+T(nx,ny-1));
T(1,ny)=0.5*(T(2,ny)+T(1,ny-1));
Told=T;
error=9e9;
tol=1e-5;
jac_iter=0
while(error>tol)
for i=2:nx-1
for j=2:ny-1
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
end
end
error=max(max(abs(T-Told)));
Told=T;
jac_iter=jac_iter+1
contourf(T,'showtext','on')
title(sprintf('steday state jacobi inerations=%d',jac_iter));
pause(0.005)
colorbar
end

2. Gauss-seidel
clear all
close all
clc
nx=10;
ny=10;
T=ones(nx,ny);
TL=400;
TR=800;
TT=600;
TB=900;
T(:,1)=TL;
T(:,ny)=TR;
T(1,:)=TT;
T(nx,:)=TB;
T(1,1)=0.5*(T(2,1)+T(1,2));
T(nx,1)=0.5*(T(nx-1,1)+T(nx,2));
T(nx,ny)=0.5*(T(nx-1,ny)+T(nx,ny-1));
T(1,ny)=0.5*(T(2,ny)+T(1,ny-1));
Told=T;
error=9e9;
tol=1e-5;
gs_iter=0
while(error>tol)
for i=2:nx-1
for j=2:ny-1
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
T(i,j)=0.25*(Told(i+1,j)+T(i-1,j)+T(i,j-1)+Told(i,j+1));
end
end
error=max(max(abs(T-Told)));
Told=T;
gs_iter=gs_iter+1
contourf(T,'showtext','on')
title(sprintf('steday stategauss inerations=%d',gs_iter));
pause(0.005)
colorbar
end

3. Successive over-relaxation
clear all
close all
clc
nx=10;
ny=10;
T=ones(nx,ny);
TL=400;
TR=800;
TT=600;
TB=900;
T(:,1)=TL;
T(:,ny)=TR;
T(1,:)=TT;
T(nx,:)=TB;
T(1,1)=0.5*(T(2,1)+T(1,2));
T(nx,1)=0.5*(T(nx-1,1)+T(nx,2));
T(nx,ny)=0.5*(T(nx-1,ny)+T(nx,ny-1));
T(1,ny)=0.5*(T(2,ny)+T(1,ny-1));
Told=T;
error=9e9;
tol=1e-5;
sor_iter=0
omega=1.6;
while(error>tol)
for i=2:nx-1
for j=2:ny-1
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
TGS(i,j)=0.25*(Told(i+1,j)+T(i-1,j)+T(i,j-1)+Told(i,j+1));
T(i,j)=(1-omega)*Told(i,j)+omega*TGS(i,j);
end
end
error=max(max(abs(T-Told)));
Told=T;
sor_iter=sor_iter+1
contourf(T,'showtext','on')
title(sprintf('steday state sor inerations=%d',sor_iter));
pause(0.005)
end

unsteady
Jacobi
clear all
close all
clc
nx=10;
ny=10;
T=ones(nx,ny);
TL=400;
TR=800;
TT=600;
TB=900;
T(:,1)=TL;
T(:,ny)=TR;
T(1,:)=TT;
T(nx,:)=TB;
T(1,1)=0.5*(T(2,1)+T(1,2));
T(nx,1)=0.5*(T(nx-1,1)+T(nx,2));
T(nx,ny)=0.5*(T(nx-1,ny)+T(nx,ny-1));
T(1,ny)=0.5*(T(2,ny)+T(1,ny-1));
Told=T;
Tprev=T;
dt=1e-2;
dx=1e-2;
dy=1e-2;
%thermaldiffusivity
alpha=1.5;
k1=alpha *dt/dx^2;
k2=alpha *dt/dy^2
error=9e9;
conv=9e9;
tol=1e-5;
jac_iter=0
jac_time_iter=0;
while(conv>tol)
while(error>tol)
for i=2:nx-1
for j=2:ny-1
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
T(i,j)=(1+2*k1+2*k2)^-1*(Tprev(i,j)+k1*(Told(i-1,j)+Told(i+1,j))+k2*(Told(i,j-1)+Told(i,j+1)));
end
end
error=max(max(abs(T-Told)));
Told=T;
jac_iter=jac_iter+1
contourf(T,'showtext','on')
title(sprintf('trasient implicit jocobi inerations=%d\nTime iterations=%d',jac_iter,jac_time_iter));
pause(0.005)
colorbar
end
conv=max(max(abs(T-Tprev)));
Tprev=T;
jac_time_iter=jac_time_iter+1
error=9e9;
end

guss
clear all
close all
clc
nx=10;
ny=10;
T=ones(nx,ny);
TL=400;
TR=800;
TT=600;
TB=900;
T(:,1)=TL;
T(:,ny)=TR;
T(1,:)=TT;
T(nx,:)=TB;
T(1,1)=0.5*(T(2,1)+T(1,2));
T(nx,1)=0.5*(T(nx-1,1)+T(nx,2));
T(nx,ny)=0.5*(T(nx-1,ny)+T(nx,ny-1));
T(1,ny)=0.5*(T(2,ny)+T(1,ny-1));
Told=T;
Tprev=T;
dt=1e-2;
dx=1e-2;
dy=1e-2;
%thermaldiffusivity
alpha=1.5;
k1=alpha *dt/dx^2;
k2=alpha *dt/dy^2
error=9e9;
conv=9e9;
tol=1e-5;
gs_iter=0
gs_time_iter=0;
while(conv>tol)
while(error>tol)
for i=2:nx-1
for j=2:ny-1
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
T(i,j)=(1+2*k1+2*k2)^-1*(Tprev(i,j)+k1*(T(i-1,j)+Told(i+1,j))+k2*(T(i,j-1)+Told(i,j+1)));
end
end
error=max(max(abs(T-Told)));
Told=T;
gs_iter=gs_iter+1
contourf(T,'showtext','on')
title(sprintf('trasient implicit guss inerations=%d\nTime iterations=%d',gs_iter,gs_time_iter));
pause(0.005)
colorbar
end
conv=max(max(abs(T-Tprev)));
Tprev=T;
gs_time_iter=gs_time_iter+1
error=9e9;
end

3. Successive over-relaxation
clear all
close all
clc
nx=10;
ny=10;
T=ones(nx,ny);
TL=400;
TR=800;
TT=600;
TB=900;
T(:,1)=TL;
T(:,ny)=TR;
T(1,:)=TT;
T(nx,:)=TB;
T(1,1)=0.5*(T(2,1)+T(1,2));
T(nx,1)=0.5*(T(nx-1,1)+T(nx,2));
T(nx,ny)=0.5*(T(nx-1,ny)+T(nx,ny-1));
T(1,ny)=0.5*(T(2,ny)+T(1,ny-1));
Told=T;
omega=1.005;
Tprev=T;
dt=1e-2;
dx=1e-2;
dy=1e-2;
%thermaldiffusivity
alpha=1.5;
k1=alpha *dt/dx^2;
k2=alpha *dt/dy^2
error=9e9;
conv=9e9;
tol=1e-5;
sor_iter=0
sor_time_iter=0;
while(conv>tol)
while(error>tol)
for i=2:nx-1
for j=2:ny-1
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
TGS(i,j)=(1+2*k1+2*k2)^-1*(Tprev(i,j)+k1*(Told(i-1,j)+Told(i+1,j))+k2*(Told(i,j-1)+Told(i,j+1)));
T(i,j)=(1-omega)*Told(i,j)+omega*(TGS(i,j));
end
end
error=max(max(abs(T-Told)));
Told=T;
sor_iter=sor_iter+1
contourf(T,'showtext','on')
title(sprintf('trasient implicit gosinerations=%d\nTime iterations=%d',sor_iter,sor_time_iter));
pause(0.005)
colorbar
end
conv=max(max(abs(T-Tprev)));
Tprev=T;
sor_time_iter=sor_time_iter+1
error=9e9;
end

Explicit Jacobi
clear all
close all
clc
nx=10;
ny=10;
T=ones(nx,ny);
TL=400;
TR=800;
TT=600;
TB=900;
T(:,1)=TL;
T(:,ny)=TR;
T(1,:)=TT;
T(nx,:)=TB;
T(1,1)=0.5*(T(2,1)+T(1,2));
T(nx,1)=0.5*(T(nx-1,1)+T(nx,2));
T(nx,ny)=0.5*(T(nx-1,ny)+T(nx,ny-1));
T(1,ny)=0.5*(T(2,ny)+T(1,ny-1));
Told=T;
Tprev=T;
dt=1e-2;
dx=7e-2;
dy=7e-2;
%thermaldiffusivity
alpha=0.05
k1=alpha *dt/dx^2;
k2=alpha *dt/dy^2
cfl=k1+k2;
conv=9e9;
tol=1e-5;
time_iter=0;
while(conv>tol)
for i=2:nx-1
for j=2:ny-1
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
% T(i,j)=0.25*(Told(i+1,j)+Told(i-1,j)+Told(i,j-1)+Told(i,j+1));
T(i,j)=(1-2*k1-2*k2)*Tprev(i,j)+k1*(Tprev(i-1,j)+Tprev(i+1,j))+k2*(Tprev(i,j-1)+Tprev(i,j+1));
end
end
conv=max(max(abs(T-Tprev)));
Tprev=T;
time_iter=time_iter+1
contourf(T,'showtext','on')
title(sprintf('trasient explicit iteration=%d ', time_iter));
pause(0.005)
colorbar
end

| Types | methods | iterations |
| Implicit steady | jacobi | 253 |
| gauss sledel | 134 | |
| successive over relaxation | 41 | |
| Implicit transient | jacobi | 672 |
| gauss sledel | 370 | |
| successive over relaxation | 668 | |
| explicit | jacobi | 593 |
*Jocobi>Gauss seidel>Successive over-relaxation according to the num of iterations both steady and unsteady
*SOR iteration method is the most effective iteration method as it took least No iteration for converging in both explicit and implicit compare to other two