Solving 2D Heat Diffusion Eqn w/ Finite Difference Method

Click For Summary
SUMMARY

The forum discussion focuses on converting a 1D finite difference method (FDM) for heat diffusion into a 2D implementation. The user seeks guidance on modifying their existing code, which utilizes a function handle and boundary conditions for a rod's temperature distribution. Key equations discussed include the heat equation in 2D, represented as u_t = c(u_xx + u_yy), and in 1D as u_t = c(u_xx). The user expresses frustration with the lack of instructional support from their instructor.

PREREQUISITES
  • Understanding of finite difference methods (FDM)
  • Familiarity with the heat equation in both 1D and 2D
  • Proficiency in MATLAB programming, particularly with function handles
  • Knowledge of boundary conditions in heat diffusion problems
NEXT STEPS
  • Research the implementation of 2D finite difference methods for heat diffusion
  • Learn about boundary condition handling in 2D heat equations
  • Explore MATLAB's array manipulation techniques for 2D matrices
  • Study numerical stability and convergence criteria for finite difference methods
USEFUL FOR

Students and researchers in computational physics, engineers working on thermal analysis, and anyone developing numerical solutions for heat diffusion problems.

logix88
Messages
12
Reaction score
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


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...
 


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
 


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: 412


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

yes, except w/o z-component.
 

Similar threads

  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
7
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
Replies
1
Views
3K