Commit aa016ec5 authored by Mark Meredith's avatar Mark Meredith
Browse files

Add amr.n_cell

parent 438538a9
Loading
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ std::optional<solver::SolverSettings> do_make_solver(solver::InputInfo ii) {
  std::string PROB_LO("geometry.prob_lo");
  std::string PROB_HI("geometry.prob_hi");
  std::string PERIODIC("geometry.is_periodic");
  std::string N_CELL("amr.n_cell");
  if (!ii.count(PROB_LO)) {
    require(PROB_LO);
    return std::nullopt;
@@ -27,9 +28,14 @@ std::optional<solver::SolverSettings> do_make_solver(solver::InputInfo ii) {
    require(PERIODIC);
    return std::nullopt;
  }
  if (!ii.count(N_CELL)) {
    require(N_CELL);
    return std::nullopt;
  }
  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]);
  auto n_cell = std::get<solver::NumberArray>(ii[N_CELL]);
  if (lows.size() != 3) {
    std::cout << "prob_lo needs 3 elements " << std::endl;
    return std::nullopt;
@@ -42,16 +48,23 @@ std::optional<solver::SolverSettings> do_make_solver(solver::InputInfo ii) {
    std::cout << "periodic needs 3 elements " << std::endl;
    return std::nullopt;
  }
  if (n_cell.size() != 3) {
    std::cout << "n_cell needs 3 elements " << std::endl;
    return std::nullopt;
  }

  std::get<0>(ss.geometry.axes).high = highs[0];
  std::get<0>(ss.geometry.axes).low = lows[0];
  std::get<0>(ss.geometry.axes).periodic = is_periodic[0];
  std::get<0>(ss.geometry.axes).n_cell = n_cell[0];
  std::get<1>(ss.geometry.axes).high = highs[1];
  std::get<1>(ss.geometry.axes).low = lows[1];
  std::get<1>(ss.geometry.axes).periodic = is_periodic[1];
  std::get<1>(ss.geometry.axes).n_cell = n_cell[1];
  std::get<2>(ss.geometry.axes).high = highs[2];
  std::get<2>(ss.geometry.axes).low = lows[2];
  std::get<2>(ss.geometry.axes).periodic = is_periodic[2];
  std::get<2>(ss.geometry.axes).n_cell = n_cell[2];
  return ss;
}
} // namespace
@@ -77,7 +90,9 @@ std::string serialize(solver::SolverSettings settings) {
  buffer << "  geometry.prob_lo     = " << xx.low << " " << yy.low << " "
         << zz.low << std::endl;
  buffer << "  geometry.prob_hi     = " << xx.high << " " << yy.high << " "
         << zz.high;
         << zz.high << std::endl;
  buffer << "  geometry.n_cell      = " << xx.n_cell << " " << yy.n_cell << " "
         << zz.n_cell;
  return buffer.str();
}

+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ struct GeometryAxis {
  double low;
  double high;
  bool periodic;
  unsigned int n_cell;
};
struct GeometrySettings {
  std::array<GeometryAxis, 3> axes;
+16 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
std::string PROB_LO("geometry.prob_lo");
std::string PROB_HI("geometry.prob_hi");
std::string PERIODIC("geometry.is_periodic");
std::string N_CELL("amr.n_cell");

TEST_CASE("empty (invalid) map", "[]") {
  solver::InputInfo ii;
@@ -19,9 +20,11 @@ TEST_CASE("from_origin", "[]") {
  ii[PROB_LO] = solver::NumberArray({0, 0, 0});
  ii[PROB_HI] = solver::NumberArray({0.004, 0.001, 0.001});
  ii[PERIODIC] = solver::NumberArray({0, 0, 0});
  ii[N_CELL] = solver::NumberArray({11, 22, 33});
  CHECK(ii.count(PROB_LO));
  CHECK(ii.count(PROB_HI));
  CHECK(ii.count(PERIODIC));
  CHECK(ii.count(N_CELL));
  auto maybe_sv = solver::make_solver(ii);

  REQUIRE(maybe_sv.has_value());
@@ -36,6 +39,9 @@ TEST_CASE("from_origin", "[]") {
  CHECK_FALSE(xx.periodic);
  CHECK_FALSE(yy.periodic);
  CHECK_FALSE(zz.periodic);
  CHECK(xx.n_cell == 11);
  CHECK(yy.n_cell == 22);
  CHECK(zz.n_cell == 33);
}

TEST_CASE("negative_positive", "[]") {
@@ -43,6 +49,7 @@ TEST_CASE("negative_positive", "[]") {
  ii[PROB_LO] = std::vector<double>({-4, -5, -6});
  ii[PROB_HI] = std::vector<double>({11.1, 22.2, 33.3});
  ii[PERIODIC] = solver::NumberArray({1, 0, 1});
  ii[N_CELL] = solver::NumberArray({11, 22, 33});

  auto maybe_sv = solver::make_solver(ii);

@@ -58,6 +65,9 @@ TEST_CASE("negative_positive", "[]") {
  CHECK(zz.low == -6);
  CHECK(zz.periodic);
  CHECK_FALSE(yy.periodic);
  CHECK(xx.n_cell == 11);
  CHECK(yy.n_cell == 22);
  CHECK(zz.n_cell == 33);
}

TEST_CASE("serialize", "[]") {
@@ -75,10 +85,15 @@ TEST_CASE("serialize", "[]") {
  std::get<1>(ss.geometry.axes).high = 0.001;
  std::get<2>(ss.geometry.axes).high = 0.001;

  std::get<0>(ss.geometry.axes).n_cell = 11;
  std::get<1>(ss.geometry.axes).n_cell = 22;
  std::get<2>(ss.geometry.axes).n_cell = 33;

  auto inputs_str = serialize(ss);

  CHECK(inputs_str == R"(
  geometry.is_periodic = 0 1 0
  geometry.prob_lo     = 0 0 0
  geometry.prob_hi     = 0.004 0.001 0.001)");
  geometry.prob_hi     = 0.004 0.001 0.001
  geometry.n_cell      = 11 22 33)");
}