Challenge

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

OBJECTIVE:

To solve Steady and Unsteady state 2D Heat Conduction Equation by using the point iterative techniques such as Jacobi, Gauss Seidel & Successive over-relaxation for both implicit and explicit schemes using MATLAB.

Problem statement:

  1. Computation area is to be a square.
  2. Assume nx = ny [No. of points on x-direction is equal to no. of points in y-direction]
  3. We assume nx = ny = 10
  4. Boundary Conditions are
    Left = 400k
    Right = 600k
    Top = 800k
    Bottom = 900k
  5. Apart from the boundary conditions, all other nodes are given an initial temperature of 300k.
  6. Various methods to be employed in solving the equation are given below:

    1. Various States: Steady-state & Unsteady-state Condition
    2. Various Schemes: Jacobi, Gauss-seidel & Successive over-relaxation
    3. Various Methods to be used in Unsteady-state: IMPLICIT & EXPLICIT

By using Point iterative method, solve the 2D Heat Conduction Equation and plot the Temperature Contour for all the three iterative methods namely Jacobi, Gauss-Siedel & SOR for Steady and Unsteady conditions under IMPLICIT scheme also additionally solving the EXPLICIT scheme for Unsteady Condition.

THEORY:

The heat equation is a partial differential equation that describes how the distribution of some quantity (such as heat) evolves over time in a solid medium, as it spontaneously flows from places where it is higher towards places where it is lower.

For a function

`u(x,y,z,t)`

of spatial variable x,y,z and time variable t

Types of Heat Conduction schemes

This transfer of Heat energy may occur under two conditions

  • Steady-state condition
  • Unsteady/Transient state condition

Unsteady state conditions are a precursor to steady state conditions. No system exists initially under steady state conditions. Some time must pass, after heat transfer is initiated, before the system reaches steady state. During that period of transition the system is under unsteady state conditions.

Time Loop Logic:

Boundary Condition Map:

Here,

TL = Left boundary

TT = Top boundary

TP= Middle/Point boundary

TB = Bottom boundary

TR = Right boundary

IMPLICIT Scheme - Steady-state Condition Program:

Steady-state Equation discretization:

In steady-state conduction, the amount of heat entering any region of an object is equal to the amount of heat coming out (if this were not so, the temperature would be rising or falling, as thermal energy was tapped or trapped in a region).

IMPLICIT Scheme Unsteady/Transient-state Condition Program:

Unsteady-state Equation discretization:

Non-steady-state situations appear after an imposed change in temperature at a boundary as well as inside of an object, as a result of a new source or sink of heat suddenly introduced within an object, causing temperatures near the source or sink to change in time.

EXPLICIT Scheme - Unsteady/Transient state Condition Program

Unsteady-state Equation discretization(EXPLICIT):

CODE CONCEPT:

my code is in such a way that we need to provide input for nx and also we need to provide in such a way that

1. steady state jacobian iteration

2. steady state gauss seidel iteration

3. steady state Successive over relaxation iteration

4. unsteady state jacobian iteration

5. unsteady state gauss seidel iteration

6. unsteady state successive over relaxation iteration

we need to provide input to select particular method

CODE

%mid term project
%solving the steady and unsteady 2d heat conduction equation
%d2t/dx2+d2t/dy2=0

clear all
close all
clc

%n=input('Enter the value of nodes = ');
%input
nx=input('enter the value of nx')

ny=nx
x=linspace(0,1,nx)
y=linspace(0,1,ny)
dx=x(2)-x(1)
dy=y(2)-y(1)

%matrix

t=300*(ones(nx,ny))

t(1,:)=600
t(:,1)=400
t(end,:)=900
t(:,end)=800

t(1,1)=(400+600)/2
t(1,ny)=(600+800)/2
t(nx,1)=(400+900)/2
t(nx,ny)=(800+900)/2

told=t
a=1.1
   T=5
   dt=1e-2 %timestep
   k1=(a*dt)/(dx^2)
   k2=(a*dt)/(dy^2)
   tp=t
tol=1e-4
error=9e9
k=2*(dx^2+dy^2)/((dx^2)*(dy^2))


iteration_method=input('provide iteration method')
%steady state
%jacobian method
if iteration_method==1
    jacobi=1
    tic
    while error>tol
        %space loop
        for i=2:nx-1
            for j=2:ny-1
                term1=(told(i-1,j)+told(i+1,j))/(dx^2)
                term2=(told(i,j-1)+told(i,j+1))/(dy^2)
                t(i,j)=(term1+term2)/k
            end
        end
         timetaken=toc
        error=max(max(abs(told-t)))
        told=t
         jacobi=jacobi+1
contourf(x,y,t,'ShowText','on')
colormap("jet")
colorbar
set(gca,'Ydir','reverse')
xlabel('x axis')
ylabel('y axis')
text1=sprintf('number of iteration = %d',jacobi)
text2=sprintf('simulation time = %f',timetaken)
title({'steady state heat conduction profile by jacobi method'; text1;text2})
    pause(0.03)
    end
end
% gauss siedel
if iteration_method==2
    gauss=1
    tic
    while error>tol
        %space loop
        for i=2:nx-1
            for j=2:ny-1
                term1=(t(i-1,j)+told(i+1,j))/(dx^2)
                term2=(t(i,j-1)+told(i,j+1))/(dy^2)
                t(i,j)=(term1+term2)/k
            end
        end
         timetaken=toc
        error=max(max(abs(told-t)))
        told=t
         gauss=gauss+1
contourf(x,y,t,'ShowText','on')
colormap("jet")
colorbar
set(gca,'Ydir','reverse')
xlabel('x axis')
ylabel('y axis')
text1=sprintf('number of iteration = %d',gauss)
text2=sprintf('simulation time = %f',timetaken)
title({'steady state heat conduction profile by gauss method'; text1;text2})
  pause(0.03)
    end
end
%SOR
if iteration_method==3
    w=input('provide relaxation factor')
    SOR=1
    tic
    while error>tol
        %space loop
        for i=2:nx-1
            for j=2:ny-1
                term1=(t(i-1,j)+told(i+1,j))/(dx^2)
                term2=(t(i,j-1)+told(i,j+1))/(dy^2)
                gauss=(term1+term2)/k
                t(i,j)=((1-w)*told(i,j))+(w*gauss)
            end
        end
         timetaken=toc
        error=max(max(abs(told-t)))
        told=t
         SOR=SOR+1
contourf(x,y,t,'ShowText','on')
colormap("jet")
colorbar
set(gca,'Ydir','reverse')
xlabel('x axis')
ylabel('y axis')
text1=sprintf('number of iteration = %d',SOR)
text2=sprintf('simulation time = %f',timetaken)
title({'steady state heat conduction profile by SOR method'; text1;text2})
pause(0.03)
    end
end
if iteration_method==4
    Jacobi_iteration = 1;
for k = 1:1400
    error = 9e9; 
    tic
    while(error > tol)
        
        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 = (told(i-1,j)) + (told(i+1,j));
                V = (told(i,j+1)) + (told(i,j-1));
                    
                t(i,j) = (tp(i,j)*Term_1) + (H*Term_2) + (V*Term_3);
   
            end
            
        end
        
        error = max(max(abs(told - t)));
        told = t;
        Jacobi_iteration = Jacobi_iteration + 1;  
        
    end
    timetaken=toc
    tp = t;
    
    %Plotting
    figure(1)
    contourf(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(implicit) = %d', Jacobi_iteration));
    %title(sprintf('simulation time = %f',timetaken));
    pause(0.03)
end
end

if iteration_method==5
    gauss_iteration = 1;
for k = 1:1400
    error = 9e9; 
    tic
    while(error > tol)
        
        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)) + (told(i+1,j));
                V = (t(i,j+1)) + (told(i,j-1));
                    
                t(i,j) = (tp(i,j)*Term_1) + (H*Term_2) + (V*Term_3);
   
            end
            
        end
        
        error = max(max(abs(told - t)));
        told = t;
        gauss_iteration = gauss_iteration + 1;  
        
    end
    
    tp = t;
    timetaken=toc
    %Plotting
    figure(1)
    contourf(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 Iterations(implicit) = %d', gauss_iteration));
    %title(sprintf('simulation time = %f',timetaken));
    pause(0.03)
end
end

if iteration_method==6
    sor = 1;
    w=1.1
for k = 1:1400
    error = 9e9; 
    tic
    while(error > tol)
        
        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)) + (told(i+1,j));
                V = (t(i,j+1)) + (told(i,j-1));
                    
                gauss = (tp(i,j)*Term_1) + (H*Term_2) + (V*Term_3);
                t(i,j)=(1-w)*told(i,j)+w*(gauss)
   
            end
            
        end
        
        error = max(max(abs(told - t)));
        told = t;
        sor = sor + 1;  
        
    end
    
    tp = t;
    timetaken=toc
    %Plotting
    figure(1)
    contourf(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 SOR Iterations(implicit) = %d', sor));
    %title(sprintf('simulation time = %f',timetaken));
    pause(0.03)
end
end















EXPLICIT

close all
clear all
clc

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

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

%Calculating Average temperature 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 orginal values to T
T_intial = T;
T_old = T;


%Calculation of 2D steady heat conduction EQUATION by Successive over-relaxation method
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;  
        %Plotting
figure(1)
contourf(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);
        end
    end

end

Output

TYPE OF SCHEME & ANALYSIS METHOD NO OF ITERATION PLOT
STEADY STATE JACOBI 208
GAUSS SEIDEL 112
SUCCESSIVE OVER RELAXATION 93
UNSTEADY IMPLICIT STATE JACOBI 2768
GAUSS SEIDEL 2514
SUCCESSIVE OVER RELAXATION 2384
EXPLICIT METHOD 1941

observation:

From the above outputs of various methods & comparing their No. of iterations, we can conclude that

  • Jacobi > Gauss-seidel > Successive over-relaxation according to the No. of iterations computed for all methods & Schemes.

  • When comparing Steady state 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 compute.

  • SOR iteration method is the most effective iteration method as it took least No. of iterations for coverging solutions in both the schemes (EXPLICIT & IMPLICIT) compared to Jacobi & Gauss-siedel.
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.