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

38 次查看(过去 30 天)

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 个评论
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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by