[Commits] [svn:einsteintoolkit] incoming/PITTNullCode/SphericalHarmonicReconGen/src/ (Rev. 118)

rhaas at tapir.caltech.edu rhaas at tapir.caltech.edu
Thu Mar 13 18:19:30 CDT 2014


User: rhaas
Date: 2014/03/13 06:19 PM

Modified:
 /PITTNullCode/SphericalHarmonicReconGen/src/
  read.cc

Log:
 SphericalHarmonicReconGen: Nicely terminate before we run out of data
 
 rather than waiting for one more step (likely) and then aborting.

File Changes:

Directory: /PITTNullCode/SphericalHarmonicReconGen/src/
=======================================================

File [modified]: read.cc
Delta lines: +36 -5
===================================================================
--- PITTNullCode/SphericalHarmonicReconGen/src/read.cc	2014-01-14 20:56:12 UTC (rev 117)
+++ PITTNullCode/SphericalHarmonicReconGen/src/read.cc	2014-03-13 23:19:30 UTC (rev 118)
@@ -22,10 +22,13 @@
 
 using namespace std;
 
-extern "C"
+namespace
 {
-  void load_modes(const CCTK_REAL time, const bool time_derivative_in_file, const bool allow_offcentered_time_stencils)
+  // returns true when the interpolation uses the last valid iteration in the file
+  bool load_modes(const CCTK_REAL time, const bool time_derivative_in_file, const bool allow_offcentered_time_stencils)
   {
+    // have we just read the last dataset from the files?
+    bool read_last_iteration = false;
     // identify iteration which corresponds to the time just before the target time "time"
     int iteration = SHR::C[0]->get_iteration(time + SHR::initial_time_in_file);
     
@@ -50,7 +53,11 @@
         if (time_derivative_in_file)
           SHR::Ct[i]->set_modes_from_file(5-(k+2), iteration+k);
       }
+      for (int i=0; i < SHR::db.size(); ++i)
+        read_last_iteration |= (iteration+k == SHR::db[i]->n_timesteps()-1);
     }
+
+    return read_last_iteration;
   }
 
   void interpolate(const CCTK_REAL time, const int tl, const bool time_derivative_in_file)
@@ -91,8 +98,11 @@
         SHR::Ct[i]->interpolate_to_(tl, L);
     }
   }
+}
 
 
+extern "C"
+{
   void SphericalHarmonicReconGeneric_SetTimeStep(CCTK_ARGUMENTS)
   {
     DECLARE_CCTK_ARGUMENTS;
@@ -193,6 +203,14 @@
 	          CCTK_INFO("Loading decomposed variables for current timestep...");
 	       
 	       for (int i=0; i < 3*NUM_METRIC_COMPONENTS; ++i) {
+		  if ((my_iteration+it_off) == SHR::db[i]->n_timesteps()-1) { // will run out in next step
+                     static bool reported_done = false;
+                     CCTK_TerminateNext(cctkGH);
+                     if (!reported_done) {
+                        CCTK_INFO("Done reading data from file.");
+                        reported_done = true;
+                     }
+                  }
 		  if ((my_iteration+it_off) >= SHR::db[i]->n_timesteps())
 		     CCTK_WARN(0, "The input file does not contain more iterations. Stopping.");
 	       }
@@ -228,6 +246,7 @@
                          initial_time+cctk_time, 
                          initial_time+cctk_time+cctk_delta_time, 
                          initial_time+cctk_time+2*cctk_delta_time };
+       bool read_last_iteration = false;
       
        // If the automatically computed time-offset is disabled,
        // we allow for off-centered stencils at the beginning.
@@ -241,14 +260,16 @@
           if (time_fd_order == 2)
              for (int i=0; i < 3; ++i)
 	     {
-	        load_modes(u[i], false, disable_auto_time_offset);
+	        read_last_iteration |=
+                  load_modes(u[i], false, disable_auto_time_offset);
 	        interpolate(u[i], 2-i, false);
 	     }
           
 	  if (time_fd_order == 4)
 	     for (int i=0; i < 5; ++i)
 	     {
-	        load_modes(u[i], false, disable_auto_time_offset);
+	        read_last_iteration |=
+	          load_modes(u[i], false, disable_auto_time_offset);
 	        interpolate(u[i], 4-i, false);
 	     }
 	  
@@ -258,13 +279,23 @@
           // just time interpolate coefficients to u[2]
           
           // load all modes centered around time u[2] to internal "coeff_in_file" array...
-          load_modes(u[2], true, disable_auto_time_offset);
+          read_last_iteration |=
+            load_modes(u[2], true, disable_auto_time_offset);
           
           // ...and use these coeffs to setup internal interpolated coeffs "coeff"
           // and copy obtained value to timelevel 0
           interpolate(u[2], 0, true);
           
        }
+
+       // check if current interpolation used the last iteration in the file, then
+       // request termination so as to not run out of data. This may terminate a
+       // bit early if the last iteration can be used for more than one
+       // interpolation.
+       if (read_last_iteration) { // will (likely) run out in next step
+          CCTK_TerminateNext(cctkGH);
+          CCTK_INFO("Likely done reading data from file.");
+       }
        
     }
 



More information about the Commits mailing list