/* 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. Support by National Science Foundation */ // EqHeat.java: Solve heat equation via finite differences import java.io.*; // Import IO library public class EqHeat { // Class constants in MKS units public static final int Nx = 11, Nt = 300; // Grid sizes public static final double Dx = 0.01, Dt = 0.1; // Step sizes public static final double KAPPA = 210.; // Thermal conductivity public static final double SPH = 900.; // Specific heat public static final double RHO = 2700.; // Al density public static void main(String[] argv) throws IOException, FileNotFoundException { int ix, t; double T[][] = new double[Nx][2]; double cons; PrintWriter q = new PrintWriter // File for gnuplot (new FileOutputStream("EqHeat.dat"), true); for ( ix=1; ix < Nx-1; ix++ ) T[ix][0] = 100.; // Initialize T[0][0] = 0.; T[0][1] = 0.; // Except ends T[Nx-1][0] = 0.; T[Nx-1][1] = 0.; cons = KAPPA/(SPH*RHO)*Dt/(Dx*Dx); // Integration factor System.out.println("constant = " + cons); // t loop for ( t=1; t <= Nt; t++ ) { // x loop for ( ix=1; ix < Nx-1; ix++ ) T[ix][1] = T[ix][0] + cons*(T[ix + 1][0] + T[ix-1][0]-2.*T[ix][0]); if ( t%10==0 || t==1 ) { // Save every N steps for ( ix = 0; ix