2d Unsteady state heat conduction equation using Gauss-seidel method

조회 수: 92 (최근 30일)
Rajat Powade
Rajat Powade 2021년 8월 25일
편집: Torsten 2023년 1월 2일

I Wrote the code for 2d unsteady state using jacobi method. Please check it is correct or not. close all

clear all

clc

%Solving the Unsteady state 2D heat conduction by Gauss Seidel Method(IMPLICIT SCHEME)

%Input Parameters

%Number of grid points

nx = 10;

ny = nx;

nt = 1400;

x = linspace(0,1,nx);

y = linspace(0,1,ny);

dx = x(2) - x(1);

dy = dx;

%Absolute error criteria > tolerance

error = 9e9;

tolerance = 1e-4;

dt = 1e-3;

%Defining Boundary conditions

T_L = 400;

T_T = 600;

T_R = 800;

T_B = 900;

T = 300*ones(nx,ny);

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;

%Calculating Average temperature at corners

T(1,1) = (T_T + T_L)/2;

T(nx,ny) = (T_R + T_B)/2;

T(1,ny) = (T_T + T_R)/2;

T(nx,1) = (T_L + T_B)/2;

%Assigning orginal values to T

T_old = T;

T_intial = T;

%Calculation of 2D steady heat conduction EQUATION by Gauss-seidel method

A= 1.1*(dt/(dx^2));

Gauss_Seidel_iteration = 1;

for k = 1:nt

    error = 9e9;
    while(error > tolerance)
        for i = 2:nx - 1
            for j = 2:ny - 1
                T(i,j)= T_intial(i,j).*(1-4*A) +  A *(T(i-1,j)+ T_old(i+1,j)+T(i,j+1)+T_old(i,j-1));
            end
        end
        error = max(max(abs(T_old - T)));
        T_old = T;
        Gauss_Seidel_iteration = Gauss_Seidel_iteration + 1;
    end
    T_intial = T;
    %Plotting
    figure(1)
    contourf(x,y,T)
    clabel(contourf(x,y,T))
    colorbar
    colormap(jet)
    set(gca, 'ydir', 'reverse')
    xlabel('X-Axis')
    ylabel('Y-Axis')
    title(sprintf('No. of Unsteady Gauss-Seidel Iterations(IMPLICIT) = %d', Gauss_Seidel_iteration));
    pause(0.03)

end

  댓글 수: 2
Ahmed Fawky
Ahmed Fawky 2023년 1월 2일
why do you take average temperatures in corners?
Torsten
Torsten 2023년 1월 2일
편집: Torsten 2023년 1월 2일
Do you have a better idea if the temperature where the edges meet is not identical on both edges ?
If fixed temperatures are set on all 4 boundary edges, the temperatures set in the corners will not influence the resulting temperature distribution over time, at least for the discretization used above.

댓글을 달려면 로그인하십시오.

채택된 답변

Wan Ji
Wan Ji 2021년 8월 25일
Hi, Rajat Powade
I have checked your code carefully and I know you have used the 5-point Gauss-Seidel difference method to obtain the solution of 2d unsteady state in heat transfer modelling. I don't think there is anything wrong with your code, and the final result looks beautiful. Only one thing that should be modfied from your code is to make it run faster by avoiding loops:
Therefore, you need to replace the following code lines
for i = 2:nx - 1
for j = 2:ny - 1
T(i,j)= T_intial(i,j).*(1-4*A) + A *(T(i-1,j)+ T_old(i+1,j)+T(i,j+1)+T_old(i,j-1));
end
end
with these three lines below
i = 2:nx - 1;
j = 2:ny - 1;
T(i,j)= T_intial(i,j).*(1-4*A) + A *(T(i-1,j)+ T_old(i+1,j)+T(i,j+1)+T_old(i,j-1));
Wish you all the best!
Wan Ji

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by