Project

2D Heat Conduction problem

The temperature distribution curve for 2D steady state conduction equation is shown below,from the figures it is clearly visible that the number of iterations in which solution converges starts decreasing from Jacobi to SOR, in case of Jacobi the number of iterations is 216 while in case of gauss seidel it is 115 and in case of SOR it is 30

Explicit Schemes:-

The temperature distribution curve for explicit schemes is shown below from the figure it is clearly visible that the number of iteration in case of Jacobi explicit is 426 iterations while in case of gauss seidel it is 334 and in case of SOR, it is 197.

Implicit Schemes:-

The figure shown below illustrates the temperature distribution in case of implicit schemes from the figure it is clearly visible that the number of iteration in each case is greater compared to explicit schemes. it takes 2471 iteration to converge in Jacobi method and 1901 in case of gauss-seidel while in case of SOR it is around 1679

in each case the rate of convergence is least in SOR method,

close all
clear all
clc

x = 1;
y = 1;
Nx = 10;
Ny = 10;
Lx = linspace(0,1,Nx);
Ly = linspace(0,1,Ny);
dx = x/(Nx-1);
dy = y/(Ny-1);

T = ones(Nx,Ny);
% Boundary conditions
% bottom boundary
T(1,2:end-1) = 900;
% top boundary 
T(Nx,2:end-1) = 600;
% left boundary
T(2:end-1,1) = 400;
% right boundary
T(2:end-1,Ny) = 800;
% top left boundary
T(Nx,1) = 500;
% bottom left boundary
T(1,1) = 650;
% top right boundary
T(Nx,Ny) = 700;
% bottom right boundary
T(1,Ny) = 850;
tol = 1e-4;

solver = 3;
 
% jacobi method 
if solver == 1;
    T = steady_state_jacobi(T,Lx,Ly,Nx,Ny,dx,dy,tol);
else if solver == 2;
        T = steady_state_gauss(T,Lx,Ly,Nx,Ny,dx,dy,tol);
    else solver == 3;
          T = steady_relax(T,Lx,Ly,Nx,Ny,dx,dy,tol);
        end
end
                

function T = steady_state_jacobi(T,Lx,Ly,Nx,Ny,dx,dy,tol)
[X,Y] = meshgrid(Lx,Ly);
jacobi_iter = 0;
error = 9e9;

k = (2/(dx^2) + 2/(dy^2));
Told = T;
tic
while(error>tol);
        for i = 2:Nx-1
            for j = 2:Ny-1
                term1 = (Told(i-1,j) + Told(i+1,j))/(k*dx^2);
                term2 = (Told(i,j+1) + Told(i,j-1))/(k*dy^2);
                T(i,j) = term1 + term2;
            end
        end
        error = max(max(abs(T-Told)));
        Told = T;
        jacobi_iter = jacobi_iter + 1;
end
toc
figure(1)
C= contourf(X,Y,T);
title(sprintf(\'Temperature Distribution using Jacobi method: %d iterations\',jacobi_iter))
xlabel(\'X Axis\')
ylabel(\'Y Axis\')
clabel(C,\'FontSize\',8)

colormap(jet) 
end


function T = steady_state_gauss(T,Lx,Ly,Nx,Ny,dx,dy,tol)
[X,Y] = meshgrid(Lx,Ly);
gauss_iter = 0;
error = 9e9;

k = (2/(dx^2) + 2/(dy^2));
Told = T;

while(error>tol);
        for i = 2:Nx-1
            for j = 2:Ny-1
                term1 = (T(i-1,j) + Told(i+1,j))/(k*dx^2);
                term2 = (Told(i,j+1) + T(i,j-1))/(k*dy^2);
                T(i,j) = term1 + term2;
            end
        end
        error = max(max(abs(T-Told)));
        Told = T;
        gauss_iter = gauss_iter + 1;
end
figure(1)
C= contourf(X,Y,T);
title(sprintf(\'Temperature distribution using gauss seidel %d iterations\',gauss_iter))
xlabel(\'X Axis\')
ylabel(\'Y Axise\')
clabel(C,\'FontSize\',8)

colormap(jet) 
end

function T = Steady_relax(T,Lx,Ly,Nx,Ny,dx,dy,tol)

[X,Y]=meshgrid(Lx,Ly);
relax_iter = 0;
error=5e9;

%Copy T for the iteration
T_old=T;

k= 2/dx^2 + 2/dy^2;
omega=2/(1+sin(pi*dx));
    while(error>tol)
        for i=2:Nx-1 
            for j=2:Ny-1
                term1=(T(i-1,j)+T_old(i+1,j))/(k*dx^2);
                term2=(T(i,j-1)+T_old(i,j+1))/(k*dy^2);
                T(i,j)=omega*(term1+term2)+(1-omega)*T_old(i,j);
            end  
        end 
        error=max(max(abs(T_old-T)));
        T_old=T;
        relax_iter = relax_iter +1;
    end
    

figure(1)
% for contouring 
C= contourf(X,Y,T);
title(sprintf(\'Temperature Distribution using successive over relaxation method %d iterations\',relax_iter));
xlabel(\'X Axis\');
ylabel(\'Y Axis\');
clabel(C,\'FontSize\',8);

% to distinguish between the colours of cold and hot area.
colormap(jet)

end

for transient analysis

close all
clear all
clc

x = 1;
y = 1;
Nx = 10;
Ny = 10;
Lx = linspace(0,1,Nx);
Ly = linspace(0,1,Ny);
dx = x/(Nx-1);
dy = y/(Ny-1);


start_time = 0;
end_time = 3;
dt = 0.01;
t = [start_time:dt:end_time];

T = ones(Nx,Ny);
% Boundary conditions
% bottom boundary
T(1,2:end-1) = 900;
% Top boundary
T(Nx,2:end-1) = 600;
% Left Boundary
T(2:end-1,1) = 400;
% Right Boundary
T(2:end-1,Ny) = 800;
% Top Left Boundary
T(Nx,1) = 500;
% bottom left boundary
T(1,1) = 650;
% top right boundary
T(Nx,Ny) = 700;
% bottom right boundary
T(1,Ny) = 850;

% thermal conductivity of aluminum in W/mk
k = 237;
% density of aluminium
rho = 2.7;
% specific heat of aluminium
Cp = 900;
alpha = 0.15;
%thermal diffucsivity 
%alpha = k/(rho*Cp);
k1 = (alpha*dt)/(dx^2);
k2 = (alpha*dt)/(dy^2);
tol = 1e-4;

solver = 3;
% for explicit and implicit transient function 

if solver == 1;
    T = jacobi_explicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol);
else if solver == 2;
        T = gauss_explicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol);
    else if solver == 3;
            T = SOR_explicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol);
        else if solver == 4;
                T = jacobi_implicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol);
            else if solver == 5;
                    T = gauss_implicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol);
                else solver == 6;
                    T = SOR_implicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol);
                end
            end
        end
    end
end

function T = jacobi_explicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol)
[X,Y] = meshgrid(Lx,Ly)
jacob_explicit_iter = 0;
error = 9e9;

Told = T;

for k =1:length(t)
    while(error>tol)
        for i = 2:Nx-1
            for j = 2:Ny-1
            
                T(i,j) = Told(i,j) + k1*(Told(i-1,j) - (2*Told(i,j)) + Told(i+1,j)) + k2*(Told(i,j-1) - (2*Told(i,j)) + Told(i,j+1));
            end
        end
        error = max(max(abs(Told-T)));
        Told = T;
        jacob_explicit_iter = jacob_explicit_iter + 1;
    end
end

figure(1)
C = contourf(X,Y,T);
colormap(jet);
clabel(C,\'FontSize\',10);
title(sprintf(\'Temperature distribution using jacobi explicit transient %d Iterations\',jacob_explicit_iter));
xlabel(\'X Axis\')
ylabel(\'Y Axis\')
end

function T = gauss_explicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol)
[X,Y] = meshgrid(Lx,Ly)
gauss_explicit_iter = 0;
error = 9e9;

Told = T;

for k =1:length(t)
    while(error>tol)
        for i = 2:Nx-1
            for j = 2:Ny-1
            
                T(i,j) = Told(i,j) + k1*(T(i-1,j) - (2*Told(i,j)) + Told(i+1,j)) + k2*(T(i,j-1) - (2*Told(i,j)) + Told(i,j+1));
            end
        end
        error = max(max(abs(Told-T)));
        Told = T;
        gauss_explicit_iter = gauss_explicit_iter + 1;
    end
end

figure(1)


C = contourf(X,Y,T);
colormap(jet);
clabel(C,\'FontSize\',10);
title(sprintf(\'Temperature distribution using gauss explicit transient %d Iterations\',gauss_explicit_iter));
xlabel(\'X Axis\')
ylabel(\'Y Axis\')
end

function T = SOR_explicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol)
[X,Y] = meshgrid(Lx,Ly)
SOR_explicit_iter = 0;
error = 9e9;

Told = T;
omega=2/(1+sin(pi*dx));

for k =1:length(t)
    while(error>tol)
        for i = 2:Nx-1
            for j = 2:Ny-1
            
                T(i,j) = omega*(Told(i,j) + k1*(T(i-1,j) - (2*Told(i,j)) + Told(i+1,j)) + k2*(T(i,j-1) - (2*T(i,j)) + Told(i,j+1))) + ((1-omega)*Told(i,j));
            end
        end
        error = max(max(abs(Told-T)));
        Told = T;
        SOR_explicit_iter = SOR_explicit_iter + 1;
    end
end

figure(1)
C = contourf(X,Y,T);
colormap(jet);
clabel(C,\'FontSize\',10);
title(sprintf(\'Temperature distribution using SOR explicit Transient %d Iterations\',SOR_explicit_iter));
xlabel(\'X Axis\')
ylabel(\'Y Axis\')
end

transient implicit schemes

function T = jacobi_implicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol)
[X,Y] = meshgrid(Lx,Ly)
jaco_iter_implicit = 0;

Told = T;
T_prev_dt = T;
term1 = (1 + (2*k1) + (2*k2))^-1;
term2 = k1*term1;
term3 = k2*term1;


for k=1:length(t)
    error = 9e9;
    while(error>tol)
        for i = 2:Nx-1
            for j = 2:Ny-1
                H=(Told(i-1,j)+Told(i+1,j));
                V=(Told(i,j+1)+Told(i,j-1));
                T(i,j)=(T_prev_dt(i,j)*term1)+(term2*H)+(term3*V);
            end
        end
        
        error = max(max(abs(Told-T)));
        Told = T;
        jaco_iter_implicit = jaco_iter_implicit + 1;
        
    end
    T_prev_dt = T;
end

C = contourf(X,Y,T);
colormap(jet);
clabel(C,\'FontSize\',12);
title(sprintf(\'transient Temperature DIstribution using Jacobi-implicit method, Iterations: %d\',jaco_iter_implicit));
xlabel(\'X Axis\')
ylabel(\'Y Axis\')


function T = gauss_implicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol)
[X,Y] = meshgrid(Lx,Ly)
gauss_iter_implicit = 0;

Told = T;
T_prev_dt = T;
term1 = (1 + (2*k1) + (2*k2))^-1;
term2 = k1*term1;
term3 = k2*term1;


for k=1:length(t)
    error = 9e9;
    while(error>tol)
        for i = 2:Nx-1
            for j = 2:Ny-1
                H=(T(i-1,j)+Told(i+1,j));
                V=(Told(i,j+1)+T(i,j-1));
                T(i,j)=(T_prev_dt(i,j)*term1)+(term2*H)+(term3*V);
            end
        end
        
        error = max(max(abs(Told-T)));
        Told = T;
        gauss_iter_implicit = gauss_iter_implicit + 1;
        
    end
    T_prev_dt = T;
end

C = contourf(X,Y,T);
colormap(jet);
clabel(C,\'FontSize\',12);
title(sprintf(\'transient Temperature DIstribution using gauss-implicit method, Iterations: %d\',gauss_iter_implicit));
xlabel(\'X Axis\')
ylabel(\'Y Axis\')

function T = SOR_implicit_transient(T,t,k1,k2,Lx,Ly,Nx,Ny,dx,dy,tol)
[X,Y] = meshgrid(Lx,Ly)
SOR_iter_implicit = 0;

omega=2/(1+sin(pi*dx));


Told = T;
T_prev_dt = T;
term1 = (1+(2*k1)+(2*k2))^-1;
term2 = k1*term1;
term3 = k2*term1;


for k=1:length(t)
    error = 9e9;
    while(error>tol)
        for i = 2:Nx-1
            for j = 2:Ny-1
                H=(T(i-1,j)+Told(i+1,j));
                V=(T(i,j-1)+Told(i,j+1));
                T(i,j)=omega*((T_prev_dt(i,j)*term1)+(H*term2)+(V*term3)) + (1-omega)*(T_prev_dt(i,j));
            end
        end
        
        error = max(max(abs(Told-T)));
        Told = T;
        SOR_iter_implicit = SOR_iter_implicit + 1;
        
    end
    T_prev_dt = T;
end

C = contourf(X,Y,T);
colormap(jet);
clabel(C,\'FontSize\',12);
title(sprintf(\'transient Temperature DIstribution using SOR-implicit method, Iterations: %d\',SOR_iter_implicit));
xlabel(\'X Axis\')
ylabel(\'Y Axis\')
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.