You are on page 1of 2

clear; close all; clc;

%%% -- Silver --
name=('Silver'); % Material name
conductivity = 406; % thermal conductivity
(W/m.K)
spacific_heat = 233; % specific heat (J/kg
K)
denisty = 10490; % density (kg/m^3)

k=conductivity;
% Geometry
%%
Lx= 1; % plate width (m)
Ly= 1; % plate length (m)
Nx=40; % nodes in x direction
Ny=40; % nodes in y direction

%Boundary condition(Temperature boundary conditions)


T_east = 300 ; % temperature on the upper side ( at y=0
"Dirichlet Conditions" )
T_west = 100 ; % temperature on the lower side ( at y=Ly
"Dirichlet Conditions" )
T_north = 100; % temperature on the left side ( at x=0
"Dirichlet Conditions" )
T_south = 300; % temperature on the right side ( at x=Lx
"Dirichlet Conditions" )

tolerence_ss= 0.000001;% tolerence for numerical simulation (0.5 deg Celesius)


north=0; % to check for Neuman condition; if 1 true, if 0
false
south=0;
west=0;
east=0;
qw=0;
qe=0;
qn=0;
qs=0;

%% Numerical method Constants Section


% initial error

dx=Lx/Nx; % delta
x
dy=Ly/Ny; % delta
y

% number of iterrations for time


alpha = conductivity/(spacific_heat*denisty); % alpha
(1/sec)

% ----------------- Initial Conditions for finite difference section


---------------

T=zeros(Nx,Ny);
T(1,:)=T_south;
T(Nx,:)=T_north;
T(:,Ny)=T_east;
T(:,1)=T_west;
T(1,1)=(T_south+T_west)/2;
T(1,Ny)=(T_south+T_east)/2;
T(Nx,Ny)=(T_north+T_east)/2;
T(Nx,1)=(T_north+T_west)/2;

% ------------------- Initial Conditions for steady state section


-------------------
Tss=T;

MSE=100; % some initial value for mean squared error


%% 3- Steady-State section

while MSE>=tolerence_ss
for i=2:Nx-1 % looping
for j=2:Ny-1
if west==1
if(j==2)
Tss(i,1)= 0.25*((2*qw*dx/k)+Tss(i+1,1)+Tss(i-1,1)+(2*Tss(i,2)));
end
end
if east==1
if(j==Ny-1)
Tss(i,Ny)=0.25*((2*qe*dx/k) + Tss(i+1,Ny)+Tss(i-1,Ny)
+(2*Tss(i,Ny-1)));
end
end
if north==1
if(i==Nx-1)
Tss(Nx,j)=0.25*((2*qn*dx/k)+Tss(Nx,j-
1)+Tss(Nx,j+1)+(2*Tss(Nx-1,j)));
end
end
if south ==1
if(i==2)
Tss(1,j)=0.25*((2*qs*dx/k)+Tss(1,j-
1)+Tss(1,j+1)+(2*Tss(2,j)));
end
end
Tss(1,1)=(Tss(1,2)+Tss(2,1))/2;
Tss(1,Ny)=(Tss(1,Ny-1)+Tss(2,Ny))/2;
Tss(Nx,Ny)=(Tss(Nx,Ny-1)+Tss(Nx-1,Ny))/2;
Tss(Nx,1)=(Tss(Nx,2)+Tss(Nx-1,1))/2;
Tss(i,j)=0.25*(Tss(i+1,j)+Tss(i,j+1)+Tss(i-1,j)+Tss(i,j-1));
error(i,j)=(Tss(i,j)-T(i,j))^2;
end
end
T=Tss;
MSE=sqrt(sum(sum(error))/(Nx*Ny));

end

contourf(Tss);

You might also like