Challenge

Week 5.1 - Mid term project - Solving the steady and unsteady 2D heat conduction problem

OBJECTIVE : 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;

GIVEN :

Top Boundary = 600 K

Bottom Boundary = 900 K

Left Boundary = 400 K

Right Boundary = 800 K

You will implement the following methods for solving implicit equations.

1. Jacobi

2. Gauss-seidel

3. Successive over-relaxation

Your absolute error criteria is 1e-4

STEADY STATE EQUATION :

MAIN CODE :

jacobi iterations (Steady)

close all
clear all
clc
% soving the steady state 2D heat conduction
% input parameters
% number of grid points
nx = 10;
ny = nx;

x = linspace(0,1,nx);
y = linspace(0,1,ny);

dx = x(2)-x(1);
dy = dx;

% absolute error criteria > tolerance
error = 9e9;
tolerance = 1e-4;

% boundary condition
T_L = 400;
T_R = 800;
T_T = 600;
T_B = 900;

T = 300*ones(nx,ny);
T(2:ny - 1, 1) = T_L;
T(2:ny - 1, nx) = T_R;
T(1, 2:nx - 1) = T_T;
T(ny, 2:nx - 1) = T_B;

% calculating average temp at corners
T(1,1) = (T_T + T_L)/2;
T(nx,ny) = (T_R + T_B)/2;
T(1,ny) = (T_T + T_R)/2;
T(nx,1) = (T_L + T_B)/2;

% Assigning original values to T
T_initial = T;
T_old = T;

% JACOBI METHOD
iterative_solver = 1;
if iterative_solver ==1
jacobi_iteration = 1;

while(error > tolerance)

for i = 2:nx - 1

for j = 2:ny -1
T(i,j) = 0.25*(T_old(i-1,j) +T_old(i+1,j) +T_old(i,j-1) +T_old(i,j+1));
end
end
error = max(max(abs(T_old - T)));
T_old = T;
jacobi_iteration = jacobi_iteration +1;
end
end

% plotting
figure(1)
contourf(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')

xlabel('xaxis')
ylabel('yaxis')
title(sprintf('No of jacobi iterations(Implicit) = %d',jacobi_iteration));
pause(0.03);

MAIN CODE :

Gauss seidal method (Steady)

close all
clear all
clc
% soving the steady state 2D heat conduction (Gauss seidal method)

% input parameters
% number of grid points
nx = 10;
ny = nx;

x = linspace(0,1,nx);
y = linspace(0,1,ny);

dx = x(2)-x(1);
dy = dx;

% absolute error criteria > tolerance
error = 9e9;
tolerance = 1e-4;

% boundary condition
T_L = 400;
T_R = 800;
T_T = 600;
T_B = 900;

T = 300*ones(nx,ny);
T(2:ny - 1, 1) = T_L;
T(2:ny - 1, nx) = T_R;
T(1, 2:nx - 1) = T_T;
T(ny, 2:nx - 1) = T_B;

% calculating average temp at corners
T(1,1) = (T_T + T_L)/2;
T(nx,ny) = (T_R + T_B)/2;
T(1,ny) = (T_T + T_R)/2;
T(nx,1) = (T_L + T_B)/2;

% Assigning original values to T
T_initial = T;
T_old = T;

% Gauss seidal method
iterative_solver = 2;
if iterative_solver ==2
Gauss_seidal_iteration = 1;

while(error > tolerance)

for i = 2:nx - 1

for j = 2:ny -1
T(i,j) = 0.25*(T(i-1,j) +T_old(i+1,j) +T(i,j-1) +T_old(i,j+1));
end
end
error = max(max(abs(T_old - T)));
T_old = T;
Gauss_seidal_iteration = Gauss_seidal_iteration +1;
end
end

% plotting
figure(1)
contourf(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')

xlabel('xaxis')
ylabel('yaxis')
title(sprintf('No of Gauss seidal iteration(Implicit) = %d',Gauss_seidal_iteration));
pause(0.03);

MAIN CODE :

successive over relaxation (Steady)

close all
clear all
clc
% soving the steady state 2D heat conduction (successive over relaxation)
% input parameters
% number of grid points
nx = 10;
ny = nx;

x = linspace(0,1,nx);
y = linspace(0,1,ny);

dx = x(2)-x(1);
dy = dx;

% absolute error criteria > tolerance
error = 9e9;
tolerance = 1e-4;
omega = 1.2;

% boundary condition
T_L = 400;
T_R = 800;
T_T = 600;
T_B = 900;

T = 300*ones(nx,ny);
T(2:ny - 1, 1) = T_L;
T(2:ny - 1, nx) = T_R;
T(1, 2:nx - 1) = T_T;
T(ny, 2:nx - 1) = T_B;

% calculating average temp at corners
T(1,1) = (T_T + T_L)/2;
T(nx,ny) = (T_R + T_B)/2;
T(1,ny) = (T_T + T_R)/2;
T(nx,1) = (T_L + T_B)/2;

% Assigning original values to T
T_initial = T;
T_old = T;

% successive over relaxation method
iterative_solver = 3;
if iterative_solver ==3
successive_over_relaxation_iteration = 1;

while(error > tolerance)

for i = 2:nx - 1

for j = 2:ny -1
T(i,j) = omega*(0.25*(T(i-1,j) +T_old(i+1,j) +T(i,j-1) +T_old(i,j+1))) +(1 - omega)*T_old(i,j);
end
end
error = max(max(abs(T_old - T)));
T_old = T;
successive_over_relaxation_iteration = successive_over_relaxation_iteration +1;
end
end

% plotting
figure(1)
contourf(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')

xlabel('xaxis')
ylabel('yaxis')
title(sprintf('successive_over_relaxation_iteration(Implicit) = %d',successive_over_relaxation_iteration));
pause(0.03);

UNSTEADY STATE EQUATION :

MAIN CODE :

No of unsteady jacobi iterations(implicit)

close all
clear all
clc
% soving the unsteady state 2D heat conduction
% input parameters
% number of grid points
nx = 10;
ny = nx;


x = linspace(0,1,nx);
y = linspace(0,1,ny);

dx = x(2)-x(1);
dy = dx;

% absolute error criteria > tolerance
error = 9e9;
tolerance = 1e-4;
dt = 10;
nt= 1000/dt;

% boundary condition
T_L = 400;
T_R = 800;
T_T = 600;
T_B = 900;

T = 300*ones(nx,ny);
T(2:ny - 1, 1) = T_L;
T(2:ny - 1, nx) = T_R;
T(1, 2:nx - 1) = T_T;
T(ny, 2:nx - 1) = T_B;

% calculating average temp at corners
T(1,1) = (T_T + T_L)/2;
T(nx,ny) = (T_R + T_B)/2;
T(1,ny) = (T_T + T_R)/2;
T(nx,1) = (T_L + T_B)/2;

% Assigning original values to T
T_initial = T;
T_old = T;

% successive over relaxation
k1 = 1.1*(dt/(dx^2));
k2 = 1.1*(dt/(dy^2));

jacobi_iteration = 1;
for k =1:nt

error= 1e9;

while(error > tolerance)

for i = 2:nx - 1

for j = 2:ny -1
term_1 = (1/(1+2*k1+2*k2));
term_2 = k1*term_1;
term_3 = k2*term_1;
H = (T_old(i-1,j))+(T_old(i+1,j));
V= (T_old(i,j+1))+(T_old(i,j-1));
T(i,j) = (T_initial(i,j)*term_1)+(H*term_2)+(V*term_3);
end
end
error = max(max(abs(T_old - T)));
T_old = T;
jacobi_iteration = jacobi_iteration +1;
end
T_intial =T;
end
% plotting
figure(1)
contourf(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')

xlabel('xaxis')
ylabel('yaxis')
title(sprintf('No of unsteady jacobi iterations(implicit) = %d',jacobi_iteration));
pause(0.03);

MAIN CODE :

No of unsteady gauss seidal iteration(implicit)

close all
clear all
clc
% soving the unsteady state 2D heat conduction
% input parameters
% number of grid points
nx = 10;
ny = nx;


x = linspace(0,1,nx);
y = linspace(0,1,ny);

dx = x(2)-x(1);
dy = dx;

% absolute error criteria > tolerance
error = 9e9;
tolerance = 1e-4;
dt = 10;
nt=1000/dt;


% boundary condition
T_L = 400;
T_R = 800;
T_T = 600;
T_B = 900;

T = 300*ones(nx,ny);
T(2:ny - 1, 1) = T_L;
T(2:ny - 1, nx) = T_R;
T(1, 2:nx - 1) = T_T;
T(ny, 2:nx - 1) = T_B;

% calculating average temp at corners
T(1,1) = (T_T + T_L)/2;
T(nx,ny) = (T_R + T_B)/2;
T(1,ny) = (T_T + T_R)/2;
T(nx,1) = (T_L + T_B)/2;

% Assigning original values to T
T_old = T;
T_initial = T;


% calculation of 2D unsteady successive over relaxation
k1 = 1.1*(dt/(dx^2));
k2 = 1.1*(dt/(dy^2));

gauss_seidal_iteration = 1;
for k =1:nt
error = 1e9;


while(error > tolerance)

for i = 2:nx - 1

for j = 2:ny -1
term_1 = 1/(1+(2*k1)+(2*k2));
term_2 = k1*term_1;
term_3 = k2*term_1;
H = (T(i-1,j))+(T_old(i+1,j));
V= (T(i,j+1))+(T_old(i,j-1));
T(i,j) = (T_initial(i,j)*term_1)+(H*term_2)+(V*term_3);
end

end
error = max(max(abs(T_old - T)));
T_old = T;
gauss_seidal_iteration = gauss_seidal_iteration +1;
end
T_intial =T;
end

% plotting
figure(1)
contourf(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')

xlabel('xaxis')
ylabel('yaxis')
title(sprintf('No of unsteady gauss seidal iteration(implicit) = %d', gauss_seidal_iteration));
pause(0.03);

MAIN CODE :

No of successive over relaxation iteration(implicit)

close all
clear all
clc
% soving the unsteady state 2D heat conduction
% input parameters
% number of grid points
nx = 10;
ny = nx;


x = linspace(0,1,nx);
y = linspace(0,1,ny);

dx = x(2)-x(1);
dy = dx;

% absolute error criteria > tolerance
error = 9e9;
tolerance = 1e-4;
dt = 10;
nt = 1000/dt;
omega =1.1;


% boundary condition
T_L = 400;
T_R = 800;
T_T = 600;
T_B = 900;

T = 300*ones(nx,ny);
T(2:ny - 1, 1) = T_L;
T(2:ny - 1, nx) = T_R;
T(1, 2:nx - 1) = T_T;
T(ny, 2:nx - 1) = T_B;

% calculating average temp at corners
T(1,1) = (T_T + T_L)/2;
T(nx,ny) = (T_R + T_B)/2;
T(1,ny) = (T_T + T_R)/2;
T(nx,1) = (T_L + T_B)/2;

% Assigning original values to T
T_initial = T;
T_old = T;
T_end = T;

% successive over relaxation
k1 = 1.1*(dt/(dx^2));
k2 = 1.1*(dt/(dy^2));

successive_over_relaxation_iteration = 1;
for k =1:nt
error = 9e9;


while(error > tolerance)

for i = 2:nx - 1

for j = 2:ny -1
term_1 = 1/(1+(2*k1)+(2*k2));
term_2 = k1*term_1;
term_3 = k2*term_1;
H = (T(i-1,j))+(T_old(i+1,j));
V= (T(i,j+1))+(T_old(i,j-1));
T(i,j) = (T_initial(i,j)*term_1)+(H*term_2)+(V*term_3);
T_end(i,j) = ((1-omega)*T_old(i,j))+(T(i,j)*omega);
end
end
error = max(max(abs(T_old - T)));
T_old = T;
successive_over_relaxation_iteration = successive_over_relaxation_iteration +1;

end
T_intial =T;

% plotting
figure(1)
contourf(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')

xlabel('xaxis')
ylabel('yaxis')
title(sprintf('No of successive over relaxation iteration(implicit) = %d',successive_over_relaxation_iteration));
pause(0.03);
end

MAIN CODE :

unsteady iteration Explicit

close all
clear all
clc
% soving the steady state 2D heat conduction (successive over relaxation)
% input parameters
% number of grid points
nx = 10;
ny = nx;
nt = 1000;


x = linspace(0,1,nx);
y = linspace(0,1,ny);

dx = x(2)-x(1);
dy = dx;

% absolute error criteria > tolerance
error = 9e9;
tolerance = 1e-4;
dt = 1e-3;
omega = 1.1;

% boundary condition
T_L = 400;
T_R = 800;
T_T = 600;
T_B = 900;

T = 300*ones(nx,ny);
T(2:ny - 1, 1) = T_L;
T(2:ny - 1, nx) = T_R;
T(1, 2:nx - 1) = T_T;
T(ny, 2:nx - 1) = T_B;

% calculating average temp at corners
T(1,1) = (T_T + T_L)/2;
T(nx,ny) = (T_R + T_B)/2;
T(1,ny) = (T_T + T_R)/2;
T(nx,1) = (T_L + T_B)/2;

% Assigning original values to T
T_initial = T;
T_old = T;

% successive over relaxation method
iterative_solver = 1;
k1 = 1.1*(dt/(dx^2));
k2 = 1.1*(dt/(dx^2));

if iterative_solver ==1
steady_explicit = 1;

for k =1:nt
error = 1;

while(error > tolerance)

for i = 2:nx - 1

for j = 2:ny -1
term_1 = T_old(i,j);
term_2 = k1*(T_old(i+1,j) - 2*T_old(i,j) + (T_old(i-1,j)));
term_3 = k2*(T_old(i,j+1) - 2*T_old(i,j) + T_old(i,j-1));
T(i,j) = term_1 + term_2 + term_3;
end
end
error = max(max(abs(T_old - T)));
T_old = T;
steady_explicit = steady_explicit +1;
end
end
end

% plotting
figure(1)
contourf(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')

xlabel('xaxis')
ylabel('yaxis')
title(sprintf('No of unsteady iteration explicit = %d', steady_explicit));
pause(0.03);

CONCLUSION :

Jacobi > gauss seidal > successive over relaxation according to the no of iterations computed for all methods and schemes.

When comparing steady and unsteady state, it is proven that steady state is the most successful one as it takes least number of iterations and least time to complete.

SOR iteration method is the most effective method as it took least number if iterations for converging solutions in the both (explicit and implict) compared to jacobi and gauss seidal.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.