From 0b2441a3061444a40db88cc36b96a000b6061523 Mon Sep 17 00:00:00 2001
From: Mark Meredith <mark.meredith@netl.doe.gov>
Date: Fri, 8 May 2020 15:38:36 -0400
Subject: [PATCH] WIP

---
 src/inputs/geometry.cpp    | 92 +++++++++++++++++++-------------------
 src/inputs/mesh.cpp        | 25 ++++++-----
 src/inputs/solver.cpp      |  7 ++-
 src/inputs/solver.hpp      |  3 +-
 src/inputs/solver_impl.hpp |  2 +-
 src/inputs/time.cpp        |  7 +--
 6 files changed, 73 insertions(+), 63 deletions(-)

diff --git a/src/inputs/geometry.cpp b/src/inputs/geometry.cpp
index 09cc521..5910b9f 100644
--- a/src/inputs/geometry.cpp
+++ b/src/inputs/geometry.cpp
@@ -2,53 +2,55 @@
 
 namespace solver {
 
-solver::GeometrySettings make_geometry(solver::InputInfo ii,
-                                       std::vector<InputsMessage> &messages) {
-  solver::GeometrySettings geo;
+  solver::GeometrySettings make_geometry(solver::InputInfo ii,
+                                         std::vector<InputsMessage> &messages) {
+    solver::GeometrySettings geo;
 
-  if (ii.count(CSG_FILENAME)) {
-    auto csg_filename = std::get<solver::StringArray>(ii[CSG_FILENAME]);
-    if (csg_filename.size() != 1) {
-      messages.push_back(
-          InputsMessage{"geometry.filename should only have 1 element"});
-    }
-  } else {
     geo.csg_filename = "";
-  }
+    if (!ii.count(CSG_FILENAME)) {
+      require(CSG_FILENAME, messages, std::vector<std::string> {""});
+    } else {
+      auto csg_filename = std::get<solver::StringArray>(ii[CSG_FILENAME]);
+      if (csg_filename.size() != 1) {
+        // messages.push_back(CSG_FILENAME, messages, 1, geo.csg_filename);
+      } else {
+        geo.csg_filename = csg_filename[0];
+      }
+    }
 
-  if (!ii.count(PROB_LO)) {
-    require(PROB_LO, messages, 0);
-  }
-  if (!ii.count(PROB_HI)) {
-    require(PROB_HI, messages, 0);
-  }
-  if (!ii.count(PERIODIC)) {
-    require(PERIODIC, messages, 0);
-  }
-  auto lows = std::get<solver::NumberArray>(ii[PROB_LO]);
-  auto highs = std::get<solver::NumberArray>(ii[PROB_HI]);
-  auto is_periodic = std::get<solver::NumberArray>(ii[PERIODIC]);
-  if (lows.size() != 3) {
-    require(PROB_LO, messages, 3);
-  } else {
-    std::get<0>(geo.axes).low = lows[0];
-    std::get<1>(geo.axes).low = lows[1];
-    std::get<2>(geo.axes).low = lows[2];
-  }
-  if (highs.size() != 3) {
-    require(PROB_HI, messages, 3);
-  } else {
-    std::get<0>(geo.axes).high = highs[0];
-    std::get<1>(geo.axes).high = highs[1];
-    std::get<2>(geo.axes).high = highs[2];
-  }
-  if (is_periodic.size() != 3) {
-    require(PERIODIC, messages, 3);
-  } else {
-    std::get<0>(geo.axes).periodic = is_periodic[0];
-    std::get<1>(geo.axes).periodic = is_periodic[1];
-    std::get<2>(geo.axes).periodic = is_periodic[2];
+    if (!ii.count(PROB_LO)) {
+      require(PROB_LO, messages, 0);
+    }
+    if (!ii.count(PROB_HI)) {
+      require(PROB_HI, messages, 0);
+    }
+    if (!ii.count(PERIODIC)) {
+      require(PERIODIC, messages, 0);
+    }
+    auto lows = std::get<solver::NumberArray>(ii[PROB_LO]);
+    auto highs = std::get<solver::NumberArray>(ii[PROB_HI]);
+    auto is_periodic = std::get<solver::NumberArray>(ii[PERIODIC]);
+    if (lows.size() != 3) {
+      require(PROB_LO, messages, 3);
+    } else {
+      std::get<0>(geo.axes).low = lows[0];
+      std::get<1>(geo.axes).low = lows[1];
+      std::get<2>(geo.axes).low = lows[2];
+    }
+    if (highs.size() != 3) {
+      require(PROB_HI, messages, 3);
+    } else {
+      std::get<0>(geo.axes).high = highs[0];
+      std::get<1>(geo.axes).high = highs[1];
+      std::get<2>(geo.axes).high = highs[2];
+    }
+    if (is_periodic.size() != 3) {
+      require(PERIODIC, messages, 3);
+    } else {
+      std::get<0>(geo.axes).periodic = is_periodic[0];
+      std::get<1>(geo.axes).periodic = is_periodic[1];
+      std::get<2>(geo.axes).periodic = is_periodic[2];
+    }
+    return geo;
   }
-  return geo;
-}
 } // namespace solver
diff --git a/src/inputs/mesh.cpp b/src/inputs/mesh.cpp
index 7f9d028..7be8c44 100644
--- a/src/inputs/mesh.cpp
+++ b/src/inputs/mesh.cpp
@@ -8,12 +8,13 @@ solver::MeshSettings make_mesh(solver::InputInfo ii,
   auto [mx, my, mz] = mesh.axes;
 
   if (!ii.count(N_CELL)) {
-    require(N_CELL, messages, 0);
+    // NumberArray defaults = std::vector<double> {0};
+    require(N_CELL, messages, 0, std::vector<double> {0});
   } else {
 
     auto n_cell = std::get<solver::NumberArray>(ii[N_CELL]);
     if (n_cell.size() != 3) {
-      require(N_CELL, messages, 3);
+      require(N_CELL, messages, 3, std::vector<double> {0});
     } else {
       mx.n_cell = n_cell[0];
       my.n_cell = n_cell[1];
@@ -23,7 +24,7 @@ solver::MeshSettings make_mesh(solver::InputInfo ii,
 
   auto fabarray_size = std::get<solver::NumberArray>(ii[FABARRAY_TILE_SZ]);
   if (fabarray_size.size() != 3) {
-    require(FABARRAY_TILE_SZ, messages, 3);
+    require(FABARRAY_TILE_SZ, messages, 3, std::vector<double> {0});
   } else {
     mx.fluid_max_tile_size = fabarray_size[0];
     my.fluid_max_tile_size = fabarray_size[1];
@@ -32,7 +33,7 @@ solver::MeshSettings make_mesh(solver::InputInfo ii,
 
   auto part_grid_size = std::get<solver::NumberArray>(ii[PARTICLE_TILE_SZ]);
   if (part_grid_size.size() != 3) {
-    require(PARTICLE_TILE_SZ, messages, 3);
+    require(PARTICLE_TILE_SZ, messages, 3, std::vector<double> {0});
   } else {
     mx.particle_max_tile_size = part_grid_size[0];
     my.particle_max_tile_size = part_grid_size[1];
@@ -41,19 +42,19 @@ solver::MeshSettings make_mesh(solver::InputInfo ii,
 
   auto grid_size_x = std::get<solver::NumberArray>(ii[GRID_SIZE_X]);
   if (grid_size_x.size() != 1) {
-    require(GRID_SIZE_X, messages, 1);
+    require(GRID_SIZE_X, messages, 1, std::vector<double> {0});
   } else {
     mx.max_grid_size = grid_size_x[0];
   }
   auto grid_size_y = std::get<solver::NumberArray>(ii[GRID_SIZE_Y]);
   if (grid_size_y.size() != 1) {
-    require(GRID_SIZE_Y, messages, 1);
+    require(GRID_SIZE_Y, messages, 1, std::vector<double> {0});
   } else {
     my.max_grid_size = grid_size_y[0];
   }
   auto grid_size_z = std::get<solver::NumberArray>(ii[GRID_SIZE_Z]);
   if (grid_size_z.size() != 1) {
-    require(GRID_SIZE_Z, messages, 1);
+    require(GRID_SIZE_Z, messages, 1, std::vector<double> {0});
   } else {
     mz.max_grid_size = grid_size_z[0];
   }
@@ -61,35 +62,35 @@ solver::MeshSettings make_mesh(solver::InputInfo ii,
   auto particle_grid_size_x =
       std::get<solver::NumberArray>(ii[PARTICLE_GRID_SIZE_X]);
   if (particle_grid_size_x.size() != 1) {
-    require(PARTICLE_GRID_SIZE_X, messages, 1);
+    require(PARTICLE_GRID_SIZE_X, messages, std::vector<double> {0});
   } else {
     mx.particle_max_grid_size = particle_grid_size_x[0];
   }
   auto particle_grid_size_y =
       std::get<solver::NumberArray>(ii[PARTICLE_GRID_SIZE_Y]);
   if (particle_grid_size_y.size() != 1) {
-    require(PARTICLE_GRID_SIZE_Y, messages, 1);
+    require(PARTICLE_GRID_SIZE_Y, messages, std::vector<double> {0});
   } else {
     my.particle_max_grid_size = particle_grid_size_y[0];
   }
   auto particle_grid_size_z =
       std::get<solver::NumberArray>(ii[PARTICLE_GRID_SIZE_Z]);
   if (particle_grid_size_z.size() != 1) {
-    require(PARTICLE_GRID_SIZE_Z, messages, 1);
+    require(PARTICLE_GRID_SIZE_Z, messages, std::vector<double> {0});
   } else {
     mz.particle_max_grid_size = particle_grid_size_z[0];
   }
 
   auto bf = std::get<solver::NumberArray>(ii[BLOCKING_FACTOR]);
   if (bf.size() != 1) {
-    require(BLOCKING_FACTOR, messages, 1);
+    require(BLOCKING_FACTOR, messages, std::vector<double> {0});
   } else {
     mesh.blocking_factor = bf[0];
   }
 
   auto volfrac = std::get<solver::NumberArray>(ii[SMALL_VOLFRAC]);
   if (volfrac.size() != 1) {
-    require(SMALL_VOLFRAC, messages, 1);
+    require(SMALL_VOLFRAC, messages, std::vector<double> {0});
   } else {
     mesh.small_volfrac = volfrac[0];
   }
diff --git a/src/inputs/solver.cpp b/src/inputs/solver.cpp
index 45d6e32..6b53f3a 100644
--- a/src/inputs/solver.cpp
+++ b/src/inputs/solver.cpp
@@ -4,19 +4,24 @@
 
 namespace solver {
 
-void require(std::string key, std::vector<InputsMessage> &messages, int size) {
+  void require(std::string key, std::vector<InputsMessage> &messages, int size, Array defaults) {
   std::ostringstream oss;
 
   if (size == 0) {
     oss << "missing required key: " << key;
+
   } else if (size == 1) {
     oss << key << " is a scalar";
+
   } else if (size == 1) {
     oss << key << " requires " << size << " elements";
+
   }
   messages.push_back(InputsMessage{oss.str()});
 }
 
+
+
 std::pair<solver::SolverSettings, std::vector<InputsMessage>>
 make_solver(solver::InputInfo ii) {
   std::vector<InputsMessage> messages;
diff --git a/src/inputs/solver.hpp b/src/inputs/solver.hpp
index 4b4ad0a..8acd97c 100644
--- a/src/inputs/solver.hpp
+++ b/src/inputs/solver.hpp
@@ -15,7 +15,8 @@ namespace solver {
 
 using NumberArray = std::vector<double>;
 using StringArray = std::vector<std::string>;
-using InputInfo = std::map<std::string, std::variant<NumberArray, StringArray>>;
+using Array = std::variant<NumberArray, StringArray>;
+using InputInfo = std::map<std::string, Array >;
 
 std::optional<InputInfo> parse_inputs(std::string);
 
diff --git a/src/inputs/solver_impl.hpp b/src/inputs/solver_impl.hpp
index 31d6956..7a02793 100644
--- a/src/inputs/solver_impl.hpp
+++ b/src/inputs/solver_impl.hpp
@@ -4,5 +4,5 @@ namespace solver {
 GeometrySettings make_geometry(solver::InputInfo, std::vector<InputsMessage> &);
 MeshSettings make_mesh(solver::InputInfo, std::vector<InputsMessage> &);
 TimeSettings make_time(solver::InputInfo, std::vector<InputsMessage> &);
-void require(std::string, std::vector<InputsMessage> &, int);
+  void require(std::string key, std::vector<InputsMessage> &messages, int, Array);
 } // namespace solver
diff --git a/src/inputs/time.cpp b/src/inputs/time.cpp
index 2604ed4..23fdcf4 100644
--- a/src/inputs/time.cpp
+++ b/src/inputs/time.cpp
@@ -8,21 +8,22 @@ solver::TimeSettings make_time(solver::InputInfo ii,
 
   auto dt_max = std::get<solver::NumberArray>(ii[DT_MAX]);
   if (dt_max.size() != 1) {
-    require(DT_MAX, messages, 1);
+    NumberArray defaults = std::vector<double> {0};
+    require(DT_MAX, messages, 1, defaults);
   } else {
     time.dt_max = dt_max[0];
   }
 
   auto dt_min = std::get<solver::NumberArray>(ii[DT_MIN]);
   if (dt_min.size() != 1) {
-    require(DT_MIN, messages, 1);
+    require(DT_MIN, messages, 1, std::vector<double> {0});
   } else {
     time.dt_min = dt_min[0];
   }
 
   auto maxstep = std::get<solver::NumberArray>(ii[MAXSTEP]);
   if (maxstep.size() != 1) {
-    require(MAXSTEP, messages, 1);
+    require(MAXSTEP, messages, 1, std::vector<double> {0});
   } else {
     time.max_step = maxstep[0];
   }
-- 
GitLab