Project

Unsteady 2D Heat Conduction Problem Analysis

##Trainseint 2D Heat Conduction Equation

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

%Main function for transient analysis
clear all
close all
clc


%Initialization of Parameters
L=1;
M=1;


nx=11;
ny=nx;
x=linspace(0,L,nx);
y=linspace(0,M,nx);


dx=x(2)-x(1);
dy=y(2)-y(1);

T=ones(nx);


T(1:nx,1)=400;
T(1:nx,nx)=800;
T(1,1:nx)=600;
T(nx,1:nx)=900;

tol=1e-04;

alpha=1.5;
dt=0.01;
w=0.9 %Under relaxation factor

k1=alpha*dt/(dx)^2;
k2=alpha*dt/(dy)^2;

fprintf(\'1.For Jacobi Method\\n2.For Gauss Seidel Method\\n3.For SOR Method\\n\') 

%Selection of function
method=input(\'Enter number for selection of Iterative Method--\');

if method==1;
    Transient_jacobi_func(nx,x,y,dx,dy,T,dt,k1,k2,tol)
elseif method==2;
    Transient_gauss_seidel_func(nx,x,y,dx,dy,T,dt,k1,k2,tol)
else method==3;
    Transient_sor_func(nx,x,y,dx,dy,T,dt,k1,k2,tol)

end


%Function for Jacobi Method
function Tout=Transient_jacobi_func(nx,x,y,dx,dy,T,dt,k1,k2,tol)

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


Told=T;
T_predictive=Told;
jacobi_iter=0;
for b=1:40  %Time loop
  error=1e+03;
  
  while error>tol  %Convergence Loop
  
  
    for i=2:nx-1   %Nodal Loop
      for j=2:nx-1
        M=Told(i-1,j)+Told(i+1,j);
        N=Told(i,j-1)+Told(i,j+1);
        T(i,j)=(T_predictive(i,j)*term1)+(M*term2)+(N*term3);
      end
   end
  error=max(max(abs(Told-T)));
  Told=T;  %Updating values
  jacobi_iter=jacobi_iter+1;
  end  
T_predictive=Told;  %Updating values
Tout=Told;
end

%Plotting contour for Temperature distribution
fprintf(\'Number of iteration done are %d \',jacobi_iter);
[X Y]=meshgrid(x,y);

contourf(X,Y,Told,\'Showtext\',\'on\');
set(gca, \'YDir\',\'reverse\');
H=colorbar;
set(H, \'YDir\',\'reverse\');
xlabel(\'X-Direction-->\');
ylabel(\'Y-Direction-->\');
title({[\'Plot of 2D Heat Conduction equation solved Implicitly using Jacobi method\'];[\'No. of Iterations-\',num2str(jacobi_iter)]});

end

%Function for Gauss Seidel Method
function Tout=Transient_gauss_seidel_func(nx,x,y,dx,dy,T,dt,k1,k2,tol)

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


Told=T;
T_predictive=Told;
gauss_iter=0
for b=1:40  %Time Loop
  
  error=1e+03;
  while error>tol  %Convergence Loop
  
  Told=T
    for i=2:nx-1  %Nodal Loop
      for j=2:nx-1
        M=T(i-1,j)+Told(i+1,j)
        N=T(i,j-1)+Told(i,j+1)
        T(i,j)=(T_predictive(i,j)*term1)+(M*term2)+(N*term3)
      end
   end
  error=max(max(abs(Told-T)));
  Told=T;   %Updating Values
  gauss_iter=gauss_iter+1;
  end  
  T_predictive=Told;  %Updating Values
  Tout=Told;
end

%Plotting contour for Temperature distribution
fprintf(\'Number of iteration done are %d \',gauss_iter);
[X Y]=meshgrid(x,y);

contourf(X,Y,Told,\'Showtext\',\'on\');
set(gca, \'YDir\',\'reverse\');
H=colorbar;
set(H, \'YDir\',\'reverse\');
xlabel(\'X-Direction-->\');
ylabel(\'Y-Direction-->\');
title({[\'Plot of 2D Heat Conduction equation solved Implicitly using Gauss Seidel method\'];[\'No. of Iterations-\',num2str(gauss_iter)]});
end


%Function for SOR -by Gauss Seidel Method
function Tout=Transient_sor_func(nx,x,y,dx,dy,T,dt,k1,k2,tol)

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

Told=T;
T_predictive=Told;
sor_iter=0;
w=0.9;
for b=1:40 %Time Loop
  
  error=1e+03;
  while error>tol  %Convergence Loop
  
  Told=T;
    for i=2:nx-1  %Nodal Loop
      for j=2:nx-1
        M=T(i-1,j)+Told(i+1,j);
        N=T(i,j-1)+Told(i,j+1);
        T(i,j)=w*((T_predictive(i,j)*term1)+(M*term2)+(N*term3))+((1-w)*T_predictive(i,j))
        
      end
   end
  error=max(max(abs(Told-T)));
  Told=T;
  sor_iter=sor_iter+1;
  end  
 
   T_predictive=Told;
   Tout=Told;
end
 
disp(\'value of iteration\'),disp(sor_iter)
[X Y]=meshgrid(x,y);

contourf(X,Y,Told,\'Showtext\',\'on\');
set(gca, \'YDir\',\'reverse\');
H=colorbar;
set(H, \'YDir\',\'reverse\');
xlabel(\'X-Direction-->\');
ylabel(\'Y-Direction-->\');
title({[\'Plot of 2D Heat Conduction equation solved Implicitly using SOR-Gauss Seidel method\'];[\'No. of Iterations-\',num2str(sor_iter)]});
end

##Jacobi Method plot

##Gauss Seidel Method Plot;

##SOR -Gauss Seidel Method Plot;

##Explicitly Solved Trainseint Equation Plot

%Script for solving Transient Equation Explicitly
clear all
close all
clc

%Defining parameters
L=1;
M=1;
n=11;
x=linspace(0,L,n);
y=linspace(0,M,n);

dx=x(2)-x(1);
dy=y(2)-y(1);

T=ones(n);


T(1:n,1)=400;
T(1:n,n)=800;
T(1,1:n)=600;
T(n,1:n)=900;

%T(1,1)=(400+600)/2
%T(n,1)=(400+900)/2
%T(1,n)=(600+800)/2
%T(n,n)=(800+900)/2

Told=T;

tol=1e-04;


alpha=1.4;
dt=0.0015;

k1=((alpha*dt)/(dx)^2);
k2=((alpha*dt)/(dy)^2);

k=0
for k=1:300  %Time loop
    error=1e+03
    while error>tol  %Convergence Loop
        
    for i=2:n-1  %Nodal Loop
        for j=2:n-1
            term1=Told(i,j);
            term2=k1*(Told(i-1,j)-(2*Told(i,j))+Told(i+1,j));
            term3=k2*(Told(i,j-1)-(2*Told(i,j))+Told(i,j+1));
            T(i,j) = term1 +term2 +term3;
        end
    end
    error=max(max(abs(T-Told)))
    Told=T;   %Updating Values
    k=k+1;
    end 
    
end
 
%Plotting contour for Temperature distribution
fprintf(\'Number of iteration done are %d \',k)
[X Y]=meshgrid(x,y);
contourf(X,Y,Told,\'Showtext\',\'on\');
xlabel(\'X-Direction-->\');
ylabel(\'Y-Direction-->\')
title({[\'Plot of 2D Heat ;Conduction equation solved Explicitly\'];[\'No. of Iterations-\',num2str(k)]});
set(gca,\'Ydir\',\'Reverse\');
H=colorbar;
set(H, \'YDir\',\'reverse\');
   

##Above plots shows the temperature distribution in 1x1 m2 domain.

##According to BC ,temperature at bottom is 900,so area near bottom area is hotter which is indicated by Yellow colour.Cold region is shown by blue colour.

#For Jacobi Method,No. of iteration are 1625.

#For Gauss Seidel Method,No. of iteration are 955.

#For SOR-Gauss Seidel Method,No. of iteration are 812.

#Itertion No. shows SOR method is fastest among three.

#Transient Equation solved explicitly gives Iteration No. 312.

#Explicit method give faster solution than Implicit Method.

#But for Explicit method CFL no. is very important.For converging solution,CFL no. should be in certain range,otherwise solution will never converge.

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.