Week 5 - Mid term project - Solving the steady and unsteady 2D heat conduction problem
Here in this project we are going to solve Steady and Unsteady(Transient) 2D heat conduction problem with using Iterative solvers.
Here, the methods of solving Iterative solvers are :-
1)Jacobi Method
2)Gauss-Siedal Method
3)Successive Over Relaxation Method(SORs)
The Assumptions that we have taken is that :-
1)the domain is unit square,
2)assume (nx=ny),
3)Initial temperature to be taken as 300K
Boundary Condition for both(Steady and Unsteady(Transient) case) are :-
1)Top Boundary = 600 K
2)Bottom Boundary = 900 K
3)Left Boundary = 400 K
4)Right Boundary = 800 K;
Taking Governing Equation of 2D heat conduction are:-
1)Steady State condition:-

2)Unsteady (Transient) State Equation:-

1)Steady State condition:-

Discretization :-
Discretizing by Central Diffencing :-

Matlab Codes :-
1)Starting from Main code :-
clear all
close all
clc
nx=10;
ny=10;
%Boundary Conditions
T = 300*ones(nx,ny);
T(1,:) = 900;
T(end,:) = 600;
T(:,1) = 400;
T(:,end) = 800;
%Creating copy of T
Told = T;
x = linspace(0,1,nx);
y = linspace(0,1,ny);
error = 100;
iterative_solver = 3;
%Function
if iterative_solver == 1
solving_jacobi(nx,ny,T,Told,error);
end
if iterative_solver == 2
solving_GS(nx,ny,T,Told,error);
end
if iterative_solver == 3
solving_SOR(nx,ny,T,Told,error);
end
2)Steady State 2D Heat Conduction using Jacobi Method:-
function solving_jacobi(nx,ny,T,Told,error)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
%jacobi method
tol = 1e-4;
jacobi_iter = 1;
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));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',jacobi_iter);
title(title_text)
pause(0.03)
jacobi_iter = jacobi_iter+1;
end
end
3)Steady State 2D Heat Conduction using Gauss-Siedal Method:-
function solving_GS(nx,ny,T,Told,error)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
%Gauss siedal method
tol = 1e-4;
GS_iter = 1;
while(error>tol)
for i = 2:nx-1
for j = 2:ny-1
T(i,j) = 0.25*(T(i+1,j)+T(i-1,j)+T(i,j+1)+T(i,j-1));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',GS_iter);
title(title_text)
pause(0.03)
GS_iter = GS_iter+1;
end
end
4)Steady State 2D Heat Conduction using SOR Method:-
function solving_SOR(nx,ny,T,Told,error)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
%SOR method
tol = 1e-4;
w = 1.1;
SOR_iter = 1;
while(error>tol)
for i = 2:nx-1
for j = 2:ny-1
T(i,j) = 0.25*(w)*(T(i+1,j)+T(i-1,j)+T(i,j+1)+T(i,j-1))+((1-w)*Told(i,j));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',SOR_iter);
title(title_text)
pause(0.03)
SOR_iter = SOR_iter+1;
end
end
Following are the outputs ,plots for the respective methods:-
- JACOBI METHOD :- Iterations shows are 207 (Highest number of Iteration in Steady State Equation )
- GAUSS-SIEDEL METHOD:- Iterations shows are 111 (Moderation number of Iteration in Steady State Equation )

- SUCCESSIVE OVER RELAXATION METHOD:- Iterations shows are 91 (least number of Iteration in Steady State Equation )

So, the number of iteration in Steady State Equation is in order:-
Jacobi Method >GS Method>SOR Method
2) UNSTEADY STATE EQUATION :-

Discretization:-
Discretizing by Central Diffrencing :-



Matlab Codes :-
1)Starting From Main Code :-
%Transient 2D Heat conduction
clear all
close all
clc
nx=10;
ny=10;
%Boundary Conditions
T = 300*ones(nx,ny);
T(1,:) = 900;
T(end,:) = 600;
T(:,1) = 400;
T(:,end) = 800;
%Creating copy of T
Told = T;
x = linspace(0,1,nx);
y = linspace(0,1,ny);
error = 100;
dx = x(2)-x(1);
dy = y(2)-y(1);
iterative_solver = 6;
%Function
if iterative_solver == 1
solving_jacobi_impl(nx,ny,T,Told,error,dx,dy);
elseif iterative_solver == 2
solving_GS_impl(nx,ny,T,Told,error,dx,dy);
elseif iterative_solver == 3
solving_SOR_impl(nx,ny,T,Told,error,dx,dy);
elseif iterative_solver == 4
solving_jacobi_expl(nx,ny,T,Told,error,dx,dy);
elseif iterative_solver == 5
solving_GS_expl(nx,ny,T,Told,error,dx,dy);
elseif iterative_solver == 6
solving_SOR_expl(nx,ny,T,Told,error,dx,dy);
end
IMPLICIT METHOD :-
2) Unsteady State 2D Heat Conduction solved Implicitly using Jacobi Method:-
function solving_jacobi_impl(nx,ny,T,Told,error,dx,dy)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
alpha = 1.4;
co=0.20;
dt=(co*dx*dx)/alpha;
k1 = (alpha*dt)/(dx*dx);
k2 = (alpha*dt)/(dy*dy);
term1 = (1+(2*k1)+(2*k2))^-1;
term2 = k1*term1;
term3 = k2*term1;
Tprev = T;
%jacobi method
tol = 1e-4;
jacobi_iter = 1;
for nt = 1:1400
while(error>tol)
for i = 2:(nx-1)
for j = 2:(ny-1)
T(i,j) = term1*Tprev(i,j)+term2*(Told(i-1,j)+Told(i+1,j))+term3*(Told(i,j+1)+Told(i,j-1));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',jacobi_iter);
title(title_text)
pause(0.02)
jacobi_iter = jacobi_iter+1;
Tprev = T;
end
end
end
3) Unsteady State 2D Heat Conduction solved Implicitly using Gauss-Siedal Method:-
function solving_GS_impl(nx,ny,T,Told,error,dx,dy)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
alpha = 1.4;
co=0.20;
dt=(co*dx*dx)/alpha;
k1 = (alpha*dt)/(dx*dx);
k2 = (alpha*dt)/(dy*dy);
term1 = (1+(2*k1)+(2*k2))^-1;
term2 = k1*term1;
term3 = k2*term1;
Tprev = T;
%jacobi method
tol = 1e-4;
GS_impl_iter = 1;
for nt = 1:1400
while(error>tol)
for i = 2:(nx-1)
for j = 2:(ny-1)
T(i,j) = term1*Tprev(i,j)+term2*(T(i-1,j)+Told(i+1,j))+term3*(Told(i,j+1)+T(i,j-1));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',GS_impl_iter);
title(title_text)
pause(0.003)
GS_impl_iter = GS_impl_iter+1;
Tprev = T;
end
end
end
4) Unsteady State 2D Heat Conduction solved Implicitly using SOR Method:-
function solving_SOR_impl(nx,ny,T,Told,error,dx,dy)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
alpha = 1.4;
co=0.20;
dt=(co*dx*dx)/alpha;
k1 = (alpha*dt)/(dx*dx);
k2 = (alpha*dt)/(dy*dy);
term1 = (1+(2*k1)+(2*k2))^-1;
term2 = k1*term1;
term3 = k2*term1;
Tprev = T;
omega= 1.4;
%jacobi method
tol = 1e-4;
SOR_impl_iter = 1;
for nt = 1:1400
while(error>tol)
for i = 2:(nx-1)
for j = 2:(ny-1)
T(i,j) = (1-omega)*Tprev(i,j)+(omega)*(term1*Tprev(i,j)+term2*(T(i-1,j)+Told(i+1,j))+term3*(Told(i,j+1)+T(i,j-1)));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',SOR_impl_iter);
title(title_text)
pause(0.03)
SOR_impl_iter = SOR_impl_iter+1;
Tprev = T;
end
end
end
Following are the outputs ,plots for the respective methods:-
- JACOBI UNSTEADY IMPLICIT :- Iterations shows are 441 (Highest number of Iteration Solving implicitly in Unsteady State Equation )

- GAUSS-SIEDEL UNSTEADY IMPLICIT :- Iterations shows are 355 (Moderation number of Iteration Solving implicitly in Unsteady State Equation )

- SUCCESSIVE OVER RELAXATION:- Iterations shows are 233 (Least number of Iteration Solving implicitly in Unsteady State Equation )

So, the number of iteration in Steady State Equation is in order:-
Jacobi Method >GS Method>SOR Method
EXPLICIT METHOD:-
5) Unsteady State 2D Heat Conduction solved Implicitly using Jacobi Method:-
function solving_jacobi_expl(nx,ny,T,Told,error,dx,dy)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
alpha = 1.4;
co=0.20;
dt=(co*dx*dx)/alpha;
k1 = (alpha*dt)/(dx*dx);
k2 = (alpha*dt)/(dy*dy);
%jacobi method
tol = 1e-4;
jacobi_expl_iter = 1;
for nt = 1:1400
while(error>tol)
for i = 2:(nx-1)
for j = 2:(ny-1)
T(i,j) = Told(i,j)+k1*(Told(i+1,j)+Told(i-1,j)-2*Told(i,j))+k2*(Told(i,j+1)+Told(i,j-1)-2*Told(i,j));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',jacobi_expl_iter);
title(title_text)
pause(0.03)
jacobi_expl_iter = jacobi_expl_iter+1;
end
end
end
6) Unsteady State 2D Heat Conduction solved Explicitly using Gauss-Siedal Method:-
function solving_GS_expl(nx,ny,T,~,error,dx,dy)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
alpha = 1.4;
co=0.20;
dt=(co*dx*dx)/alpha;
k1 = (alpha*dt)/(dx*dx);
k2 = (alpha*dt)/(dy*dy);
Told = T;
%jacobi method
tol = 1e-4;
GS_expl_iter = 1;
for nt = 1:1400
while(error>tol)
for i = 2:(nx-1)
for j = 2:(ny-1)
T(i,j) = T(i,j)+k1*(Told(i+1,j)+T(i-1,j)-2*T(i,j))+k2*(Told(i,j+1)+T(i,j-1)-2*T(i,j));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',GS_expl_iter);
title(title_text)
pause(0.03)
GS_expl_iter = GS_expl_iter+1;
end
end
end
7) Unsteady State 2D Heat Conduction solved Explicitly using SOR Method:-
function solving_SOR_expl(nx,ny,T,Told,error,dx,dy)
x=linspace(0,1,nx);
y=linspace(0,1,ny);
alpha = 1.4;
co=0.20;
dt=(co*dx*dx)/alpha;
k1 = (alpha*dt)/(dx*dx);
k2 = (alpha*dt)/(dy*dy);
omega = 1.4;
%jacobi method
tol = 1e-4;
SOR_expl_iter = 1;
for nt = 1:1400
while(error>tol)
for i = 2:(nx-1)
for j = 2:(ny-1)
T(i,j) = omega*(T(i,j)+k1*(Told(i+1,j)+T(i-1,j)-2*T(i,j))+k2*(Told(i,j+1)+T(i,j-1)-2*T(i,j)))+((1-omega)*Told(i,j));
end
end
error = max(max(abs(T-Told)));
Told = T;
contourf(x,y,T)
colorbar
xlabel('X axis')
ylabel('Y axis')
title_text = sprintf('Iteration_number = %d',SOR_expl_iter);
title(title_text)
pause(0.03)
SOR_expl_iter = SOR_expl_iter+1;
end
end
end
Following are the outputs ,plots for the respective methods:-
- JACOBI UNSTEADY EXPLICIT :- Iterations shows are 255 (Highest number of Iteration Solving Explicitly in Unsteady State Equation )

- GAUSS-SIEDEL UNSTEADY EXPLICIT :- Iterations shows are 162 (Highest number of Iteration Solving Explicitly in Unsteady State Equation )

- SUCCESSIVE OVER RELAXATION UNSTEADY EXPLICIT :- Iterations shows are 87 (Highest number of Iteration Solving Explicitly in Unsteady State Equation )

So, the number of iteration in Steady State Equation is in order:-
Jacobi Method >GS Method>SOR Method
Conclusion
:-
1)Successive over Relaxation Method takes less time to converge as well as take less iteations also .
2)Steady state solution is the fastest to converge the and compute the solution.
3)Explicit Method takes less time to converge as well as take less iteations also.