Commits

Nathan Goldbaum committed aa74dde

Middevlopment check-in

  • Participants
  • Parent commits e75fb0c

Comments (0)

Files changed (5)

File src/enzo/ActiveParticle.C

     return;
 }
 
+int ActiveParticleType::ReadDataset(int ndims, hsize_t *dims, char *name, hid_t group,
+				    hid_t data_type, void *read_to);
+{
+  hid_t file_dsp_id;
+  hid_t dset_id;
+  hid_t h5_status;
+  herr_t      h5_error = -1;
+  int i, j, k, dim;
+  /* get data into temporary array */
+
+  file_dsp_id = H5Screate_simple((Eint32) ndims, dims, NULL);
+  if( file_dsp_id == h5_error ){ENZO_FAIL("Error creating file dataspace");}
+
+  dset_id =  H5Dopen(group, name);
+  if( dset_id == h5_error )ENZO_VFAIL("Error opening %s", name)
+
+  h5_status = H5Dread(dset_id, data_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, (VOIDP) read_to);
+  if( dset_id == h5_error )ENZO_VFAIL("Error reading %s", name)
+
+  h5_status = H5Sclose(file_dsp_id);
+  if( dset_id == h5_error )ENZO_VFAIL("Error closing dataspace %s", name)
+
+  h5_status = H5Dclose(dset_id);
+  if( dset_id == h5_error )ENZO_VFAIL("Error closing %s", name)
+			     
+  return SUCCESS;
+}
+
 int ActiveParticleType::WriteDataset(int ndims, hsize_t *dims, char *name, hid_t group,
-		  hid_t data_type, void *data)
+				     hid_t data_type, void *data)
 {
 
   hid_t file_dsp_id;

File src/enzo/ActiveParticle.h

 			  ActiveParticleFormationData &data);
   int static WriteDataset(int ndims, hsize_t *dims, char *name, hid_t group,
 			  hid_t data_type, void *data);
+  int static ReadDataset(int ndims, hsize_t *dims, char *name, hid_t group,
+			 hid_t data_type, void *read_to);
   /* Several pure virtual functions */
   
   /* This should return the number of new star particles created, and should
    int (*ifunc)(),
    int (*feedfunc)(grid *thisgrid_orig, ActiveParticleFormationData &data),
    int (*writefunc)(ActiveParticleType *these_particles, int n, int GridRank, hid_t group_id),
+   int (*readfunc)(ActiveParticleType *particles_on_disk, int n, int GridRank, hid_t group_id),
    ActiveParticleType *particle
    ){
     this->formation_function = ffunc;
     this->initialize = ifunc;
     this->feedback_function = feedfunc;
     this->write_function = writefunc;
+    this->read_function = readfunc;
     get_active_particle_types()[this_name] = this;
   }
 
   int (*formation_function)(grid *thisgrid_orig, ActiveParticleFormationData &data);
   int (*feedback_function)(grid *thisgrid_orig, ActiveParticleFormationData &data);
   int (*write_function)(ActiveParticleType *these_particles, int n, int GridRank, hid_t group_id);
+  int (*read_function)(ActiveParticleType *particles_on_disk, int n, int GridRank, hid_t group_id);
   void (*describe_data_flags)(ActiveParticleFormationDataFlags &flags);
   ParticleBufferHandler* (*allocate_buffers)(int NumberOfParticles);
   ActiveParticleType* particle_instance;
      (&active_particle_class::AllocateBuffers),
      (&active_particle_class::InitializeParticleType),
      (&active_particle_class::EvaluateFeedback),
-     (&active_particle_class::WriteToOutput),
+     (&active_particle_class::WriteToOutput)
+     (&active_particle_class::ReadFromOutput),
      pp);
   return pinfo;
 }

File src/enzo/ActiveParticle_CenOstriker.C

 #include "TopGridData.h"
 #include "EventHooks.h"
 #include "ActiveParticle.h"
+#include "h5utilities.h"
 
 #ifdef NEW_CONFIG
 
 
   hid_t CenOstrikerGroupID = H5Gcreate(group_id,"CenOstriker",0);
 
+  writeStringAttribute(CenOstrikerGroupID,"active_particle_type","CenOstriker");
+  writeScalarAttribute(CenOstrikerGroupID,HDF5_INT,"number_of_active_particles_of_this_type",&n);
+
   ActiveParticleType_CenOstriker *ParticlesToWrite = static_cast<ActiveParticleType_CenOstriker*>(these_particles);
 
   char *ParticlePositionLabel[] =
-     {"CenOstrikerParticle_position_x", "CenOstrikerParticle_position_y", "CenOstrikerParticle_position_z"};
+     {"Particle_position_x", "Particle_position_y", "Particle_position_z"};
   char *ParticleVelocityLabel[] =
-     {"CenOstrikerParticle_velocity_x", "CenOstrikerParticle_velocity_y", "CenOstrikerParticle_velocity_z"};
+     {"Particle_velocity_x", "Particle_velocity_y", "Particle_velocity_z"};
 
   /* Create temporary buffers to store particle data */
 
 		  CenOstrikerGroupID, HDF5_FILE_REAL, (VOIDP) Velocity[dim]);
   }
   
-  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);
+  WriteDataset(1,&TempInt,"mass",CenOstrikerGroupID,HDF5_FILE_REAL,(VOIDP) Mass);
+  WriteDataset(1,&TempInt,"creation_time",CenOstrikerGroupID,HDF5_FILE_REAL,(VOIDP) BirthTime);
+  WriteDataset(1,&TempInt,"dynamical_time",CenOstrikerGroupID,HDF5_FILE_REAL,(VOIDP) DynamicalTime);
+  WriteDataset(1,&TempInt,"metallicity_fraction",CenOstrikerGroupID,HDF5_FILE_REAL,(VOIDP) Metallicity);
 }
 
 class CenOstrikerBufferHandler : public ParticleBufferHandler

File src/enzo/New_Grid_ReadGrid.C

 		ENZO_FAIL("Error reading GravityBoundaryType.");
       }
 
+    /* 5) Read active particle info */
+    
+    if (fscanf(fptr, "NumberOfActiveParticles = %"ISYM"\n", &NumberOfActiveParticles) != 1) {
+      ENZO_FAIL("error reading NumberOfActiveParticles.");
+    }
+    
+    if (NumberOfActiveParticles > 0) {
+      
+      /* Read particle file name. */
+      
+      if (fscanf(fptr, "ParticleFileName = %s\n", procfilename) != 1) {
+	ENZO_FAIL("Error reading ParticleFileName.");
+      }
+    }
+    
     // If HierarchyFile has different Ghostzones (which should be a parameter not a macro ...)
     // (useful in a restart with different hydro/mhd solvers) 
     int ghosts =DEFAULT_GHOST_ZONES;
 
   } // end: if (NumberOfParticles > 0) && ReadData && (MyProcessorNumber == ProcessorNumber)
  
+  if (NumberOfActiveParticles > 0 && ReadData && (MyProcessorNumber == ProcessorNumber)) {
+
+    /* Open file if not already done (note: particle name must = grid name). */
+
+    if ((NumberOfBaryonFields == 0 || ReadParticlesOnly) && NumberOfParticles == 0) {
+
+#ifndef SINGLE_HDF5_OPEN_ON_INPUT 
+      file_id = H5Fopen(procfilename, H5F_ACC_RDONLY, H5P_DEFAULT);
+      if( file_id == h5_error )ENZO_VFAIL("Error opening file %s", name)
+#endif
+ 
+      group_id = H5Gopen(file_id, name);
+      if( group_id == h5_error )ENZO_VFAIL("Error opening group %s", name)
+
+    } 
+
+    /* Open the active particles group */
+
+    hid_t ActiveParticleGroupID = H5Gopen(group_id, "ActiveParticles");
+
+    /* Loop over enabled active particle types */
+
+    int NumberOfActiveParticlesOnDisk;
+    
+    ActiveParticleType **ActiveParticlesOnDisk;
+
+    for (i = 0; i < EnabledActiveParticlesCount; i++)
+      {
+    
+	/* Instantiate an active particle helper of this type
+	   This class contains the function that allows us to read from disk */
+
+	ActiveParticleType_info *ActiveParticleTypeToEvaluate = EnabledActiveParticles[i];
+	
+	/* Create an empty buffer that particles in the data file will be read into */
+
+	ActiveParticleType **ActiveParticlesOfThisTypeOnDisk;
+	int NumberOfActiveParticlesOfThisType;
+
+	/* Read the active particles from disk */
+
+	ActiveParticleTypeToEvaluate->read_function(ActiveParticlesOfThisTypeOnDisk,
+						    &NumberOfActiveParticlesOfThisType,
+						    GridRank,
+						    ActiveParticleGroupID);
+	
+	int OldNumberOfActiveParticles = NumberOfActiveParticlesOnDisk;
+
+	ActiveParticleType **OldActiveParticles = ActiveParticlesOnDisk;
+
+	NumberOfActiveParticlesOnDisk += NumberOfActiveParticlesOfThisType;
+	
+	ActiveParticlesOnDisk = new ActiveParticleType*[NumberOfActiveParticlesOnDisk];
+
+	for (i = 0; i < OldNumberOfActiveParticles; i++) {
+	  ActiveParticlesOnDisk[i] = OldActiveParticles[i];
+	}
+	for (i = 0; i < NumberOfActiveParticlesOfThisType; i++) {
+	  ActiveParticlesOnDisk[OldNumberOfActiveParticles + i] = ActiveParticlesOfThisTypeOnDisk[i];
+	}
+
+	delete [] OldActiveParticles;
+	delete [] ActiveParticlesOfThisTypeOnDisk;
+	
+      } // end: for EnabledActiveParticlesCount
+
+    this->ActiveParticles = ActiveParticlesOnDisk;
+
+  } // end: if (NumberOfActiveParticles > 0) && ReadData && (MyProcessorNumber == ProcessorNumber)
+
 
   /* Close file. */
  

File src/enzo/New_Grid_WriteGrid.C

 	
 	/* Write them to disk */
 
-	ActiveParticleTypeToEvaluate->write_function(*ActiveParticlesOfThisType,NumberOfActiveParticlesOfThisType,
-						    GridRank,ActiveParticleGroupID);
-
+	ActiveParticleTypeToEvaluate->write_function(*ActiveParticlesOfThisType,
+						     NumberOfActiveParticlesOfThisType,
+						     GridRank,
+						     ActiveParticleGroupID);
+						     
 	/* Clean up */
 
 	delete [] ActiveParticlesOfThisType;