Challenge

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

Solving the Steady and unsteady equation for 2D heat conduction
Aim:
  • Solve the 2D heat conduction equation by using the point iterative techniques.
Input
  • Top Boundary = 600 K
  • Bottom Boundary = 900 K
  • Left Boundary = 400 K
  • Right Boundary = 800 K

You will implement the following methods for solving implicit equation

  • Jacobi method
  • Gauss seidel method
  • Over relaxation

Your absolute error criteria is 1e-4

Matlab code
State state analysis
close all
clear all
clc
%inputs
nx=10;
ny=nx;
% initialize
t=ones(nx,ny);
% copy of t old value
told=t;
% boundry condition
t(:,1)=400;
t(1,:)=900;
t(:,end)=800;
t(end,:)=600;
% x,y coordinates
x=linspace(0,1,nx);
y=linspace(0,1,ny);
dx=x(2)-x(1);
dy=y(2)-y(1);
% iteration process
iterative_solver=3;
% iterative_solver(gs)=2;
% iterative_solver(sor)=3;
error=9e9;
%jacobi method steady state analysis
tol=1e-5;
k=2*(dx^2+dy^2)/(dx^2*dy^2);
if iterative_solver==1
jacobi_iteration=1;
while(error>tol)
for i=2:nx-1
for j=2:ny-1
t(i,j)=(((told(i-1,j)+told(i+1,j))/dx^2)+((told(i,j+1)+told(i,j-1))/dy^2))/k;
end
end
error=max (max(abs(told-t)));
told=t;
colormap(jet)
contourf(x,y,t)
jacobi_iteration = jacobi_iteration + 1;
title_text = sprintf('Iteration Number = %d', jacobi_iteration);
title(title_text)
colorbar
pause(0.001 ...
)
end
%Gauss seidel method
elseif iterative_solver==2
gauss_seidel_iteration=1;
while(error>tol)
for i=2:nx-1
for j=2:ny-1
t(i,j)=(((t(i-1,j)+t(i+1,j))/dx^2)+((t(i,j+1)+t(i,j-1))/dy^2))/k;
end
end
error=max (max(abs(told-t)));
told=t;
colormap(jet)
contourf(x,y,t)
gauss_seidel_iteration = gauss_seidel_iteration + 1;
title_text = sprintf('Iteration Number = %d', gauss_seidel_iteration);
title(title_text)
colorbar
pause(0.001 ...
)
end
% Over relaxation method
elseif iterative_solver== 3
omega=2;
sor_iteration=1;
while(error>tol)
for i=2:nx-1
for j=2:ny-1
t(i,j)=(((t(i-1,j)+t(i+1,j))/dx^2)+((t(i,j+1)+t(i,j-1))/dy^2))/k;
t(i,j)=told(i,j)*(1-omega)+(omega*t(i,j));
end
end
error=max (max(abs(told-t)));
told=t;
colormap(jet)
contourf(x,y,t)
sor_iteration = sor_iteration + 1;
title_text = sprintf('Iteration Number = %d', sor_iteration);
title(title_text)
colorbar
pause(0.001 ...
)
end
end
Steady state analysis procedure
  • Solve the steady state equation time defendent varaible dx,dy.
  • create the codes x direction,y direction.
  • Initialize the matrix form gives to ones value for all.
  • Give the boundry condition 2d plate top,bottom,right,left.
  • Give x,y coordinates value for using linspace
  • Iterative solver using compare less than error values.
  • error value mention that 9e-9.
  • Using numeric formula central differencing equation.
  • Equation should be value is less than given value.
  • So implementing the implicit method
  • Jacobi method
  • Gauss seidel method
  • Over relaxation method
  • Using for loop,elseif
  • Create the contour plots.

Contour plots

Transient explicit method
close all
clear all
clc
%inputs
nx=10;
ny=nx;
time=1;
% initialize
t=ones(nx,ny);
% copy of t old value
told=t;
% boundry condition
t(:,1)=400;
t(1,:)=900;
t(:,end)=800;
t(end,:)=600;
% x,y coordinates
x=linspace(0,1,nx);
y=linspace(0,1,ny);
dx=x(2)-x(1);
dy=y(2)-y(1);
alpha=1;
dt=0.001;
% iteration process
iterative_solver=1;
% iterative_solver(gs)=2;
% iterative_solver(sor)=3;
% error=9e9;
nt=time/dt;
%trainsient explicit method
tol=1e-5;
k1=alpha*(dt/dx^2);
k2=alpha*(dt/dy^2);
if iterative_solver==1
iteration=1;
% while(error>tol)
for k=1:nt
for i=2:nx-1
for j=2:ny-1
t(i,j)=told(i,j)+k1*(told(i-1,j)-2*told(i,j)+told(i+1,j))+k2*(told(i,j-1)-2*told(i,j)+told(i,j+1));
end
end
% error=max (max(abs(told-t)));
told=t;
colormap(jet)
contourf(x,y,t)
iteration = iteration + 1;
title_text = sprintf('time step = %d', iteration);
title(title_text)
colorbar
pause(0.001 ...
)
end
end
Transient explicit method procedure
  • Solve the steady state equation time defendent varaible dx,dy.
  • Create the codes x direction,y direction.
  • Initialize the matrix form gives to ones value for all.
  • Give the boundry condition 2d plate top,bottom,right,left.
  • Give x,y coordinates value for using linspace
  • Using number of time steps heat conduction of plate.
  • Using numeric formula central differencing equation.
  • Equation should be value is less than given value.
  • So implementing the implicit method
  • Jacobi method
  • Gauss seidel method
  • Over relaxation method
  • Using for loop,elseif
  • Create the contour plots.

Contour plots

Transient implicit method
close all
clear all
clc
%inputs
nx=10;
ny=nx;
dt=0.01;
alpha=1;
% initialize
t=ones(nx,ny);
% copy of t old value
told=t;
% boundry condition
t(:,1)=400;
t(1,:)=900;
t(:,end)=800;
t(end,:)=600;
% x,y coordinates
x=linspace(0,1,nx);
y=linspace(0,1,ny);
dx=x(2)-x(1);
dy=y(2)-y(1);
% iteration process
iterative_solver=2;
error=9e9;
%jacobi method steady state analysis
tol=1e-5;
k1=alpha*(dt/dx^2);
k2=alpha*(dt/dy^2);
if iterative_solver==1
jacobi_iteration=1;
while(error>tol)
for i=2:nx-1
for j=2:ny-1
term1=1+2*k1+2*k2;
t(i,j)=(told(i,j)+k1*(told(i-1,j)+told(i+1,j))+k2*(told(i,j+1)+told(i,j-1)))/term1;
end
end
error=max (max(abs(told-t)));
told=t;
colormap(jet)
contourf(x,y,t)
jacobi_iteration = jacobi_iteration + 1;
title_text = sprintf('Iteration Number = %d', jacobi_iteration);
title(title_text)
colorbar
pause(0.001 ...
)
end
% Gauss seidel theorem
elseif iterative_solver==2
gauss_seidel_iteration=1;
while(error>tol)
for i=2:nx-1
for j=2:ny-1
term1=1+2*k1+2*k2;
t(i,j)=(t(i,j)+k1*(t(i-1,j)+t(i+1,j))+k2*(t(i,j+1)+t(i,j-1)))/term1;
end
end
error=max (max(abs(told-t)));
told=t;
colormap(jet)
contourf(x,y,t)
gauss_seidel_iteration = gauss_seidel_iteration + 1;
title_text = sprintf('Iteration Number = %d', gauss_seidel_iteration);
title(title_text)
colorbar
pause(0.001 ...)
% over relaxation
end
elseif iterative_solver== 3
omega=2;
sor_iteration=1;
while(error>tol)
for i=2:nx-1
for j=2:ny-1
term1=1+2*k1+2*k2;
t(i,j)=(t(i,j)+k1*(t(i-1,j)+t(i+1,j))+k2*(t(i,j+1)+t(i,j-1)))/term1;
t(i,j)=t(i,j)*(1-omega)+(omega*t(i,j));
end
end
error=max (max(abs(told-t)));
told=t;
colormap(jet)
contourf(x,y,t)
sor_iteration = sor_iteration + 1;
title_text = sprintf('Iteration Number = %d', sor_iteration);
title(title_text)
colorbar
pause(0.001 ...
)
end
end
Contour plots
Jacobi method iteration=330
Gauss-Seidel method iteration=213
Over relaxation method iteration=101
Observered :
Finally compare the 3 equation result iteration values
Transient state implicit analysis for
  • Jacobi iteration=330
  • Gauss seidel iteration=213
  • SOR iteration=101 this method short iteration give solution is connverged.

Transient Explicit method

Solution converging takes time step to 1001.

Steady state anaysis

  • jacobi iteration =235
  • Gauss seidel iteration=155
  • SOR method=35

Finally we observed Successive over realaxation methods takes less iteration value solution is coverged.

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.