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 the 2D heat conduction equation under steady and transient conditions using the explicit and implicit methods. OBJECTIVE Steady state analysis & Transient State Analysis Solve the 2D heat conduction equation by using the point iterative…
Manu Mathai
updated on 02 Mar 2023
AIM
To solve the 2D heat conduction equation under steady and transient conditions using the explicit and implicit methods.
OBJECTIVE
Solve the 2D heat conduction equation by using the point iterative techniques that were taught in the class. The Boundary conditions for the problem are as follows;
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 equations.
Your absolute error criteria is 1e-4
INTRODUCTION
Heat conduction (or thermal conduction) is the transmission of heat from one object to another one that has a different temperature, when they are in direct contact with each other. Is project we are going to solve the 2D heat conduction equation under steady and transient conditions using the explicit and implicit methods. The heat equation is a second order partial differential equation that describes how the distribution of some quantity such as heat evolves over time in a solid medium, as it spontaneously flows from place where it is higher towards places where it is lower. It is a special case of the diffusion equation.
In physics and engineering contexts, especially in the context of diffusion through a medium, it is more common to fix a Cartesian coordinate system and then to consider the specific case of a function T(x, y, z, t) of three spatial variables (x, y, z) and time variable t. One then says that u is a solution of the heat equation.
∂2T∂t2=α.(∂2T∂x2+∂2T∂y2+∂2T∂z2)
THEORY
Discretization
Discretization methods are used to divide the region of a continuous function i.e., the real solution to a system of differential equations into a discrete function, where the solution values are defined at each point in space and time. Discretization simply refers to the spacing between each point in solution space and then replace derivatives in the governing equation with difference quotients.
Finite Difference Method
In numerical analysis, finite-difference methods (FDM) are a class of numerical techniques for solving differential equations by approximating derivatives with finite differences. Based on finite differences, it gives the numerical solutions for the values at discrete points in the domain which are known as grid points.
Finite differences method are used to compute approximate derivatives. This is used in numerical analysis in numerical ordinary differential equations and numerical partial differential equations, which gives the numerical solution of ordinary and partial differential equations respectively. The resulting methods are called finite-difference methods. Finite difference representations of derivatives are derived from Taylor series expansions.
Point Iterative Technique
An iterative method uses an initial value to generate a sequence of improving approximate solutions for a class of problems, in which the n-th approximation is derived from the previous ones. A specific implementation of an iterative method, including the termination criteria, is an algorithm of the iterative method. An iterative method is called convergent if the corresponding sequence converges for given initial approximations.
Steady State
The meaning of Steady-state is that the properties measured in any field of space do not vary with respect to time. In general, even after some time(t) the properties in a considered point of interest do not vary and will remain constant throughout the process. This is the basic concept of a steady-state system. So when a system is said to be in a Steady-state condition, then, it is providing a better case to fix the assumption values which makes the calculation better and is also majorly used in Engineering problems and when we see this concept applied in the domain of heat transfer, our region of interest would be in finding the heat transfer across the field to find out its temperature profile.
Steady-state conduction is the form of conduction that happens when the temperature difference driving the conduction is constant, so that after an equilibration time, the spatial distribution of temperatures in the conducting object does not change any further. In steady-state conduction, the amount of heat entering any region of an object is equal to the amount of heat coming out (if this were not so, the temperature would be rising or falling, as thermal energy was tapped or trapped in a region).
The Steady State form of the 2-D Heat Conduction Equation is given by,
∂2T∂x2+∂2T∂y2=0 or ∇2T=0 (Laplacian Equation)
Transient State (Unsteady State)
Heat transfer is the phenomenon that causes the flow of heat energy from the elevated temperature source to the lower temperature side. The modes of heat transfer also can be classified as Conduction, Convection, and Radiation, and here we deal only with conduction. Any system when involving a change in energy within itself due to temperature difference starts as an Unsteady state condition wherein the change in temperature occurs with respect to time. This is because during the start of the process there would be a huge temperature difference between the system and the surroundings due to which it adapts an unsteady or transient condition of heat transfer initially, but later on, when the inlet energy flow and the energy going out (which causes the transient condition) becomes equal, there will be only steady-state heat transfer prevailing inside the system till the end until achieving a Steady-state of the temperature profile, provided there is no external influence of any properties over the system that causes a change in the temperature profile.
During any period in which temperatures changes in time at any place within an object, the mode of thermal energy flow is termed transient conduction. Another term is "non-steady-state" conduction, referring to the time-dependence of temperature fields in an object.
The Transient form of the 2-D Heat Conduction Equation is given by,
∂T∂t+α(∂2T∂x2+∂2T∂y2)=0 or ∂T∂t+α(∇T)=0
Where, ∇T = Laplacian of T.
Explicit Method
When a direct computation is made for an unknown quantity in terms of known quantity. This computation is called Explicit. This method requires stability criteria which when satisfied leads to stable solution. Because of the stability criteria small time steps has to be taken to obtain stable solutions. With decrease in time step the number of computation increases and hence the computational time required for the solution to converge is less and accuracy of the solution is high.
Implicit Method
When a computation is made for dependent variable are defined by set of equations and a matrix is involved to find the unknown variable. This computation is called Implicit method. This method is unconditionally stable as a result, no stability criteria is required to obtain a stable results and the computational time required for the solution to converge is high and accuracy of the solution is less relative to explicit method because this method uses simultaneous equations and uses guess values as the initial values to find the approximated values. If the guess values are closer to the desired value the computation time is less. As there is no stability criteria requirement larger time steps can be used.
ITERATIVE SOLVERS
In CFD, we may have a set of linear equations which we can solve by two no. of ways (i) Direct method and (ii) Iterative method.
(i) Direct Method
The direct method uses both Gauss-Seidel and Jacobian methods where it can solve a (n x n) matrix with a fixed number of steps. But, this method is inefficient for some engineering problems, since some may have millions of cells forming a huge matrix to solve. Hence for the solving of such kind of huge matrix, the system must require more space. Therefore, the usage of the Direct Method is not a feasible way to get the linear equations solved in CFD.
Thus we go for an alter for solving such equations, that is by using Iterative Methods.
(ii) Iterative Method
The iterative methods are a better and efficient aliter for the Direct method. Here we will be solving the equations in a way that takes the previously calculated values for a particular grid point at its corresponding time step(for transient condition only) or from its previous time step to calculate the function at that specific point with the help of the reframed governing equations that follows the criterion of different iterative solvers, like,
Of which all the above-mentioned iterative solvers are of Implicit forms. Apart from this, for the Unsteady-state condition, we also do have an explicit form/method to solve the problem statement.
The following flow-chart represents the follow-up of the procedure, how an Iterative solver functions.
In numerical linear algebra, the Jacobi method is an iterative algorithm for determining the solutions of a strictly diagonally dominant system of linear equations. Each diagonal element is solved for, and an approximate value is plugged in. The process is then iterated until it converges.
It is one of the types of Iterative solvers, which solves for the diagonal elements of the matrix formed by the linear equations, and the values are approximated in each of the iterations and are just inserted again into the equation until it converges. It generally forms its right-hand side with known values i.e., taking the values from the previous iterations only.
Gauss-Seidel method is an iterative method to solve a set of linear equations and is very much similar to Jacobi’s method. This method is also known as the Liebmann method or the method of successive displacement. The name successive displacement is because the second unknown is determined from the first unknown in the current iteration, and the third unknown is determined from the first and second unknowns.
It is also similar to the Jacobian method, and also strictly requires the diagonal matrix for it to perfectly converge. The only difference is that it also forms the right-hand side with values that were just calculated from that corresponding iteration step.
The method of successive over-relaxation (SOR) is a variant of the Gauss-Siedel method for solving a linear system of equations, resulting in faster convergence. A similar method can be used for any slowly converging iterative process
This method is used over the Jacobian (or) Gauss-Seidel methods to enhance their results even more quickly with an additional component called Scaling Factor(alpha).
TWO - DIMENSIONAL STEADY STATE HEAT CONDUCTION EQUATION
The steady state Two -Dimensional Heat Conduction Equation,
∂2T∂x2+∂2T∂y2=0
∇2T=0 (Laplacian Equation)
This is the second order partial differential equation. Laplace's equation are in the simplest form of elliptic partial differential equation.
To discretize this second order partial differential equation in space along (x & y axis) to use the Central Difference scheme for space derivative. The partial derivative can be approximated using the derivative definition will be applied for space.
∂2T∂x2=Ti+1,j−2Ti,j+Ti−1,jdx2
∂2T∂y2=Ti,j+1−2Ti,j+Ti,j−1dy2
Substituting above Equations in steady state Two -Dimensional Heat Conduction Equation,
Ti+1,j−2Ti,j+Ti−1,jdx2+Ti,j+1−2Ti,j+Ti,j−1dy2=0
Rearranging the Equation,
2Ti,jdx2+2Ti,jdy2=Ti+1,j+Ti−1,jdx2+Ti,j+1+Ti,j−1dy2
Simplifying the equation by considering,
T(i,j) = TP
T(i+1,j) = TR
T(i-1,j) = TL
T(i,j+1) = TT
T(i,j-1) = TB
Tp⎡⎢ ⎢⎣2(dx2)+(dy2)(dx2)⋅(dy2)⎤⎥ ⎥⎦=TR+TLdx2+TT+TBdy2
Considering K=2((dx2)+(dy2))(dx2)⋅(dy2)
Rearranging the Equations,
Ti,j=(1k)Ti+1,j+Ti−1,jdx2+(1k)Ti,j+1+Ti,j−1dy2
or
Ti,j=(1k)[Ti+1,j+Ti−1,jdx2+Ti,j+1+Ti,j−1dy2]
Jacobian Iterative Solver
T(i,j)=(T(i−1,j)+T(i+1,j)k⋅dx2+T(i,j−1)+T(i,j−1)k⋅dy2)old
Gauss-Seidel Iterative Solver
T(i,j)=(T(i−1,j)old+T(i+1,j)k⋅dx2+T(i,j−1)old+T(i,j−1)k⋅dy2)
Successive Over Relaxation Iterative Solver
T(i,j)=(1−ω)T(i,j)old+ω(T(i−1,j)old+T(i+1,j)k⋅dx2+T(i,j−1)old+T(i,j−1)k⋅dy2)
TRANSIENT STATE ANALYSIS OF 2-D HEAT CONDUCTION EQUATION
TRANSIENT STATE
The Two -Dimensional Transient Heat Conduction equation is,
∂T∂t=α⋅[∂2T∂x2+∂2T∂y2]
This is the second order partial differential equation. Laplace's equation are in the simplest form of elliptic partial differential equation and time dependent partial differential equation.
To discretize this equation in space and time to use the Forward Difference scheme for time derivative and Central Difference scheme for space derivative. The partial derivative can be approximated using the derivative definition will be applied both for space and time;
Here the terms represents,
∂T∂t=TimeDerivativeterm
[∂2T∂x2+∂2T∂y2]=SpaceDerivativeTerm
α = Thermal Diffusivity
Time derivative
Applying Forward difference scheme for the time derivative;
∂2T∂x2=Ti+1,j−2Ti,j+Ti−1,jdx2
∂2T∂y2=Ti,j+1−2Ti,j+Ti,j−1dy2
Substituting the above equations in Two -Dimensional Transient Heat Conduction equation
Tn+1i,j−Tni,j△t=α⋅[Ti+1,j−2Ti,j+Ti−1,jdx2+Ti,j+1−2Ti,j+Ti,j−1dy2]n
Rearranging the Equation;
Tn+1i,j=Tni,j+α⋅(Δtdx2)⋅(Ti+1,j−2Ti,j+Ti−1,j)+α⋅(Δtdy2)⋅(Ti,j+1−2Ti,j+Ti,j−1)]n
Considering,
K1=α⋅(Δtdx2)
K2=α⋅(Δtdy2)
Tn+1i,j=Tni,j+[(K1)⋅(Ti+1,j−2Ti,j+Ti−1,j)+(K2)⋅(Ti,j+1−2Ti,j+Ti,j−1)]n
where n+1 and n are two consecutive steps in time and i,j are neighbouring points of the discretized x an Y - coordinate (grid points). The only unknown in the equation written in this way is Tn+1i,j .To solve for this unknown to get an equation that allows us to advance in time as Time Marching Procedure Method. This equation is used in program to solve the 2-D Heat conduction equation numerically.
Explicit And Implicit Method
(ie;), if know the state at n, can calculate the state at n+1.
Explicit Equation
Tn+1i,j=Tni,j+[(K1)⋅(Ti+1,j−2Ti,j+Ti−1,j)+(K2)⋅(Ti,j+1−2Ti,j+Ti,j−1)]n
or
Tn+1p=Tnp+[(K1)⋅(TR−2TP+TL)+(K2)⋅(TT−2TP+TB)]n
Implicit equation
Tn+1i,j=Tni,j+[(K1)⋅(Ti+1,j−2Ti,j+Ti−1,j)+(K2)⋅(Ti,j+1−2Ti,j+Ti,j−1)]n+1
or
Tn+1i,j=Tni,j+(K1)⋅(Ti+1,j+Ti−1,j)+(K2)⋅(Ti,j+1+Ti,j−1)n+11+(2⋅(K1+K2))
Tn+1P=TnP+(K1)⋅(TR+TL)+(K2)⋅(TT+TB)n+11+(2⋅(K1+K2))
Courant Number
The Courant-Friedrichs-Lewy (CFL) condition is absolutely essential in solving the partial differential equations. This non dimensionless number arises while solving the time marching problems. It expresses that the distance that any information travels during the time step length within the mesh must be lower than the distance between mesh elements.
In other words, information from a given cell or mesh element must propagate only to its immediate neighbors. The derivation of the CFL condition leads to the formula for Courant number and is given by,
CFL=α⋅ΔtΔx2≤0.25;α⋅ΔtΔy2≤0.25
Where,
CFL = Courant number, u
α = Thermal Diffusivity
Δt = Time step size
Δx = The length between mesh elements.
When the Courant number exceeds the value of 0.5 for Heat conduction equation the solution will be unstable and blew off, instabilities are amplified throughout the domain and may cause divergence of the simulation.
CFL=α⋅(Δt)[1Δx2+1Δy2]≤0.5
Courant number can be controlled by altering the time or space interval. When the space interval is reduced or time interval is increased the courant number increases. Since courant number governs the stability of a problem in an explicit method it is very important to choose the intervals precisely.
SOLVING AND MODELLING APPROACH
STEP 1: Defining the input parameters for the domain.
STEP 2: Defining the distance to the number of nodes provided.
STEP 3: Assigning the Initial Temperature to the respective number of nodes .
STEP 4: Applying Boundary conditions to the Left, Right, Top and Bottom of the domain and assigning to the corner nodes.
STEP 6: Updating the Initial and old Temperature values.
STEP7: Creating a function to Compute the Iterative methods.
STEP 8: Using the iterative method (Jacobi, Gauss seidal and SOR method)to determine the Temperature distribution at steady state for the respective number of nodes.
STEP 9: Updating the current temperature Value.
STEP 10: Calling a function to detrmine the Temperature distribution @ steady state.
STEP 12: Using contourf, the temperature distribution are potted for x and y Direction.
MATLAB CODING
STEADY STATE HEAT CONDUCTION
Function Code:
% Creating a function to solve Iterative Methods,
function [T,iteration]=Iterative_solver(tol,error,It_s,nx,ny,T_old,T,dx,dy,k)
iteration=0;
switch It_s % Switching to Iterative Methods
%% Solving Using Jacobi Method,
case 1
while(error>tol) % Convergence loop
for i=2:nx-1 % Spacial loop on x
for j=2:ny-1 % spacial loop on y
H=(T_old(i-1,j)+T_old(i+1,j))/(dx^2);
V=(T_old(i,j-1)+T_old(i,j+1))/(dy^2);
T(i,j)=k*(H+V);
end
end
error=max(max(abs(T-T_old)));
T_old=T; % Updating Temperature
iteration=iteration+1;
end
%% Solving Using Gauss Seidal method,
case 2
while(error>tol) % Convergence loop
for i=2:nx-1 % Spacial loop on x
for j=2:ny-1 % spacial loop on y
H=(T(i-1,j)+T_old(i+1,j))/(dx^2);
V=(T(i,j-1)+T_old(i,j+1))/(dy^2);
T(i,j)=k*(H+V);
end
end
error=max(max(abs(T-T_old)));
T_old=T; % Updating Temperature
iteration=iteration+1;
end
%% Solving Using Successive Over Relaxation Method (SOR),
case 3
omega=1.5;
while(error>tol) % Convergence loop
for i=2:nx-1 % Spacial loop on x
for j=2:ny-1 % spacial loop on y
H=(T(i-1,j)+T_old(i+1,j))/(dx^2);
V=(T(i,j-1)+T_old(i,j+1))/(dy^2);
T(i,j)=k*(H+V);
T(i,j)=T_old(i,j)*(1-omega)+(omega*T(i,j));
end
end
error=max(max(abs(T-T_old)));
T_old=T; % Updating Temperature
iteration=iteration+1;
end
end
end
Main Code:
%% Solving 2-D Temperature Heat Conduction Equation,
% Steady State Heat Conduction Equation,
clear all;close all;clc
%% Inputting the parameters for Domain,
l=1; % Length of the domain
nx=40; % Number of Nodes on X -Axis
ny=nx; % Number of Nodes on y -Axis
% Defining the length of domain repect to number of nodes,
x=linspace(0,l,nx);
y=linspace(0,l,ny);
% Finding the Grid Size along x and y axis,
dx=x(2)-x(1); % Along X-axis
dy=y(2)-y(1); % Along Y-axis
%% Defining the Temperature,
T_i=250; % Initial condition for Temperature
T=T_i*ones(nx,ny);
% Applying Boundary Conditions,
T_L=400;
T_T=600;
T_R=800;
T_B=900;
% Assigning Boundary Conditions on Nodes,
T(1,:)=600; % Temperature on Top
T(end,:)=900; % Temperature on Bottom
T(:,1)=400; % Temperature on Left
T(:,end)=800; % Temperature on Right
% Assigning Average Temperature on Corner Grids,
T(1,1)=(T_L+T_T)/2;
T(1,ny)=(T_R+T_T)/2;
T(nx,1)=(T_L+T_B)/2;
T(nx,ny)=(T_B+T_R)/2;
% Updating the Temperature,
T_old=T;
% Defining Error & Tolerance;
tol=1e-4; % Tolerence
error=1e5; % Error
It_s=1:3; % For Different Iterative Schemes (Jcobo - 1, Gauss Seidal- 2, SOR - 3)
% Calculation
k=(dx^2*dy^2)/(2*(dx^2+dy^2));
%% Calling a function to solve Iterative Solvers,
[T_J,iteration_jacobi]=Iterative_solver(tol,error,It_s(1),nx,ny,T_old,T,dx,dy,k); % Calling Jacobi Method
[T_GS,iteration_GS]=Iterative_solver(tol,error,It_s(2),nx,ny,T_old,T,dx,dy,k); % Calling Gauss Seidal Method
[T_SOR,iteration_SOR]=Iterative_solver(tol,error,It_s(3),nx,ny,T_old,T,dx,dy,k); % Calling SOR Method
%% Plotting,
% Plotting for Temperature Distribution by Jacobi Method
figure("Name",'STEADY STATE ANALYSIS')
contourf(x,y,T_J,'ShowText','on','LineWidth',0.5);
colorbar
colormap(jet)
set(gca,'YDir','reverse')
text_title=({'2-DSteady State Heat Conduction (Jacobi Method)';['No.of.Grid Points =',num2str(nx)];['Total Iterations =',num2str(iteration_jacobi)]});
title(text_title)
xlabel('X-Direction')
ylabel('Y-Direction')
% Plotting for Temperature Distribution by Gauss Seidal Method
figure("Name",'STEADY STATE ANALYSIS')
contourf(x,y,T_GS,'ShowText','on','LineWidth',0.5);
colorbar
colormap(jet)
set(gca,'YDir','reverse')
text_title=({'2-D Steady State Heat Conduction (Gauss Seidal Method)';['No.of.Grid Points =',num2str(nx)];['Total Iterations =',num2str(iteration_GS)]});
title(text_title)
xlabel('X-Direction')
ylabel('Y-Direction')
% Plotting for Temperature Distribution by Successive Over Relaxation (SOR) Method
figure("Name",'STEADY STATE ANALYSIS')
contourf(x,y,T_SOR,'ShowText','on','LineWidth',0.5);
colorbar
colormap(jet)
set(gca,'YDir','reverse')
text_title=({'2-D Steady State Heat Conduction (SOR Method)';['No.of.Grid Points =',num2str(nx)];['Total Iterations =',num2str(iteration_SOR)]});
title(text_title)
xlabel('X-Direction')
ylabel('Y-Direction')
Code Explanation
TRANSIENT STATE HEAT CONDUCTION
EXPLICIT:
%% Solving 2-D Temperature Heat Conduction Equation,
% Transient Heat Conduction Equation, By Using Explicit Method,
clear all;close all;clc
% Inputting the parameters for Domain,
l=1; % Length of the domain
nx=40; % Number of Nodes on X -Axis
ny=nx; % Number of Nodes on y -Axis
% Defining the length of domain repect to number of nodes,
x=linspace(0,l,nx); % Along X-Direction
y=linspace(0,l,ny); % Along Y- Direction
% Finding the Grid Size along x and y axis,
dx=x(2)-x(1);
dy=y(2)-y(1);
% Defining the Initial Temperature,
T_i=250; % Initial condition for Temperature
T=T_i*ones(nx,ny); % Assigning Temperature on nodes
% Applying Boundary Conditions,
T_L=400; % Temperature on the Left
T_T=600; % Temperature on the TOP
T_R=800; % Temperature on the RIGHT
T_B=900; % Temperature on the BOTTOM
% Assigning Boundary Conditions on Nodes,
T(1,:)=600; % Temperature on Top
T(end,:)=900; % Temperature on Bottom
T(:,1)=400; % Temperature on Left
T(:,end)=800; % Temperature on Right
% Assigning Average Temperature on Corner Grids,
T(1,1)=(T_L+T_T)/2;
T(1,ny)=(T_R+T_T)/2;
T(nx,1)=(T_L+T_B)/2;
T(nx,ny)=(T_B+T_R)/2;
% Updating the current Temperature,
T_old=T;
% Defining the Time Steps
t=0.15; % Time for Temperature Distribution
dt=1e-4; % Time steps
nt=t/dt; % Number of Time Steps
alpha=1.4; % Thermal Diffusivity
% Calculations,
k1=alpha*(dt/dx^2);
k2=alpha*(dt/dy^2);
CFL=k1+k2;
%% TIME MARCHING PROCEDURE,
Iteration=1;
for k=1:nt % Time loop
for i=2:nx-1 % Space loop
for j=2:ny-1 % Space loop
H=(T_old(i+1,j)-2*T(i,j)+T_old(i-1,j));
V=(T_old(i,j+1)-2*T(i,j)+T_old(i,j-1));
T(i,j)=T_old(i,j)+k1*(H)+k2*(V);
end
end
T_old=T;
Iteration=Iteration+1;
end
%% PLOTTING FOR EXPLICIT METHOD
figure('Name','TRANSIENT STATE ANALYSIS - EXPLICIT')
contourf(x,y,T,'ShowText','on','LineWidth',0.5);
colorbar
colormap(jet)
set(gca,'YDir','reverse')
title('2-D Transient State Heat Conduction (Explicit Method)')
text=sprintf(['Total Iterations =%d; ','CFL=%g\n ','Grid Points=%g; ','dt=%g; ','dx=%g'],...
Iteration,CFL,nx,dt,dx);
subtitle(text)
xlabel('X-Direction')
ylabel('Y-Direction')
Code Explanation:
IMPLICIT:
%% Solving 2-Dimensional Temperature Heat Conduction Equation,
% Transient Heat Conduction Equation, By Using Implicit Method,
clear all;close all;clc
%% Inputting the Domain Parmeters,
l=1; % Length of the domain
nx=40; % Number of Nodes on X -Axis
ny=nx; % Number of Nodes on y -Axis
% Defining the length of domain repect to number of nodes,
x=linspace(0,l,nx);
y=linspace(0,l,ny);
% Finding the Grid Size along x and y axis,
dx=x(2)-x(1); % On X-axis
dy=y(2)-y(1); % on Y-axis
%% Defining the Initial Temperature,
T_i=250; % Initial condition for Temperature
T=T_i*ones(nx,ny); % Assigning Temperature on nodes
% Applying Boundary Conditions,
T_L=400; % Temperature on the Left
T_T=600; % Temperature on the TOP
T_R=800; % Temperature on the RIGHT
T_B=900; % Temperature on the BOTTOM
% Assigning Boundary Conditions on Nodes,
T(1,:)=600; % Temperature on Top
T(end,:)=900; % Temperature on Bottom
T(:,1)=400; % Temperature on Left
T(:,end)=800; % Temperature on Right
% Assigning Average Temperature on Corner Grids,
T(1,1)=(T_L+T_T)/2;
T(1,ny)=(T_R+T_T)/2;
T(nx,1)=(T_L+T_B)/2;
T(nx,ny)=(T_B+T_R)/2;
% Updating the Temperatures,
T_old=T;
T_prev=T;
% Defining the Time Steps
t=0.2; % Time for Temperature Distribution
dt=1e-4; % Time steps
nt=t/dt; % Number of Time Steps
alpha=1.4; % Thermal Diffusivity
% Calculations,
k1=alpha*(dt/dx^2);
k2=alpha*(dt/dy^2);
CFL=k1+k2;
Term1=1/(1+(2*(k1+k2)));
Term2=k1*Term1;
Term3=k2*Term1;
% Defining the Tolerence,
tol=1e-4; % Tolerence Creteria
omega=1.2; % Relaxation Factor
Iteration=1; % Initial Iteration
%% Input User Selection Prompt,
prompt=(['Select Iterative Method\n (1).JACOBI ITERATIVE METHOD\n ' ...
'(2).GAUSS SEIDAL ITERATIVE METHOD\n ' ...
'(3).SOR ITERATIVE METHOD\n']);
Iterative_Method=input(prompt);
%% Solving 2-D Using Iterative Method,
% Time loop,
tic
for k=1:nt
error=1e5; % Initialize Error on each iteration time loop
if Iterative_Method==1 %% Jacobi Iterative Method
% Convergence loop
while error>tol
% Nodal loop
for i=2:nx-1
for j=2:ny-1
H=(T_old(i+1,j)+T_old(i-1,j));
V=(T_old(i,j+1)+T_old(i,j-1));
T(i,j)=((T_prev(i,j)*Term1)+(Term2*H)+(Term3*V));
end
end
error=max(max(abs(T-T_old)));
% Updating temperatures,
T_old=T;
Iteration=Iteration+1;
end
end
%% Gauss Seidal Iterative Method
if Iterative_Method==2
% Convergence loop
while error>tol
% Nodal loop
for i=2:nx-1
for j=2:ny-1
H=(T_old(i+1,j)+T(i-1,j));
V=(T_old(i,j+1)+T(i,j-1));
T(i,j)=((T_prev(i,j)*Term1)+(Term2*H)+(Term3*V));
end
end
error=max(max(abs(T-T_old)));
% Updating temperatures,
T_old=T;
Iteration=Iteration+1;
end
end
%% Successive Over Relaxation (SOR) Iterative Method
if Iterative_Method==3
% Convergence loop
while error>tol
% Nodal loop
for i=2:nx-1
for j=2:ny-1
H=(T(i-1,j)+T_old(i+1,j));
V=(T(i,j-1)+T_old(i,j+1));
T(i,j)=((T_prev(i,j)*Term1)+(Term2*H)+(Term3*V));
T(i,j)=(T_old(i,j)*(1-omega))+omega*T(i,j);
end
end
error=max(max(abs(T-T_old)));
% Updating temperatures,
T_old=T;
Iteration=Iteration+1;
end
end
T_prev=T;
sim_time_Jacobi=toc; % Simulation time for Jacobi Iteration
sim_time_Gs=toc; % Simulation time for Gauss seidal Iteration
sim_time_SOR=toc; % Simulation time for SOR Iteration
%% Plotting
figure(1)
contourf(x,y,T,'ShowText','on','LineWidth',0.5)
colorbar
colormap('jet')
set(gca,'YDir','reverse')
if Iterative_Method==1
title('2-D Transient State Heat Conduction (Implicit - Jacobi Method)')
text=sprintf(['Total Iterations =%d; ','CFL=%g\n ','Grid Points=%g; ','dt=%g; ','dx=%g\n','Simulation Time=%g'],...
Iteration,CFL,nx,dt,dx,sim_time_Jacobi);
subtitle(text)
elseif Iterative_Method==2
title('2-D Transient State Heat Conduction (Implicit - Gauss Seidal Method)')
text=sprintf(['Total Iterations =%d; ','CFL=%g\n ','Grid Points=%g; ','dt=%g; ','dx=%g\n','Simulation Time=%g'],...
Iteration,CFL,nx,dt,dx,sim_time_Gs);
subtitle(text)
elseif Iterative_Method==3
title('2-D Transient State Heat Conduction (Implicit - SOR Method)')
text=sprintf(['Total Iterations =%d; ','CFL=%g\n ','Grid Points=%g; ','dt=%g; ','dx=%g\n','Simulation Time=%g'],...
Iteration,CFL,nx,dt,dx,sim_time_SOR);
subtitle(text)
end
xlabel('X-Direction')
ylabel('Y-Direction')
end
Code Explanation:
RESULT
STEADY STATE HEAT CONDUCTION
TRANSIENT STATE
EXPLICIT
IMPLICIT
CONCLUSION
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...
Week 3: Flow over a backward facing step
AIM: To run the simulation of Flow over a Backward facing step with three different base mesh sizes with help of using Converge Studio, Cygwin and Paraview and camparing the parameters. OBJECTIVE:- . Run 3 simulation . with 3 different base mesh sizes are 1. dx = 2e-3m dy = 2e-3m dz = 2e-3m …
11 Sep 2023 08:35 AM IST
Project 2 - 3D CFD modelling of Air cooling system and liquid cooling system for battery thermal management
1. Comparative study of thermal performance of air-cooled and liquid-cooled battery modules:- Air-cooled module:- The temperature distribution over the module surface with the air-cooling system at the end of the discharge process. The flow rate and temperature of the air at the inlet of the cooling system are 3 L/s and…
11 Sep 2023 08:25 AM IST
Week 1: Channel flow simulation using CONVERGE CFD
Introduction: Channel flow is an internal flow in which the confining walls change the hydrodynamic structure of the flow from an arbitrary state at the channel inlet to a certain state at the outlet. The simplest illustration of internal flow is a laminar flow in a circular tube, while a turbulent flow in the rotor of…
01 Sep 2023 10:15 AM IST
Project 1 - 1d modelling of liquid cooling system
Problem Description: we have a cooling plate mounted with 2 modules, each containing multiple cells. The flow pattern indicates that water is used as the coolant, flowing from a tank of limited capacity. The goal is to analyze the thermal behavior of the system, including plotting the top and bottom module temperatures,…
01 Sep 2023 10:03 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.