All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: To solve 2D heat conduction equation for steady and transient state using various iterative techniques such as Jacobi, Gauss Seidel and Successive over relaxation methods using MATLAB. Problem Define; Heat conduction equation is define by the pde ∂T∂t=α.∂2T∂x+∂2T∂y+∂2T∂z…
KURUVA GUDISE KRISHNA MURHTY
updated on 10 Aug 2022
AIM:
To solve 2D heat conduction equation for steady and transient state using various iterative techniques such as Jacobi, Gauss Seidel and Successive over relaxation methods using MATLAB.
Problem Define;
Heat conduction equation is define by the pde
∂T∂t=α.∂2T∂x+∂2T∂y+∂2T∂z
which is the heat distribution in 3D space with the period of time.
where alpha is known to be \'thermal diffusivity\' (m^2/s)
Given that, the number of grid points in x direction is equal to y direction and the domain is assumed to be an unit squre.
Boundary conditions given
First let\'s define what are the iterative techniques we are using here:
In this iteration technique we assume the initial values at all nodes to calculate the new values, which will updated once we find the all the nodes values and this process will goes on untill we arrive with an converge solution. For different simulateneous equations with many unknowns first we have to make the equations into Diagonally dominant matrix form for converging results.
In this iteration we assume the values obtained in Jacobi iteration for the next equation immediately without waiting for completion of first cycle.
This method is an updated version of previous two. In addition we use the relaxation factor to ease the process. For this analysis we use the relaxation facor to be greater than 1 and less than 2.
∂T∂t=α.∂2T∂x+∂2T∂y
For steady state there are no change in temperature hence the Steady state becomes
∂2T∂x+∂2T∂y=0
For solving steady state 2D using different iterative techniques
The steady state equation is discretised using 2nd order CDS:
TL−2T+TRΔx2+TB−2T+TTΔy2=0
On simplifying,
assume,k=2Δx2+Δy2Δx2.Δy2
we can write
TP=1k(TL+TRΔx2+TB+TTΔy2)
MATLAB CODE FOR STEADY STATE:
clear all
close
clc
%% inputs
nx = 20; % number of grids in x direction
ny = nx; % number of grids in y direction
tolerance = 1e-5; % tolerance
error = 9e9; % initial guess for the error
T=5; % time limit
dt = 1e-2; % time step
x = linspace(0,1,nx); % x axis mesh
y = linspace(0,1,ny); % y axis mesh
% grid spacing
dx= x(2)-x(1);
dy= y(2)-y(1);
[xx,yy] = meshgrid(x,y);
% matrix difination
t= 300*ones(nx,ny); % Initail temperatures guess
t(end,:) = 900; % top face
t(1,:) = 600; % Bottom face
t(:,1) = 400; % left face
t(:,end) = 800; % right face
k = (2*(dx^2+dy^2)/(dx^2*dy^2));
t_old = t;
t_p = t;
%% Solving method
method = 'which method ?'
solver = input(method); % \'1\' for jacobi
% \'2\' for Gauss-sidel
% \'3\' for SOR
%% JACOBI SOLVER
if solver ==1
iter_1= 1;
tic;
% Convergence loop
while(error>tolerance)
for i = 2:(nx-1) % loop of equations
for j = 2:(ny-1) % loop of summation
TL = t_old(i-1,j);
TR = t_old(i+1,j);
TB = t_old(i,j-1);
TT = t_old(i,j+1);
H= (TL +TR)/dx^2;
V = (TB +TT)/dy^2;
t(i,j) = (H +V)/k;
end
end
time = toc;
error=max(max(abs(t_old-t)));
t_old = t;
iter_1=iter_1 +1;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('Steady state using javobi = %d', iter_1);
title_text2 = sprintf('Simulation time +%f s', time);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
end
%% Gauss-siedel method
if solver ==2
iter_2= 1;
tic;
% Convergence loop
while(error>tolerance)
for i = 2:(nx-1) % loop of equations
for j = 2:(ny-1) % loop of summation
%TL = t_old(i-1,j);
TR = t_old(i+1,j);
%TB = t_old(i,j-1);
TT = t_old(i,j+1);
H= (t(i-1,j) + TR)/dx^2;
V= (t(i,j-1) + TT)/dy^2;
t(i,j) = (H +V)/k;
end
end
time2 = toc;
error=max(max(abs(t_old-t)));
t_old = t;
iter_2=iter_2 +1;
time= toc;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('Steady state using GS = %d', iter_2);
title_text2 = sprintf('Simulation time +%f s', time);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
end
%% Successive over relaxation (SOR) method
alpha = 0.3; % thermal diffusivity
omega = 1.2; % SOR value, should be greater than 1 and less than 2
if solver ==3
iter_3= 1;
tic;
% Convergence loop
while(error>tolerance)
for i = 2:(nx-1) % loop of equations
for j = 2:(ny-1) % loop of summation
%TL = t_old(i-1,j);
TR = t_old(i+1,j);
%TB = t_old(i,j-1);
TT = t_old(i,j+1);
H= (t(i-1,j) + TR)/dx^2;
V= (t(i,j-1) + TT)/dy^2;
tgs(i,j) = (H +V)/k;
t(i,j) = (1-omega)*(t_old(i,j))+omega*tgs(i,j);
end
end
time3 = toc;
error=max(max(abs(t_old-t)));
t_old = t;
iter_3=iter_3 +1;
time= toc;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('Steady state using SOR = %d', iter_3);
title_text2 = sprintf('Simulation time +%f s', time3);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
end
output:
Jacobi
Gauss-seidel
Successive over-relaxation
Solving Transient state (Implicit)
Implicit method uses the parameters which are inter-dependent with each other in the same time step. Most of the mordern day discretization uses this method because of its usefulness in hiher time steps and stable characteristics.
Tn+1=Tn+k1(TL−2T+TR)n+1+k1(TB−2T+TT)n+1
MATHS CODE:
clear all
close all
clc
%% inputs
nx = 20; % number of grids in x direction
ny = nx; % number of grids in y direction
alpha = 1.4; % thermal diffusivity
omega = 1.2; % SOR value, should be greater than 1 and less than 2
tolerance = 1e-5; % tolerance
error = 9e9; % initial guess for the error
T=5; % time limit
dt = 1e-2; % time step
x = linspace(0,1,nx); % x axis mesh
y = linspace(0,1,ny); % y axis mesh
% grid spacing
dx= x(2)-x(1);
dy= y(2)-y(1);
[xx,yy] = meshgrid(x,y);
% matrix difination
t= 300*ones(nx,ny); % Initail temperatures guess
t(end,:) = 900; % top face
t(1,:) = 600; % Bottom face
t(:,1) = 400; % left face
t(:,end) = 800; % right face
k1= alpha*dt/dx^2;
k2= alpha*dt/dy^2;
k = 1+(2*k1)+(2*k2);
t_old = t;
t_p = t;
%% Solving method
method = 'which method ? '
solver = input(method); % \'1\' for jacobi
% \'2\' for Gauss-sidel
% \'3\' for SOR
%% JACOBI SOLVER
if solver ==1
iter_1= 1;
tic;
% Convergence loop
while(error>tolerance)
for i = 2:(nx-1) % loop of equations
for j = 2:(ny-1) % loop of summation
TL = t_old(i-1,j);
TR = t_old(i+1,j);
TB = t_old(i,j-1);
TT = t_old(i,j+1);
H= TL +TR;
V = TB +TT;
t(i,j) = ((t_p(i,j)+H*k1 +V*k2)/k);
end
end
time = toc;
error=max(max(abs(t_old-t)));
t_old = t;
iter_1=iter_1 +1;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('transient state Implicit using javobi = %d', iter_1);
title_text2 = sprintf('Simulation time +%f s', time);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
end
%% Gauss-siedel method
if solver ==2
iter_2= 1;
tic;
% Convergence loop
while(error>tolerance)
for i = 2:(nx-1) % loop of equations
for j = 2:(ny-1) % loop of summation
%TL = t_old(i-1,j);
TR = t_old(i+1,j);
%TB = t_old(i,j-1);
TT = t_old(i,j+1);
H = t(i-1,j) +TR;
V = t(i,j-1) +TT;
t(i,j) = ((t_p(i,j)+H*k1 +V*k2)/k);
end
end
time2 = toc;
error=max(max(abs(t_old-t)));
t_old = t;
iter_2=iter_2 +1;
time= toc;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('transient state Implicit using GS = %d', iter_2);
title_text2 = sprintf('Simulation time +%f s', time);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
end
%% Successive over relaxation (SOR) method
if solver ==3
iter_3= 1;
tic;
% Convergence loop
while(error>tolerance)
for i = 2:(nx-1) % loop of equations
for j = 2:(ny-1) % loop of summation
TL = t_old(i-1,j);
TR = t_old(i+1,j);
TB = t_old(i,j-1);
TT = t_old(i,j+1);
H = t(i-1,j) +TR;
V = t(i,j-1) +TT;
tgs(i,j) = ((t_p(i,j)+H*k1 +V*k2)/k);
t(i,j) = (1-omega)*(t_old(i,j))+omega*tgs(i,j);
end
end
time3 = toc;
error=max(max(abs(t_old-t)));
t_old = t;
iter_3=iter_3 +1;
time= toc;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('transient state Implicit using SOR = %d', iter_3);
title_text2 = sprintf('Simulation time +%f s', time3);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
end
OUTPUT:
Jacobi
Gauss-seidel
Successive over-relaxation
Transient State 2D (Explicit):
In the explicit method the next values is estimated based on the already exsisted parameters, which means the n+1 nodes is calculated by nth step parameters.
Here, the time derivative is discretised by FDS first order while space derivative is discretised by 2nd order CDS;
∂T∂t=α∇2T
∂T∂t=Tn+1−TmΔt
Tn+1=Tn+αΔt(TL−2T+TRΔx2+TB−2T+TTΔy2)
Assuming k1=α(ΔtΔx2),k2=α(ΔtΔy2)
Tn+1+Tn+k1(TL−2Tn+TR)+k2(TB−2Tn+TT)
MATHS CODE:
clear all
close all
clc
%% inputs
nx = 10; % number of grids in x direction
ny = nx; % number of grids in y direction
alpha = 0.3; % thermal diffusivity
omega = 1.2; % SOR value, should be greater than 1 and less than 2
tolerance = 1e-4; % tolerance
error = 9e9; % initial guess for the error
T=5; % time limit in sec
dt = 0.01; % time step
nt = T/dt;
x = linspace(0,1,nx); % x axis mesh
y = linspace(0,1,ny); % y axis mesh
% grid spacing
dx= x(2)-x(1);
dy= y(2)-y(1);
[xx,yy] = meshgrid(x,y);
% matrix difination
t= 300*ones(nx,ny); % Initail temperatures guess
t(end,:) = 900; % top face
t(1,:) = 600; % Bottom face
t(:,1) = 400; % left face
t(:,end) = 800; % right face
k1= alpha*dt/dx^2;
k2= alpha*dt/dy^2;
k = 1-(2*k1)-(2*k2); % Explicit constant term
t_old = t;
t_p = t;
%% Solving method
method = 'which method ? '
solver = input(method); % \'1\' for jacobi
% \'2\' for Gauss-sidel
% \'3\' for SOR
%% JACOBI SOLVER
if solver ==1
iter_1 = 1;
nt = T/dt;
tic
for m = 1:nt
while (error>tolerance)
for i = 2:nx-1
for j = 2:ny-1
TL = t_old(i-1,j);
TR = t_old(i+1,j);
TB = t_old(i,j-1);
TT = t_old(i,j+1);
H = TL +TR;
V = TB +TT;
t(i,j) = t_p(i,j)*k + k1*H +k2*V;
end
end
error = max(max(abs(t-t_old)));
t_old = t;
iter_1 = iter_1 +1;
end
t_p = t;
end
time1 = toc;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('transient state Explicit using Jacobi = %d', iter_1);
title_text2 = sprintf('Simulation time +%f s', time1);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
%% Gauss-siedel method
if solver ==2
iter_2 = 1;
nt = T/dt;
tic
for m = 1:nt
while (error>tolerance)
for i = 2:nx-1
for j = 2:ny-1
%TL = t_old(i-1,j);
TR = t_old(i+1,j);
%TB = t_old(i,1j-1);
TT = t_old(i,j+1);
H = t(i-1,j) +TR;
V = t(i,j-1) +TT;
t(i,j) = t_p(i,j)*k +H*k1 +V*k2;
end
end
error = max(max(abs(t-t_old)));
t_old = t;
iter_2 = iter_2 +1;
end
t_p = t;
end
time2 = toc;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('transient state Explicit using GS = %d', iter_2);
title_text2 = sprintf('Simulation time +%f s', time2);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
%% Successive over relaxation (SOR) method
if solver ==3
iter_3 = 1;
tic
for m = 1:nt
while (error>tolerance)
for i = 2:nx-1
for j = 2:ny-1
%TL = t_old(i-1,j);
TR = t_old(i+1,j);
%TB = t_old(i,j-1);
TT = t_old(i,j+1);
H = t(i-1,j) +TR;
V = t(i,j-1) +TT;
tgs(i,j) = t_p(i,j)*k +H*k1 +V*k2;
t(i,j) = (1-omega)*(t_old(i,j))+omega*tgs(i,j);
end
end
error = max(max(abs(t-t_old)));
t_old = t;
iter_3 = iter_3 +1;
end
t_p = t;
end
time3 = toc;
[x,y]= contourf(xx,yy,t);
colormap(jet)
colorbar
clabel(x,y)
pause(0.03)
title_text1 = sprintf('transient state Explicit using SOR = %d', iter_3);
title_text2 = sprintf('Simulation time +%f s', time3);
title_text3 = sprintf('Final error = %f' , error);
title({title_text1; title_text2;title_text3})
end
OUTPUT:
Jacobi
Gauss-seidel
Successive over-relaxation
For Explicit Scheme, we cannot use the same time steps and length of mesh domain, as it yields to higher CFL number, which leads to unstable solution unconverging. For the convenient I have taken the time steps and length domain for both x and y axis mentioned in the code section.
Results and Observations:
Comparing with the Different iterations approaches and states, we can conclude the following things
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 1 : CFD Meshing for Tesla Cyber Truck
CFD Meshing for Tesla Cyber Truck Initial Model First of all…
09 Nov 2022 05:46 PM IST
Week 10 - Simulating Combustion of Natural Gas.
COMBUSTION Combustion is defined as a chemical reaction in which a hydrocarbon reacts with an oxidant to form products, accompanied by the release of energy in the form of heat. Combustion manifests as awode domain during the design, analysis, and performance characteristics stage by being an integral part of various…
08 Nov 2022 07:38 PM IST
Week 9 - Parametric study on Gate valve.
Theory: Introduction: Gate valves are designed for fully open or fully closed service. They are installed in pipelines as isolating valves and should not be used as control or regulating valves. Operation of a gate valve is performed doing an either clockwise to close (CTC) or clockwise…
07 Nov 2022 05:07 PM IST
Week 12 - Validation studies of Symmetry BC vs Wedge BC in OpenFOAM vs Analytical H.P equation
Angles to test: θ=100 θ=250 θ=450 Expected Results Validate Hydro-dynamic length with the numerical result Validate the fully developed flow velocity profile with its analytical profile Validate maximum velocity and pressured drop for fully developed flow Post-process Shear stress and validate…
06 Nov 2022 06:53 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.