Challenge

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

Objective: To solve the 2D conduction equation using a Transient solver and a Steady state solver using iterative techniques (Jacobi, Gauss Seidal, SOR)

  1. Assume that the domain is a unit square.
  2. Assume nx= ny [Number of points along the x direction is equal to the number of points along the y direction]
  3. Boundary conditions for steady and transient case.
    1. Left: 400 K
    2. Top: 600 K
    3. Right: 800 K
    4. Bottom: 900 K

Steady state analysis using (Jacobi, Gauss Seidal, SOR)

The 2D steady State heat conduction equation is given as

`(∂²T/∂x²)+(∂²T/∂y²)=0`

Discertizing the equation using central difference scheme we get,

`(((Tⁿᵢ₋₁,ⱼ‒2.Tⁿᵢ,ⱼ+Tⁿᵢ₊₁,ⱼ))/(Δx^2 ))+(((Tⁿᵢ,ⱼ-₁‒2.Tⁿᵢ,ⱼ+Tⁿᵢ,ⱼ₊₁))/(Δy^2 ))=0`

Rearranging the above equation, we get,

`Tᵢ,ⱼ=C1(Tᵢ₊₁,ⱼ+Tᵢ-₁,ⱼ)+C2(Tᵢ,ⱼ₊₁+Tᵢ,ⱼ-₁)`

`C1=(Δy^2)/(2.(Δx^2+Δy^2 ) ) C2=(Δx^2)/(2.(Δx^2+Δy^2 ) )`

For Jacobi iteration the formula becomes,

`Tᵢ,ⱼⁿ⁺¹=(Tⁿᵢ₊₁,ⱼ+Tⁿᵢˍ₁,ⱼ+Tⁿᵢ,ⱼ₊₁+Tⁿᵢ,ⱼˍ₁)/4`

For Gauss Seidal iteration the formula becomes,

`Tᵢ,ⱼⁿ⁺¹=(Tⁿ⁺¹ᵢˍ₁,ⱼ+Tⁿᵢ₊₁,ⱼ+Tⁿ⁺¹ᵢ,ⱼˍ₁+Tⁿᵢ,ⱼ₊₁)/4`

The SOR iteration the formula becomes,

`Tⁿ^(+1) ᵢ,ⱼ=(1-w)Tⁿᵢ,ⱼ+w.Tjacobi`

The 2D transient heat conduction equation is given as:

`(∂T/∂t)=α(∂²T/∂x²+∂²T/∂y²)`

Discertizing the equation using central difference scheme in space and FDS in time we get,

`(Tⁿ⁺¹ᵢ,ⱼ-Tⁿᵢ,ⱼ)/∆t=(((Tⁿᵢ₋₁,ⱼ‒2.Tⁿᵢ,ⱼ+Tⁿᵢ₊₁,ⱼ))/(Δx^2 ))+(((Tⁿᵢ,ⱼ_₁‒2.Tⁿᵢ,ⱼ+Tⁿᵢ,ⱼ₊₁))/(Δy^2 ))`

Rearranging the above equation, we get (Explicit Scheme)

`Tⁿ^(+1) ᵢ,ⱼ=(1-2k1-2k2)Tⁿᵢ,ⱼ+k1(Tⁿᵢ₋₁,ⱼ+Tⁿᵢ₊₁,ⱼ)+k2(Tⁿᵢ,ⱼ_₁+Tⁿᵢ,ⱼ₊₁)`

`k1= α(∆t/(∆x^2 )) k2=α(∆t/(∆y^2 ))`

Similarly, for Implicit Scheme,

`(Tⁿ^(+1) ᵢ,ⱼ)={Tⁿᵢ,ⱼ+k1(Tⁿ^(+1) ᵢ_₁,ⱼ+Tⁿ^(+1) ᵢ₊₁,ⱼ)+k2(Tⁿ^(+1) ᵢ,ⱼ₋₁+Tⁿ^(+1) ᵢ,ⱼ₊₁)}/(1+2k1+2k2)`

STEADY STATE

1)JACOBI

close all
clear all
clc

nx=10;
ny=10;
x=linspace(0,1,nx);
dx=x(2)-x(1);
y=linspace(0,1,ny);
dy=y(2)-y(1);
T=100*ones(nx,ny);
T(:,1)=400;
T(:,nx)=800;
T(1,:)=900;
T(ny,:)=600;
Told=T;
k1=0.5*(dy^2/(dy^2+dx^2));
k2=0.5*(dx^2/(dy^2+dx^2));
iterative=1;
error=9e9;
tol=1e-4;
if iterative==1
    jacobi=1;
    while(error>tol)
        for j=2:ny-1
            for i=2:nx-1
                T(i,j)=k1*(Told(i-1,j)+Told(i+1,j))+k2*(Told(i,j-1)+Told(i,j+1));
            end
        end
        error=max(max(abs(Told-T)));
        Told=T;
        jacobi=jacobi+1;
        contourf(x,y,T)
        [C,h]=contourf(x,y,T);
         clabel(C,h);
        
           
        xlabel('X axis');
        ylabel('Y axis');
        title_text=sprintf("jacobi iteration number=%d",jacobi);
        title(title_text);
        pause(0.03)
    end
end
   

GRAPH

In this programme we have taken 10 no of grid points were taken for steady analysis and it is found that in jacobi method 215 interations were made.

2)Gauss Seidel

close all
clear all
clc

nx=10;
ny=10;
x=linspace(0,1,nx);
dx=x(2)-x(1);
y=linspace(0,1,ny);
dy=y(2)-y(1);
T=100*ones(nx,ny);
T(:,1)=400;
T(:,nx)=800;
T(1,:)=900;
T(ny,:)=600;
Told=T;
k1=0.5*(dy^2/(dy^2+dx^2));
k2=0.5*(dx^2/(dy^2+dx^2));
iterative=2;
error=9e9;
tol=1e-4;
if iterative==2
    gauss=1;
    while(error>tol)
        for j=2:ny-1
            for i=2:nx-1
                T(i,j)=k1*(T(i-1,j)+Told(i+1,j))+k2*(T(i,j-1)+Told(i,j+1));
            end
        end
        error=max(max(abs(Told-T)));
        Told=T;
        gauss=gauss+1;
         contourf(x,y,T)
        [C,h]=contourf(x,y,T);
         clabel(C,h);
           
        xlabel('X axis');
        ylabel('Y axis');
        title_text=sprintf("gauss iteration number=%d",gauss);
        title(title_text);
        pause(0.03)
    end
end
   

GRAPH

In this programme we have taken 10 no of grid points were taken for steady analysis and it is found that in gauss seidel method 115 interations were made.

3)SOR METHOD

close all
clear all
clc

nx=10;
ny=10;
x=linspace(0,1,nx);
dx=x(2)-x(1);
y=linspace(0,1,ny);
dy=y(2)-y(1);
T=100*ones(nx,ny);
T(:,1)=400;
T(:,nx)=800;
T(1,:)=900;
T(ny,:)=600;
Told=T;
k1=0.5*(dy^2/(dy^2+dx^2));
k2=0.5*(dx^2/(dy^2+dx^2));
iterative=3;
error=9e9;
tol=1e-4;
w=1.5;
if iterative==3
    sor=1;
    while(error>tol)
        for j=2:ny-1
            for i=2:nx-1
               T1(i,j)=k1*(T(i-1,j)+Told(i+1,j))+k2*(T(i,j-1)+Told(i,j+1));
               T(i,j)=(1-w)*Told(i,j)+w*T1(i,j);

            end
        end
        error=max(max(abs(Told-T)));
        Told=T;
        sor=sor+1;
         contourf(x,y,T)
         [C,h]=contourf(x,y,T);
         clabel(C,h);
        
           
        xlabel('X axis');
        ylabel('Y axis');
        title_text=sprintf("sor iteration number=%d",sor);
        title(title_text);
        pause(0.03)
    end
end
   

GRAPH

In this programme we have taken 10 no of grid points were taken for steady analysis and it is found that in SOR method 30 interations were made.

UNSTEADY STATE

1)JACOBI

T(:,1)=400;
T(:,nx)=800;
T(1,:)=900;
T(ny,:)=600;
Told=T;
Tprev=T;
alpha=1.25;
% t=0.1;
dt=1e-3;
nt=100;
k1=(alpha*dt)/dx^2;
k2=(alpha*dt)/dy^2;
term1=(1+(2*k1)+(2*k2))^-1;
 iterative=1;
% error=9e9;
 tol=1e-4;
 if iterative==1
     jacobi=1;
time=0;
for k=1:nt
    error=9e9;
    while(error>tol)
    
    
        for j=2:ny-1
            for i=2:nx-1
                T(i,j)=term1*Tprev(i,j)+k1*term1*(Told(i+1,j)+Told(i-1,j))+k2*term1*(Told(i,j-1)+Told(i,j+1));
            end
        end
        
      
        error=max(max(abs(Told-T)));
        Told=T;
        jacobi=jacobi+1;
    end
    Tprev=T;
   time=time+dt;
        
         contourf(x,y,T)
        [C,h]=contourf(x,y,T);
         clabel(C,h);
           
        xlabel('X axis');
        ylabel('Y axis');
        title_text=sprintf('total time=%g and jacobi iteration number=%d',time,jacobi);
        title(title_text);
        pause(0.03)
end
 end
 

   

GRAPH

In this programme we have taken 20 no of grid points were taken for unsteady analysis and it is found that in jacobi method 2281 interations were made in total time of 0.1.

2)GAUSS SIEDEL

close all
clear all
clc

nx=20;
ny=20;
x=linspace(0,1,nx);
dx=x(2)-x(1);
y=linspace(0,1,ny);
dy=y(2)-y(1);
T=300*ones(nx,ny);
T(:,1)=400;
T(:,nx)=800;
T(1,:)=900;
T(ny,:)=600;
Told=T;
Tprev=T;
alpha=1.25;
% t=0.1;
dt=1e-3;
nt=100;
k1=(alpha*dt)/dx^2;
k2=(alpha*dt)/dy^2;
term1=(1+(2*k1)+(2*k2))^-1;
 iterative=2;
% error=9e9;
 tol=1e-4;
 if iterative==2
     gauss=1;
time=0;
for k=1:nt
    error=9e9;
    while(error>tol)
    
    
        for j=2:ny-1
            for i=2:nx-1
                T(i,j)=term1*Tprev(i,j)+k1*term1*(T(i+1,j)+Told(i-1,j))+k2*term1*(T(i,j-1)+Told(i,j+1));
            end
        end
        
      
        error=max(max(abs(Told-T)));
        Told=T;
        gauss=gauss+1;
    end
    Tprev=T;
   time=time+dt;
        
         contourf(x,y,T)
        [C,h]=contourf(x,y,T);
         clabel(C,h);
           
        xlabel('X axis');
        ylabel('Y axis');
        title_text=sprintf('total time=%g and gauss iteration number=%d',time,gauss);
        title(title_text);
        pause(0.03)
end
 end
 

   

GRAPH

In this programme we have taken 20 no of grid points were taken for unsteady analysis and it is found that in GAUSS SEIDEL method 1890 interations were made in total time of 0.1.

3)SOR

close all
clear all
clc

nx=20;
ny=20;
x=linspace(0,1,nx);
dx=x(2)-x(1);
y=linspace(0,1,ny);
dy=y(2)-y(1);
T=300*ones(nx,ny);
T(:,1)=400;
T(:,nx)=800;
T(1,:)=900;
T(ny,:)=600;
Told=T;
Tprev=T;
alpha=1.25;
% t=0.1;
dt=1e-3;
nt=100;
k1=(alpha*dt)/dx^2;
k2=(alpha*dt)/dy^2;
term1=(1+(2*k1)+(2*k2))^-1;
 iterative=3;
% error=9e9;
 tol=1e-4;
 w=1.1;
 if iterative==3
     sor=1;
time=0;
for k=1:nt
    error=9e9;
    while(error>tol)
    
    
        for j=2:ny-1
            for i=2:nx-1
                T1(i,j)=term1*Tprev(i,j)+k1*term1*(T(i+1,j)+Told(i-1,j))+k2*term1*(T(i,j-1)+Told(i,j+1));
                T(i,j)=(1-w)*Tprev(i,j)+w*T1(i,j);
            end
        end
        
      
        error=max(max(abs(Told-T)));
        Told=T;
        sor=sor+1;
    end
    Tprev=T;
   time=time+dt;
        
         contourf(x,y,T)
        [C,h]=contourf(x,y,T);
         clabel(C,h);
           
        xlabel('X axis');
        ylabel('Y axis');
        title_text=sprintf('total time=%g and sor iteration number=%d',time,sor);
        title(title_text);
        pause(0.03)
end
 end
 

   

GRAPH

In this programme we have taken 20 no of grid points were taken for unsteady analysis and it is found that in SOR method 2258 interations were made in total time of 0.1.

CONCLUSIONS

From this programme analysis and graph we concluded that

i)In steady state analysis jacobi took more no of interations than gauss and Sor to converge.

ii)Out of three iterative solvers Sor took less iterations to converge because of relaxation factor.

iii)In unsteady analysis jacobi has more iterations then SOR,then gauss.

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.