Commit 480173eb authored by Mark Meredith's avatar Mark Meredith
Browse files

Time is optional

parent ab325fe2
Loading
Loading
Loading
Loading
Loading
+17 −27
Original line number Diff line number Diff line
@@ -12,47 +12,37 @@ std::optional<solver::TimeSettings> make_time(solver::InputInfo ii) {
  std::string MAXSTEP("mfix.max_step");
  std::string TSTOP("mfix.stop_time");

  if (!ii.count(DT_MAX)) {
    require(DT_MAX);
    return std::nullopt;
  }
  if (!ii.count(DT_MIN)) {
    require(DT_MIN);
    return std::nullopt;
  }
  if (!ii.count(MAXSTEP)) {
    require(MAXSTEP);
    return std::nullopt;
  }
  if (!ii.count(TSTOP)) {
    require(TSTOP);
    return std::nullopt;
  }
  auto dt_max = std::get<solver::NumberArray>(ii[DT_MAX]);
  auto dt_min = std::get<solver::NumberArray>(ii[DT_MIN]);
  auto maxstep = std::get<solver::NumberArray>(ii[MAXSTEP]);
  auto tstop = std::get<solver::NumberArray>(ii[TSTOP]);
  if (dt_max.size() != 1) {
    std::cout << "dt_max is a scalar: " << dt_max.size() << std::endl;
    return std::nullopt;
  } else {
    time.dt_max = dt_max[0];
  }

  auto dt_min = std::get<solver::NumberArray>(ii[DT_MIN]);
  if (dt_min.size() != 1) {
    std::cout << "dt_min is a scalar" << std::endl;
    return std::nullopt;
  } else {
    time.dt_min = dt_min[0];
  }

  auto maxstep = std::get<solver::NumberArray>(ii[MAXSTEP]);
  if (maxstep.size() != 1) {
    std::cout << "max_step is a scalar" << std::endl;
  } else {
    time.max_step = maxstep[0];
  }

  if (!ii.count(TSTOP)) {
    require(TSTOP);
    return std::nullopt;
  }
  auto tstop = std::get<solver::NumberArray>(ii[TSTOP]);
  if (tstop.size() != 1) {
    std::cout << "tstop is a scalar" << std::endl;
    return std::nullopt;
  }

  time.dt_max = dt_max[0];
  time.dt_min = dt_min[0];
  time.max_step = maxstep[0];
  } else {
    time.tstop = tstop[0];
  }

  return time;
}