Solving 2D Heat Diffusion Eqn w/ Finite Difference Method

In summary, the conversation discusses the process of writing a FD explicit method for temperature distribution on a 2D plane. The main focus is on modifying a 1D solver to work for 2D, and the conversation includes discussions on equations for 1D and 2D heat diffusion and the use of finite difference equations. The conversation also includes some frustration with the lack of help from a teacher.
  • #1
logix88
12
0
I have to write a FD expilicit method, for temp dist on 2D plane.

I am trying to mod the 1D solver to 2D solver, the code below is a 1D solver. Any possible suggestions how it can be done? I initially, derived u(i,j+1) for 2D

for in that derivation i,j corresponds to x,y... where as in 1D i,j is x,t

I don't know how I can factor time in, and if I can actually use the 1D code. If anyone could point me in the right direction, give me a sample code or something it would be great. thanks!

btw, the guy who teaches this SUCKS! all he gave was this stupid code, and literally nothing else.


Code:
f: funtion handle
g1,g2, left right hand BC
L: length of rod
T= length of simulation
n=no. of subintervals of x
m=no. of subintervals of t
c: thermal diffusivity const.

function [y0,y,yL,g1k,u',g2k] = Heat(f,g1,g2,L, T, n, m, c)


h= L/n;
x=h:h:(n-1)*h;
k=T/m;
r=c*k/n;
rr=1-2*r;
t=k:k:m*k;

y0=feval(f,0);
y=feval(f,x);
yL=feval(f,L);

g1k=feval(g1,t);
g2k=feval(g2,t);

% for internal points, have
%    u_new(j) = u_old(j) + r*(u_old(j+1)-2*u_old(j)+u_old(j-1))
% for the two end-points, have
%    u_new(1) = u_old(1) + r*(u_old(2)-2*u_old(1)+u_old(N-1))     
%    u_new(N) = u_old(N) + r*(u_old(2)-2*u_old(N)+u_old(N-1))     
% clearly the endpoints are redundant: u(1)= u(N) at all times.  I just
% kept them around for plotting convenience.  

u(1,1)= r*y0+rr*y(1)+r*y(2);
u(2:n-2,1)=r*y(1:n-3)'+rr*y(2:n-2)'+r*y(3:n-1);
u(n-1,1)= r*y(n-2)+rr*y(n-1)+r*yL;

for j=1:m
    u(1,j) = r*g1k(j-1)+rr*u(1,j-1)+r*u(2,j-1);
    u(2:n-2,j)=r*u(1:n-3,j-1)'+rr*u(2:n-2,j-1)'+r*u(3:n-1,j-1);
    u(n-1,j)= r*u(n-2,j-1)+rr*u(n-1,j-1)+r*g2k(j-1);
end
 
Physics news on Phys.org
  • #2


logix88 said:
I have to write a FD expilicit method, for temp dist on 2D plane.

I am trying to mod the 1D solver to 2D solver, the code below is a 1D solver. Any possible suggestions how it can be done? I initially, derived u(i,j+1) for 2D

for in that derivation i,j corresponds to x,y... where as in 1D i,j is x,t

I don't know how I can factor time in, and if I can actually use the 1D code. If anyone could point me in the right direction, give me a sample code or something it would be great. thanks!

btw, the guy who teaches this SUCKS! all he gave was this stupid code, and literally nothing else.


Code:
f: funtion handle
g1,g2, left right hand BC
L: length of rod
T= length of simulation
n=no. of subintervals of x
m=no. of subintervals of t
c: thermal diffusivity const.

function [y0,y,yL,g1k,u',g2k] = Heat(f,g1,g2,L, T, n, m, c)


h= L/n;
x=h:h:(n-1)*h;
k=T/m;
r=c*k/n;
rr=1-2*r;
t=k:k:m*k;

y0=feval(f,0);
y=feval(f,x);
yL=feval(f,L);

g1k=feval(g1,t);
g2k=feval(g2,t);

% for internal points, have
%    u_new(j) = u_old(j) + r*(u_old(j+1)-2*u_old(j)+u_old(j-1))
% for the two end-points, have
%    u_new(1) = u_old(1) + r*(u_old(2)-2*u_old(1)+u_old(N-1))     
%    u_new(N) = u_old(N) + r*(u_old(2)-2*u_old(N)+u_old(N-1))     
% clearly the endpoints are redundant: u(1)= u(N) at all times.  I just
% kept them around for plotting convenience.  

u(1,1)= r*y0+rr*y(1)+r*y(2);
u(2:n-2,1)=r*y(1:n-3)'+rr*y(2:n-2)'+r*y(3:n-1);
u(n-1,1)= r*y(n-2)+rr*y(n-1)+r*yL;

for j=1:m
    u(1,j) = r*g1k(j-1)+rr*u(1,j-1)+r*u(2,j-1);
    u(2:n-2,j)=r*u(1:n-3,j-1)'+rr*u(2:n-2,j-1)'+r*u(3:n-1,j-1);
    u(n-1,j)= r*u(n-2,j-1)+rr*u(n-1,j-1)+r*g2k(j-1);
end

What are the equations for 2-D heat diffusion? Or even 1-D for that matter. Seems like it would be good to be clear on those equations, and then morph them into finite difference equations...
 
  • #3


berkeman said:
What are the equations for 2-D heat diffusion? Or even 1-D for that matter. Seems like it would be good to be clear on those equations, and then morph them into finite difference equations...

u_t=c(u_xx+u_yy) for 2D

u_t=c(u_xx) for 1D
 
  • #4


logix88 said:
u_t=c(u_xx+u_yy) for 2D

u_t=c(u_xx) for 1D

Do you mean this (from the wikipedia page for Heat Equation)?
 

Attachments

  • cac926f3ef073e43817e26cb15d01ca8.png
    cac926f3ef073e43817e26cb15d01ca8.png
    1.1 KB · Views: 376
  • #5


berkeman said:
Do you mean this (from the wikipedia page for Heat Equation)?

yes, except w/o z-component.
 

FAQ: Solving 2D Heat Diffusion Eqn w/ Finite Difference Method

1. What is the 2D Heat Diffusion Equation?

The 2D Heat Diffusion Equation, also known as the Heat Equation, is a partial differential equation that describes the flow of heat through a 2-dimensional object over time. It is commonly used in physics and engineering to model heat transfer in various systems.

2. What is the Finite Difference Method?

The Finite Difference Method is a numerical technique used to solve differential equations, such as the Heat Equation. It involves discretizing the domain into a grid and approximating the derivatives in the equation using the values at each grid point. These equations can then be solved iteratively to obtain a numerical solution.

3. How is the Finite Difference Method used to solve the 2D Heat Diffusion Equation?

To solve the 2D Heat Diffusion Equation using the Finite Difference Method, the domain is divided into a grid with evenly spaced points. The equation is then discretized at each grid point, and a system of linear equations is formed. This system can be solved iteratively using numerical techniques, such as the Gauss-Seidel method, to obtain a numerical solution for the temperature at each grid point.

4. What are the main assumptions made when using the Finite Difference Method to solve the 2D Heat Diffusion Equation?

The main assumptions made when using the Finite Difference Method are that the material is homogeneous and isotropic, the thermal properties are constant, and the boundary conditions are specified. These assumptions simplify the equation and allow for a numerical solution to be obtained.

5. What are some applications of solving the 2D Heat Diffusion Equation with the Finite Difference Method?

The 2D Heat Diffusion Equation with the Finite Difference Method has many practical applications, such as predicting the temperature distribution in buildings, analyzing heat transfer in electronic devices, and studying the thermal behavior of materials in manufacturing processes. It is also used in weather forecasting and climate modeling to simulate the transfer of heat in the atmosphere.

Similar threads

Replies
41
Views
9K
Replies
3
Views
3K
Replies
2
Views
2K
Replies
2
Views
2K
Replies
1
Views
2K
Replies
1
Views
4K
Replies
9
Views
3K
Replies
4
Views
3K
Back
Top