Solving 2D Heat Diffusion Eqn w/ Finite Difference Method

AI Thread Summary
The discussion revolves around modifying a 1D finite difference solver for heat diffusion to a 2D solver. The original poster is struggling to incorporate time into their 2D derivation, where indices i and j represent spatial dimensions, contrasting with their previous 1D implementation where they represented space and time. They seek guidance on how to adapt their existing code, including sample code or pointers to resources. Key equations for heat diffusion are mentioned, specifically the 2D heat equation u_t = c(u_xx + u_yy) and the 1D version u_t = c(u_xx). The conversation highlights the need for clarity on these equations to effectively transition from a 1D to a 2D finite difference method. Frustration with the teaching approach is also expressed, indicating a lack of adequate instructional support.
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: 403


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

yes, except w/o z-component.
 
Back
Top