Commits

Anonymous committed 38215bd

added OutputFromEvolveLevel

Comments (0)

Files changed (2)

src/enzo/EvolveLevel.C

  
 int RadiationFieldUpdate(LevelHierarchyEntry *LevelArray[], int level,
 			 TopGridData *MetaData);
-int WriteStreamData(HierarchyEntry *Grids[], int NumberOfGrids, 
-		    TopGridData *MetaData, int CycleCount, int EndStep = FALSE);
-int WriteMovieData(char *basename, int filenumber,
-		   LevelHierarchyEntry *LevelArray[], TopGridData *MetaData,
-		   FLOAT WriteTime);
-int WriteTracerParticleData(char *basename, int filenumber,
-		   LevelHierarchyEntry *LevelArray[], TopGridData *MetaData,
-		   FLOAT WriteTime);
-
-#ifdef USE_HDF5_GROUPS
-int Group_WriteAllData(char *basename, int filenumber, HierarchyEntry *TopGrid,
-		 TopGridData &MetaData, ExternalBoundary *Exterior,
-		 FLOAT WriteTime = -1);
-#else
-int WriteAllData(char *basename, int filenumber, HierarchyEntry *TopGrid,
-		 TopGridData &MetaData, ExternalBoundary *Exterior,
-		 FLOAT WriteTime = -1);
-#endif
+OutputFromEvolveLevel(moo);
  
 int ComputeRandomForcingNormalization(LevelHierarchyEntry *LevelArray[],
                                       int level, TopGridData *MetaData,
     }
 
     JBPERF_STOP("evolve-level-22"); // StarParticleFinalize()
-
-    /* Check for movie output (only check if this is bottom of hierarchy). */
- 
-    JBPERF_START("evolve-level-23"); // WriteMovieData()
-
-    if (LevelArray[level+1] == NULL)
-      if (LevelArray[level]->GridData->ReturnTime() >=
-	  MetaData->TimeLastMovieDump + MetaData->dtMovieDump &&
-	  MetaData->dtMovieDump > 0.0) {
-	MetaData->TimeLastMovieDump += MetaData->dtMovieDump;
-	if (WriteMovieData(MetaData->MovieDumpName,
-			  MetaData->MovieDumpNumber++, LevelArray, MetaData,
-			  LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-	  fprintf(stderr, "Error in WriteMovieData.\n");
-	  return FAIL;
-	}
-      }
- 
-    JBPERF_STOP("evolve-level-23"); // WriteMovieData()
-
-    /* Check for tracer particle output (only if this bottom of hierarchy). */
- 
-    JBPERF_START("evolve-level-24"); // WriteTracerParticleData()
-
-    if (LevelArray[level+1] == NULL)
-      if (LevelArray[level]->GridData->ReturnTime() >=
-	  MetaData->TimeLastTracerParticleDump +
-	  MetaData->dtTracerParticleDump &&
-	  MetaData->dtTracerParticleDump > 0.0) {
-	MetaData->TimeLastTracerParticleDump += MetaData->dtTracerParticleDump;
-	if (WriteTracerParticleData(MetaData->TracerParticleDumpName,
-				    MetaData->TracerParticleDumpNumber++,
-				    LevelArray, MetaData,
-			  LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-	  fprintf(stderr, "Error in WriteTracerParticleData.\n");
-	  return FAIL;
-	}
-      }
- 
-    JBPERF_STOP("evolve-level-24"); // WriteTracerParticleData()
-
     /* If cosmology, then compute grav. potential for output if needed. */
  
     JBPERF_START("evolve-level-25"); // PrepareDensityField()
  
     JBPERF_STOP("evolve-level-25"); // PrepareDensityField()
 
-    /* Check for new level output (only if this is bottom of hierarchy). */
- 
-    JBPERF_START("evolve-level-26"); // WriteAllData()
+    OutputFromEvolveLevel(moo)
 
-    if (MetaData->OutputFirstTimeAtLevel > 0 &&
-	level >= MetaData->OutputFirstTimeAtLevel &&
-	LevelArray[level+1] == NULL) {
-
-      MetaData->OutputFirstTimeAtLevel = level+1;
-      LevelHierarchyEntry *Temp2 = LevelArray[0];
-
-      while (Temp2->NextGridThisLevel != NULL)
-	Temp2 = Temp2->NextGridThisLevel; /* ugh: find last in linked list */
-
-#ifdef USE_HDF5_GROUPS
-      if (Group_WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
-		       Temp2->GridHierarchyEntry, *MetaData, Exterior,
-		       LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-	fprintf(stderr, "Error in Group_WriteAllData.\n");
-	return FAIL;
-      }
-#else
-      if (WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
-		       Temp2->GridHierarchyEntry, *MetaData, Exterior, 
-		       LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-	fprintf(stderr, "Error in WriteAllData.\n");
-	return FAIL;
-      }
-#endif
-
-    }
- 
-    /* Check for new output from new file in file system, but only
-       when at bottom of hierarchy */
-    
-#ifdef USE_MPI
-    MPI_Barrier(MPI_COMM_WORLD);
-#endif
-    if ( (access("outputNow", F_OK) != -1 ) &&
-    LevelArray[level+1] == NULL) {
-#ifdef USE_MPI
-      MPI_Barrier(MPI_COMM_WORLD);
-#endif
-      LevelHierarchyEntry *Temp2 = LevelArray[0];
-      while (Temp2->NextGridThisLevel != NULL)
-    Temp2 = Temp2->NextGridThisLevel; /* ugh: find last in linked list */
-      printf("Detected outputNow.\n");
-#ifdef USE_HDF5_GROUPS
-      if (Group_WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
-		       Temp2->GridHierarchyEntry, *MetaData, Exterior,
-		       LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-	fprintf(stderr, "Error in Group_WriteAllData.\n");
-	return FAIL;
-      }
-#else
-      if (WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
-		       Temp2->GridHierarchyEntry, *MetaData, Exterior, 
-		       LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-	fprintf(stderr, "Error in WriteAllData.\n");
-	return FAIL;
-      }
-#endif
-      if (MyProcessorNumber == ROOT_PROCESSOR)
-      if (unlink("outputNow")) {
-    fprintf(stderr, "Error deleting 'outputNow'\n");
-    return FAIL;
-      }
-    } 
-      
-    /* Check to see if new subcycle information has been given to us */
-    
-#ifdef USE_MPI
-    MPI_Barrier(MPI_COMM_WORLD);
-#endif
-    if ( (access("subcycleCount", F_OK) != -1 ) &&
-        LevelArray[level+1] == NULL) {
-      printf("Detected subcycleCount\n");
-#ifdef USE_MPI
-      MPI_Barrier(MPI_COMM_WORLD);
-#endif
-      FILE *fptr; 
-      if ((fptr = fopen("subcycleCount", "r")) == NULL) {
-        fprintf(stderr, "Error opening subcycle file subcycleCount.  Continuing.\n");
-      }
-      else {
-        /* Grab the number of cycles to dump on */
-        char line[MAX_LINE_LENGTH];
-        if (fgets(line, MAX_LINE_LENGTH, fptr) == NULL) {
-          fprintf(stderr, "Error reading subcycle file subcycleCount.  Skipping.\n");
-        } else {
-          sscanf(line, "%"ISYM, &MetaData->SubcycleSkipDataDump);
-          MetaData->SubcycleLastDataDump = MetaData->SubcycleNumber;
-        }
-        fclose(fptr);
-#ifdef USE_MPI
-        MPI_Barrier(MPI_COMM_WORLD);
-#endif
-        if (MyProcessorNumber == ROOT_PROCESSOR)
-          if (unlink("subcycleCount")) {
-            fprintf(stderr, "Error deleting subcycleCount.\n");
-          }
-      }
-    }
-
-    /* Check to see if we should start outputting interpolated data based on
-       the cycles of the highest level */
-
-    if (MetaData->SubcycleNumber >= MetaData->SubcycleLastDataDump +
-        MetaData->SubcycleSkipDataDump   &&
-        MetaData->SubcycleSkipDataDump > 0) {
-      printf("Writing data based on SubcycleDumpSkipping (%"ISYM" %"ISYM" %"ISYM")\n",
-          MetaData->SubcycleNumber, MetaData->SubcycleLastDataDump,
-          MetaData->SubcycleSkipDataDump);
-      MetaData->SubcycleLastDataDump += MetaData->SubcycleSkipDataDump;
-#ifdef USE_MPI
-      MPI_Barrier(MPI_COMM_WORLD);
-#endif
-      LevelHierarchyEntry *Temp2 = LevelArray[0];
-      while (Temp2->NextGridThisLevel != NULL)
-        Temp2 = Temp2->NextGridThisLevel; /* ugh: find last in linked list */
-
-#ifdef USE_HDF5_GROUPS
-      if (Group_WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
-            Temp2->GridHierarchyEntry, *MetaData, Exterior,
-            LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-        fprintf(stderr, "Error in Group_WriteAllData.\n");
-        return FAIL;
-      }
-#else
-      if (WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
-            Temp2->GridHierarchyEntry, *MetaData, Exterior,
-            LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-        fprintf(stderr, "Error in WriteAllData.\n");
-        return FAIL;
-      }
-#endif
-
-    } 
-
-    /* Check for stop by file-touching */
-
-#ifdef USE_MPI
-    MPI_Barrier(MPI_COMM_WORLD);
-#endif
-    if ( (access("stopNow", F_OK) != -1 ) &&
-    LevelArray[level+1] == NULL) {
-#ifdef USE_MPI
-      MPI_Barrier(MPI_COMM_WORLD);
-#endif
-      LevelHierarchyEntry *Temp2 = LevelArray[0];
-      while (Temp2->NextGridThisLevel != NULL)
-    Temp2 = Temp2->NextGridThisLevel; /* ugh: find last in linked list */
-      printf("Detected stopNow\n");
-#ifdef USE_HDF5_GROUPS
-      if (Group_WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
-		       Temp2->GridHierarchyEntry, *MetaData, Exterior,
-		       LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-	fprintf(stderr, "Error in Group_WriteAllData.\n");
-	return FAIL;
-      }
-#else
-      if (WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
-		       Temp2->GridHierarchyEntry, *MetaData, Exterior, 
-		       LevelArray[level]->GridData->ReturnTime()) == FAIL) {
-	fprintf(stderr, "Error in WriteAllData.\n");
-	return FAIL;
-      }
-#endif
-      if (MyProcessorNumber == ROOT_PROCESSOR)
-    if (unlink("stopNow")) {
-      fprintf(stderr, "Error deleting stopNow\n");
-      return FAIL;
-    } 
-      fprintf(stderr, "Stopping due to request on level %"ISYM"\n", level);
-      my_exit(EXIT_SUCCESS);
-    }
-
-
-    JBPERF_STOP("evolve-level-26"); // WriteAllData()
-
-    /* Check for stop (unpleasant to exit from here, but...). */
- 
-    if (MetaData->StopFirstTimeAtLevel > 0 &&
-	level >= MetaData->StopFirstTimeAtLevel &&
-	LevelArray[level+1] == NULL) {
-
-      // Write movie data in all grids if necessary
-
-      if (MovieSkipTimestep != INT_UNDEFINED)
-	for (int mlevel = 0; mlevel < MAX_DEPTH_OF_HIERARCHY; mlevel++) {
-	  if (LevelArray[mlevel] == NULL) break;
-	  delete [] Grids;
-	  NumberOfGrids = GenerateGridArray(LevelArray, mlevel, &Grids);
-	  if (WriteStreamData(Grids, NumberOfGrids, MetaData,
-			      LevelCycleCount[mlevel], TRUE) == FAIL) {
-	    fprintf(stderr, "Error in WriteStreamData.\n");
-	    return FAIL;
-	  }
-	}
-
-      fprintf(stderr, "Stopping due to request on level %"ISYM"\n", level);
-      my_exit(EXIT_SUCCESS);
-    }
- 
     /* For each grid, delete the GravitatingMassFieldParticles. */
  
     JBPERF_START("evolve-level-27"); // DeleteGravitatingMassFieldParticles()

src/enzo/OutputFromEvolveLevel.C

+//
+// OutputFromEvolveLevel.C
+// 
+// Written by: David Collins 
+// date      : June 10, 2009, 3:37 pm
+// 
+// Purpose   : Control various outputs from the EvolveLevel routine.
+
+//Needs some headers
+
+int WriteMovieData(char *basename, int filenumber,
+		   LevelHierarchyEntry *LevelArray[], TopGridData *MetaData,
+		   FLOAT WriteTime);
+int WriteStreamData(HierarchyEntry *Grids[], int NumberOfGrids, 
+		    TopGridData *MetaData, int CycleCount, int EndStep = FALSE);
+int WriteTracerParticleData(char *basename, int filenumber,
+		   LevelHierarchyEntry *LevelArray[], TopGridData *MetaData,
+		   FLOAT WriteTime);
+
+int OutputFromEvolveLevel(LevelHierarchyEntry *LevelArray[]){
+  /*Crap I need:
+    LevelArray
+    MetaData
+    level
+    Exterior
+  */
+  int Write = FALSE, ExitEnzo = FALSE;
+
+  //Do all "bottom of hierarchy" checks
+  if (LevelArray[level+1] == NULL){
+    
+    /* Check for movie output */
+    
+    if (LevelArray[level]->GridData->ReturnTime() >=
+	MetaData->TimeLastMovieDump + MetaData->dtMovieDump &&
+	MetaData->dtMovieDump > 0.0) {
+      MetaData->TimeLastMovieDump += MetaData->dtMovieDump;
+      if (WriteMovieData(MetaData->MovieDumpName,
+			 MetaData->MovieDumpNumber++, LevelArray, MetaData,
+			 LevelArray[level]->GridData->ReturnTime()) == FAIL) {
+	fprintf(stderr, "Error in WriteMovieData.\n");
+	return FAIL;
+      }
+    }
+    
+    /* Check for tracer particle output */
+    
+    if (LevelArray[level]->GridData->ReturnTime() >=
+	MetaData->TimeLastTracerParticleDump +
+	MetaData->dtTracerParticleDump &&
+	MetaData->dtTracerParticleDump > 0.0) {
+      MetaData->TimeLastTracerParticleDump += MetaData->dtTracerParticleDump;
+      if (WriteTracerParticleData(MetaData->TracerParticleDumpName,
+				  MetaData->TracerParticleDumpNumber++,
+				  LevelArray, MetaData,
+				  LevelArray[level]->GridData->ReturnTime()) == FAIL) {
+	fprintf(stderr, "Error in WriteTracerParticleData.\n");
+	return FAIL;
+      }
+    }
+    
+    /* Check for new level output */
+
+    if (MetaData->OutputFirstTimeAtLevel > 0 &&
+	level >= MetaData->OutputFirstTimeAtLevel){
+      MetaData->OutputFirstTimeAtLevel = level+1;
+      Write = TRUE;
+    }
+ 
+    // File directed output:
+    // Existence of the file outputNow will cause enzo to output the next time the bottom
+    //    of the hierarchy is reached.
+    // a file subcycleCount will change the number of subcycle skip output
+    // a file stopNow will output and then exit enzo.
+    
+    int outputNow = -1, stopNow = -1, subcycleCount=-1;
+    if( UseFileDirectedOutput == TRUE){
+      
+#ifdef USE_MPI
+      MPI_Barrier(MPI_COMM_WORLD);
+#endif
+      outputNow = access("outputNow", F_OK);
+      subcycleCount = access("subcycleCount", F_OK);
+      stopNow = access("stopNow", F_OK) ;
+
+      if ( outputNow != -1 ){
+	printf("Detected outputNow\n");
+	Write = TRUE;
+      }
+
+      if( stopNow != -1 ) {
+	printf("Detected stopNow\n");
+	ExitEnzo = TRUE;
+	Write = TRUE;
+      }
+
+      /* Check to see if new subcycle information has been given to us */
+      
+      if ( subcycleCount != -1 ){
+	printf("Detected subcycleCount\n");
+	
+	FILE *fptr; 
+	if ((fptr = fopen("subcycleCount", "r")) == NULL) {
+	  fprintf(stderr, "Error opening subcycle file subcycleCount.  Continuing.\n");
+	}
+	else {
+	  /* Grab the number of cycles to dump on */
+	  char line[MAX_LINE_LENGTH];
+	  if (fgets(line, MAX_LINE_LENGTH, fptr) == NULL) {
+	    fprintf(stderr, "Error reading subcycle file subcycleCount.  Skipping.\n");
+	  } else {
+	    sscanf(line, "%"ISYM, &MetaData->SubcycleSkipDataDump);
+	    MetaData->SubcycleLastDataDump = MetaData->SubcycleNumber;
+	  }
+	  fclose(fptr);
+	}
+      }
+      
+      
+#ifdef USE_MPI
+      MPI_Barrier(MPI_COMM_WORLD);
+#endif
+      if (MyProcessorNumber == ROOT_PROCESSOR){
+	if( outputNow != -1 )
+	  if (unlink("outputNow")) {
+	    fprintf(stderr, "Error deleting 'outputNow'\n");
+	    return FAIL;
+	  }
+	if( subcycleCount != -1 )
+	  if (unlink("subcycleCount")) {
+	    fprintf(stderr, "Error deleting subcycleCount.\n");
+	  }
+	if( stopNow != -1 )
+	  if (unlink("stopNow")) {
+	    fprintf(stderr, "Error deleting stopNow\n");
+	    return FAIL;
+	  } 
+      } 
+      
+      /* Check for stop by file-touching */
+      
+#ifdef USE_MPI
+      MPI_Barrier(MPI_COMM_WORLD);
+#endif
+      
+    }//File Directed Output
+    
+    /* Check to see if we should start outputting interpolated data based on
+       the cycles of the highest level */
+    
+    if (MetaData->SubcycleNumber >= MetaData->SubcycleLastDataDump +
+	MetaData->SubcycleSkipDataDump   &&
+	MetaData->SubcycleSkipDataDump > 0) {
+      printf("Writing data based on SubcycleDumpSkipping (%"ISYM" %"ISYM" %"ISYM")\n",
+	     MetaData->SubcycleNumber, MetaData->SubcycleLastDataDump,
+	     MetaData->SubcycleSkipDataDump);
+      MetaData->SubcycleLastDataDump += MetaData->SubcycleSkipDataDump;
+      Write= TRUE;
+    } 
+    
+    if (MetaData->StopFirstTimeAtLevel > 0 &&
+	level >= MetaData->StopFirstTimeAtLevel){
+      ExitEnzo = TRUE;
+      Write = TRUE;
+    }
+  }//Finest Level
+  if( ExitEnzo == TRUE ){
+    // Write movie data in all grids if necessary
+    HierarchyEntry **Grids;    
+    if (MovieSkipTimestep != INT_UNDEFINED)
+      for (int mlevel = 0; mlevel < MAX_DEPTH_OF_HIERARCHY; mlevel++) {
+	if (LevelArray[mlevel] == NULL) break;
+	delete []Grids;
+	NumberOfGrids = GenerateGridArray(LevelArray, mlevel, &Grids);
+	if (WriteStreamData(Grids, NumberOfGrids, MetaData,
+			    LevelCycleCount[mlevel], TRUE) == FAIL) {
+	  fprintf(stderr, "Error in WriteStreamData.\n");
+	  return FAIL;
+	}
+      }
+    
+    fprintf(stderr, "Stopping due to request on level %"ISYM"\n", level);
+    my_exit(EXIT_SUCCESS);
+  }
+  
+  if( Write == TRUE ){
+    
+    LevelHierarchyEntry *Temp2 = LevelArray[0];
+    while (Temp2->NextGridThisLevel != NULL)
+      Temp2 = Temp2->NextGridThisLevel; /* ugh: find last in linked list */
+#ifdef USE_HDF5_GROUPS
+    if (Group_WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
+			   Temp2->GridHierarchyEntry, *MetaData, Exterior,
+			   LevelArray[level]->GridData->ReturnTime()) == FAIL) {
+      fprintf(stderr, "Error in Group_WriteAllData.\n");
+      return FAIL;
+    }
+#else
+    if (WriteAllData(MetaData->DataDumpName, MetaData->DataDumpNumber++,
+		     Temp2->GridHierarchyEntry, *MetaData, Exterior, 
+		     LevelArray[level]->GridData->ReturnTime()) == FAIL) {
+      fprintf(stderr, "Error in WriteAllData.\n");
+      return FAIL;
+    }
+#endif
+  }//Write == TRUE
+  
+  return SUCCESS;
+}