/* ************************************************************************ * EqHeat_M.java: Solve heat equation using with finite differences * * copyright RH Landau, Oregon State Univ, 8/99 * * * * modified 8/01 DH McIntyre to create output file for Maple surfdata plot. * File contains (x,y,z) data points where x=time, y=position, z=temperature * ************************************************************************ */ import java.io.*; /* Import input-output Library */ public class EqHeat_xyz { // Class constants public static final int NX = 51; /* grid size */ public static final int NT = 101; /* Number time points to save */ public static final int DT = 200; /* Number of time iterations/save*/ public static final double THC = 0.12; /* thermal conductivity*/ public static final double SPH = 0.113; /* specific heat */ public static final double RHO = 15.; /* density */ // method must throw exceptions if does not handle them. public static void main(String[] argv) throws IOException, FileNotFoundException { int ix, t; double[] [] u = new double[NX][2]; /* 2-D array declared, allocated */ double cons; // Open file EqHeat.dat for output data, use JDK 1.1 methods PrintWriter q = new PrintWriter( new FileOutputStream("EqHeat_xyz.dat"), true); /*Print data to file for input to Maple * Maple data files want numbers separated by spaces * We only ouput z here, so x and y values are assumed to go from * 0 to (N-1) where N is the number of values (per line for x, # lines for y) */ for(ix=1; ix < NX-1; ix++) u[ix][0]=100.; /* t=0 all points at 100 C */ for(t=0; t < 2; t++) /* except the endpoints */ { u[0][t] = 0.; u[NX-1][t] = 0.; } cons=THC/(SPH*RHO); /* material constants */ for(t=1; t < NT*DT; t++) /* loop over max timesteps */ { for(ix=1; ix < NX-1; ix++) /* loop over space */ { u[ix][1] = u[ix][0]+cons*(u[ix+1][0]+u[ix-1][0]-2.0*u[ix][0]); } if((t%DT==0) || (t==1)) /* save every DT time steps */ { for(ix=0 ; ix < NX; ix++) { q.println(t+" "+ix+" "+u[ix][1]); //output data with spaces } } for(ix=1; ix < NX-1; ix++) u[ix][0]=u[ix][1]; /*shift new values to old */ } //end time loop System.out.println("data stored in EqHeat_xyz.dat"); } //end main }//end class