Finite Difference Method for Conductive Heat Flow in Solids

2023 EESC W3400
Lec 20: Finite difference method illustrated with
2D time-independent conductive heat flow
Computational Earth Science
Bill Menke, Instructor
Emily Glazer, Teaching Assistant
TR 2:40 – 3:55
Today
New (and fairly technical) Stuff
Finite Difference Method for Solving Dynamical Problems
Today
all
Lecture
Thursday
all in-class projects
so be sure to attend
Example of
Temperature variation in heat-conducting solid
in the equilibrium approximation
(meaning no time dependence)
increase
in heat
net flux in
heat source
heat proportional
to temperature
heat flows from
hot to cold
Inside
at every inside
point
equation is
satisfied
obey top BC
obey left BC
obey right BC
obey bottom BC
obey equation
obey top BC
equations
obey left BC
equations
obey equation
number of equations
top & bottom
left and right
interior
number of equations
top & bottom
left and right
interior
suggests problem is solvable
creates quite a
bookkeeping problem!
creates quite a
bookkeeping problem!
simplified by “lookup tables”
i=iofk[k,0];
j=jofk[k,0];
k=kofij[i,j];
# lookup tables translate between matrix (i,j)
# and vector ordering k
M= Lx*Ly;
iofk = np.zeros((M,1),dtype=int);
jofk = np.zeros((M,1),dtype=int);
kofij = np.zeros((Lx,Ly),dtype=int);
k=0;
for ix in range(Lx):
    for iy in range(Ly):
        iofk[k,0]=ix;
        jofk[k,0]=iy;
        kofij[ix,iy]=k;
        k=k+1;
fortunately
most of them are zero
in our case,
no more than 5 per row
Steps to making a sparse matrix D
(1)
create three vectors Dr, Dc and Dv to hold the row-index,
 
column-index, and value of non-zero elements of D
(2) For each  non-zero elements of D,
 
set one row of Dr, Dc and Dv
(3) Call a Python method that creates the sparse matrix
5
4
Pmax = 100000;
maximum number of non-zero elements
(1)
create the three vectors
Pmax = 100000;
Dr = np.zeros((Pmax,1),dtype=int);
Dc = np.zeros((Pmax,1),dtype=int);
row and column vectors must be integer
Pmax = 100000;
Dr = np.zeros((Pmax,1),dtype=int);
Dc = np.zeros((Pmax,1),dtype=int);
Dv = np.zeros((Pmax,1));
value vector
Pmax = 100000;
Dr = np.zeros((Pmax,1),dtype=int);
Dc = np.zeros((Pmax,1),dtype=int);
Dv = np.zeros((Pmax,1));
s = np.zeros((M,1));
(2) For each  non-zero elements of D, set one row of Dr, Dc and Dv
nr=0;
counter for the rows of D
 
every point in the grid is a different row
nr=0;
ne=0;
counter for the non-zero elements of D
 
nr=0;
ne=0;
mel=0; mer=0; meb=0; met=0; mi=0;
counters for the number of left, right, bottom,
top and interior points
 
nr=0;
ne=0;
mel=0; mer=0; meb=0; met=0; mi=0;
for ix in range(Lx):
    for iy in range(Ly):
[code here to set the
elements of one row
at a time of D]
 
loop over all the grid points
 
# left boundary point
if( (ix==0) and (iy>0) and (iy<(Ly-1))):
test whether this (ix,iy) in on the left boundary
 
# left boundary point
if( (ix==0) and (iy>0) and (iy<(Ly-1))):
 
k=kofij[ix,iy];
convert (ix,iy) of D into a k of m
 
# left boundary point
if( (ix==0) and (iy>0) and (iy<(Ly-1))):
 
k=kofij[ix,iy];
mel=mel+1;
this is a left element, so increment the
 
left-element counter
 
# left boundary point
if( (ix==0) and (iy>0) and (iy<(Ly-1))):
 
k=kofij[ix,iy];
mel=mel+1;
 
Dr[ne,0] = nr;
 
Dc[ne,0] = k;
 
Dv[ne,0] = 1.0;
Define this non-zero element
row of D
col of D
value of D
# left boundary point
if( (ix==0) and (iy>0) and (iy<(Ly-1))):
 
k=kofij[ix,iy];
mel=mel+1;
 
Dr[ne,0] = nr;
 
Dc[ne,0] = k;
 
Dv[ne,0] = 1.0;
 
ne=ne+1;
increment the element counter
# left boundary point
if( (ix==0) and (iy>0) and (iy<(Ly-1))):
 
k=kofij[ix,iy];
mel=mel+1;
 
Dr[ne,0] = nr;
 
Dc[ne,0] = k;
 
Dv[ne,0] = 1.0;
 
ne=ne+1;
 
s[k,0]=ExLeft[iy-1,0];
set the RHS vector
# left boundary point
if( (ix==0) and (iy>0) and (iy<(Ly-1))):
 
k=kofij[ix,iy];
mel=mel+1;
 
Dr[ne,0] = nr;
 
Dc[ne,0] = k;
 
Dv[ne,0] = 1.0;
 
ne=ne+1;
 
s[k,0]=ExLeft[iy-1,0];
 
nr=nr+1;
we are done with the row of D,
so increment the row-counter
# else is an interior point
else:
I have skipped the other boundaries
the is the code for the interior where the
differential equation is solved
# else is an interior point
else:
 
k00=kofij[ix-1,iy-1]; # interior
 
k01=kofij[ix-1,iy];
 
k02=kofij[ix-1,iy+1];
 
k10=kofij[ix,iy-1];
 
k11=kofij[ix,iy];
 
k12=kofij[ix,iy+1];
 
k20=kofij[ix+1,iy-1];
 
k21=kofij[ix+1,iy];
 
k22=kofij[ix+1,iy+1];
 
ks of the 9 points
centered on this
(ix,iy).
k of (ix,iy) is k11
in my notation
# else is an interior point
else:
 
k00=kofij[ix-1,iy-1]; # interior
 
k01=kofij[ix-1,iy];
 
k02=kofij[ix-1,iy+1];
 
k10=kofij[ix,iy-1];
 
k11=kofij[ix,iy];
 
k12=kofij[ix,iy+1];
 
k20=kofij[ix+1,iy-1];
 
k21=kofij[ix+1,iy];
 
k22=kofij[ix+1,iy+1];
 
mi=mi+1;
increment the interior-point counter
# Term 1
Dr[ne,0] = nr;
Dc[ne,0] = k01;
Dv[ne,0] = Dxr2;
ne=ne+1;
# Term 2
Dr[ne,0] = nr;
Dc[ne,0] = k21;
Dv[ne,0] = Dxr2;
ne=ne+1;
# Term 3
Dr[ne,0] = nr;
Dc[ne,0] = k11;
Dv[ne,0] = -2.0*Dxr2 -2.0*Dyr2;
ne=ne+1;
# Term 4
Dr[ne,0] = nr;
Dc[ne,0] = k10;
Dv[ne,0] = Dyr2;
ne=ne+1;
# Term 5
Dr[ne,0] = nr;
Dc[ne,0] = k12;
Dv[ne,0] = Dyr2;
ne=ne+1;
# RHS
s[k11,0]=-f[ix,iy];
# RHS
s[k11,0]=-f[ix,iy];
nr=nr+1;
done with the row
(3) Call a Python method that creates the sparse matrix
Dsparse=sparse.coo_matrix((Dv[0:ne,0:1].ravel(),
(Dr[0:ne,0:1].ravel(),Dc[0:ne,0:1].ravel())),shape=(M,M)).tocsr();
del Dv; del Dr; del Dc;
construct sparse D
delete Dr Dc Dv
which are big and no longer needed
solve matrix equation
mest = gda_cvec(las.spsolve(Dsparse,s.ravel()));
put solution in matrix form
T = np.zeros((Lx,Ly));
for k in range(M):
    i = iofk[k,0];
    j = jofk[k,0];
    T[i,j] = mest[k,0];
and we’re done!
(except for plotting)
as usual
the hard part is the
BOOKKEEPING
Slide Note
Embed
Share

Illustrated with examples, the finite difference method is applied to analyze 2D time-independent conductive heat flow in solids. The conservation of heat energy, temperature variation in heat-conducting solids, and boundary conditions are discussed in detail. Emphasis is placed on solution techniques for dynamical problems using matrix calculations and satisfying equations at boundary points.

  • Heat flow
  • Finite difference method
  • Conductive solids
  • Conservation of energy
  • Boundary conditions

Uploaded on Feb 25, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. 2023 EESC W3400 Lec 20: Finite difference method illustrated with 2D time-independent conductive heat flow Computational Earth Science Bill Menke, Instructor Emily Glazer, Teaching Assistant TR 2:40 3:55

  2. Today New (and fairly technical) Stuff Finite Difference Method for Solving Dynamical Problems

  3. Today all Lecture Thursday all in-class projects so be sure to attend

  4. Example of Temperature variation in heat-conducting solid in the equilibrium approximation (meaning no time dependence)

  5. Conservation of heat energy ? ??? ??+??? ?? ??= ?? ?? ?? and ? + ? ?? increase in heat ?? net flux in heat source

  6. ??? ??+??? ?? ??= + ? ?? ?? ?? ?? and ? heat proportional to temperature ? = ???? ??= ??? ?? ?? heat flows from hot to cold ??= ??? ??

  7. ??? ??+??? ?? ??= + ? ?? ? = ???? ??= ??? ?2? ??2+?2? ?? ??= ? ??? + ? ?? ??2 ??= ??? ??

  8. ?2? ??2+?2? ?? ??= ? ??? + ? ??2 ? = ?/? at equilibrium ?? ??=0 ?2? ??2+?2? ??2= ?

  9. boundary ? = ???? boundary ? = ???? boundary ? = ???? Inside ?2? ??2+?2? ??2= ? boundary ? = ????

  10. at every boundary point ? is specified at every boundary point ? is specified at every boundary point ? is specified at every inside point equation is satisfied at every boundary point ? is specified

  11. only consider points on a ?? ?? grid use matrix ??? for ? ??,?? values

  12. obey top BC obey left BC obey right BC obey bottom BC obey equation

  13. ? obey top BC ?00= ???? ?10= ???? ?20= ???? ? ?? equations

  14. ? obey left BC ?00= ????? ?01= ????? ?11= ????? ? ?? 2 equations

  15. ? ? obey equation ??? in interior obeys the equation ? ? ???= ? ?? 2 ?? 2 equations

  16. ?2? ??2+?2? ? + 1 at ??,?? ??2= ? ? ?? ???+ ,? 1 ??= ??+1,? ??,? ? ?

  17. ?2? ??2+?2? at ??,?? ??2= ? ? 1 ? ?? ???+ ,? 1 ??= ??+1,? ??,? ? ? ?? ??? ,? 1 ??= ??,? ?? 1,? ?

  18. ?2? ??2+?2? at ??,?? ??2= ? ? ?? ???+ ,? 1 ??= ??+1,? ??,? ? ? ?? ??? ,? 1 ??= ??,? ?? 1,? ? ?2? ??2 1 ?? ?? ?

  19. ?2? ??2+?2? at ??,?? ??2= ? ?2? ??2 1 ?2?? 1,? 2??,?+ ??+1,?

  20. ?2? ??2+?2? at ??,?? ??2= ? ?2? ??2 1 ?2??,? 1 2??,?+ ??,?+1

  21. ?2? ??2+?2? at ??,?? ??2= ? = ???

  22. ?2? ??2+?2? at ??,?? ??2= ? 1 1 ?2?? 1,? 2??,?+ ??+1,? + ?2??,? 1 2??,?+ ??,?+1 = ??? ?? 1,? ?2 2??,? ?2+??+1,? ??,? 1 ?2 2??,? ?2+??,?+1 + = ??? ?2 ?2 ?? 1,? ?2+??+1,? ?2??,?+??,? 1 ?2+??,?+1 2 2 ?2 ?2+ ?2= ???

  23. ?2? ??2+?2? at ??,?? ??2= ? ? equation at ??,?? involves 5 points ? ?? 1,? ?2+??+1,? ?2??,?+??,? 1 ?2+??,?+1 2 2 ?2 ?2+ ?2= ???

  24. number of unknown Temperature values: ? = ?? ?? number of equations 2?? top & bottom +2 ?? 2 left and right + ?? 2 ?? 2 interior

  25. number of unknown Temperature values: ? = ?? ?? number of equations 2?? 2?? top & bottom +2?? 4 +2 ?? 2 left and right +???? 2?? 2??+ 4 + ?? 2 ?? 2 interior = ????= ?

  26. number of unknown Temperature values: ? = ?? ?? number of equations ? = ?? ?? number of unknown equal number of equations ? = ? suggests problem is solvable

  27. Solution method write down matrix equation of the form ?? = ?for unknown ???s every equation (boundary or interior) is a row and solve the equation

  28. Logistical issue #1 whereas the matrix equation ?? = ?has unknown vector? unknown temperatures are a matrix?

  29. ? ? ? ? ? ? ? ? ? Solution to Logistical issue #1 unwrap the matrix ? into a vector ? ? ? ? ? ? ? ? ? ?

  30. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? creates quite a bookkeeping problem!

  31. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? simplified by lookup tables ? i=iofk[k,0]; j=jofk[k,0]; k=kofij[i,j]; ? creates quite a bookkeeping problem!

  32. # lookup tables translate between matrix (i,j) # and vector ordering k M= Lx*Ly; iofk = np.zeros((M,1),dtype=int); jofk = np.zeros((M,1),dtype=int); kofij = np.zeros((Lx,Ly),dtype=int); k=0; for ix in range(Lx): for iy in range(Ly): iofk[k,0]=ix; jofk[k,0]=iy; kofij[ix,iy]=k; k=k+1;

  33. Logistical issue #2 the matrix ? in the matrix equation ?? = ?is huge ??= ??= 100 ? = ? = ?? ??= 10,000 ? 10,000 10,000 ? 100,000,000 elements ?

  34. Solution to Logistical issue #2 define ? as a sparse matrix so that only it non-zero elements are stored ? fortunately most of them are zero 10,000 10,000 ? in our case, ? no more than 5 per row

  35. Steps to making a sparse matrix D (1)create three vectors Dr, Dc and Dv to hold the row-index, column-index, and value of non-zero elements of D (2) For each non-zero elements of D, set one row of Dr, Dc and Dv (3) Call a Python method that creates the sparse matrix

  36. ?? ?? ?=5 ?? ? = 4 ?.? 5 4 ?.? ?

  37. (1)create the three vectors Pmax = 100000; maximum number of non-zero elements

  38. Pmax = 100000; Dr = np.zeros((Pmax,1),dtype=int); Dc = np.zeros((Pmax,1),dtype=int); row and column vectors must be integer

  39. Pmax = 100000; Dr = np.zeros((Pmax,1),dtype=int); Dc = np.zeros((Pmax,1),dtype=int); Dv = np.zeros((Pmax,1)); value vector

  40. Pmax = 100000; Dr = np.zeros((Pmax,1),dtype=int); Dc = np.zeros((Pmax,1),dtype=int); Dv = np.zeros((Pmax,1)); s = np.zeros((M,1)); RHS vector of ?? = ?

  41. (2) For each non-zero elements of D, set one row of Dr, Dc and Dv nr=0; counter for the rows of D every point in the grid is a different row

  42. nr=0; ne=0; counter for the non-zero elements of D

  43. nr=0; ne=0; mel=0; mer=0; meb=0; met=0; mi=0; counters for the number of left, right, bottom, top and interior points

  44. nr=0; ne=0; mel=0; mer=0; meb=0; met=0; mi=0; for ix in range(Lx): for iy in range(Ly): loop over all the grid points [code here to set the elements of one row at a time of D]

  45. # left boundary point if( (ix==0) and (iy>0) and (iy<(Ly-1))): test whether this (ix,iy) in on the left boundary

  46. # left boundary point if( (ix==0) and (iy>0) and (iy<(Ly-1))): k=kofij[ix,iy]; convert (ix,iy) of D into a k of m

  47. # left boundary point if( (ix==0) and (iy>0) and (iy<(Ly-1))): k=kofij[ix,iy]; mel=mel+1;this is a left element, so increment the left-element counter

  48. # left boundary point if( (ix==0) and (iy>0) and (iy<(Ly-1))): k=kofij[ix,iy]; mel=mel+1; Dr[ne,0] = nr; Dc[ne,0] = k; Dv[ne,0] = 1.0; Define this non-zero element row of D col of D value of D

  49. # left boundary point if( (ix==0) and (iy>0) and (iy<(Ly-1))): k=kofij[ix,iy]; mel=mel+1; Dr[ne,0] = nr; Dc[ne,0] = k; Dv[ne,0] = 1.0; ne=ne+1; increment the element counter

  50. # left boundary point if( (ix==0) and (iy>0) and (iy<(Ly-1))): k=kofij[ix,iy]; mel=mel+1; Dr[ne,0] = nr; Dc[ne,0] = k; Dv[ne,0] = 1.0; ne=ne+1; s[k,0]=ExLeft[iy-1,0]; set the RHS vector

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#