Solving 2D Heat Diffusion Eqn w/ Finite Difference Method

Click For Summary

Discussion Overview

The discussion revolves around the implementation of a finite difference explicit method for solving the heat diffusion equation in two dimensions. Participants are exploring how to adapt a one-dimensional solver to accommodate two-dimensional scenarios, including the necessary equations and boundary conditions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant seeks guidance on modifying a one-dimensional finite difference code to solve for temperature distribution in a two-dimensional plane, expressing uncertainty about incorporating time into the model.
  • Another participant asks for the equations governing two-dimensional heat diffusion, suggesting that clarity on these equations would aid in transforming them into finite difference equations.
  • Participants provide the heat diffusion equations: u_t = c(u_xx + u_yy) for 2D and u_t = c(u_xx) for 1D, with one confirming the source of the equations as a Wikipedia page.
  • There is a clarification that the 2D equation does not include a z-component, indicating a focus on the planar case.

Areas of Agreement / Disagreement

Participants generally agree on the form of the heat diffusion equations, but there remains uncertainty regarding the implementation details and how to effectively transition from a 1D to a 2D solver.

Contextual Notes

Participants have not resolved how to factor time into the 2D model or whether the existing 1D code can be directly adapted for 2D applications. There are also indications of frustration with the instructional support provided.

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


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