Week 5.1 - Mid term project - Solving the steady and unsteady 2D heat conduction problem
Aim: Solve the 2D heat conduction equation by using the point iterative techniques.
Objectives:
To solve the 2D heat conduction equation by using the point iterative techniques such as
- Jacobi
- Gauss-seidel
- Successive over-relaxation
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
And, the absolute error criteria are 1e-4,
The following are the cases that the equation should solve;
- Steady state equation solving.
- Unsteady state equation solving using explicit scheme.
- Unsteady state equation solving using implicit scheme.
Consider, that the area is a square geometry under the given boundary conditions
Steady state equation solving:
In the steady state condition, the amount of heat that leaves a body is equal to the amount of heat entering body without varying with time.
The general, 2D steady state heat conduction equation with no heat generation is
(δ2T)/(δx2)+(δ2T)/(δy2)=0
Discretization: Here, we use the central differencing method to discretize the second order PDE w.r.t x and y, that takes the information from both sides of the node.
so, by discretizing the above PDE using Central differencing scheme we get:
((TL-2TP+TR)/(δx2) + ((TT-2TP+TB)/(δy2))=0
By simplifying the above equation:
Tp =1/K ((TL+TR)/(δx2) + (TT+TB)/(δy2))
where, K= 2*((δx2)+(δy2)/(δx2δy2)
The above equation can be solved to compute the Temperature distribution by using fixed points method like Jacobi, Gauss-seidel, Successive over-relaxation.
Jacobi Method:
Tn+1i,j = 1/K (((Tni-1,j +Tni+1, j)/δx2) + (Tni, j-1+Tni,j+1)/δy2)
Here, from this method the Temperature Tn+1i,j is converged with Tn by n no.of iterating at each node repeatedly. After the equation is converged the Tn value is updated with Tn+1i,j This method is also called the method of simultaneous displacements.
Gauss Seidel:
Tn+1i,j = 1/K (((Tn+1i-1,j +Tni+1, j)/δx2) + (Tn+1i, j-1+Tni,j+1)/δy2)
Here, the Tn+1i,j is converged with Tn+1 by n+1 no.of iterating at each node repeatedly. Here we are solving the n+1th equation so the t old values are updated till nth iteration.
Successive over-relaxation:
Tn+1i,j = Tni, j(1-ω) + ω(TG.S)
where ω is relaxation factor
if ω > 1 ⇒ over relaxation
ω<1>
Usually SOR is a enhance iterative method that enhancers the values of Gauss seidel
Matlab code:
- steady state head conduction equation solverclear allclose allclc<!-- [if mso]>
<![endif]--><!-- [if mso]>
<![endif]-->% inputs and bct_t = 600;t_b = 900;t_l = 400;t_r = 800;nx = 10;ny = 10;T=300*ones(nx,ny); %initial temperature 300kx = linspace(0,1,nx);y = linspace(0,1,ny);dx=(x(2)-x(1));dy=(y(2)-y(1));k=2* (dx^2 + dy^2)/(dx^2 * dy^2);tolerance = 1e-4;T(2:ny - 1, 1) = t_l;T(2:ny - 1, nx) = t_r;T(1, 2:nx - 1) = t_t;T(ny, 2:nx - 1) = t_b;%assigning the values at the corner positions of the T matrix by taking average of adjacent valuesT(1,1)=(t_l+t_r)/2;T(ny,1)=(t_l+t_b)/2;T(1,nx)=(t_r+t_t)/2;T(ny,nx)=(t_r+t_b)/2;<!-- [if mso]>
<![endif]-->% jacobi methoderror_jacobi=1;t_old=T;J_iter=1;while(error_jacobi > tolerance)% space loopfor i=2:nx-1for j=2:ny-1T(i,j) = 1/k * ((t_old(i+1,j)+t_old(i-1,j))/dx^2+(t_old(i,j+1)+t_old(i,j-1))/dy^2);endenderror_jacobi = max(max(abs(t_old-T)));t_old = T;J_iter = 1+J_iter;endfigure(1)contourf(x,y,T)clabel(contourf(x,y,T))colorbarcolormap(jet)set(gca, 'ydir', 'reverse')xlabel x-axisylabel Y-axistitle(sprintf('No. of iterations in Jacobi method = %d',J_iter));pause (1);<!-- [if mso]>
<![endif]-->%Gauss-seidel methoderror_gauss_seidel=1;gauss_seidel_iter =1;t_old_1 = T;t_old_initial = T;while (error_gauss_seidel > tolerance)for i=2:nx-1for j=2:ny-1t_old_1(i,j) = ((t_old_1(i+1,j)+t_old_1(i-1,j))/dx^2+(t_old_1(i,j+1)+t_old_1(i,j-1))/dy^2)/k;endenderror_gauss_seidel= max(max(abs(t_old_initial-t_old_1)));t_old_initial = t_old_1;gauss_seidel_iter= gauss_seidel_iter+1;endfigure(2)contourf(x,y,t_old_1)clabel(contourf(x,y,t_old_1))colorbarcolormap(jet)set(gca, 'ydir', 'reverse')xlabel x-axisylabel Y-axistitle(sprintf('No. of iterations in gauss seidel method = %d',gauss_seidel_iter));pause (1);<!-- [if mso]>
<![endif]-->%Successive over-relaxationerror_sor=1;sor_iter=1;t_old_initial_2=T;t_old_2=T;alpha=1.4;while(error_sor>tolerance)for i=2:nx-1for j=2:ny-1t_old_2(i,j) = (1-alpha)*t_old_initial_2(i,j)+(alpha/k)*((t_old_2(i+1,j)+t_old_2(i-1,j))/dx^2+(t_old_2(i,j+1)+t_old_2(i,j-1))/dy^2);endenderror_sor = max(max(abs(t_old_initial_2-t_old_2)));t_old_initial_2=t_old_2;sor_iter=sor_iter+1;endfigure(3)contourf(x,y,t_old_2)clabel(contourf(x,y,t_old_initial_2))colorbarcolormap(jet)set(gca, 'ydir', 'reverse')xlabel x-axisylabel Y-axistitle(sprintf('No. of iterations in sor method = %d',sor_iter));pause (1);Explanation:
- At first, we defined the input and boundary condition parameters of matrix T as 10x10 and defined the axis length as 1m and error as 1 and tolerance value as 1e-4
- And the above calculated K equation is defined and then calculated the corner points of the square matrix by taking the average of adjacent points.
- Here, we define the convergence loop and space loop then define the specified iteration equation as derived above, when we run the iteration, the maximum temperature is calculated within the tolerance.
- After the completion of the iteration the old values of T are updated.
- Then plotted the x, y and T values
Results:



Conclusion:
Here, we observe that for all type of iterative techniques the results are almost similar and the plotted graph is similar in all cases, but the number iterations ran in the Jacobi method are more nearly 208 and the rest of the methods results less iterations.
Unsteady state (or) Transient state equation solving using explicit scheme:
In a transient state condition, the heat transfer takes place between the system and surroundings within the boundary condition by varying the time interval. Then general two-dimensional heat transfer equation in Transient state condition is:
(δT/δt)=α((δ2T)/(δx2)+(δ2T)/(δy2))
(Tn+1p-Tnp)/Δt = α ((TL-2TP+TR)/(∇x2) + ((TT-2TP+TB)/(∇y2))n
If it runs n timesteps = explicit
if it runs n+1 timesteps = implicit
(Tn+1p-Tnp)/Δt = Tnp+ K1(TL-2TP+TR)n + K2(TT-2TP+TB)n
where, CFLx = K1 = (αΔt)/(∇x2))
CFLy = K2 = (αΔt)/(∇y2)
the solution is efficient if CFLx + CFLy ≤ 0.5 and considering α =1.4
Matlab code:
clear allclose allclc<!-- [if mso]>
<![endif]-->%inputs and boundary conditionst_t = 600;t_b = 900;t_l = 400;t_r = 800;nx = 10;ny = nx; % size of matrixT=100*ones(nx,ny); %initial temperature 100kx = linspace(0,1,nx);y = linspace(0,1,ny);dx=(x(2)-x(1));dy=(y(2)-y(1));tolerance = 1e-4;alpha=1.4;dt=1e-4;<!-- [if mso]>
<![endif]-->T(2:ny - 1, 1) = t_l; %first column elementsT(2:ny - 1, nx) = t_r; %last column elementsT(1, 2:nx - 1) = t_t; %first row elementsT(ny, 2:nx - 1) = t_b; %last row elements%assigning the values at the corner positions of the T matrix by taking average of adjacent valuesT(1,1)=(t_l+t_r)/2;T(ny,1)=(t_l+t_b)/2;T(1,nx)=(t_r+t_t)/2;T(ny,nx)=(t_r+t_b)/2;%solving the equation using explicit schemeT_old = T;term1=T;term2=T;term3=T;error_expicit=1;<!-- [if mso]>
<![endif]-->%time loopfor nt=1:1400error =1;%convergence loopwhile (error > tolerance)%space loopfor i=2:nx-1for j=2:ny-1% simplified explicit equationterm1 = T_old(i,j);term2= alpha*(dt/(dx^2))*((T_old(i+1,j)-2*T_old(i,j)+T_old(i-1,j)));term3= alpha*(dt/(dy^2))*((T_old(i,j+1)-2*T_old(i,j)+T_old(i,j-1)));T(i,j)=term1+term2+term3;endenderror = max(max(abs(T_old - T)));T_old = T; % updating the old T valueserror_expicit = error_expicit+1;endend<!-- [if mso]>
<![endif]-->contourf(x,y,T) -countour plotclabel(contourf(T))colormap(jet)set(gca, 'ydir', 'reverse')xlabel x-axisylabel y-axistitle(sprintf('No. of iterations in explict method = %d',error_expicit));pause(1);
- At first, we defined the inputs and boundary conditions of the matrix of size 10x10 that means it's a square matrix and calculated the corner mid points of the matrix.
- And defined the axis length as 1m and error as 1 and tolerance value as 1e-4, alpha value as 1.4. Then I defined the initial error and T old values.
- Then mentioned the time loop and convergence loop, then the space loop.
- Then, we defined the simplified explicit scheme by simplifying the terms. After the computation of the code loop vise within the tolerance limits.
- After that the T old values are updated at the end of the iterations.
- Then plotted the contour values of x and y and temperature T values in the graph.
clear allclose allclc<!-- [if mso]>
<![endif]-->%inputs and boundary conditionst_t = 600;t_b = 900;t_l = 400;t_r = 800;nx = 10;ny = nx; % size of matrixT=270*ones(nx,ny); %initial temperature 270kx = linspace(0,0.1,nx);y = linspace(0,0.1,ny);dx=(x(2)-x(1));dy=(y(2)-y(1));tolerance = 1e-4;error=1;alpha=1.4;dt=0.2;T(2:ny - 1, 1) = t_l; %first column elementsT(2:ny - 1, nx) = t_r; %last column elementsT(1, 2:nx - 1) = t_t; %first row elementsT(ny, 2:nx - 1) = t_b; %last row elements%assigning the values at the corner positions of the T matrix by taking average of adjacent valuesT(1,1)=(t_l+t_r)/2;T(ny,1)=(t_l+t_b)/2;T(1,nx)=(t_r+t_t)/2;T(ny,nx)=(t_r+t_b)/2;<!-- [if mso]>
<![endif]-->T_old = T;T_prev =T;k1=alpha*(dt/dx^2);k2=alpha*(dt/dy^2);term1=(1+(2*k1)+(2*k2))^-1;term2=k1*term1;term3=k2*term1;w=1.4;jacobi_method=1;GS_method=1;SOR_method=1;jacobi_iter=1;% Jacobi methodif (jacobi_method==1)for nt=1:1400 % time loopwhile error>tolerance % convergence loopfor i=2:nx-1 % space loopfor j=2:ny-1H=(T_old(i-1,j)) + (T_old(i+1,j));V=(T_old(i,j-1)) + (T_old(i,j+1));T(i,j) = ((term1*T_prev(i,j)) + (term2*H) + (term3*V));endenderror=max(max(abs(T_old-T)));T_old=T;T_prev = T;jacobi_iter=jacobi_iter+1;endfigure(1)contourf(x,y,T)clabel(contourf(T))colormap(jet)set(gca, 'ydir', 'reverse')xlabel x-axisylabel y-axistitle(sprintf('no.of iterations in Jacobi method = &d time steps = %d',jacobi_iter,nt))pause(0.05)endend% Gauss-seidelGS_iter=1;if (GS_method==1)for nt=1:1400 % time loopwhile error > tolerance % convergence loopfor i=2:nx-1 % space loopfor j=2:ny-1H=(T_old(i-1,j)) + (T_old(i+1,j));V=(T_old(i,j-1)) + (T_old(i,j+1));T(i,j) = ((term1*T_prev(i,j)) + (term2*H) + (term3*V));endendGS_iter=GS_iter+1;error=max(max(abs(T_old-T)));T_old=T;T_prev = T_old;end<!-- [if mso]>
<![endif]-->figure(2)contourf(x,y,T)clabel(contourf(T))colormap(jet)set(gca, 'ydir', 'reverse')xlabel x-axisylabel y-axistitle(sprintf('no.of iterations in Gauss seidel method = %d time steps = %d',GS_iter,nt))pause(0.03)endend%Successive Over relaxationSOR_iter = 1;if (SOR_method==1)for nt=1:1400 % time loopwhile error > tolerance % convergence loopfor i=2:nx-1 % space loopfor j=2:ny-1H=(T_old(i-1,j)) + (T_old(i+1,j));V=(T_old(i,j-1)) + (T_old(i,j+1));T(i,j) = (1-w)*T(i,j)+w*((term1*T_prev(i,j)) + (term2*H) + (term3*V));endendSOR_iter=SOR_iter+1;error=max(max(abs(T_old-T)));T_old=T;T_prev = T_old;endfigure(3)contourf(x,y,T)clabel(contourf(T))colormap(jet)set(gca, 'ydir', 'reverse')xlabel x-axisylabel y-axistitle(sprintf('no.of iterations in SOR method = %d time steps = %d',SOR_iter,nt))pause(0.03)endend


- At first, we defined the inputs and boundary conditions of the matrix of size 10x10 that means it's a square matrix and calculated the corner mid points of the matrix.
- And defined the axis length as 1m and error as 1 and tolerance value as 1e-4, alpha value as 1.4. Then I defined the initial error and T old values.
- Then mentioned the time loop and convergence loop, then the space loop of all the three interative methods.
- After the computation of the code loop vise within the tolerance limits, and plotted the T, x and y coordinates by defining the no of iterations and tiimesteps.
- Her, after the end of iterations the iterative method and the Told valued are updated.
Conclusion:
Here, the equation is converged by using three interative methods and we observed that the Jacobi method run more iterative steps that other.
The rate of iterations is Jacobi > Gauss-seidel > Successive over relaxation.
In the Steady state condition the given equation is converged with less iterations and less time steps compared to Transient state stimulation. And by comparing both the stimulation methods Successive over relaxation method ran effectively with less iteratives for converging the equation in both Emplicit and Implicit schemes.