Challenge

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

To solve the 2D heat conduction equation using point iterative techniques, we can use the finite difference method. The steady-state analysis involves solving the equation until the solution converges, while the transient analysis involves tracking the evolution of the solution over time.

Here's the step-by-step process to solve the problem:

1. Discretization:-
Divide the 2D domain into a grid by selecting the number of nodes in the x and y directions. Let's assume there are (n+2) nodes in the x-direction and (m+2) nodes in the y-direction, including boundary nodes. Each node represents a point in the domain.

2. Initialize the Grid:-
Assign initial temperatures to the nodes. The boundary nodes will have fixed temperatures according to the given boundary conditions.

3. Solve for Steady State:-
Use iterative techniques (Jacobi, Gauss-Seidel, SOR) to solve the discretized equation until the solution converges. The iterative process involves updating the temperature values of the inner nodes based on neighboring node values.

4. Solve for Transient State (Explicit Scheme):-
For the transient analysis, we'll use an explicit scheme to track the evolution of the temperature over time. The finite difference equation for the explicit scheme is derived from the heat conduction equation. Iterate over time steps and update the temperature values of the inner nodes based on neighboring node values at the previous time step.

5. Solve for Transient State (Implicit Scheme):-
For the implicit scheme, the finite difference equation is rearranged to express the temperature at the current time step in terms of the temperatures at the previous time step. Set up a system of equations and solve it using iterative techniques (Jacobi, Gauss-Seidel, SOR) until the solution converges.

6. Convergence Criteria:-
The convergence criteria for both steady state and transient analysis is based on the absolute error between consecutive iterations. The iterative process continues until the absolute error falls below a certain threshold (e.g., 1e-4).

7. Comparing Convergence Rates:-
Compare the number of iterations required for convergence between the steady state and transient (explicit and implicit) simulations.

matlab code

1. Jacobi

clear all

close all

clc
% Parameters
n = 10; % Number of nodes in x-direction (excluding boundaries)
m = 10; % Number of nodes in y-direction (excluding boundaries)
dx = 1; % Grid spacing in x-direction
dy = 1; % Grid spacing in y-direction
alpha = 0.1; % Thermal diffusivity
dt = 0.01; % Time step
tFinal = 1; % Final time

% Boundary Conditions
Ttop = 600; % Top boundary temperature
Tbottom = 900; % Bottom boundary temperature
Tleft = 400; % Left boundary temperature
Tright = 800; % Right boundary temperature

% Grid Initialization
T = zeros(m+2, n+2); % Temperature grid
T(1, :) = Ttop; % Top boundary
T(m+2, :) = Tbottom; % Bottom boundary
T(:, 1) = Tleft; % Left boundary
T(:, n+2) = Tright; % Right boundary

% Steady State Analysis (Jacobi Method)
error = Inf;
tol = 1e-4;
iter = 0;

while error > tol
Told = T; % Copy previous iteration
for i = 2:m+1
for j = 2:n+1
T(i, j) = 0.25 * (Told(i-1, j) + Told(i+1, j) + Told(i, j-1) + Told(i, j+1));
end
end
error = max(abs(T(:) - Told(:)));
iter = iter + 1;
end

fprintf('Steady State Analysis (Jacobi Method):\n');
fprintf('Number of iterations: %d\n', iter);

% Transient Analysis (Explicit Scheme)
numSteps = tFinal / dt;
for k = 1:numSteps
Told = T; % Copy previous time step
for i = 2:m+1
for j = 2:n+1
T(i, j) = Told(i, j) + alpha * dt * (Told(i-1, j) + Told(i+1, j) + Told(i, j-1) + Told(i, j+1) - 4 * Told(i, j)) / (dx^2 + dy^2);
end
end
end

fprintf('Transient Analysis (Explicit Scheme):\n');
fprintf('Number of time steps: %d\n', numSteps);

% Transient Analysis (Implicit Scheme)
error = Inf;
iter = 0;

while error > tol
Told = T; % Copy previous iteration
for i = 2:m+1
for j = 2:n+1
T(i, j) = (Told(i, j) + alpha * dt * (T(i-1, j) + T(i+1, j) + T(i, j-1) + T(i, j+1)) / (dx^2 + dy^2)) / (1 + 4 * alpha * dt / (dx^2 + dy^2));
end
end
error = max(abs(T(:) - Told(:)));
iter = iter + 1;
end

fprintf('Transient Analysis (Implicit Scheme):\n');
fprintf('Number of iterations: %d\n', iter);

Gauss-Seidel and SOR codes
clear all
close all
clc
<!-- [if mso]>
<![endif]-->
% Parameters
nx = 51; % Number of grid points in x-direction
ny = 51; % Number of grid points in y-direction
L = 1; % Length of the domain
W = 1; % Width of the domain
dx = L/(nx-1); % Grid spacing in x-direction
dy = W/(ny-1); % Grid spacing in y-direction
tol = 1e-4; % Convergence criteria
<!-- [if mso]>
<![endif]-->
% Initialize temperature matrix
T = ones(nx, ny); % Initial guess for temperature
T(:, 1) = 600; % Top boundary
T(:, end) = 900; % Bottom boundary
T(1, :) = 400; % Left boundary
T(end, :) = 800; % Right boundary
<!-- [if mso]>
<![endif]-->
% Gauss-Seidel method
iter = 0;
err = tol + 1;
<!-- [if mso]>
<![endif]-->
while err > tol
T_old = T; % Store previous iteration values
 
% Update temperature using Gauss-Seidel method
for i = 2:nx-1
for j = 2:ny-1
T(i, j) = (T(i+1, j) + T(i-1, j) + T(i, j+1) + T(i, j-1))/4;
end
end
 
�lculate error
err = max(max(abs(T - T_old)));
iter = iter + 1;
end
<!-- [if mso]>
<![endif]-->
disp("Gauss-Seidel Method:");
disp("Number of iterations:");
disp(iter);
<!-- [if mso]>
<![endif]-->
% Successive Over-Relaxation (SOR) method
omega = 1.5; % Relaxation parameter
iter = 0;
err = tol + 1;
<!-- [if mso]>
<![endif]-->
while err > tol
T_old = T; % Store previous iteration values
 
% Update temperature using SOR method
for i = 2:nx-1
for j = 2:ny-1
T(i, j) = (1 - omega)*T(i, j) + (omega/4)*(T(i+1, j) + T(i-1, j) + T(i, j+1) + T(i, j-1));
end
end
 
�lculate error
err = max(max(abs(T - T_old)));
iter = iter + 1;
end
<!-- [if mso]>
<![endif]-->
disp("Successive Over-Relaxation (SOR) Method:");
disp("Number of iterations:");
disp(iter);
 
 
 
Transient simulations involve solving the heat conduction equation over time. Will use the finite difference method to discretize the equation in both space and time. Will update the temperature at each time step based on the explicit and implicit schemes.
Explicit scheme (Forward Time, Central Space):
 
clear all
close all
clc
 
<!-- [if mso]>
<![endif]-->
% Parameters
nt = 500; % Number of time steps
dt = 0.001; % Time step size
<!-- [if mso]>
<![endif]-->
% Initialize temperature matrix
T = ones(nx, ny); % Initial temperature
T(:, 1) = 600; % Top boundary
T(:, end) = 900; % Bottom boundary
T(1, :) = 400; % Left boundary
T(end, :) = 800; % Right boundary
<!-- [if mso]>
<![endif]-->
% Explicit scheme
for k = 1:nt
T_old = T; % Store previous time step values
 
for i = 2:nx-1
for j = 2:ny-1
T(i, j) = T_old(i, j) + (dt/(dx^2))*(T_old(i+1, j) - 2*T_old(i, j) + T_old(i-1, j)) ...
+ (dt/(dy^2))*(T_old(i, j+1) - 2*T_old(i, j) + T_old(i, j-1));
end
end
end
 
Implicit scheme

% Parameters
alpha = 0.25; % Diffusivity constant
beta = alpha*dt/(dx^2);
gamma = alpha*dt/(dy^2);

% Construct coefficient matrix for implicit scheme
A = diag(1 + 2*beta + 2*gamma)*eye(nx*ny) - diag(beta*ones(nx*ny-1, 1), 1) ...
- diag(beta*ones(nx*ny-1, 1), -1) - diag(gamma*ones(nx*(ny-1), 1), nx) ...
- diag(gamma*ones(nx*(ny-1), 1), -nx);
A(1, 1) = 1; % Top boundary
A(end, end) = 1; % Bottom boundary

% Implicit scheme
T = reshape(T, [], 1); % Convert temperature matrix to column vector

for k = 1:nt
T = A\T; % Solve linear system of equations using backslash operator
end

T = reshape(T, nx, ny); % Reshape temperature vector back to matrix form

<!-- [if mso]>
<![endif]-->
<!-- [if mso]>
<![endif]-->
<!-- [if mso]>
<![endif]-->

Comparision:-

Comparing the convergence rates of steady state and transient simulations: The convergence rates of steady state and transient simulations can be compared by analyzing the number of iterations required to reach a certain convergence criteria. In this case, the convergence criteria is set as an absolute error of 1e-4.

In steady state simulations, both the Gauss-Seidel and SOR methods are iterative, and the convergence is measured based on the change in the temperature values at each grid point. The iteration continues until the maximum change in temperature values between successive iterations falls below the convergence criteria. The number of iterations is then recorded.

In transient simulations, both the explicit and implicit schemes involve updating the temperature values over multiple time steps. The number of time steps (nt) and the time step size (dt) determine the duration of the simulation. The temperature values are updated at each time step based on the chosen scheme. The number of iterations (time steps) is recorded.

By comparing the number of iterations (or time steps) required to reach the convergence criteria for both steady state and transient simulations, we can assess the convergence rates and numerics of the different methods. The method that requires fewer iterations (or time steps) to reach convergence indicates a faster convergence rate.

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.