Matthew Turk avatar Matthew Turk committed 0293794

Adding FieldObjects to the Grid, along with debugging routines to verify them.

This is the first step. Note that allocation is currently managed by Enzo
itself. Future versions will turn off SkipFieldValueAllocation and allow the
FieldDescriptor to manage allocation.

Collapse test now proceeds without error, although the fields themselves have
not yet been utilized; they currently merely act as passive (but meaningful)
tracers.

Comments (0)

Files changed (11)

src/enzo/CollapseTestInitialize.C

 	     0) == FAIL) {
     ENZO_FAIL("Error in CollapseTestInitializeGrid.");
   }
+  TopGrid.GridData->ReconstructFieldMapping();
 
   /* Convert minimum initial overdensity for refinement to mass
      (unless MinimumMass itself was actually set). */

src/enzo/EvolveLevel.C

     for (grid1 = 0; grid1 < NumberOfGrids; grid1++)
       Grids[grid1]->GridData->ClearBoundaryFluxes();
   }
+#ifdef FIELD_DEBUG
+    for (grid1 = 0; grid1 < NumberOfGrids; grid1++)
+      Grids[grid1]->GridData->VerifyFieldMapping();
+#endif
  
   /* After we calculate the ghost zones, we can initialize streaming
      data files (only on level 0) */
 #include "Star.h"
 #include "FOF_allvars.h"
 #include "MemoryPool.h"
+#include "field_objects/FieldObjects.h"
 
 #ifdef FLUX_FIX
 #include "TopGridData.h"
   FLOAT *CellWidth[MAX_DIMENSION];
   fluxes *BoundaryFluxes;
 
+  // Field Registry
+  FieldRegistry Fields;
+
   // For restart dumps
 
   int NumberOfSubgrids;
 
    void InheritProperties(grid *ParentGrid);
 
+   // Field Registry
+   void ReconstructFieldMapping();
+   void VerifyFieldMapping();
+
 /* set the grid dimensions, left, right edges and cell quantities based
    on arguments (gg #5,6) */
 

src/enzo/Grid_InheritProperties.C

  
   for (int field = 0; field < NumberOfBaryonFields; field++)
     FieldType[field]      = ParentGrid->FieldType[field];
+
+  this->ReconstructFieldMapping();
  
   CourantSafetyNumber    = ParentGrid->CourantSafetyNumber;
   PPMFlatteningParameter = ParentGrid->PPMFlatteningParameter;

src/enzo/Grid_VerifyFieldMapping.C

+/***********************************************************************
+/
+/  GRID CLASS (RECONSTRUCT MAPPING FOR FIELDS)
+/
+/  written by: Matthew Turk, Greg Bryan
+/  date:       March, 2013
+/  modified1:
+/
+/  PURPOSE:
+/
+************************************************************************/
+ 
+//
+//  Assign basic values to a grid (allocate fields)
+//
+
+#include "preincludes.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"
+ 
+void grid::VerifyFieldMapping()
+{
+#ifdef FIELD_DEBUG
+  int field;
+  int FoundError = FALSE;
+  std::string name;
+  FieldDescriptor *fd;
+  for (int field = 0; field < NumberOfBaryonFields; field++) {
+    // We now do a double map lookup
+    name = BaseFieldIDs[FieldType[field]];
+    fd = this->Fields[name];
+    if ((fd == NULL) || (fd->GetValues() != this->BaryonField[field])) {
+      fprintf(stderr, "PROBLEM: %s has become unlocked (%"ISYM" / %"ISYM")\n",
+              name.c_str(), field, FieldType[field]);
+      FoundError = TRUE;
+    }
+  }
+  if (FoundError == FALSE) {
+    fprintf(stderr, "ERROR-FREE\n");
+  }
+#endif
+ 
+}

src/enzo/Grid_destructor.C

   /* exit(EXIT_FAILURE); */
   }
 #endif /* UNUSED */
+
+  // Field Registry
+
+  FieldRegistry::iterator iter;
+  for (iter = this->Fields.begin();
+       iter != this->Fields.end(); ++iter) {
+    if (iter->second != NULL) {
+      delete (iter->second);
+    }
+  }
  
   for (i = 0; i < MAX_DIMENSION; i++) {
     delete [] CellLeftEdge[i];

src/enzo/Make.config.objects

         Grid_CosmologyReadParticles3D.o \
         Grid_ReadHierarchyInformationHDF5.o \
 	Grid_ReadRandomForcingFields.o \
+	Grid_ReconstructFieldMapping.o \
+	Grid_VerifyFieldMapping.o \
 	Grid_RemoveForcingFromBaryonFields.o \
 	Grid_RemoveParticle.o \
 	Grid_RestoreEnergyConsistency.o \
         ZeusSource.o \
         Zeus_xTransport.o \
         Zeus_yTransport.o \
-        Zeus_zTransport.o
+        Zeus_zTransport.o \
+        field_objects/FieldDescriptor.o \
+        field_objects/FieldRegistry.o
 
 #-----------------------------------------------------------------------
 # Objects for radiative transfer module

src/enzo/ReadParameterFile.C

 
   if (debug) printf("Initialdt in ReadParameterFile = %e\n", *Initialdt);
 
+  // Now that we know our rank, we can fill our Field Registry
+
+  FillFieldRegistry(MetaData.TopGridRank, &BaseFieldTypes, &BaseFieldIDs);
 
   CheckShearingBoundaryConsistency(MetaData);
   return SUCCESS;
 /
 ************************************************************************/
 
+#define DEFINE_STORAGE
 #include "preincludes.h"
  
 #ifdef USE_MPI
 #include <string.h>
 #include <unistd.h>
  
-#define DEFINE_STORAGE
 #include "EnzoTiming.h"
 #include "ErrorExceptions.h"
 #include "performance.h"

src/enzo/field_objects/FieldDescriptor.C

     FieldDescriptor *BaseDefinition,
     int CellDimensions[MAX_DIMENSIONS],
     long_int LeftEdge[MAX_DIMENSIONS],
-    float **FieldPointer) {
+    float **FieldPointer, int SkipValueAllocation) {
   int dim;
   this->ValueCentering = BaseDefinition->ValueCentering;
   this->Rank = BaseDefinition->Rank;
 
   // This sets up how we handle the values we point to.
   this->DeallocateFieldValues = this->DeallocateFieldPointer = 0;
-  this->SetPointer(FieldPointer);
+  this->SetPointer(FieldPointer, SkipValueAllocation);
+
+#ifdef FIELD_DEBUG
+  fprintf(stderr, "OWNERSHIP OF %s IS %"ISYM" %"ISYM"\n",
+          this->GetName(), this->DeallocateFieldValues,
+          this->DeallocateFieldPointer);
+#endif
 }
 
 FieldDescriptor::FieldDescriptor(
   return *(this->FieldPointer);
 }
 
-void FieldDescriptor::SetPointer(float **NewPointer) {
+void FieldDescriptor::SetPointer(float **NewPointer, int SkipValueAllocation) {
   if (NewPointer == NULL) {
     this->AllocateFieldPointer();
     NewPointer = this->FieldPointer;
     this->FieldPointer = NewPointer;
   }
   // If we need to, also allocate values
-  if (NewPointer[0] == NULL) {
+  if ((NewPointer[0] == NULL) && (SkipValueAllocation == 0)) {
     this->AllocateFieldValues();
   }
 }

src/enzo/field_objects/FieldDescriptor.h

       FieldDescriptor(FieldDescriptor* BaseDefinition,
                       int CellDimensions[MAX_DIMENSIONS],
                       long_int LeftEdge[MAX_DIMENSIONS],
-                      float **FieldPointer = NULL);
+                      float **FieldPointer = NULL,
+                      int SkipValueAllocation = 0);
       FieldDescriptor(CenteringType ValueCentering, int Rank,
                       int CellDimensions[MAX_DIMENSIONS],
                       long_int LeftEdge[MAX_DIMENSIONS],
           int CopyDims[MAX_DIMENSIONS]);
 
       void DeallocateIfNeeded();
-      void SetPointer(float **NewPointer);
+      void SetPointer(float **NewPointer, int SkipValueAllocation = 0);
       void AllocateFieldValues();
       void AllocateFieldPointer();
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.