Challenge

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

Solving 2D heat conduction under steady, usteady,transit conditions:

Steady state jacobi iterations:

close all
clear all
clc

nx=10;
ny=nx;

x=linspace(0,1,nx);
y=linspace(0,1,ny);

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

error=9e9;
tolerance=1e-4;

T_L=400;
T_R=800;
T_T=600;
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;

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;

T_initial=T;
T_old=T;

iterative_solver=1;

if iterative_solver ==1
    jacobi_iteration=1;
    while (error>tolerance)
        for i=2:nx-1
            for j=2:ny-1
                T(i,j)=0.25*(T_old(i-1,j)+T_old(i+1,j)+T_old(i,j-1)+T_old(i,j+1));
            end
        end
        error=max(max(abs(T_old-T)));
        T_old=T;
        jacobi_iteration=jacobi_iteration+1;
    end
end

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 jacobi iterations (Implicit)= %d' , jacobi_iteration));
pause(0.03);

      

Steady state gauss siedel iterations:

close all
clear all
clc

nx=10;
ny=nx;

x=linspace(0,1,nx);
y=linspace(0,1,ny);

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

error=9e9;
tolerance=1e-4;

T_L=400;
T_R=800;
T_T=600;
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;

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;

T_initial=T;
T_old=T;

iterative_solver=2;

if iterative_solver ==2
    gauss_siedel_iteration=1;
    while (error>tolerance)
        for i=2:nx-1
            for j=2:ny-1
                T(i,j)=0.25*(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_siedel_iteration=gauss_siedel_iteration+1;
    end
end

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 gauss siedel iterations (Implicit)= %d' , gauss_siedel_iteration));
pause(0.03);

      

Steady state successive over relaxation iterations:

close all
clear all
clc

nx=10;
ny=nx;

x=linspace(0,1,nx);
y=linspace(0,1,ny);

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

error=9e9;
tolerance=1e-4;
alpha=1.2;

T_L=400;
T_R=800;
T_T=600;
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;

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;

T_initial=T;
T_old=T;

iterative_solver=3;

if iterative_solver ==3
    successive_over_relaxation_iteration=1;
    while (error>tolerance)
        for i=2:nx-1
            for j=2:ny-1
                T(i,j)=alpha*(0.25*(T(i-1,j)+T_old(i+1,j)+T(i,j-1)+T_old(i,j+1)))+(1-alpha)*T_old(i,j);
            end
        end
        error=max(max(abs(T_old-T)));
        T_old=T;
        successive_over_relaxation_iteration=successive_over_relaxation_iteration+1;
    end
end

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 SOR iterations (Implicit)= %d' , successive_over_relaxation_iteration));
pause(0.03);

      

Unsteady state jacobi iterations:

close all
clear all
clc

nx=10;
ny=nx;
nt=1400;

x=linspace(0,1,nx);
y=linspace(0,1,ny);

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

error=9e9;
tolerance=1e-4;
dt=1e-3;

T_L=400;
T_R=800;
T_T=600;
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;

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;

T_old=T;
T_initial=T;

k1=1.1*(dt/(dx^2));
k2=1.1*(dt/(dy^2));

jacobi_iteration=1;
for k=1:nt
    error=9e9;
    while (error>tolerance)
        for i=2:nx-1
            for j=2:ny-1

                term1=1/(1+(2*k1)+(2*k2));
                term2=k1*term1;
                term3=k2*term1;
                H=(T_old(i-1,j))+(T_old(i+1,j));
                V=(T_old(i,j+1))+(T_old(i,j-1));
                T(i,j)=(T_initial(i,j)*term1)+(H*term2)+(V*term3);
            end
        end

        error=max(max(abs(T_old-T)));
        T_old=T;
        jacobi_iteration=jacobi_iteration+1;
    end
    T_initial=T;
end 

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 jacobi iterations (Implicit)= %d' , jacobi_iteration));
pause(0.03);



Unsteady state gauss siedel iterations:

close all
clear all
clc

nx=10;
ny=nx;
nt=1400;

x=linspace(0,1,nx);
y=linspace(0,1,ny);

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

error=9e9;
tolerance=1e-4;
dt=1e-3;

T_L=400;
T_R=800;
T_T=600;
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;

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;

T_old=T;
T_initial=T;

k1=1.1*(dt/(dx^2));
k2=1.1*(dt/(dy^2));

gauss_siedel_iteration=1;
for k=1:nt
    error=9e9;
    while (error>tolerance)
        for i=2:nx-1
            for j=2:ny-1

                term1=1/(1+(2*k1)+(2*k2));
                term2=k1*term1;
                term3=k2*term1;
                H=(T(i-1,j))+(T_old(i+1,j));
                V=(T(i,j+1))+(T_old(i,j-1));
                T(i,j)=(T_initial(i,j)*term1)+(H*term2)+(V*term3);
            end
        end

        error=max(max(abs(T_old-T)));
        T_old=T;
        gauss_siedel_iteration=gauss_siedel_iteration+1;
    end
    T_initial=T;
end 

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 siedel iterations (Implicit)= %d' , gauss_siedel_iteration));
pause(0.03);



Unsteady state successive over relaxation iterations:

close all
clear all
clc

nx=10;
ny=nx;
nt=1400;

x=linspace(0,1,nx);
y=linspace(0,1,ny);

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

error=9e9;
tolerance=1e-4;
dt=1e-3;
alpha=1.2;

T_L=400;
T_R=800;
T_T=600;
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;

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;

T_old=T;
T_initial=T;
T_end=T;

k1=1.1*(dt/(dx^2));
k2=1.1*(dt/(dy^2));

successive_over_relaxation_iteration=1;
for k=1:nt
    error=9e9;
    while (error>tolerance)
        for i=2:nx-1
            for j=2:ny-1

                term1=1/(1+(2*k1)+(2*k2));
                term2=k1*term1;
                term3=k2*term1;
                H=(T(i-1,j))+(T_old(i+1,j));
                V=(T(i,j+1))+(T_old(i,j-1));
                T(i,j)=(T_initial(i,j)*term1)+(H*term2)+(V*term3);
                T_end(i,j)=((1-alpha)*T_old(i,j))+(T(i,j)*alpha);
            end
        end

        error=max(max(abs(T_old-T)));
        T_old=T_end;
        successive_over_relaxation_iteration=successive_over_relaxation_iteration+1;
    end
    T_initial=T_end;
end 

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 successive over relaxation iterations (Implicit)= %d' , successive_over_relaxation_iteration));
pause(0.03);



Steady state explicit iterations:

close all
clear all
clc

nx=10;
ny=nx;
nt=1400;

x=linspace(0,1,nx);
y=linspace(0,1,ny);

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

error=9e9;
tolerance=1e-4;
dt=1e-3;
alpha=1.2;

T_L=400;
T_R=800;
T_T=600;
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;

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;

T_old=T;
T_initial=T;

k1=1.1*(dt/(dx^2));
k2=1.1*(dt/(dy^2));


iterative_solver=1;

if iterative_solver==1
    steady_explicit_iteration=1;
    for k=1:nt
        error=1;

        while (error>tolerance)
            for i=2:nx-1
                for j=2:ny-1

                    term1=T_old(i,j);
                    term2=k1*(T_old(i+1,j)-2*T_old(i,j)+(T_old(i-1,j)));
                    term3=k2*(T_old(i,j+1)-2*T_old(i,j)+(T_old(i,j-1)));
                    T(i,j)=term1+term2+term3;

                end
            end

            error=max(max(abs(T_old-T)));
            T_old=T;
            steady_explicit_iteration=steady_explicit_iteration+1;
        end
    end 
end

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 steady explicit iterations = %d' , steady_explicit_iteration));
pause(0.03);



Final result:

Scheme Method Iterations
Steady implicit Jacobi 208
Gauss Siedel 112
Successive over relaxation 76
Unsteady implicit Jacobi 3880
Gauss siedel 3612
Successive over relaxation 3124
explicit 1941
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.

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.