Week 5.1 - Mid term project - Solving the steady and unsteady 2D heat conduction problem
- Top Boundary = 600 K
- Bottom Boundary = 900 K
- Left Boundary = 400 K
- Right Boundary = 800 K
- Initial temperature inside the domain = 298 K
- Top - Left corner = 500 K
- Top - Right corner = 700 K
- Bottom - Left corner = 650 K
- Bottom - Right corner = 850 K
- Absolute error criteria = 1e-4













clear all
close all
clc
n = 10;
x = linspace(0,1,n);
y = linspace(0,1,n);
dx = x(2) - x(1);
dy = dx;
nt = 1000;
dt = 0.02;
a = 1200;
k1 = (a*dt)/(dx^2);
k2 = (a*dt)/(dy^2);
CFL = k1+k2;
T = 300*ones(n,n);
T(1,:) = 600; % Top Boundary Temp. in Kelvin
T(end,:) = 900; % Bottom Boundary Temp. in Kelvin
T(:,1) = 400; % Left Boundary Temp. in Kelvin
T(:,end) = 800; % Right Boundary Temp. in Kelvin
T(1,1) = 500; % Top - Left corner Temp. in Kelvin
T(1,end) = 700; % Top - Right corner Temp. in Kelvin
T(end,1) = 650; % Bottom - Left corner Temp. in Kelvin
T(end,end) = 850; % Bottom - Right corner Temp. in Kelvin
jacobi_iter = 0;
jacobi_error = 9e9;
tol = 1e-4;
Told = T;
T_previous = Told;
term1 = (1+2*k1+2*k2)^(-1);
term2 = (k1*term1);
term3 = (k2*term1);
tic
for k = 1:nt
while jacobi_error > tol
for i = 2:(n-1)
for j = 2:(n-1)
H = Told(i-1,j)+Told(i+1,j);
V = Told(i,j-1)+Told(i,j+1);
T(i,j) = (T_previous(i,j)*term1)+(H*term2)+(V*term3);
end
end
jacobi_iter = jacobi_iter + 1;
jacobi_error = max(max(abs(Told-T)));
Told = T;
time_jc = toc;
end
T_previous = T;
end
figure(1)
contourf(x,y,T,'Showtext','on')
colormap(jet)
colorbar
xlabel('X Axis')
ylabel('Y Axis')
title(['Unsteady state Implicit Jacobi = ' num2str( jacobi_iter) ' Iteration'])
clear all
close all
clc
n = 10;
x = linspace(0,1,n);
y = linspace(0,1,n);
dx = x(2) - x(1);
dy = dx;
nt = 1000;
dt = 0.02;
a = 1200;
k1 = (a*dt)/(dx^2);
k2 = (a*dt)/(dy^2);
CFL = k1+k2;
T = 300*ones(n,n);
T(1,:) = 600; % Top Boundary Temp. in Kelvin
T(end,:) = 900; % Bottom Boundary Temp. in Kelvin
T(:,1) = 400; % Left Boundary Temp. in Kelvin
T(:,end) = 800; % Right Boundary Temp. in Kelvin
T(1,1) = 500; % Top - Left corner Temp. in Kelvin
T(1,end) = 700; % Top - Right corner Temp. in Kelvin
T(end,1) = 650; % Bottom - Left corner Temp. in Kelvin
T(end,end) = 850; % Bottom - Right corner Temp. in Kelvin
gauss_iter = 0;
gauss_error = 9e9;
tol = 1e-4;
Told = T;
T_previous = Told;
term1 = (1+2*k1+2*k2)^(-1);
term2 = (k1*term1);
term3 = (k2*term1);
tic
for k = 1:nt
while gauss_error > tol
for i = 2:(n-1)
for j = 2:(n-1)
H = T(i-1,j)+T(i+1,j);
V = T(i,j-1)+T(i,j+1);
T(i,j) = (T_previous(i,j)*term1)+(H*term2)+(V*term3);
end
end
gauss_iter = gauss_iter + 1;
gauss_error = max(max(abs(Told-T)));
Told = T;
time_gs = toc;
end
T_previous = Told;
end
figure(1)
contourf(x,y,T,'Showtext','on')
colormap(jet)
colorbar
xlabel('X Axis')
ylabel('Y Axis')
title(['UNSTEADY STATE IMPLICIT GAUSS SEIDEL = ' num2str( gauss_iter) ' Iteration'])
clear all
close all
clc
n = 10;
x = linspace(0,1,n);
y = linspace(0,1,n);
dx = x(2) - x(1);
dy = dx;
nt = 1000;
dt = 0.02;
a = 1200;
k1 = (a*dt)/(dx^2);
k2 = (a*dt)/(dy^2);
CFL = k1+k2;
T = 300*ones(n,n);
T(1,:) = 600; % Top Boundary Temp. in Kelvin
T(end,:) = 900; % Bottom Boundary Temp. in Kelvin
T(:,1) = 400; % Left Boundary Temp. in Kelvin
T(:,end) = 800; % Right Boundary Temp. in Kelvin
T(1,1) = 500; % Top - Left corner Temp. in Kelvin
T(1,end) = 700; % Top - Right corner Temp. in Kelvin
T(end,1) = 650; % Bottom - Left corner Temp. in Kelvin
T(end,end) = 850; % Bottom - Right corner Temp. in Kelvin
SOR_iter = 0;
SOR_error = 9e9;
tol = 1e-4;
Told = T;
T_previous = Told;
term1 = (1+2*k1+2*k2)^(-1);
term2 = (k1*term1);
term3 = (k2*term1);
w = 2/(1+sin(pi*dx)); % Relaxation parameter for SOR Method
%w = 1.2;
%%
tic
for k = 1:nt
while SOR_error > tol
for i = 2:(n-1)
for j = 2:(n-1)
H = T(i-1,j)+T(i+1,j);
V = T(i,j-1)+T(i,j+1);
T(i,j) = w*((T_previous(i,j)*term1)+(H*term2)+(V*term3)) - (w-1)*T(i,j);
end
end
SOR_iter = SOR_iter + 1;
SOR_error = max(max(abs(Told-T)));
Told = T;
time_sor = toc;
end
T_previous = T;
end
figure(1)
contourf(x,y,T,'Showtext','on')
colormap(jet)
colorbar
xlabel('X Axis')
ylabel('Y Axis')
title(['UNSTEADY STATE FOR IMPLICIT SOR = ' num2str( SOR_iter) ' Iteration'])






Unsteady state implicit SOR:

EXPLANATION:
Here, We find the Iteration and errors from the each results|
Sr. No. |
Method |
Iterations |
Errors |
|
1. |
Steady State (Jacobi) |
207 |
9.48e-05 |
|
2. |
Steady State (Gauss-Seidel) |
111 |
9.586e-05 |
|
3. |
Steady State (SOR) |
29 |
8.57e-05 |
|
4. |
Unsteady state Explicit |
- |
0 |
|
5. |
Unsteady state Implicit (Jacobi) |
206 |
9.83e-05 |
|
6. |
Unsteady state Implicit (Gauss-Seidel) |
111 |
9.32e-05 |
|
7. |
Unsteady state Implicit (SOR) |
29 |
7.71e-05 |
- From the table, we can conclude that the Jacobi method took lots of iteration to converge and the Successive over-relaxation method took the least, whereas the Gauss – seidel iteration lies between the Jacobi and SOR.
CONCLUSION:
- Thus, in MATLAB, the 2D linear heat conduction equation is been solved by using the point iterative technique using the methods Jacobi, Gauss – seidel, Successive over Relaxation (SOR) for both implicit and explicit scheme.
- The number of iteration and error values for each method is calculated and displayed in the above table.
- The temperature distribution plots are plotted for each method.