Commits

Matthew Turk committed c94f50f

Move to using a FieldSpecification, implement an Apply function, setup some
field labels, and setup a grid preconditioner.

Comments (0)

Files changed (9)

src/enzo/FieldContainer.C

     return;
 }
 
-FieldContainer::FieldContainer(FieldContainer &fields)
+FieldContainer::FieldContainer(FieldContainer *fields)
 {
     std::map<std::string, float>::iterator it;
     std::string field_name;
-    for(it = fields.start(); it != fields.end(); it++)
+    for(it = fields->start(); it != fields->end(); it++)
     {
         field_name = (*it).first;
-        this->add_field(field_name, fields.field_numbers[field_name],
-                        fields[field_name]);
+        this->AddField(field_name, fields->field_numbers[field_name],
+                        (*fields)[field_name]);
     }
 }
 
-void FieldContainer::add_field(std::string field_name, int FieldNumber,
+void FieldContainer::AddField(std::string field_name, int FieldNumber,
                                float value)
 {
     if (this->field_values.count(field_name) != 0)
         ENZO_VFAIL("Tried to reset default for %s", field_name.c_str())
     this->field_values[field_name] = value;
     this->field_numbers[field_name] = FieldNumber;
+    this->field_names.push_back(field_name);
     return;
 }
 
-void FieldContainer::clear()
+void FieldContainer::Clear()
 {
     for (std::map<std::string, float>::iterator it =
             this->field_values.begin();
     return;
 }
 
-int FieldContainer::needs(std::string field_name)
+int FieldContainer::Needs(std::string field_name)
 {
     if (this->field_values.count(field_name) == 0) return FALSE;
     else return TRUE;
     return this->field_values.end();
 }
 
+void FieldContainer::SetupGrid(ProblemTypeGrid *thisgrid)
+{
+    /* We get our size ... */
+    int size = 1, dim;
+    for (dim = 0; dim < thisgrid->GridRank; dim++)
+      size *= thisgrid->GridDimension[dim];
+
+    /* Here we add on all the appropriate field numbers and whatnot. */
+    thisgrid->NumberOfBaryonFields = 0;
+    std::vector<std::string>::iterator it;
+    for (it = this->field_names.begin();
+         it != this->field_names.end();
+         it++)
+    {
+      thisgrid->FieldType[thisgrid->NumberOfBaryonFields] =
+        this->field_numbers[(*it)];
+      thisgrid->BaryonField[thisgrid->NumberOfBaryonFields++] =
+        new float[size];
+    }
+    return;
+}
+
+void FieldContainer::SetupDataLabels(EnzoProblemType *ptype)
+{
+    std::vector<std::string>::iterator it;
+    for (it = this->field_names.begin();
+         it != this->field_names.end();
+         it++)
+    {
+        ptype->AddDataLabel((*it).c_str());
+    }
+}
+
+void FieldContainer::Apply(ProblemTypeGrid *thisgrid, int cellindex)
+{
+    
+    return;
+}
 
 #endif

src/enzo/FieldContainer.h

 {
     public:
         FieldContainer();
-        FieldContainer(FieldContainer &orig);
+        FieldContainer(FieldContainer *orig);
         float &operator[](std::string);
-        void add_field(std::string, int FieldNumber,
+        void AddField(std::string, int FieldNumber,
                        float value = FLOAT_UNDEFINED);
-        void clear();
-        int needs(std::string field_name);
+        void Clear();
+        void SetupGrid(ProblemTypeGrid *thisgrid);
+        void Apply(ProblemTypeGrid *thisgrid, int cellindex);
+        int Needs(std::string field_name);
         std::map<std::string, float>::iterator start();
         std::map<std::string, float>::iterator end();
+        void SetupDataLabels(EnzoProblemType *ptype);
     protected:
         std::map<std::string, float> field_values;
         std::map<std::string, field_type> field_numbers;
+        std::vector<std::string> field_names;
 };
 
 #endif
 
 // inline int grid::TurbulenceSimulationInitializeGrid (TURBULENCE_INIT_PARAMETERS_DECL);
 
-
+#ifdef NEW_PROBLEM_TYPES
+class ProblemTypeGrid : private grid {
+    friend class EnzoProblemType;
+    friend class FieldContainer;
+};
 #endif
+
+
+#endif

src/enzo/InitializationKernel.C

     this->additive = additive;
 }
 
-void InitializationKernelConstant::apply(FieldContainer &fields,
+void InitializationKernelConstant::Apply(FieldContainer *fields_,
                 FLOAT x, FLOAT y, FLOAT z,
                 FLOAT dx, FLOAT dy, FLOAT dz)
 {
+    FieldContainer fields = (*fields_);
     std::map<std::string, float>::iterator it;
     for(it = this->constants->start();
         it != this->constants->end();

src/enzo/InitializationKernel.h

     public:
 
         InitializationKernel() {};
-        virtual void apply(FieldContainer &fields,
+        virtual void Apply(FieldContainer *fields,
                    FLOAT x, FLOAT y, FLOAT z,
                    FLOAT dx, FLOAT dy, FLOAT dz) = 0;
 
     public:
         InitializationKernelConstant(FieldContainer *constants,
                     int additive = FALSE);
-        void apply(FieldContainer &fields,
+        void Apply(FieldContainer *fields,
                    FLOAT x, FLOAT y, FLOAT z,
                    FLOAT dx, FLOAT dy, FLOAT dz);
 

src/enzo/Make.config.objects

         PressurelessCollapseInitialize.o \
         ProblemType.o \
         ProblemType_RotatingCylinder.o \
-        ProblemType_CollapsingCoolingCloud.o \
-	ProblemType_ExplodingCloud.o \
         ProcMap.o \
         project.o \
         projectbool.o \

src/enzo/ProblemType.C

 
 }
 
-void ApplyKernels(grid *thisgrid)
+void EnzoProblemType::ApplyKernels(grid *thisgrid_orig)
 {
     /* Now we iterate over every cell */
+    ProblemTypeGrid *thisgrid =
+      static_cast<ProblemTypeGrid *>(thisgrid_orig);
+
+    FLOAT x,y,z;
+    int i, j, k, cellindex, ki;
+
+    /* We get the container into which all our cells will be placed. */
+    FieldContainer *cell_vals = new FieldContainer(this->FieldSpecification);
+    cell_vals->SetupGrid(thisgrid);
+
+    for (k = 0; k < thisgrid->GridDimension[2]; k++)
+      for (j = 0; j < thisgrid->GridDimension[1]; j++)
+        for (i = 0; i < thisgrid->GridDimension[0]; i++){
+
+          /* Compute position */
+          x=y=z=0.0;
+
+          cellindex = i + j*thisgrid->GridDimension[0]
+                        + k*thisgrid->GridDimension[0]
+                           *thisgrid->GridDimension[1];
+
+          x = thisgrid->CellLeftEdge[0][i] + 0.5*thisgrid->CellWidth[0][i];
+          y = thisgrid->CellLeftEdge[1][j] + 0.5*thisgrid->CellWidth[1][j];
+          z = thisgrid->CellLeftEdge[2][k] + 0.5*thisgrid->CellWidth[2][k];
+
+          cell_vals->Clear();
+          for (ki = 0; ki < this->NumberOfKernels; ki++) {
+            this->kernels[ki]->Apply(cell_vals, x, y, z,
+                thisgrid->CellWidth[0][i],
+                thisgrid->CellWidth[0][j],
+                thisgrid->CellWidth[0][k]);
+          }
+          cell_vals->Apply(thisgrid, cellindex);
+
+        }
+
 }
 
 #endif

src/enzo/ProblemType.h

 #ifndef __PROBLEM_TYPES__
 #define __PROBLEM_TYPES__
 
+class ProblemTypeGrid;
+
 #include "InitializationKernel.h"
 #include "FieldContainer.h"
 #include <string>
     {return SUCCESS;}
     int AddDataLabel(const char *FieldName);
     virtual void SetupKernels()=0;
-    void ApplyKernels(grid *thisgrid) {return;}
+    void ApplyKernels(grid *thisgrid);
 
 protected:
     //.. constructor
         }
         int NumberOfKernels;
         InitializationKernel *kernels[100];
+        FieldContainer *FieldSpecification;
 
     private:
 };
 //! failsafe version to select the plug-in
 EnzoProblemType *select_problem_type( std::string problem_type_name );
 
-
-
 #endif
 #endif

src/enzo/ProblemType_RotatingCylinder.C

 
     void SetupKernels()
     {
-        FieldContainer *background_fields = new FieldContainer;
-        background_fields->add_field("Density", Density, RotatingCylinderDensity);
-        background_fields->add_field("TotalEnergy", TotalEnergy, RotatingCylinderTotalEnergy);
-        background_fields->add_field("GasEnergy", InternalEnergy,
-                          RotatingCylinderTotalEnergy);
-        background_fields->add_field("x-velocity", Velocity1, 0.0);
-        background_fields->add_field("y-velocity", Velocity2, 0.0);
-        background_fields->add_field("z-velocity", Velocity3, 0.0);
-        background_fields->add_field("Metal_Density", Metallicity, 0.0);
+        FieldContainer &field_definitions = *(new FieldContainer);
+        field_definitions.AddField("Density", Density);
+        field_definitions.AddField("TotalEnergy", TotalEnergy);
+        field_definitions.AddField("GasEnergy", InternalEnergy);
+        field_definitions.AddField("x-velocity", Velocity1);
+        field_definitions.AddField("y-velocity", Velocity2);
+        field_definitions.AddField("z-velocity", Velocity3);
+        field_definitions.AddField("Metal_Density", Metallicity);
+        this->FieldSpecification = &field_definitions;
+        this->FieldSpecification->SetupDataLabels(this);
+
+        FieldContainer &background_fields = *(new
+            FieldContainer(field_definitions));
+        background_fields["Density"] = RotatingCylinderDensity;
+        background_fields["TotalEnergy"] = RotatingCylinderTotalEnergy;
+        background_fields["GasEnergy"] = RotatingCylinderTotalEnergy;
+        background_fields["x-velocity"] = 0.0;
+        background_fields["y-velocity"] = 0.0;
+        background_fields["z-velocity"] = 0.0;
+        background_fields["Metal_Density"] = 0.0;
 
         InitializationKernelConstant *background = 
-            new InitializationKernelConstant(background_fields);
+            new InitializationKernelConstant(&background_fields);
 
         this->AddKernel(static_cast<InitializationKernel*>(background));
     }