Commits

John Wise committed d5ea4b6

Adding quantity mirroring between normal and active particles.

  • Participants
  • Parent commits 58c31a2

Comments (0)

Files changed (7)

File src/enzo/ActiveParticleFinalize.C

+/***********************************************************************
+/
+/  ACTIVE PARTICLE INITIALIZATION
+/
+/  written by: John Wise
+/  date:       March, 2009
+/  modified1:  November, 2011 (JHW) -- converting to active particles
+/
+/  PURPOSE: Contains all routines to finalize the star particles.
+/
+************************************************************************/
+#ifdef USE_MPI
+#include "mpi.h"
+#endif
+#include <map>
+#include <iostream>
+#include <stdexcept>
+#include <stdlib.h>
+#include <stdio.h>
+#include "ErrorExceptions.h"
+#include "performance.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 "TopGridData.h"
+#include "LevelHierarchy.h"
+#include "CommunicationUtilities.h"
+#include "ActiveParticle.h"
+
+/* prototypes */
+
+int CommunicationUpdateStarParticleCount(HierarchyEntry *Grids[],
+					 TopGridData *MetaData,
+					 int NumberOfGrids,
+					 int TotalStarParticleCountPrevious[]);
+
+
+int ActiveParticleFinalize(HierarchyEntry *Grids[], TopGridData *MetaData,
+			   int NumberOfGrids, LevelHierarchyEntry *LevelArray[], 
+			   int level, int TotalStarParticleCountPrevious[])
+{
+
+  if (!StarParticleCreation && !StarParticleFeedback)
+    return SUCCESS;
+
+  LCAPERF_START("ActiveParticleFinalize");
+
+  /* Update the star particle counters. */
+
+  CommunicationUpdateStarParticleCount(Grids, MetaData, NumberOfGrids,
+				       TotalStarParticleCountPrevious);
+
+  /* Update position and velocity of star particles from the actual
+     particles */
+
+  int grid_num;
+  for (grid_num = 0; grid_num < NumberOfGrids; grid_num++) {
+    Grids[grid_num]->GridData->MirrorActiveParticles(COPY_IN);
+  } // ENDFOR grids
+
+  /* TODO Items:
+     1. Add feedback spheres
+     2. Accretion from grid to particles (or from pre-determined rates)
+     3. Output sink particle information
+     4. Change particle statuses for stellar births and deaths
+     5. Reset accretion rates
+     6. Store MBH mass accretion history
+     7. Merge star particles.  It is probably not necessary here and
+        should be done in ActiveParticleInitialize.
+
+     JHW Thought: this should be done in a "finalize" routine for each
+     active particle type.
+
+   */
+
+  LCAPERF_STOP("ActiveParticleFinalize");
+  return SUCCESS;
+
+}

File src/enzo/ActiveParticleInitialize.C

+/***********************************************************************
+/
+/  ACTIVE PARTICLE INITIALIZATION
+/
+/  written by: John Wise
+/  date:       March, 2009
+/  modified1:  November, 2011 (JHW) -- Converted to active particles.
+/
+/  PURPOSE: Contains all routines to initialize the star particles.
+/
+************************************************************************/
+
+#include <map>
+#include <iostream>
+#include <stdexcept>
+#include <stdlib.h>
+#include <stdio.h>
+#include "performance.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 "TopGridData.h"
+#include "LevelHierarchy.h"
+#include "ActiveParticle.h"
+
+int StarParticlePopIII_IMFInitialize(void);
+int FindTotalNumberOfParticles(LevelHierarchyEntry *LevelArray[]);
+void RecordTotalStarParticleCount(HierarchyEntry *Grids[], int NumberOfGrids,
+				  int TotalStarParticleCountPrevious[]);
+
+int ActiveParticleInitialize(HierarchyEntry *Grids[], TopGridData *MetaData,
+			     int NumberOfGrids, LevelHierarchyEntry *LevelArray[], 
+			     int ThisLevel, int TotalStarParticleCountPrevious[])
+{
+
+  /* Return if this does not concern us */
+  if (!(StarParticleCreation || StarParticleFeedback)) 
+    return SUCCESS;
+
+  LCAPERF_START("ActiveParticleInitialize");
+
+  /* Set MetaData->NumberOfParticles and prepare TotalStarParticleCountPrevious
+     these are to be used in CommunicationUpdateStarParticleCount 
+     in StarParticleFinalize */  
+
+  MetaData->NumberOfParticles = FindTotalNumberOfParticles(LevelArray);
+  NumberOfOtherParticles = MetaData->NumberOfParticles - NumberOfStarParticles;
+  RecordTotalStarParticleCount(Grids, NumberOfGrids, 
+			       TotalStarParticleCountPrevious);
+
+  /* TODO: Merging */
+
+  /* Active particle initialization
+     1. mirror quantities from active to normal particles
+  */
+
+  int grid_num;
+  for (grid_num = 0; grid_num < NumberOfGrids; grid_num++) {
+    Grids[grid_num]->GridData->MirrorActiveParticles(COPY_OUT);
+  } // ENDFOR grids
+
+  LCAPERF_STOP("ActiveParticleInitialize");
+  return SUCCESS;
+
+}

File src/enzo/ActiveParticleRoutines.C

   type = _grid->ParticleType[_id];
   Identifier = _grid->ParticleNumber[_id];
   Mass = (double)(_grid->ParticleMass[_id]);
-  BirthTime = _grid->ParticleAttribute[0][_id];
-  DynamicalTime = _grid->ParticleAttribute[1][_id];
-  Metallicity = _grid->ParticleAttribute[2][_id];
+
+  // No more attributes.  Everything stored in active particles.
+//  BirthTime = _grid->ParticleAttribute[0][_id];
+//  DynamicalTime = _grid->ParticleAttribute[1][_id];
+//  Metallicity = _grid->ParticleAttribute[2][_id];
   this->ConvertMassToSolar();
 }
 
   CurrentGrid = _grid;
   level = _level;
   GridID = _grid->ID;
-  BirthTime = _grid->ParticleAttribute[0][_id];
-  DynamicalTime = _grid->ParticleAttribute[1][_id];
-  Metallicity = _grid->ParticleAttribute[2][_id];
+
+  // No more attributes.  Everything stored in active particles.
+//  BirthTime = _grid->ParticleAttribute[0][_id];
+//  DynamicalTime = _grid->ParticleAttribute[1][_id];
+//  Metallicity = _grid->ParticleAttribute[2][_id];
 
   // below is removed because we want to keep Star->Mass as double 
   // during the run - Ji-hoon Kim, Dec.2009

File src/enzo/EvolveLevel.C

 int ComputeRandomForcingNormalization(LevelHierarchyEntry *LevelArray[],
                                       int level, TopGridData *MetaData,
                                       float * norm, float * pTopGridTimeStep);
-int CreateSiblingList(HierarchyEntry ** Grids, int NumberOfGrids, SiblingGridList *SiblingList, 
+int CreateSiblingList(HierarchyEntry ** Grids, int NumberOfGrids, 
+		      SiblingGridList *SiblingList, 
 		      int StaticLevelZero,TopGridData * MetaData,int level);
 
 #ifdef FLUX_FIX
 			 int NumberOfGrids, LevelHierarchyEntry *LevelArray[], 
 			 int level, Star *&AllStars,
 			 int TotalStarParticleCountPrevious[]);
+int ActiveParticleInitialize(HierarchyEntry *Grids[], TopGridData *MetaData,
+			     int NumberOfGrids, LevelHierarchyEntry *LevelArray[], 
+			     int ThisLevel, int TotalStarParticleCountPrevious[]);
+int ActiveParticleFinalize(HierarchyEntry *Grids[], TopGridData *MetaData,
+			   int NumberOfGrids, LevelHierarchyEntry *LevelArray[], 
+			   int level, int TotalStarParticleCountPrevious[]);
 int AdjustRefineRegion(LevelHierarchyEntry *LevelArray[], 
 		       TopGridData *MetaData, int EL_level);
 int AdjustMustRefineParticlesRefineToLevel(TopGridData *MetaData, int EL_level);
 
     /* Initialize the star particles */
 
+#ifdef ACTIVE_PARTICLE_IMPLEMENTED
+    ActiveParticleInitialize(Grids, MetaData, NumberOfGrids, LevelArray,
+	                     level, TotalStarParticleCountPrevious);
+#else
     Star *AllStars = NULL;
     StarParticleInitialize(Grids, MetaData, NumberOfGrids, LevelArray,
 			   level, AllStars, TotalStarParticleCountPrevious);
+#endif
+    
 
 #ifdef TRANSFER
     /* Initialize the radiative transfer */
       }*/
 #endif
 
-
       /* Include 'star' particle creation and feedback. */
 
-      Grids[grid1]->GridData->StarParticleHandler
-	(Grids[grid1]->NextGridNextLevel, level ,dtLevelAbove);
-
 #ifdef ACTIVE_PARTICLE_IMPLEMENTED
       Grids[grid1]->GridData->ActiveParticleHandler
 	(Grids[grid1]->NextGridNextLevel, level ,dtLevelAbove);
+#else
+      Grids[grid1]->GridData->StarParticleHandler
+	(Grids[grid1]->NextGridNextLevel, level ,dtLevelAbove);
 #endif
 
       /* Include shock-finding */
  
     /* Finalize (accretion, feedback, etc.) star particles */
 
+#ifdef ACTIVE_PARTICLE_IMPLEMENTED
+    ActiveParticleFinalize(Grids, MetaData, NumberOfGrids, LevelArray,
+			   level, TotalStarParticleCountPrevious);
+#else
     StarParticleFinalize(Grids, MetaData, NumberOfGrids, LevelArray,
 			 level, AllStars, TotalStarParticleCountPrevious);
+#endif
 
     /* For each grid: a) interpolate boundaries from the parent grid.
                       b) copy any overlapping zones from siblings. */

File src/enzo/Grid.h

 
   int ActiveParticleHandler(HierarchyEntry* SubgridPointer, int level,
 			    float dtLevelAbove);
+  int MirrorActiveParticles(int direction);
+
 
   /* Returns averaged velocity from the 6 neighbor cells and itself */
 

File src/enzo/Grid_MirrorActiveParticles.C

+/***********************************************************************
+/
+/  GRID CLASS (MIRROR ACTIVE AND NORMAL PARTICLE INFO)
+/
+/  written by: John Wise
+/  date:       November, 2011
+/  modified1:  
+/
+/  PURPOSE:
+/
+************************************************************************/
+ 
+#include <string.h>
+#include <map>
+#include <iostream>
+#include <stdexcept>
+#include <stdio.h>
+#include <math.h>
+#include <iostream>
+#include <math.h>
+#include <assert.h>
+#include "ErrorExceptions.h"
+#include "performance.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 "fortran.def"
+#include "CosmologyParameters.h"
+#include "ActiveParticle.h"
+
+int grid::MirrorActiveParticles(int direction)
+{
+
+  int i;
+
+  LCAPERF_START("grid_MirrorActiveParticles");
+
+  // Normal -> active particles
+  if (direction == COPY_IN) {
+
+    for (i = 0; i < NumberOfActiveParticles; i++) {
+      this->ActiveParticles[i]->UpdatePositionVelocity();
+    }
+
+  }
+
+  // Active -> normal particles
+  else if (direction == COPY_OUT) {
+
+    for (i = 0; i < NumberOfActiveParticles; i++) {
+      this->ActiveParticles[i]->MirrorToParticle();
+    }
+
+  } 
+
+  else {
+    ENZO_FAIL("Bad direction value");
+  }
+
+  LCAPERF_STOP("grid_MirrorActiveParticles");
+  return SUCCESS;
+
+}

File src/enzo/Make.config.objects

 OBJS_CONFIG_LIB = \
         acml_st1.o \
         ActiveParticle.o \
+	ActiveParticleFinalize.o \
+	ActiveParticleInitialize.o \
 	ActiveParticleRoutines.o \
         ActiveParticle_CenOstriker.o \
 	ActiveParticle_DisableParticle.o \
 	Grid_KHInitializeGrid.o \
         Grid_MagneticFieldResetter.o \
 	Grid_MirrorStarParticles.o \
+	Grid_MirrorActiveParticles.o \
 	Grid_MoveAllParticles.o \
 	Grid_MoveAllStars.o \
 	Grid_MoveParticlesFOF.o \