Commits

Matthew Turk  committed 0f7fd7c

Using SetupFields

  • Participants
  • Parent commits c47e73b

Comments (0)

Files changed (3)

File src/enzo/ProblemType.C

 
 }
 
-void FieldContainer::add_field(std::string field_name, float default_value)
+void FieldContainer::add_field(std::string field_name, int FieldNumber,
+                               float default_value)
 {
     if (this->default_values.count(field_name) != 0)
         ENZO_VFAIL("Tried to reset default for %s", field_name.c_str())
     this->default_values[field_name] = default_value;
+    this->field_numbers[field_name] = FieldNumber;
     return;
 }
 

File src/enzo/ProblemType.h

 {
     public:
         float &operator[](std::string);
-        void add_field(std::string, float default_value);
+        void add_field(std::string, int FieldNumber, float default_value);
         void reset();
         int needs(std::string field_name);
     private:
         std::map<std::string, float> field_values;
         std::map<std::string, float> default_values;
+        std::map<std::string, field_type> field_numbers;
 };
 
 class EnzoProblemType
     virtual ~EnzoProblemType()
     {}
     int DataLabelCount;
+    void ReadConfig(FILE *fptr);
 
     grid *CreateNewUniformGrid(grid *ParentGrid,
             int Rank, int Dimensions[], 

File src/enzo/ProblemType_RotatingCylinder.C

 
       /* local declarations */
 
-      char line[MAX_LINE_LENGTH];
-      int  i, j, dim, ret, NumberOfSubgridZones[MAX_DIMENSION],
+      int  i, j, dim, NumberOfSubgridZones[MAX_DIMENSION],
            SubgridDims[MAX_DIMENSION];
 
       /* make sure it is 3D */
 
       /* read input from file */
 
-      while (fgets(line, MAX_LINE_LENGTH, fptr) != NULL) {
+      this->ReadConfig(fptr);
 
-        ret = 0;
-
-        /* read parameters specifically for radiating shock problem*/
-
-        ret += sscanf(line, "RotatingCylinderOverdensity  = %"FSYM, &RotatingCylinderOverdensity);
-        ret += sscanf(line, "RotatingCylinderSubgridLeft = %"PSYM,
-            &RotatingCylinderSubgridLeft);
-        ret += sscanf(line, "RotatingCylinderSubgridRight = %"PSYM,
-            &RotatingCylinderSubgridRight);
-        ret += sscanf(line, "RotatingCylinderLambda = %"FSYM,
-            &RotatingCylinderLambda);
-
-        ret += sscanf(line, "RotatingCylinderTotalEnergy = %"FSYM,
-            &RotatingCylinderTotalEnergy);
-
-        ret += sscanf(line, "RotatingCylinderRadius = %"PSYM,
-            &RotatingCylinderRadius);
-        ret += sscanf(line, "RotatingCylinderCenterPosition = %"PSYM" %"PSYM" %"PSYM,
-            RotatingCylinderCenterPosition, RotatingCylinderCenterPosition+1,
-            RotatingCylinderCenterPosition+2);
-
-        ret += sscanf(line, "TestProblemUseMetallicityField  = %"ISYM, &TestProblemData.UseMetallicityField);
-        ret += sscanf(line, "TestProblemInitialMetallicityFraction  = %"FSYM, &TestProblemData.MetallicityField_Fraction);
-
-        /* if the line is suspicious, issue a warning */
-
-        if (ret == 0 && strstr(line, "=") && (strstr(line, "RotatingCylinder") || strstr(line, "TestProblem")) &&
-            line[0] != '#' && MyProcessorNumber == ROOT_PROCESSOR)
-          fprintf(stderr,
-              "*** warning: the following parameter line was not interpreted:\n%s\n",
-          line);
-
-      } // end input from parameter file
-
+      FieldContainer background;
+      this->SetupFields(background);
 
       this->InitializeUniformGrid(TopGrid.GridData,
             RotatingCylinderDensity,
 
     void SetupFields(FieldContainer &Fields)
     {
-        Fields.add_field("Density", 0.0);
-        Fields.add_field("TotalEnergy", 0.0);
-        Fields.add_field("GasEnergy", 0.0);
-        Fields.add_field("x-velocity", 0.0);
-        Fields.add_field("y-velocity", 0.0);
-        Fields.add_field("Metal_Density", 0.0);
+        Fields.add_field("Density", Density, RotatingCylinderDensity);
+        Fields.add_field("TotalEnergy", TotalEnergy, RotatingCylinderTotalEnergy);
+        Fields.add_field("GasEnergy", InternalEnergy,
+                          RotatingCylinderTotalEnergy);
+        Fields.add_field("x-velocity", Velocity1, 0.0);
+        Fields.add_field("y-velocity", Velocity2, 0.0);
+        Fields.add_field("z-velocity", Velocity3, 0.0);
+        Fields.add_field("Metal_Density", Metallicity, 0.0);
     }
 
-    void ReadConfig(void)
+    void ReadConfig(FILE *fptr)
     {
         /* read input from file */
-        while (fgets(line, MAX_LINE_LENGTH, fptr) != NULL) {
-            ret = 0;
+      char line[MAX_LINE_LENGTH];
+      int ret;
+      while (fgets(line, MAX_LINE_LENGTH, fptr) != NULL) {
+          ret = 0;
 
-            /* read parameters specifically for RotatingCylinder problem*/
-            ret += sscanf(line, "RotatingCylinderOverdensity  = %"FSYM, this->RotatingCylinderOverdensity);
-            ret += sscanf(line, "RotatingCylinderSubgridLeft = %"PSYM,
-                this->RotatingCylinderSubgridLeft);
-            ret += sscanf(line, "RotatingCylinderSubgridRight = %"PSYM,
-                this->RotatingCylinderSubgridRight);
-            ret += sscanf(line, "RotatingCylinderLambda = %"FSYM,
-                this->RotatingCylinderLambda);
-            ret += sscanf(line, "RotatingCylinderTotalEnergy = %"FSYM,
-                this->RotatingCylinderTotalEnergy);
-            ret += sscanf(line, "RotatingCylinderRadius = %"PSYM,
-                this->RotatingCylinderRadius);
-            ret += sscanf(line, "RotatingCylinderCenterPosition = %"PSYM" %"PSYM" %"PSYM,
-			  this->RotatingCylinderCenterPosition, (this->RotatingCylinderCenterPosition)+1,
-			  (this->RotatingCylinderCenterPosition)+2);
+          /* read parameters specifically for RotatingCylinder problem*/
+          ret += sscanf(line, "RotatingCylinderOverdensity  = %"FSYM, this->RotatingCylinderOverdensity);
+          ret += sscanf(line, "RotatingCylinderSubgridLeft = %"PSYM,
+              this->RotatingCylinderSubgridLeft);
+          ret += sscanf(line, "RotatingCylinderSubgridRight = %"PSYM,
+              this->RotatingCylinderSubgridRight);
+          ret += sscanf(line, "RotatingCylinderLambda = %"FSYM,
+              this->RotatingCylinderLambda);
+          ret += sscanf(line, "RotatingCylinderTotalEnergy = %"FSYM,
+              this->RotatingCylinderTotalEnergy);
+          ret += sscanf(line, "RotatingCylinderRadius = %"PSYM,
+              this->RotatingCylinderRadius);
+          ret += sscanf(line, "RotatingCylinderCenterPosition = %"PSYM" %"PSYM" %"PSYM,
+            this->RotatingCylinderCenterPosition, (this->RotatingCylinderCenterPosition)+1,
+            (this->RotatingCylinderCenterPosition)+2);
 
-            ret += sscanf(line, "TestProblemUseMetallicityField  = %"ISYM, this->TestProblemData.UseMetallicityField);
-            ret += sscanf(line, "TestProblemInitialMetallicityFraction  = %"FSYM, this->TestProblemData.MetallicityField_Fraction);
+          ret += sscanf(line, "TestProblemUseMetallicityField  = %"ISYM, TestProblemData.UseMetallicityField);
+          ret += sscanf(line, "TestProblemInitialMetallicityFraction  = %"FSYM, TestProblemData.MetallicityField_Fraction);
 
-            /* if the line is suspicious, issue a warning */
+          /* if the line is suspicious, issue a warning */
 
-            if (ret == 0 && strstr(line, "=") && (strstr(line, "RotatingCylinder") || strstr(line, "TestProblem")) &&
-                line[0] != '#' && MyProcessorNumber == ROOT_PROCESSOR)
-              fprintf(stderr,
-                  "*** warning: the following parameter line was not interpreted:\n%s\n", line);
+          if (ret == 0 && strstr(line, "=") && (strstr(line, "RotatingCylinder") || strstr(line, "TestProblem")) &&
+              line[0] != '#' && MyProcessorNumber == ROOT_PROCESSOR)
+            fprintf(stderr,
+                "*** warning: the following parameter line was not interpreted:\n%s\n", line);
 
-      } // end input from parameter file
-    }  
+    } // end input from parameter file
+  }  
 
 };