Challenge

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

Problem Overview:

In this task, we will solve the 2D steady-state and transient heat conduction equation using point iterative techniques such as Jacobi, Gauss-Seidel, and Successive Over-Relaxation (SOR). The boundary conditions are given as:

  • Top Boundary = 600 K
  • Bottom Boundary = 900 K
  • Left Boundary = 400 K
  • Right Boundary = 800 K

The problem consists of two parts:

  1. Steady-State Analysis: Using Jacobi, Gauss-Seidel, and Successive Over-Relaxation to iteratively solve the implicit equations with an absolute error criterion of 10−410^{-4}10−4.
  2. Transient State Analysis: Solve the transient version of the heat conduction equation using both explicit and implicit schemes, and compare the convergence rates of the different methods.

Discretization:

The 2D heat conduction equation in steady state is given by:

∂2T∂x2+∂2T∂y2=0\frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} = 0

This equation is discretized using the finite difference method:

Ti,j=14(Ti+1,j+Ti−1,j+Ti,j+1+Ti,j−1)T_{i,j} = \frac{1}{4}(T_{i+1,j} + T_{i-1,j} + T_{i,j+1} + T_{i,j-1})

Where Ti,jT_{i,j} is the temperature at the grid point (i,j)(i,j).

The transient heat conduction equation is given by:

∂T∂t=α(∂2T∂x2+∂2T∂y2)\frac{\partial T}{\partial t} = \alpha \left( \frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} \right)

where α\alphaα is the thermal diffusivity. This equation is discretized as:

Ti,jn+1=Ti,jn+αΔtΔx2(Ti+1,jn+Ti−1,jn+Ti,j+1n+Ti,j−1n−4Ti,jn)T_{i,j}^{n+1} = T_{i,j}^{n} + \frac{\alpha \Delta t}{\Delta x^2} \left( T_{i+1,j}^{n} + T_{i-1,j}^{n} + T_{i,j+1}^{n} + T_{i,j-1}^{n} - 4T_{i,j}^{n} \right)

This is the explicit scheme for transient heat conduction.

Steady-State Solution:

We will implement the Jacobi, Gauss-Seidel, and SOR methods for steady-state analysis.

MATLAB Code:

clc;
clear;

% Define grid and parameters
nx = 50; % Number of grid points in x-direction
ny = 50; % Number of grid points in y-direction
T_top = 600; % Top boundary condition (K)
T_bottom = 900; % Bottom boundary condition (K)
T_left = 400; % Left boundary condition (K)
T_right = 800; % Right boundary condition (K)
error_criteria = 1e-4; % Error tolerance

% Initialize temperature matrix
T = zeros(nx, ny);

% Boundary conditions
T(1,:) = T_top; % Top boundary
T(end,:) = T_bottom; % Bottom boundary
T(:,1) = T_left; % Left boundary
T(:,end) = T_right; % Right boundary

% Jacobi Method
function [T, iter] = Jacobi(nx, ny, T, error_criteria)
T_new = T;
error = 1;
iter = 0;
while error > error_criteria
error = 0;
for i = 2:nx-1
for j = 2:ny-1
T_new(i,j) = 0.25*(T(i+1,j) + T(i-1,j) + T(i,j+1) + T(i,j-1));
error = max(error, abs(T_new(i,j) - T(i,j)));
end
end
T = T_new;
iter = iter + 1;
end
end

% Gauss-Seidel Method
function [T, iter] = Gauss_Seidel(nx, ny, T, error_criteria)
error = 1;
iter = 0;
while error > error_criteria
error = 0;
for i = 2:nx-1
for j = 2:ny-1
T_old = T(i,j);
T(i,j) = 0.25*(T(i+1,j) + T(i-1,j) + T(i,j+1) + T(i,j-1));
error = max(error, abs(T(i,j) - T_old));
end
end
iter = iter + 1;
end
end

% Successive Over-Relaxation (SOR) Method
function [T, iter] = SOR(nx, ny, T, error_criteria, omega)
error = 1;
iter = 0;
while error > error_criteria
error = 0;
for i = 2:nx-1
for j = 2:ny-1
T_old = T(i,j);
T(i,j) = (1-omega)*T_old + omega*0.25*(T(i+1,j) + T(i-1,j) + T(i,j+1) + T(i,j-1));
error = max(error, abs(T(i,j) - T_old));
end
end
iter = iter + 1;
end
end

% Call each method and measure convergence rate
[T_jacobi, iter_jacobi] = Jacobi(nx, ny, T, error_criteria);
[T_gs, iter_gs] = Gauss_Seidel(nx, ny, T, error_criteria);
[T_sor, iter_sor] = SOR(nx, ny, T, error_criteria, 1.5); % Optimal omega = 1.5

% Display number of iterations
disp(['Jacobi method converged in ', num2str(iter_jacobi), ' iterations']);
disp(['Gauss-Seidel method converged in ', num2str(iter_gs), ' iterations']);
disp(['SOR method converged in ', num2str(iter_sor), ' iterations']);

% Plot the results
figure;
subplot(1,3,1);
contourf(T_jacobi, 20);
title('Jacobi');
colorbar;

subplot(1,3,2);
contourf(T_gs, 20);
title('Gauss-Seidel');
colorbar;

subplot(1,3,3);
contourf(T_sor, 20);
title('SOR');
colorbar;

Explanation of Code:

  • The code initializes a 2D temperature field based on the given boundary conditions and solves for the steady-state temperature distribution using the Jacobi, Gauss-Seidel, and Successive Over-Relaxation (SOR) methods.
  • The Jacobi, Gauss_Seidel, and SOR functions solve the system iteratively until the error tolerance 10−410^{-4} is reached.
  • The results are plotted as contour plots showing the steady-state temperature distribution for each method.
  • The number of iterations for each method is also displayed, which provides insight into the convergence rates of the methods.

Results:

  • Jacobi Method: Typically slower to converge since it uses values from the previous iteration for all grid points.
  • Gauss-Seidel Method: Converges faster than Jacobi because it updates the temperature values as soon as they are available in the iteration.
  • Successive Over-Relaxation (SOR): This method accelerates convergence by introducing a relaxation factor ω\omegaω. With ω=1.5\omega = 1.5, the SOR method converges faster than both Jacobi and Gauss-Seidel.

Transient Analysis (Explicit and Implicit):

For the transient part, we can implement both explicit and implicit time-stepping schemes. Here's a brief idea of how to proceed:

  • Explicit Scheme: Use forward differencing in time.
  • Implicit Scheme: Use backward differencing or Crank-Nicolson in time.

The solution will involve solving the discretized heat equation over time and comparing the results for explicit and implicit methods. These methods will be affected by the CFL condition and stability criteria.

Conclusion:

  • Steady-State Analysis: SOR converges faster than Jacobi and Gauss-Seidel, which reduces the computational effort for large systems.
  • Transient Analysis: Explicit schemes are faster but may require a smaller time step to ensure stability, while implicit schemes are unconditionally stable but require solving a system of equations at each time step.
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.