Commits

Nathan Goldbaum committed fc30a2c Merge

Merging

Comments (0)

Files changed (8)

src/enzo/grid/Make.module.objects

 	Grid_TracerParticleCreateParticles.o \
 	Grid_TracerParticleOutputData.o \
 	Grid_TracerParticleSetVelocity.o \
-	Grid_UpdateActiveParticle.o \
 	Grid_UpdateParticlePosition.o \
 	Grid_UpdateParticleVelocity.o \
 	Grid_UpdateParticleWithActiveParticle.o \

src/enzo/grid/particles/Grid_AccreteOntoAccretingParticle.C

File contents unchanged.

src/enzo/grid/particles/Grid_ConstructFeedbackZone.C

File contents unchanged.

src/enzo/grid/particles/Grid_UpdateActiveParticle.C

-/***********************************************************************
-/
-/  GRID CLASS (Update the active particle on this grid with the field 
-/              info from id == ThisParticle->identifier)
-/
-/  written by: Nathan Goldbaum
-/  date:       June 2012
-/
-************************************************************************/
-
-#include "preincludes.h"
-
-#include "ErrorExceptions.h"
-#include "macros_and_parameters.h"
-#include "typedefs.h"
-#include "global_data.h"
-#include "Fluxes.h"
-#include "GridList.h"
-#include "ExternalBoundary.h"
-#include "Grid.h"
-#include "Hierarchy.h"
-#include "ActiveParticle.h"
-
-int grid::UpdateActiveParticle(ActiveParticleType* ThisParticle) {
-    // Return if this doesn't concern us
-  if (ProcessorNumber != MyProcessorNumber)
-    return SUCCESS;
-
-  int i;
-  int iFound = -1, pFound = -1;
-  float CellVolume = 1.0;
-
-  for (i = 0; i<NumberOfActiveParticles; i++) {
-    if (this->ActiveParticles[i]->ReturnID() == ThisParticle->ReturnID()) {
-      iFound = i;
-      break;
-    }
-  }
-
-  if (iFound == -1)
-    return SUCCESS;
-
-  this->ActiveParticles[iFound] = ThisParticle;
-
-  ENZO_FAIL("NJG: Need to check this in a debugger\n");
-
-  return SUCCESS;
-}

src/enzo/headers/Grid.h

 
   int UpdateStarParticles(int level);
 
-  int UpdateActiveParticle(ActiveParticleType* ThisParticle);
-
   int UpdateParticleWithActiveParticle(PINT ID);
 
   int AddH2Dissociation(Star *AllStars);

src/enzo/particles/Make.module.objects

 	ActiveParticle_SampleParticle.o \
 	ActiveParticle_SphereContained.o \
 	ActiveParticle_SpringelHernquist.o \
+	AssignActiveParticlesToGrids.o \
 	DetachActiveParticles.o \
+	ParticleBufferHandler.o \
+	ParticleBufferHandler_AllocateBuffer.o \
+	ParticleBufferHandler_UnpackBuffer.o \
 	RecordTotalActiveParticleCount.o \
 
 # ENZO BUILD SYSTEM DIRECTORY MODULE
 ENZO_OBJS +=\
 	CalculatePopIIILifetime.o \
 	CalculateSubtractionParameters.o \
-	ParticleBufferHandler.o \
-	ParticleBufferHandler_AllocateBuffer.o \
-	ParticleBufferHandler_UnpackBuffer.o \
 	ParticleMergeRoutines.o \
 	ParticleSplitter.o \
 	RecalibrateAccretingMass.o \

src/enzo/particles/active_particles/ActiveParticle_AccretingParticle.C

File contents unchanged.

src/enzo/particles/active_particles/AssignActiveParticlesToGrids.C

+/***********************************************************************
+/
+/  AssignActiveParticlesToGrids:
+/  Assigning a list of active particles to the appropriate grid.
+/
+/  written by: Nathan Goldbaum
+/  date:       June, 2012
+/  modified1:
+/
+/  PURPOSE: Given a list of active particles, this function will 
+/           traverse the hierarchy and assign them to the appropriate 
+/           grid.  If a particle with the same ID as the one under 
+/           consideration is already assigned to the wrong grid, that 
+/           particle is deleted.  If the particle is already assigned 
+/           to the correct grid, the mirrored particle is updated.
+/
+************************************************************************/
+
+#ifdef USE_MPI
+#include "communicators.h"
+#endif 
+
+#include "preincludes.h"
+
+#include "ErrorExceptions.h"
+#include "macros_and_parameters.h"
+#include "typedefs.h"
+#include "global_data.h"
+#include "units.h"
+#include "Fluxes.h"
+#include "GridList.h"
+#include "ExternalBoundary.h"
+#include "Grid.h"
+#include "Hierarchy.h"
+#include "LevelHierarchy.h"
+#include "TopGridData.h"
+#include "CommunicationUtilities.h"
+#include "phys_constants.h"
+
+int GenerateGridArray(LevelHierarchyEntry *LevelArray[], int level,
+		      HierarchyEntry **Grids[]);
+int CommunicationSyncNumberOfParticles(HierarchyEntry *GridHierarchyPointer[],int NumberOfGrids);
+
+int AssignActiveParticlesToGrids(ActiveParticleType** ParticleList, int nParticles, 
+				 LevelHierarchyEntry *LevelArray[]) 
+{
+  int LevelMax, SavedGrid, NumberOfGrids, i, level, NumberOfLevelGrids, gridnum;
+  HierarchyEntry **LevelGrids = NULL;
+  FLOAT* pos = NULL;
+  float mass;
+  
+  for (i = 0; i<nParticles; i++) {
+    // Find the grid and processor this particle lives on
+    LevelMax = SavedGrid = -1;
+    for (level = 0; level < MAX_DEPTH_OF_HIERARCHY; level++) {
+      NumberOfLevelGrids = GenerateGridArray(LevelArray, level, &LevelGrids);     
+      for (gridnum = 0; gridnum < NumberOfLevelGrids; gridnum++) 
+	if (LevelGrids[gridnum]->GridData->ReturnProcessorNumber() == MyProcessorNumber)
+	  if (LevelGrids[gridnum]->GridData->PointInGrid(ParticleList[i]->ReturnPosition()) == true &&
+	      LevelGrids[gridnum]->GridData->isLocal() == true) { 
+	    SavedGrid = gridnum;
+	    LevelMax = level;
+	  }
+      delete [] LevelGrids;
+      LevelGrids = NULL;
+    }
+    
+    /* Assign the merged particles to grids. */
+    
+    if (NumberOfProcessors == 1) {
+      grid* OldGrid = ParticleList[i]->ReturnCurrentGrid();
+      int ID = ParticleList[i]->ReturnID();
+      int foundP = FALSE; 
+      int foundAP = FALSE;
+      NumberOfGrids = GenerateGridArray(LevelArray, LevelMax, &LevelGrids); 
+      
+      // If the particle moved we need to add it to the new grid and remove
+      // it from the old grid.
+      if (OldGrid != LevelGrids[SavedGrid]->GridData) {
+	if (LevelGrids[SavedGrid]->GridData->AddActiveParticle(static_cast<ActiveParticleType*>(ParticleList[i])) == FAIL)
+	  ENZO_FAIL("Active particle grid assignment failed");
+	if (SavedGrid != -1) {
+	  foundAP = OldGrid->RemoveActiveParticle(ID,LevelGrids[SavedGrid]->GridData->ReturnProcessorNumber());
+	  foundP = OldGrid->RemoveParticle(ID);
+	  if ((foundP != TRUE) || (foundAP != TRUE))
+	    return FAIL;
+	  OldGrid->SetNumberOfActiveParticles(OldGrid->ReturnNumberOfActiveParticles()-1);
+	  OldGrid->CleanUpMovedParticles();
+	}
+      }
+      // If the particle didn't change grids, we still need to mirror the AP data to the particle list.
+      else {
+	LevelGrids[SavedGrid]->GridData->UpdateParticleWithActiveParticle(ParticleList[i]->ReturnID());
+      }
+    }
+    else {
+#ifdef USE_MPI
+      /* Find the processor which has the maximum value of
+	 LevelMax and assign the accreting particle to the
+	 SavedGrid on that processor.  */
+      struct { Eint32 value; Eint32 rank; } sendbuf, recvbuf;
+      MPI_Comm_rank(EnzoTopComm, &sendbuf.rank); 
+      sendbuf.value = LevelMax;
+      MPI_Allreduce(&sendbuf, &recvbuf, 1, MPI_2INT, MPI_MAXLOC, EnzoTopComm);
+      NumberOfGrids = GenerateGridArray(LevelArray, recvbuf.value, &LevelGrids); 
+      if (LevelMax == recvbuf.value) {
+	if (LevelGrids[SavedGrid]->GridData->AddActiveParticle(static_cast<ActiveParticleType*>(ParticleList[i])) == FAIL) {
+	  ENZO_FAIL("Active particle grid assignment failed"); 
+	} 
+	// Still need to mirror the AP data to the particle list.
+	else {
+	  LevelGrids[SavedGrid]->GridData->UpdateParticleWithActiveParticle(ParticleList[i]->ReturnID());
+	}
+      }
+      LevelMax = recvbuf.value;
+#endif // endif parallel
+    }
+    
+    /* Sync the updated particle counts accross all proccessors */
+    
+    CommunicationSyncNumberOfParticles(LevelGrids, NumberOfGrids);
+    
+    delete [] LevelGrids;
+    
+  }
+
+  return SUCCESS;
+}