! From: "COMPUTATIONAL PHYSICS, 2nd Ed" ! by RH Landau, MJ Paez, and CC Bordeianu ! Copyright Wiley - VCH, 2007. ! Electronic Materials copyright: R Landau, Oregon State Univ, 2007; ! MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. ! Supported by the US National Science Foundation ! ! eqheat.f90: Solution of heat equation using with finite diffs Program heat Implicit none Double precision :: cons, ro, sph, thk, u(101, 2) Integer :: i, k, max open(9, FILE = 'eqheat.dat', Status = 'Unknown') sph = 0.113 ! specific heat iron thk = 0.12 ! thermal conductivity iron ro = 7.8 ! density for iron cons = thk/(sph*ro) max = 30000 ! number of iterations ! t = 0, all points at 100 C Do i = 1, 100 u(i, 1) = 100.0 End Do Do i = 1, 2 ! Endpoints always zero u(1, i) = 0.0 u(101, i) = 0.0 End Do ! loop over time Do k = 1, max ! loop over space Do i = 2, 100 u(i, 2) = u(i, 1) + cons*(u(i+ 1, 1) + u(i- 1, 1) - 2*u(i, 1)) End Do If ( (Mod(k, 1000) == 0) .or. (k == 1) ) then ! every 1000 steps Do i = 1, 101, 2 write(9, 22) u(i, 2) End Do Write (9, 22) EndIf ! new values - > old Do i = 2, 100 u(i, 1) = u(i, 2) End Do End Do 22 format (f10.6) close(9) Stop 'data saved in eqheat.dat (for gnuplot)' End Program heat