/* ************************************************************************ * EqHeatcsv.java: Solve heat equation using with finite differences * * copyright RH Landau, Oregon State Univ, 8/99 * * * * comment: Output data saved in file in 3D grid format of gnuplot * * modified 8/01 DH McIntyre to create csv ouput file for Visad spreadsheet * ************************************************************************ */ import java.io.*; /* Import input-output Library */ public class EqHeatcvs { // Class constants public static final int NX = 101; /* grid size */ public static final int NTIMES = 80000; /* No iterations */ 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.csv for output data, use JDK 1.1 methods PrintWriter q = new PrintWriter( new FileOutputStream("EqHeat.csv"), true); /*Print two header lines for VisAd csv (comma separated values) file * First header gives mapping of domain(x,y) to range (z) * Second header tells which data appears * We only ouput z here, so x and y values are assume to go from * 0 to (N-1) where N is the number of values (per line for x, # lines for y) */ q.println("(position,time)->(temperature)"); q.println("temperature"); for(ix=1; ix <= NX-2; 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 <= NTIMES; t++) /* loop over max timesteps */ { for(ix=1; ix <= NX-2; 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%200==0) || (t==1)) /* save every 200 time steps */ { for(ix=0 ; ix <= NX-1; ix++) { q.print(u[ix][1]+" , "); //output data with commas } q.println(); /* end line of output*/ } for(ix=1; ix <= NX-2; ix++) u[ix][0]=u[ix][1]; /*shift new values to old */ } //end time loop System.out.println("data stored in EqHeat.csv"); } //end main }//end class