Project

Week 5.2 - Mid term project - Steady vs unsteady state analysis

Question

Compare the convergence rate [Number of iterations] of the steady state and transient [explicit and implicit] simulations and justify the numerics.

Steady-State 2-D Heat Conduction:

The steady state condution has been simulated and it's code is as shown in the file attached below. The 2-D steady state conduction problem has been solved by using three itervative solvers namely Jacobi method, Gauss-Siedel method and SOR method.

1. Among these three methods, the Jacobi method requires the more number of iterations since in this method, values are updated only after the current iteration is over.

2. In the gauss-seidel method, the number of iterations required are less than that of jacobi method since in this method, values are updated as and when they are obtained even if the current iteration is not over.

3. In the SOR method, the process of convergence in the case of Gauss-siedel method is accelarated by using relaxation fator. So, the SOR method converges faster than Gauss-Siedel method and hence the SOR method requires the least number of operations among all the three iterative solvers. However, we need to select the optimum value of Relaxation factor since very high value of this factor will cause the oscillation of temperature value about the final value and hence in this case, the SOR will need more number of iterations to converge the solution.

In this problem, the number of iterations required are as follows:

1. Jacobi Method : 207 (number of iterations)

2. Gauss-Siedel method : 111(number of iterations)

3. SOR method (Relaxation factor=1.1): 92(number of iterations)

Lx=1;Ly=1;
nx=10;ny=10;
w=1.1;
dx=Lx/(nx-1);
dy=Ly/(ny-1);



x=linspace(0,1,nx);
y=x;

for i=1:nx
    for j=1:ny
        if i==1|| i==10 || j==1 || j==10
        T(1,i)=600;
        T(10,j)=900;
        T(i,10)=800;
        T(i,1)=400;
        T(1,1)=(600+400)/2;
        T(1,10)=(600+800)/2;
        T(10,1)=(400+900)/2;
        T(10,10)=(900+800)/2;
       
        else
            T(i,j)=300;
        end
             
    end
end

k=0.5*(dx^2*dy^2)/(dx^2+dy^2);

error=9e9;
tol=1e-4;

Iteration_counter=0;
Told=T;


    Iter_solver=input('enter the value of solver typen 1 for jacobi n 2 for gauss-siedel n 3 for SOR method');

if Iter_solver ==1 %Jacobi Method
    
while error>tol

    
    for i=2:nx-1
        for j=2:ny-1
            term1=Told(i-1,j)+Told(i+1,j);
            term2=Told(i,j-1)+Told(i,j+1);
            T(i,j)=k*term1/(dx^2)+k*term2/(dy^2);
        end
    end

     Td=(T-Told);
      error=max(Td,[],'all');
      Iteration_counter=Iteration_counter+1;
      Told=T;
      
    
end  
title_text=sprintf('Jacobi Method and the number of iterations are %d',Iteration_counter);
      

elseif Iter_solver ==2 % Gauss-siedel method
    while error>tol

    
    for i=2:nx-1
        for j=2:ny-1
            term1=T(i-1,j)+Told(i+1,j);
            term2=T(i,j-1)+Told(i,j+1);
            T(i,j)=k*term1/(dx^2)+k*term2/(dy^2);
        end
    end

     Td=(T-Told);
      error=max(Td,[],'all');
      Iteration_counter=Iteration_counter+1;
      Told=T;
      
    end     
    title_text=sprintf('Gauss-Seidel Method and the number of iterations are %d',Iteration_counter);
       
elseif Iter_solver ==3  %Successive-over relaxation method
    while error>tol

    
    for i=2:nx-1
        for j=2:ny-1
            term1=T(i-1,j)+Told(i+1,j);
            term2=T(i,j-1)+Told(i,j+1);
            Tgauss(i,j)=k*term1/(dx^2)+k*term2/(dy^2);
           T(i,j)=(1-w)*Told(i,j)+w*Tgauss(i,j);
                 
        end
    end
     
     Td=abs(T-Told);
     error=max(Td,[],'all');
     Told=T;
     Iteration_counter=Iteration_counter+1;
    
      
   end
title_text=sprintf('SOR method and the number of iterations are %d',Iteration_counter);
        


end

figure(1);
 contourf(x,y,T,'ShowText','on');
 colorbar;
 set(gca,'YDIR','reverse');
 colormap(jet);
 xlabel('X-axis grid points');
  ylabel('y-axis grid points');
  title(title_text);
  
 

    

Transient Conduction (Explicit Method):

In the transient conduction problem by using explicit method, it is like a direct method of calculating the temperature values at different nodes. The number of iterations here depend on the number of timesteps for which the simulation has been run and hence in this case number of iterations is equal to the number of timesteps. For such problem, number of timesteps equal to 1400-1500 is considered a safe value. However, the solution may even converge at a lesser number of iterations also.

Lx=1;Ly=1;
nx=10;ny=10;
w=1.1;
dx=Lx/(nx-1);
dy=Ly/(ny-1);

nt=500;
dt=0.4/nt;


Iteration_counter=0;

x=linspace(0,1,nx);
y=x;
alpha=1.1;

for i=1:nx
    for j=1:ny
        if i==1|| i==10 || j==1 || j==10
        T(1,i)=600;
        T(10,j)=900;
        T(i,10)=800;
        T(i,1)=400;
        T(1,1)=(600+400)/2;
        T(1,10)=(600+800)/2;
        T(10,1)=(400+900)/2;
        T(10,10)=(900+800)/2;
       
        else
            T(i,j)=300;
        end
             
    end
end

Told=T;
term1=alpha*dt/(dx)^2;
term2=alpha*dt/(dy)^2;


 for nt=1:1000
    for i=2:nx-1
        for j=2:ny-1
            T(i,j)=Told(i,j)*(1-2*term1-2*term2)+(Told(i-1,j)+Told(i+1,j))*term1+ (Told(i,j-1)+Told(i,j+1))*term2;
        end
    end
    
      Told=T;
      Iteration_counter=Iteration_counter+1;
 end
 title_text=sprintf('the number of iterations are %d',Iteration_counter);
 figure(1);
 contourf(x,y,T,'ShowText','on');
 colorbar;
 set(gca,'YDIR','reverse');
 colormap(jet);
 xlabel('X-axis grid points');
  ylabel('y-axis grid points');
  title(title_text);
 
    


Above figure shows that number of iterations are 1000. But the same solution can be obtained at 500 number of iterations also.

Transient Conduction (Implicit Method):

the transient conduction when solved by using implicit method, needs to be solved by using the itertive solvers.

The explaination given for the comparison of number of iterations in Jacobi, Gauss-Siedel and SOR method in the case of Steady state conduction is also applicable here also.

The Jacobi method will have the highest number of iterations and SOR method will have the least number of iterations.

In this problem, the number of iterations required are as follows:

1. Jacobi Method : 2820 (number of iterations)

2. Gauss-Siedel method : 2292(number of iterations)

3. SOR method (Relaxation factor=1.1): 2137(number of iterations)

We can clearly that Jacobi method has the highest number of iterations and SOR method has the least number of iterations.

%implicit method for transient conduction
clear all
clc
close all

Lx=1;Ly=1;
nx=10;ny=10;
w=1.1;
dx=Lx/(nx-1);
dy=Ly/(ny-1);

% nt=500;
dt=0.008;
alpha=1.1;
error=9e9;
tol=1e-4;


x=linspace(0,1,nx);
y=x;


for i=1:nx
    for j=1:ny
        if i==1|| i==10 || j==1 || j==10
        T(1,i)=600;
        T(10,j)=900;
        T(i,10)=800;
        T(i,1)=400;
        T(1,1)=(600+400)/2;
        T(1,10)=(600+800)/2;
        T(10,1)=(400+900)/2;
        T(10,10)=(900+800)/2;
       
        else
            T(i,j)=300;
        end
             
    end
end

Told=T; 
Tprev=T;
Tgauss=T;
k1=alpha*dt/(dx)^2;
k2=alpha*dt/(dy)^2;
term1=1/(1+2*k1+2*k2);
term2=term1*k1;
term3=term1*k2;

I_C=0;

Iter_solver=input('enter the value of solver typen 1 for jacobi n 2 for gauss-siedel n 3 for SOR method');

if Iter_solver==1  %Jacobi method
for nt=1:1400
    error=9e9;
    while error>tol
      for i=2:nx-1
           for j=2:ny-1
             H=Told(i-1,j)+Told(i+1,j);
             V=Told(i,j-1)+Told(i,j+1);
             T(i,j)=Tprev(i,j)*term1+term2*H+term3*V;
%              T(i,j)=(1-w)*Told(i,j)+w*Tgauss(i,j);
            
           end
        
      end
       Td=T-Told;
       error=max(Td,[],'all');
       Told=T;
       I_C=I_C+1;
    end
    
    Tprev=T;
end
title_text=sprintf('Jacobi Method and the number of iterations are %d',I_C);
elseif Iter_solver==2 %Gauss-siedel method
    for nt=1:1400
    error=9e9;
    while error>tol
      for i=2:nx-1
           for j=2:ny-1
             H=T(i-1,j)+Told(i+1,j);
             V=T(i,j-1)+Told(i,j+1);
             T(i,j)=Tprev(i,j)*term1+term2*H+term3*V;
%              T(i,j)=(1-w)*Told(i,j)+w*Tgauss(i,j);
            
           end
        
      end
       Td=T-Told;
       error=max(Td,[],'all');
       Told=T;
       I_C=I_C+1;
    end
    
    Tprev=T;
    end
    title_text=sprintf('Gauss-Seidel Method and the number of iterations are %d',I_C);
elseif Iter_solver==3 %SOR Method
    for nt=1:1400
    error=9e9;
    while error>tol
      for i=2:nx-1
           for j=2:ny-1
             H=T(i-1,j)+Told(i+1,j);
             V=T(i,j-1)+Told(i,j+1);
             Tgauss(i,j)=Tprev(i,j)*term1+term2*H+term3*V;
             T(i,j)=(1-w)*Told(i,j)+w*Tgauss(i,j);
            
           end
        
      end
       Td=T-Told;
       error=max(Td,[],'all');
       Told=T;
       I_C=I_C+1;
    end
    
    Tprev=T;
    end
title_text=sprintf('SOR Method and the number of iterations are %d',I_C);
end

contourf(x,y,T);
colorbar;
 set(gca,'YDIR','reverse');
 colormap(jet);
xlabel('X-axis grid points');
  ylabel('y-axis grid points');
  title(title_text);

 

Final conclusions:

1. In the staeady state conduction, the number of iterations required will be less than that of the transient conduction. The reason is that in the transient solution, the temperature values from the previous timestep are used to calculate the temperature values in the current iteration which is not the case with steady state solution. This is why the number of iterations in the transient solution is more than that of the steady-state solution.

2. Jacobi method will always have higher number of iterations among all other iterative solvers and SOR method will have lesser number of iterations.

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.