Commits

John Wise committed 21fca28 Merge

Merging PR #3

Comments (0)

Files changed (9)

src/enzo/ActiveParticle.C

     return;
 }
 
+int ActiveParticleType::WriteDataset(int ndims, hsize_t *dims, char *name, hid_t group,
+		  hid_t data_type, void *data)
+{
+
+  hid_t file_dsp_id;
+  hid_t dset_id;
+  hid_t h5_status;
+  herr_t h5_error = -1;
+  
+  file_dsp_id = H5Screate_simple((Eint32) ndims, dims, NULL);
+  if( file_dsp_id == h5_error )
+    ENZO_VFAIL("Error creating dataspace for %s", name)
+      
+  dset_id =  H5Dcreate(group, name, data_type, file_dsp_id, H5P_DEFAULT);
+  if( dset_id == h5_error )
+    ENZO_VFAIL("Error creating dataset %s", name)
+      
+  h5_status = H5Dwrite(dset_id, data_type, H5S_ALL, H5S_ALL, H5P_DEFAULT,
+		       (VOIDP) data);
+  if( h5_status == h5_error )
+    ENZO_VFAIL("Error writing dataset %s", name)
+
+  h5_status = H5Sclose(file_dsp_id);
+  if( h5_status == h5_error )
+    ENZO_VFAIL("Error closing dataspace %s", name)
+
+  h5_status = H5Dclose(dset_id);
+  if( h5_status == h5_error )
+    ENZO_VFAIL("Error closing dataset %s", name)
+
+  return SUCCESS;
+}
+
+
+
 void ActiveParticleType::ConstructData(grid *_grid,
             ActiveParticleFormationDataFlags &flags,
             ActiveParticleFormationData &data) {

src/enzo/ActiveParticle.h

 			    ActiveParticleFormationData &data);
   void static DestroyData(grid *_grid,
 			  ActiveParticleFormationData &data);
+  int static WriteDataset(int ndims, hsize_t *dims, char *name, hid_t group,
+			  hid_t data_type, void *data);
   /* Several pure virtual functions */
   
   /* This should return the number of new star particles created, and should
   ParticleBufferHandler* (*allocate_buffers)(int NumberOfParticles);
   ActiveParticleType* particle_instance;
 private:
-
   /* This is distinct from the global as a redundant error-checking
      pattern */
   static int TotalEnabledParticleCount;
 
 };
 
-int write_dataset(int ndims, hsize_t *dims, char *name, hid_t group,
-		  hid_t data_type, void *data)
-{
-
-  hid_t file_dsp_id;
-  hid_t dset_id;
-  hid_t h5_status;
-  herr_t h5_error = -1;
-  
-  file_dsp_id = H5Screate_simple((Eint32) ndims, dims, NULL);
-  if( file_dsp_id == h5_error )
-    ENZO_VFAIL("Error creating dataspace for %s", name)
-      
-  dset_id =  H5Dcreate(group, name, data_type, file_dsp_id, H5P_DEFAULT);
-  if( dset_id == h5_error )
-    ENZO_VFAIL("Error creating dataset %s", name)
-      
-  h5_status = H5Dwrite(dset_id, data_type, H5S_ALL, H5S_ALL, H5P_DEFAULT,
-		       (VOIDP) data);
-  if( h5_status == h5_error )
-    ENZO_VFAIL("Error writing dataset %s", name)
-
-  h5_status = H5Sclose(file_dsp_id);
-  if( h5_status == h5_error )
-    ENZO_VFAIL("Error closing dataspace %s", name)
-
-  h5_status = H5Dclose(dset_id);
-  if( h5_status == h5_error )
-    ENZO_VFAIL("Error closing dataset %s", name)
-
-  return SUCCESS;
-}
-
 template <class active_particle_class>
 ActiveParticleType_info *register_ptype(std::string name)
 {

src/enzo/ActiveParticle_CenOstriker.C

 
 int ActiveParticleType_CenOstriker::WriteToOutput(ActiveParticleType *these_particles, int n, int GridRank, hid_t group_id)
 {
-  ActiveParticleType_CenOstriker *ParticlesToWrite = static_cast<ActiveParticleType_CenOstriker *>(these_particles);
+  /* Create a new subgroup within the active particle group for active particles of type CenOstriker */
+
+  hid_t CenOstrikerGroupID = H5Gcreate(group_id,"CenOstriker",0);
+
+  ActiveParticleType_CenOstriker *ParticlesToWrite = static_cast<ActiveParticleType_CenOstriker*>(these_particles);
 
   char *ParticlePositionLabel[] =
      {"CenOstrikerParticle_position_x", "CenOstrikerParticle_position_y", "CenOstrikerParticle_position_z"};
   }
 
   for (dim = 0; dim < GridRank; dim++) {
-    write_dataset(1,&TempInt,ParticlePositionLabel[dim],
-		  group_id, HDF5_FILE_PREC, (VOIDP) Position[dim]);
+    WriteDataset(1,&TempInt,ParticlePositionLabel[dim],
+		  CenOstrikerGroupID, HDF5_FILE_PREC, (VOIDP) Position[dim]);
   }
 
   for (dim = 0; dim < GridRank; dim++) {
-    write_dataset(1,&TempInt,ParticleVelocityLabel[dim],
-		  group_id, HDF5_FILE_PREC, (VOIDP) Velocity[dim]);
+    WriteDataset(1,&TempInt,ParticleVelocityLabel[dim],
+		  CenOstrikerGroupID, HDF5_FILE_REAL, (VOIDP) Velocity[dim]);
   }
   
-  write_dataset(1,&TempInt,"CenOstriker_mass",group_id,HDF5_FILE_PREC,(VOIDP) Mass);
-  write_dataset(1,&TempInt,"CenOstriker_creation_time",group_id,HDF5_FILE_PREC,(VOIDP) BirthTime);
-  write_dataset(1,&TempInt,"CenOstriker_dynamical_time",group_id,HDF5_FILE_PREC,(VOIDP) DynamicalTime);
-  write_dataset(1,&TempInt,"CenOstriker_metallicity_fraction",group_id,HDF5_FILE_PREC,(VOIDP) Metallicity);
+  WriteDataset(1,&TempInt,"CenOstriker_mass",CenOstrikerGroupID,HDF5_FILE_REAL,(VOIDP) Mass);
+  WriteDataset(1,&TempInt,"CenOstriker_creation_time",CenOstrikerGroupID,HDF5_FILE_REAL,(VOIDP) BirthTime);
+  WriteDataset(1,&TempInt,"CenOstriker_dynamical_time",CenOstrikerGroupID,HDF5_FILE_REAL,(VOIDP) DynamicalTime);
+  WriteDataset(1,&TempInt,"CenOstriker_metallicity_fraction",CenOstrikerGroupID,HDF5_FILE_REAL,(VOIDP) Metallicity);
 }
 
 class CenOstrikerBufferHandler : public ParticleBufferHandler

src/enzo/ActiveParticle_SampleParticle.C

   static ParticleBufferHandler *AllocateBuffers(int NumberOfParticles);
   static int EvaluateFeedback(grid *thisgrid_orig, ActiveParticleFormationData &data);
   static int InitializeParticleType(void);
+  
   ENABLED_PARTICLE_ID_ACCESSOR
 };
 

src/enzo/ActiveParticle_SinkParticle.C

   static ParticleBufferHandler *AllocateBuffers(int NumberOfParticles);
   static int EvaluateFeedback(grid *thisgrid_orig, ActiveParticleFormationData &data);
   static int InitializeParticleType();
+
   ENABLED_PARTICLE_ID_ACCESSOR
 
   static float OverflowFactor;

src/enzo/New_Grid_ReadGrid.C

 /  modified4:  Robert Harkness, April 2008
 /  modified5:  Matthew Turk, September 2009 for refactoring and removing IO_TYPE
 /  modified6:  Michael Kuhlen, October 2010, HDF5 hierarchy
+/  modified7:  Nathan Goldbaum, November 2011, Active Particle Support
 /
 /  PURPOSE:
 /
 
   } // end: if (NumberOfParticles > 0) && ReadData && (MyProcessorNumber == ProcessorNumber)
  
+
   /* Close file. */
  
   if ( (MyProcessorNumber == ProcessorNumber) &&

src/enzo/New_Grid_WriteGrid.C

 /  modified3:  Robert Harkness, April 2008
 /  modified4:  Matthew Turk, September 2009
 /  modified5:  Michael Kuhlen, October 2010, HDF5 hierarchy
+/  modified6:  Nathan Goldbaum, November 2011, Active Particle Support  
 /
 /  PURPOSE:
 /
 //      where the Old values aren't required)
  
 #include <hdf5.h>
+#include <map>
+#include <iostream>
+#include <stdexcept>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "GridList.h"
 #include "ExternalBoundary.h"
 #include "Grid.h"
-#include "ActiveParticles.h"
+#include "fortran.def"
+#include "CosmologyParameters.h"
+#include "ActiveParticle.h"
 
 void my_exit(int status);
  
 
     fprintf(fptr, "NumberOfParticles   = %"ISYM"\n", NumberOfParticles);
 
+    fprintf(fptr, "NumberOfActiveParticles =%"ISYM"\n", NumberOfActiveParticles);
+
     if (NumberOfParticles > 0)
       fprintf(fptr, "ParticleFileName = %s\n", procfilename); // must be same as above
  
   if (NumberOfActiveParticles > 0) {
     /* Iterate over the enabled active particle types */
 
+    hid_t ActiveParticleGroupID = H5Gcreate(group_id, "ActiveParticles", 0);
+
     for (i = 0; i < EnabledActiveParticlesCount; i++)
       {
 
+	/* Instantitate an active particle helper of this type
+	   This class contains the function that allows us to write to disk */
+
 	ActiveParticleType_info *ActiveParticleTypeToEvaluate = EnabledActiveParticles[i];
-	bool BufferExists = false;
-	
 
 	/* Count the number of active particles of this type  */
 	
 	int NumberOfActiveParticlesOfThisType = LocationOfActiveParticlesOfThisType.size();
 
 	/* Put the active particles of this type in a temporary buffer */
-
-	ActiveParticlesOfThisType = new ActiveParticleType*[NumberOfActiveParticlesOfThisType];
+	
+	ActiveParticleType **ActiveParticlesOfThisType = new ActiveParticleType*[NumberOfActiveParticlesOfThisType];
 
 	for (j = 0; j<NumberOfActiveParticlesOfThisType; j++) {
 	  ActiveParticlesOfThisType[j] = this->ActiveParticles[LocationOfActiveParticlesOfThisType[j]];
 	}
 	
-	ActiveParticleTypeToEvaluate->WriteToOutput(ActiveParticlesOfThisType,NumberOfActiveParticlesOfThisType,GridRank,group_id);
+	/* Write them to disk */
 
+	ActiveParticleTypeToEvaluate->write_function(*ActiveParticlesOfThisType,NumberOfActiveParticlesOfThisType,
+						    GridRank,ActiveParticleGroupID);
+
+	/* Clean up */
+
+	delete [] ActiveParticlesOfThisType;
 
       }
     

src/enzo/TopGridData.h

 
   boundary_type ParticleBoundaryType;
   PINT          NumberOfParticles;
+  
+  /* Active Particle Data */
+
+  /* TODO: Update NumberOfActiveParticles
+  /* PINT   NumberOfActiveParticles; */
 
   /* Hydro Parameters.  
      These are here out of convenience, the real ones are in the grids. */

src/enzo/WriteParameterFile.C

 // This routine writes the parameter file in the argument and sets parameters
 //   based on it.
  
+#include <map>
+#include <iostream>
+#include <vector>
 #include <stdio.h>
 #include <string.h>
 #include <time.h>
+#include <stdlib.h>
+#include <assert.h>
 #include <math.h>
 #include "ErrorExceptions.h"
 #include "macros_and_parameters.h"
 #include "ExternalBoundary.h"
 #include "Grid.h"
 #include "TopGridData.h"
-
+#include "ActiveParticle.h"
  
 /* function prototypes */
  
   fprintf(fptr, "ParticleBoundaryType   = %"ISYM"\n",MetaData.ParticleBoundaryType);
   fprintf(fptr, "NumberOfParticles      = %"PISYM" (do not modify)\n",
 	  MetaData.NumberOfParticles);
- 
+
+  ActiveParticleMap map = get_active_particle_types();
+
+  ActiveParticleMap::const_iterator end = map.end();
+
+  for (ActiveParticleMap::const_iterator it = map.begin(); it != end; ++it) {
+    fprintf(fptr, "AppendActiveParticleType =%s\n", it->first);
+  }
+
   fprintf(fptr, "CourantSafetyNumber    = %"FSYM"\n",
 	  MetaData.CourantSafetyNumber);
   fprintf(fptr, "PPMFlatteningParameter = %"ISYM"\n",