Challenge

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

Aim :

To 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;

Solution :

Below, is the sequence of several programs starting with IMPLICIT Scheme of steady and unsteady state conditions for three iterative methods Jacobi, Gauss-Seidel and SOR followed by EXPLICIT Scheme for Unsteady/transient Scheme.

IMPLICIT Scheme :

Jacobi Iteration :

close all
clear all
clc

% Solving the steady state 2D heat conduction (Jacobi Method)

% Input paramaters
% 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;

% Defining boundary conditions
T_L = 400;
T_T = 600;
T_R = 800;
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;

% Calculatiing Average temperatures 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;

% Calculation of 2D staedy heat conduction EQUATION by 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)
contour(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')
xlabel('X-Axis')
ylabel('Y-Axis')
title(sprintf('No. of Jacobi Iterations (IMPLICIT) = %d', jacobi_iteration));
pause(0.03)

Output :

Gauss-Seidel Method :

close all
clear all
clc

% Solving the steady state 2D heat conduction (Gauss-Seidel Method)

% Input paramaters
% 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;

% Defining boundary conditions
T_L = 400;
T_T = 600;
T_R = 800;
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;

% Calculatiing Average temperatures 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;

% Calculation of 2D staedy heat conduction EQUATION by GAUSS-DEIDEL METHOD

iterative_solver = 2;

if iterative_solver == 2
    Gauss_seidel_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_seidel_iteration = Gauss_seidel_iteration + 1;

    end
end

% Plotting
figure(1)
contour(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')
xlabel('X-Axis')
ylabel('Y-Axis')
title(sprintf('No. of Gauss-Seidel Iterations (IMPLICIT) = %d', Gauss_seidel_iteration));
pause(0.03)close all
clear all
clc

% Solving the steady state 2D heat conduction (Gauss-Seidel Method)

% Input paramaters
% 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;

% Defining boundary conditions
T_L = 400;
T_T = 600;
T_R = 800;
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;

% Calculatiing Average temperatures 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;

% Calculation of 2D staedy heat conduction EQUATION by GAUSS-DEIDEL METHOD

iterative_solver = 2;

if iterative_solver == 2
    Gauss_seidel_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_seidel_iteration = Gauss_seidel_iteration + 1;

    end
end

% Plotting
figure(1)
contour(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')
xlabel('X-Axis')
ylabel('Y-Axis')
title(sprintf('No. of Gauss-Seidel Iterations (IMPLICIT) = %d', Gauss_seidel_iteration));
pause(0.03)

Output :

Successive - Over Iteration :

close all
clear all
clc

% Solving the steady state 2D heat conduction (Successive over-relaxation Method)

% Input paramaters
% 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;

% Defining boundary conditions
T_L = 400;
T_T = 600;
T_R = 800;
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;

% Calculatiing Average temperatures 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;

% Calculation of 2D staedy heat conduction EQUATION by 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)
contour(x,y,T)
clabel(contourf(x,y,T))
colorbar
colormap(jet)
set(gca, 'ydir', 'reverse')
xlabel('X-Axis')
ylabel('Y-Axis')
title(sprintf('No. of Successive Over-Relaxation Iterations (IMPLICIT) = %d', Successive_Over_Relaxation_iteration));
pause(0.03)

Output :

Implicit Scheme Unsteady / Transient Condition :

Jacobi Iteration :

close all
clear all
clc

% Solving the Unsteady state 2D heat conduction by Jacobi Method(EXPLICIT SCHEME)

% Input paramaters
% Number of grid points
nx = 10;
ny = nx;
nt = 1400;

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;

% Defining boundary conditions
T_L = 400;
T_T = 600;
T_R = 800;
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;

% Calculatiing Average temperatures 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 Unstaedy heat conduction EQUATION by JACOBI METHOD
k1 = 1.1*(dt/(dx^2));
k2 = 1.1*(dt/(dy^2));

jacobi_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_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_initial = T;

    % Plotting
    figure(1)
    contour(x,y,T)
    clabel(contourf(x,y,T))
    colorbar
    colormap(jet)
    set(gca, 'ydir', 'reverse')
    xlabel('X-Axis')
    ylabel('Y-Axis')
    title(sprintf('No. of Unsteady Jacobi Iterations (EXPLICIT) = %d', jacobi_iteration));
    pause(0.03)

end

Output :

Gauss - Seidel Method :

close all
clear all
clc

% Solving the Unsteady state 2D heat conduction by Gauss-Seidel Method(EXPLICIT SCHEME)

% Input paramaters
% Number of grid points
nx = 10;
ny = nx;
nt = 1400;

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;

% Defining boundary conditions
T_L = 400;
T_T = 600;
T_R = 800;
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;

% Calculatiing Average temperatures 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 Unstaedy heat conduction EQUATION by GAUSS-SEIDEL METHOD
k1 = 1.1*(dt/(dx^2));
k2 = 1.1*(dt/(dy^2));

gauss_seidel_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);

            end

        end

        error = max(max(abs(T_old - T)));
        T_old = T;
        gauss_seidel_iteration = gauss_seidel_iteration + 1;

    end

    T_initial = T;

    % Plotting
    figure(1)
    contour(x,y,T)
    clabel(contourf(x,y,T))
    colorbar
    colormap(jet)
    set(gca, 'ydir', 'reverse')
    xlabel('X-Axis')
    ylabel('Y-Axis')
    title(sprintf('No. of Unsteady Gauss-seidel Iterations (EXPLICIT) = %d', gauss_seidel_iteration));
    pause(0.03)

end

Output :

Successive - Over Iteration Method :

close all
clear all
clc

% Solving the Unsteady state 2D heat conduction by Successive over-relaxation Method(EXPLICIT SCHEME)

% Input paramaters
% Number of grid points
nx = 10;
ny = nx;
nt = 1400;

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;

% Defining boundary conditions
T_L = 400;
T_T = 600;
T_R = 800;
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;

% Calculatiing Average temperatures 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;
T_end = T;

% Calculation of 2D Unstaedy heat conduction EQUATION by SUCCESSIVE OVER-RELAXATION METHOD
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_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);
                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_end;
        successive_over_relaxation_iteration = successive_over_relaxation_iteration + 1;

    end

    T_initial = T_end;

    % Plotting
    figure(1)
    contour(x,y,T)
    clabel(contourf(x,y,T))
    colorbar
    colormap(jet)
    set(gca, 'ydir', 'reverse')
    xlabel('X-Axis')
    ylabel('Y-Axis')
    title(sprintf('No. of Unsteady Successive over-relaxation Iterations (EXPLICIT) = %d', successive_over_relaxation_iteration));
    pause(0.03)

end

Output :

Explicit Scheme :

close all
clear all
clc

% Solving the Unsteady state 2D heat conduction (EXPLICIT SCHEME)

% Input paramaters
% Number of grid points
nx = 10;
ny = nx;
nt = 1400;

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;

% Defining boundary conditions
T_L = 400;
T_T = 600;
T_R = 800;
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;

% Calculatiing Average temperatures 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 Unstaedy heat conduction EQUATION

iterative_solver = 1;
k1 = 1.1*(dt/(dx^2));
k2 = 1.1*(dt/(dy^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)
    contour(x,y,T)
    clabel(contourf(x,y,T))
    colorbar
    colormap(jet)
    set(gca, 'ydir', 'reverse')
    xlabel('X-Axis')
    ylabel('Y-Axis')
    title(sprintf('No. of Unsteady Iterations (EXPLICIT) = %d', Steady_explicit));
    pause(0.03)

Output :

Conclusions :

From the Outputs of various Methods and comparing their No. of iterations, we can conclude :

  1. Jacobi > Gauss-seidel > Successive Over relaxation according to the No. of iterations for all computed for all methods & schemes.
  2. When comparing steady and un-steady state we found that steady state is most successful as it takes less times to iterations and least time to compute.
  3. SOR method is more effective that Jacobi and Gauss-seidel as it takes less No. of Iterations for converging solutions in both schemes.
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.