0% found this document useful (0 votes)
20 views10 pages

ME685 Homework4

Uploaded by

harsh garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views10 pages

ME685 Homework4

Uploaded by

harsh garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Homework Assignment 4

(Harsh Garg – 200411)


Q1. A hot plate with an initial temperature of 0C is heated by a source 𝑞 =
500 [C/s]. The plate has a thermal diffusivity of 𝛼 = 0.5 [m2 /s]. The plate
has the following boundary conditions,
The plate has a dimension of 1m x 1m. Solve the PDE over 𝑡 ∈ [0,0.25] [s] by
two approaches. a) Explicit Method. b) ADI Scheme. Plot the thermal
contour plots in the x-y plane at time intervals of 0.05 s.
1. Explicit Method:
PSEUDOCODE:
1. Initialize Parameters:
• Set the dimensions of the domain: Lx, Ly.
• Define the maximum time 𝑡𝑚𝑎𝑥 .
• Set the step sizes: ℎ𝑥 , ℎ𝑡 .
• Calculate the number of steps in each direction: 𝑁𝑥 , 𝑁𝑦 , 𝑁𝑡 .
• Define initial temperatures and boundary conditions.
2. Set Coefficients and Conditions:
• Set coefficients for the heat equation (𝜆).
• Define parameters for Neumann boundary conditions (𝑎, 𝑞).
3. Solve Heat Equation:
• Iterate over time steps 𝑘 = 2 𝑡𝑜 𝑁𝑡 .
• Implement the finite difference method to solve the heat
equation.
• Update the temperature distribution at each time step based on
the discretized heat equation and boundary conditions.
4. Plotting:
• Create a figure to display contour plots of temperature at
different time intervals.
• Generate subplots for specific time intervals
(t=0.05,0.10,0.15,0.20,0.25).
• Plot the temperature distribution using contourf function.
• Add titles to each subplot indicating the corresponding time.
• Add a main title for the entire figure.
5. Return Result:
• Store the final temperature distribution in TempDistribution
variable.
6. End of Function.
MATLAB CODE:
function TempDistribution=parabolic2dexplicitNuemann
%------------Nuemann Biundary Condition at x=1 i.e.
dT/dy=0------------
Lx=1; % maximum length along x axis
Ly=1; % maximum length along y axis
tmax=0.25; % maximum time scale
hx=0.02; % length step size
ht=0.0001; % time stepsize
Nx=Lx/hx; Ny=Ly/hx; Nt=tmax/ht;
Ti=0;Ty0=0;Ty1=100;Tx0=50;
Tinit=Ti*ones(Ny,Nx); % initial condition
T(:,:,1)=Tinit;
T(1,:,1:Nt)=Ty0; % Boundary condition y=0
T(end,:,1:Nt)=Ty1; % Boundary condition y=Ly
T(:,1,1:Nt)=Tx0; % Boundary condition x=0
coeff=0.5; % Thermal diffusivity
lambda=ht*coeff/(hx)^2;
a=0; % from Nuemann Boundary
Condition
q=500*ht; % Heat Flux condition
%------------Solve for
dT/dt=lambda*(d^2T/dx^2+d^2T/dy^2)+q-------------
for k=2:Nt
T(2:end-1,end,k)=T(2:end-1,end,k-1)+lambda*(-
4*T(2:end-1,end,k-1)+2*T(2:end-1,end-1,k-1)...
+2*a*hx+T(1:end-2,end,k-1)+T(3:end,end,k-1))+q;
T(2:end-1,2:end-1,k)=T(2:end-1,2:end-1,k-1)+lambda*(-
4*T(2:end-1,2:end-1,k-1)+T(1:end-2,2:end-1,k-1)...
+T(3:end,2:end-1,k-1)+T(2:end-1,1:end-2,k-1)+T(2:end-
1,3:end,k-1))+q;

end
TempDistribution=T;
% Create a new figure
figure;
subplot(2, 3, 1);
% At t = 0.05
contourf(TempDistribution(:,:,Nt/5));
title('t = 0.05');

subplot(2, 3, 2);
% At t = 0.10
contourf(TempDistribution(:,:,(2*Nt)/5));
title('t = 0.10');

subplot(2, 3, 3);
% At t = 0.15
contourf(TempDistribution(:,:,(3*Nt)/5));
title('t = 0.15');

subplot(2, 3, 4);
% At t = 0.20
contourf(TempDistribution(:,:,(4*Nt)/5));
title('t = 20');

subplot(2, 3, 5);
% At t = 0.25
contourf(TempDistribution(:,:,end));
title('t = 0.25');

sgtitle('Thermal contour plots at time intervals of 0.05


s');
end
PLOTS:
Thermal contour plots at time intervals of 0.05s
2. ADI Scheme:
PSEUDOCODE:
1. Initialization:
a. Define constants such as maximum length along x and y axes,
maximum time scale, length step size, and time step size.
b. Set initial conditions and boundary temperatures.
c. Define the thermal diffusivity coefficient.
2. Construct Matrices for Finite Difference Method:
a. Initialize matrices for the finite difference method to solve the
2D heat equation.
b. Construct matrices for the x and y directions, considering
Neumann boundary conditions.
3. Iterative Solution:
a. Loop over time steps (k = 2 to Nt).
b. For each time step:
i. Initialize temporary matrices to store intermediate
values.
ii. Apply boundary conditions at x = 0 and x = Lx.
iii. Solve for the temperature distribution in the y-direction
using the implicit method.
iv. Apply boundary conditions at y = 0 and y = Ly.
v. Solve for the temperature distribution in the x-direction
using the implicit method.
vi. Update the temperature distribution for the current time
step.
4. Visualization:
a. Create a new figure for visualization.
b. Plot contour plots of temperature distribution at specified time
intervals (t = 0.05, 0.10, 0.15, 0.20, 0.25) using subplot function.
c. Set titles for each subplot.
d. Set a title for the entire figure.
MATLAB CODE:
function TempDistribution=parabolic2dADINuemann
%---------Nuemann Biundary Condition at x=1 i.e. dT/dx=0-
--------------
Lx=1; % maximum length along x axis
Ly=1; % maximum length along y axis
tmax=0.25; % maximum time scale
hx=0.01; % length step size
ht=0.001; % time stepsize
Nx=Lx/hx; Ny=Ly/hx; Nt=tmax/ht;
Ti=0;Ty0=0;Ty1=100;Tx0=50;
Tinit=Ti*ones(Ny,Nx); % initial condition
T(:,:,1)=Tinit;
a=0; % Nuemann boundary at x=Lx
T(1,:,1:Nt)=Ty0; % Boundary condition at y=0
T(end,:,1:Nt)=Ty1; % Boundary condition y=Ly
T(:,1,1:Nt)=Tx0; % Boundary condition x=0
coeff=0.5; % Thermal diffusivity
lam=ht*coeff/(hx)^2;
q=500*ht;
Ax=eye(Nx);
for i=2:Nx-1
Ax(i,i)=2*(1+lam);
Ax(i,i-1)=-lam;
Ax(i,i+1)=-lam;
end
Ax(end,end)=2*(1+lam);
Ax(end,end-1)=-2*lam;
Ay=eye(Ny);
for i=2:Ny-1
Ay(i,i)=2*(1+lam);
Ay(i,i-1)=-lam;
Ay(i,i+1)=-lam;
end
Ay;
for k=2:Nt
bhalf=zeros(Ny,1);
b=zeros(Nx,1);
Temp=zeros(Ny,Nx);
Tempf=zeros(Ny,Nx);
Temp(:,1)=T(:,1,k-1);
Tempf(1,:)=T(1,:,k-1);
for i=2:Nx-1
bhalf(2:end-1)=2*(1-lam)*T(2:end-1,i,k-
1)+lam*T(2:end-1,i-1,k-1)+lam*T(2:end-1,i+1,k-1)+q;
bhalf(1)=T(1,i,k-1);bhalf(end)=T(end,i,k-1);
Temp(:,i)=Ay\bhalf;
end
bhalf(2:end-1)=2*(1-lam)*T(2:end-1,Nx,k-
1)+2*lam*T(2:end-1,Nx-1,k-1)+2*a*hx+q;
bhalf(1)=T(1,Nx,k-1); bhalf(end)=T(end,Nx,k-1);
Temp(:,end)=Ay\bhalf;

for i=2:Ny-1
b(2:end-1)=(2*(1-lam)*Temp(i,2:end-1)+lam*Temp(i-
1,2:end-1)+lam*Temp(i+1,2:end-1)+q)';
b(1)=Temp(i,1);b(end)=2*(1-
lam)*Temp(i,end)+lam*Temp(i-1,end)+lam*Temp(i+1,end)-
2*lam*a*hx+q;
Tempf(i,:)=(Ax\b)';
end
Tempf(Ny,:)=T(end,:,k-1);
T(:,:,k)=Tempf;
end
TempDistribution=T;
% Create a new figure
figure;
subplot(2, 3, 1);
% At t = 0.05
contourf(TempDistribution(:,:,Nt/5));
title('t = 0.05');

subplot(2, 3, 2);
% At t = 0.10
contourf(TempDistribution(:,:,(2*Nt)/5));
title('t = 0.10');

subplot(2, 3, 3);
% At t = 0.15
contourf(TempDistribution(:,:,(3*Nt)/5));
title('t = 0.15');

subplot(2, 3, 4);
% At t = 0.20
contourf(TempDistribution(:,:,(4*Nt)/5));
title('t = 20');

subplot(2, 3, 5);
% At t = 0.25
contourf(TempDistribution(:,:,end));
title('t = 0.25');

sgtitle('Thermal contour plots at time intervals of 0.05


s');
end
PLOTS:
Thermal contour plots at time intervals of 0.05s

You might also like