Project

2D heat conduction

Formula for 2D Heat Conduction Equation :-

1) For Transient State Analysis

`((del^2T)/(delx^2)+(del^2T)/(dely^2))alpha=(delT)/(delt)`

2) For Steady state analysis

`(del^2T)/(delx^2)+(del^2T)/(dely^2)=0`

Some of the constant taken for solving the equation :-

  • Number of grid points along x-direction nx = 10
  • Number of grid points along x-direction ny = ny
  • Length of domain in both x and y direction L = 1 m
  • Temperature taken at all node except Boundary condition is 1K
  • Time step dt = 0.005
  • Alpha αα = 0.25
  • error = 9e9
  • tolerance = 1e-4

Transient State Analysis using Jacobi method implicitl

% Transient State Analysis using Jacobi method implicitly

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny);

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Take the value of dt = 0.025
dt = 0.005;
% Creating the copy of u
Told = T;
% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k1 and k2
k1 = alpha*(dt/dx^2);
k2 = alpha*(dt/dy^2);

% Iteration calculation
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% jacobi method
if iterative_solver == 1
    jacobi_iteration = 1;
    while error > tolerance
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = Told(i-1,j);
                Tt = Told(i,j+1);
                Tb = Told(i,j-1);
                term1 = (1+2*k1+2*k2);
                T(i,j) = ((Told(i,j))+(k1*(Tr+Tl))+(k2*(Tt+Tb)))/term1;
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        Told = T;
        
        colormap(jet)
        contourf(x,y,T)
        jacobi_iteration = jacobi_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', jacobi_iteration);
        title(title_text)
        colorbar
        pause(0.03)
    end
end

RESULT:

\"\"

Transient State Analysis using Gauss Seidel method implicitly

% Transient State Analysis using Gauss Seidel method implicitly

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny);

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Take the value of dt = 0.025
dt = 0.005;
% Creating the copy of u
Told = T;
% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k1 and k2
k1 = alpha*(dt/dx^2);
k2 = alpha*(dt/dy^2);

% Iteration calculation
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% Gauss Seidel method
if iterative_solver == 1
    Gauss_iteration = 1;
    while error > tolerance
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = T(i-1,j);
                Tt = Told(i,j+1);
                Tb = T(i,j-1);
                term1 = (1+2*k1+2*k2);
                T(i,j) = ((Told(i,j))+(k1*(Tr+Tl))+(k2*(Tt+Tb)))/term1;
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        Told = T;
        
        colormap(jet)
        contourf(x,y,T)
        Gauss_iteration = Gauss_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', Gauss_iteration);
        title(title_text)
        colorbar
        pause(0.03)
    end
end

RESULT:

\"\"

Transient State Analysis using SOR method implicitly:

% Transient State Analysis using SOR method implicitly

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny);

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Take the value of dt = 0.025
dt = 0.005;
% Creating the copy of u
Told = T;
% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k1 and k2
k1 = alpha*(dt/dx^2);
k2 = alpha*(dt/dy^2);

% Iteration calculation
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% SOR method
if iterative_solver == 1
    SOR_iteration = 1;
    while error > tolerance
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = Told(i-1,j);
                Tt = Told(i,j+1);
                Tb = Told(i,j-1);
                term1 = (1+2*k1+2*k2);
                T(i,j) = (Told(i,j)*(1-alpha)) + alpha*(((Told(i,j))+(k1*(Tr+Tl))+(k2*(Tt+Tb)))/term1);
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        Told = T;
        
        colormap(jet)
        contourf(x,y,T)
        SOR_iteration = SOR_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', SOR_iteration);
        title(title_text)
        colorbar
        pause(0.03)
    end
end

RESULT:

\"\"

Transient State Analysis using Jacobi method Explicitly:

% Transient State Analysis using Jacobi method explicitly

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny);

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Take the value of dt = 0.025
dt = 0.005;
% Creating the copy of u
Told = T;
% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k1 and k2
k1 = alpha*(dt/dx^2);
k2 = alpha*(dt/dy^2);

% Iteration calculation
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% jacobi method
if iterative_solver == 1
    jacobi_iteration = 1;
    while error > tolerance
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = Told(i-1,j);
                Tt = Told(i,j+1);
                Tb = Told(i,j-1);
                term1 = (1-2*k1-2*k2);
                T(i,j) = ((Told(i,j)*term1)+(k1*(Tr+Tl))+(k2*(Tt+Tb)));
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        Told = T;
        
        colormap(jet)
        contourf(x,y,T)
        jacobi_iteration = jacobi_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', jacobi_iteration);
        title(title_text)
        colorbar
        pause(0.03)
    end
end

RESULT:

\"\"

Transient State Analysis using Gauss Seidel method Explicitly

% Transient State Analysis using Gauss Seidel method explicitly

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny);

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Take the value of dt = 0.025
dt = 0.005;
% Creating the copy of u
Told = T;
% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k1 and k2
k1 = alpha*(dt/dx^2);
k2 = alpha*(dt/dy^2);

% Iteration calculation
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% Gauss Seidel method
if iterative_solver == 1
    Gauss_seidel_iteration = 1;
    while error > tolerance
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = T(i-1,j);
                Tt = Told(i,j+1);
                Tb = T(i,j-1);
                term1 = (1-2*k1-2*k2);
                T(i,j) = ((Told(i,j)*term1)+(k1*(Tr+Tl))+(k2*(Tt+Tb)));
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        Told = T;
        
        colormap(jet)
        contourf(x,y,T)
        Gauss_seidel_iteration = Gauss_seidel_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', Gauss_seidel_iteration);
        title(title_text)
        colorbar
        pause(0.03)
    end
end

RESULT:

\"\"

Transient State Analysis using SOR method Explicitly

% Transient State Analysis using SOR method explicitly

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny);

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Take the value of dt = 0.025
dt = 0.005;
% Creating the copy of u
Told = T;
% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k1 and k2
k1 = alpha*(dt/dx^2);
k2 = alpha*(dt/dy^2);

% Iteration calculation
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% SOR method
if iterative_solver == 1
    SOR_iteration = 1;
    while error > tolerance
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = Told(i-1,j);
                Tt = Told(i,j+1);
                Tb = Told(i,j-1);
                term1 = (1-2*k1-2*k2);
                T(i,j) = (Told(i,j)*(1-alpha)) + alpha*((Told(i,j)*term1)+(k1*(Tr+Tl))+(k2*(Tt+Tb)));
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        Told = T;
        
        colormap(jet)
        contourf(x,y,T)
        SOR_iteration = SOR_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', SOR_iteration);
        title(title_text)
        colorbar
        pause(0.03)
    end
end

RESULT:

\"\"

Steady State Analysis using Jacobi method

% Steady State Analysis using Jacobi method

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny);

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Creating the copy of u
Told = T;

% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k
k = (2*(dx^2+dy^2))/(dx^2*dy^2);

% Iteration calculation
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% jacobi method
if iterative_solver == 1
    jacobi_iteration = 1;
    while error > tolerance
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = Told(i-1,j);
                Tt = Told(i,j+1);
                Tb = Told(i,j-1);
                
                T(i,j) = (((Tr+Tl)/dx^2)+((Tt+Tb)/dy^2))/k;
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        Told = T;
        
        colormap(jet)
        contourf(x,y,T)
        jacobi_iteration = jacobi_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', jacobi_iteration);
        title(title_text)
        colorbar
        pause(0.03)
    end
end

RESULT

\"\"

Steady State Analysis using Gauss Seidel method

% Steady State Analysis using Gauss Seidel method

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny);

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Creating the copy of u
Told = T;

% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k
k = (2*(dx^2+dy^2))/(dx^2*dy^2);

% Iteration calculation
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% Gauss Seidel method
if iterative_solver == 1
    Gauss_Seidal_iteration = 1;
    while error > tolerance
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = T(i-1,j);
                Tt = Told(i,j+1);
                Tb = T(i,j-1);
                
                T(i,j) = (((Tr+Tl)/dx^2)+((Tt+Tb)/dy^2))/k;
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        Told = T;
        
        colormap(jet)
        contourf(x,y,T)
        Gauss_Seidal_iteration = Gauss_Seidal_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', Gauss_Seidal_iteration);
        title(title_text)
        colorbar
        pause(0.03)
    end
end

RESULT

\"\"

Steady State Analysis using SOR method

% Steady State Analysis using SOR method

close all
clear all
clc

% Inputs
nx = 10;
ny = nx;

% Calculating the value for x and y
x = linspace(0,1,nx);
dx = x(2)-x(1);
y = linspace(0,1,ny);
dy = y(2)-y(1);

% Defining the value of Temperature
T = ones(nx,ny)*399;

% Boundary condition for Temperature
T(:,1) = 400;
T(1,:) = 600;
T(:,end) = 800;
T(end,:) = 900;

% Creating the copy of u
Told = T;

% Assume the value of alpha = 0.5
alpha = 0.25;

% Calculating the value of k
k = (2*(dx^2+dy^2))/(dx^2*dy^2);

% Iteration calculation condition
iterative_solver = 1;

% putting the value of error and tolerance
error = 9e9;
tolerance = 1e-4;

% SOR method
if iterative_solver == 1
    SOR_iteration = 1;
    while error > tolerance
        % Nodal loop
        for i = 2:nx-1
            for j = 2:ny-1
                Tr = Told(i+1,j);
                Tl = Told(i-1,j);
                Tt = Told(i,j+1);
                Tb = Told(i,j-1);
                
                T(i,j) = (Told(i,j)*(1-alpha)) + alpha*((((Tr+Tl)/dx^2)+((Tt+Tb)/dy^2))/k);
            end
        end
        error_n = max(abs(Told-T));
        error = max(error_n);
        
        % Update the value Told after compleating every nodal loop
        Told = T;
        
        % Plotting the graph to showing the temperature chainging
        colormap(jet)
        contourf(x,y,T);
        SOR_iteration = SOR_iteration + 1;
        title_text = sprintf(\'Iteration Number = %d\', SOR_iteration);
        title(title_text)
        xlabel(\'x-axis\')
        ylabel(\'y-axis\')
        colorbar
        pause(0.03)
    end
end

RESULT:

\"\"

RESULT OF THE PLOTS:

  • For Transient State Analysis Implicitly the result comes out to total iteration by jacobi is 693, Gauss Seidel is 606 and by Successive over-relaxation is 2463.
  • For Transient State Analysis Explicitly the result comes out to total iteration by jacobi is 506, Gauss Seidel is 416 and by Successive over-relaxation is 1808.
  • For Steady State Analysis the result comes out to total iteration by jacobi is 217, Gauss Seidel is 117 and by Successive over-relaxation is 731.
  • So by all the above result the fastest result comes out in steady state analysis using Gauss Seidal method in only 117 iteration.
  • From the above Transient State Analysis both Explicit and Implicit, explicit method is much faster than the implicit method in all the three method.
  • Comapare to all the three method Gauss seidel method will give result in minimum iteration.

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.