2D steady and Unsteady heat conduction
https://drive.google.com/open?id=1JoM_4_iwn00KOt9VtpVBg8h8GBCoxt4A
1. The above link provides the code for the steady state 2D heat conduction, function code for each iteration method and a short theory about iterative methods in PDF.
2. The result of 2D heat conduction is shown below in a contour plot. The output of the result for different iteration methods is the same but the no of iterations and the time is taken for convergence differs and is explained below.
Result:
Fig: Steady-state 2d Heat conduction contour plot
Result Analysis:
1. The above contour satisfies the Dirichlet Boundary condition applied. The top boundary condition is 600K and hence the origin of Y-plot is at the top, and the bottom is at 900K. Similarly with left and right sides of the boundary.
2. The results for three different methods are tabulated below as follows:
| No of Iterations | Time taken (sec) | Error | |
| Jacobi Iteration | 955 | 2.062450 | 9.9e-05 |
| Gauss-Siedel | 508 | 1.553412 | 9.9e-05 |
| Over-Relaxation(value = 1.5) | 180 | 1.133952 | 9.3e-05 |
| Under-Relaxation(value = 0.5) | 1391 | 2.914771 | 9.9e-05 |
4. Based on the above table, we can conclude that the Over-Relaxation iteration method gets into faster convergence. This is easily understood since the Jacobi Iteration uses the previous Iteration value and takes more time and iteration to gather data and execute while Gauss-Siedel evaluates in the current value and the relaxation parameters act as a catalyst to Gauss-Siedel to increase or decrease the convergence value.
5. Over-Relaxation value gives more convergence but lack stability and vice-versa in case of under-relaxation.
Unsteady Analysis:
The below code represents the transient simulation of a 2D heat conduction for both Explicit and Implicit method. The results are analyzed below the code. The transient simulation is done for Jacobi and Gauss Siedel method. The resulting analysis is compared with the Steady state solution.
% Code for the Explicit method
%% Solving steady state 2D heat analysis using unsteady explicit methods
% The equation is d2u/dx2 + d2u/dy2 = 0;
%Explicit functions
function sol = explicit_jacobi(Told,alpha_x,alpha_y,i,j)
sol = Told(i,j)+alpha_x*(Told(i+1,j)-2*Told(i,j)+Told(i-1,j))...
+alpha_y*(Told(i,j+1)-2*Told(i,j)+Told(i,j-1));
end
function sol = explicit_gauss(T,Told,alpha_x,alpha_y,i,j)
sol = Told(i,j)+alpha_x*(T(i+1,j)-2*T(i,j)+T(i-1,j))...
+alpha_y*(T(i,j+1)-2*T(i,j)+T(i,j-1));
end
% Main programme
clear all
close all
clc
% Space Initialization
Lx = 1; Ly = 1;
nx = 11;
ny = 11;
dx = Lx/(nx-1); dy = Ly/(ny-1);
% Time Initialization
time = 0.4;
k = 0.05; % Thermal Diffusivity
dt = 0.01;
nt = time/dt;
alpha_x = k*dt/(dx^2);
alpha_y = k*dt/(dx^2);
% Mesh
x = linspace(0,Lx,nx);
y = linspace(0,Ly,ny);
[X, Y] = meshgrid(x,y);
% Limits
tol = 1e-4;
error = 9e9;
% Temp Initialization
T = ones(nx,ny);
% Boundary conditions
T(:,1) = 400; % Left
T(:,end) = 800; % Right
T(1,2:end-1) = 600; % Top
T(end,2:end-1) = 900; % Bottom
% Copying T
Told = T;
display(\'Three methods to solve 2D Steady heat Conduction\');
display(\'1. Jacobi Iteration\');
display(\'2. Gauss siedel Iteration\');
method = input(\'Choose any of above three methods for solving: \');
% Explicit method
iter = 1;
tic
for k = 1:nt
while(error>tol)
for i = 2:nx-1
for j = 2:ny-1
if method == 1
T(i,j) = explicit_jacobi(Told,alpha_x,alpha_y,i,j);
elseif method == 2
T(i,j) = explicit_gauss(T,Told,alpha_x,alpha_y,i,j);
else
break;
end
end
end
error = max(max(abs(Told - T)));
Told = T;
iter = iter+1;
end
end
toc
%% Plotting
C = contourf(X,Y,T,\'edgecolor\',\'none\');
set(gca,\'YDIR\',\'reverse\');
colormap(jet);
clabel(C,\'FontSize\',12);
title(sprintf(\'No of Iterations: %d\',iter));
hold on;
% Iteration and Time display
display(\'2D heat conduction Implicit method\');
fprintf(\'No of iteration taken is %d\\n\',iter);
fprintf(\'Time taken for solving is %f\\n\',toc);
fprintf(\'The error obtained is %f\\n\',error);
% Code for the Implicit method
%% Solving steady state 2D heat analysis using Crank-Nicolson Implicit method.
% The equation is d2u/dx2 + d2u/dy2 = 0;
%Implicit functions
function sol = implicit_jacobi(Told,r,i,j,T_prev_dt)
term1 = (1-2*r)/(1+2*r);
term2 = r/(1+2*r);
H = (Told(i-1,j)+Told(i+1,j));
V = (Told(i,j-1)+Told(i,j+1));
sol = (T_prev_dt(i,j)*term1)+(term2*H)+(term2*V);
end
function sol = implicit_gauss(T,r,i,j,T_prev_dt)
term1 = (1-2*r)/(1+2*r);
term2 = r/(1+2*r);
H = (T(i-1,j)+T(i+1,j));
V = (T(i,j-1)+T(i,j+1));
sol = (T_prev_dt(i,j)*term1)+(term2*H)+(term2*V);
end
clear all
close all
clc
% Space Initialization
Lx = 1; Ly = 1;
nx = 11;
ny = 11;
dx = Lx/(nx-1); dy = Ly/(ny-1);
% Time Initialization
time = 0.2;
k = 1.65e-4; % Thermal Diffusivity
dt = 4;
nt = 100;
r = k*dt/(dx^2);
% k1 = r_x/2;
% k2 = k1;
% Mesh
x = linspace(0,Lx,nx);
y = linspace(0,Ly,ny);
[X, Y] = meshgrid(x,y);
% Limits
tol = 1e-4;
error = 9e9;
% Temp Initialization
T = 400.*ones(nx,ny);
% Boundary conditions
T(:,1) = 400; % Left
T(:,end) = 800; % Right
T(1,2:end-1) = 600; % Top
T(end,2:end-1) = 900; % Bottom
% Copying T
Told = T;
display(\'Three methods to solve 2D Steady heat Conduction\');
display(\'1. Jacobi Iteration\');
display(\'2. Gauss siedel Iteration\');
method = input(\'Choose any of above three methods for solving: \');
% Implicit method
iter = 1;
T_prev_dt = Told;
for k = 1:nt
while(error > tol)
for i = 2:nx-1
for j = 2:ny-1
if method == 1
T(i,j) = implicit_jacobi(Told,r,i,j,T_prev_dt);
elseif method == 2
T(i,j) = implicit_gauss(T,r,i,j,T_prev_dt);
else
break;
end
end
end
T;
error = max(max(abs(Told - T)));
Told = T;
iter = iter+1;
end
% Plotting
C = contourf(X,Y,T,\'edgecolor\',\'none\');
set(gca,\'YDIR\',\'reverse\');
colormap(jet);
clabel(C,\'FontSize\',12);
title(sprintf(\'No of iterations: %d\',iter));
pause(0.003)
%Looping the previous value
Told = T;
T_prev_dt = T;
error = 9e9;
end
%% Plotting
C = contourf(X,Y,T,\'edgecolor\',\'none\');
set(gca,\'YDIR\',\'reverse\');
colormap(jet);
clabel(C,\'FontSize\',12);
title(sprintf(\'No of iterations: %d\',iter));
pause(0.003)
% % Iteration and Time display
display(\'2D heat conduction Implicit method\');
fprintf(\'No of iteration taken is %d\\n\',iter);
fprintf(\'Time taken for solving is %f\\n\',toc);
Result:
Fig: Unsteady 2D heat conduction through Jacobi Explicit method
Fig: Unsteady 2D heat conduction through Gauss-Siedel Explicit method
Fig: Unsteady 2D heat conduction through Jacobi Implicit method
Fig: Unsteady 2D heat conduction through Gauss-Siedel Implicit method
From the above figures,
1. It can be seen that Gauss-Siedel Iteration takes less time when compared to Jacobi Iteration.
2. It can also be observed that Implicit method takes lesser time when compared to the explicit method for solving the heat conduction. Also, in the implicit method, we require only the stable condition at the end of the output rather than the process happening in the intermediate stage. In explicit method, it takes care of each and every step and hence the stability is a major concern in case of the explicit method.
3. Below table represents the time and iteration obtained for the Unsteady method.
| Method | Iteration method | Time taken | No of Iterations |
| Explicit |
Jacobi method Gauss Siedel method |
0.780341 0.735160 |
1178 1075 |
| Implicit |
Jacobi method Gauss Siedel method |
21.797051 46.130636 |
823 650 |
4. The implicit method makes use of same time level and hence takes less no of iterations so solve, but takes more time.