Commit 96fbcc9a authored by Mark Meredith's avatar Mark Meredith
Browse files

Remove InputsFile

parent 504e8094
Loading
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
################################################################################

add_library(parser
  inputs_file.cpp
  parser.cpp
  solver.cpp
  )

src/inputs_file.cpp

deleted100644 → 0
+0 −73
Original line number Diff line number Diff line
#include <cassert>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

#include "inputs.hpp"

template <class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>; // not needed as of C++20

namespace inputs_file {

solver_settings::SolverSettings InputsFile::load() {

  std::ifstream infile(m_path);
  if (!infile.good()) {
    std::cout << "Error reading file: " << m_path << std::endl;
    return solver_settings::SolverSettings();
  }
  std::stringstream buffer;
  buffer << infile.rdbuf();
  infile.close();

  auto maybe_inputinfo = parser::parse_inputs(buffer.str());
  if (!maybe_inputinfo.has_value()) {
    std::cout << "Error parsing file: " << m_path << std::endl;
    return solver_settings::SolverSettings();
  }

  auto inputinfo = maybe_inputinfo.value();

  // for (auto it = inputinfo.begin(); it != inputinfo.end(); ++it) {
  //   std::visit(
  //       overloaded{
  //           [it](parser::NumberArray aa) { std::cout <<  it->first << " nums
  //           " << aa.size() << std::endl;
  //           },
  //           [it](parser::StringArray aa) { std::cout <<  it->first << "
  //           strings " << aa.size() << std::endl;
  //           },
  //       },
  //       it->second);
  // }

  auto maybe_solversettings = solver_settings::make_solver(inputinfo);
  if (!maybe_solversettings.has_value()) {
    std::cout << "Invalid solver settings file: " << m_path << std::endl;
    return solver_settings::SolverSettings();
  }
  return maybe_solversettings.value();
}

void InputsFile::save(solver_settings::SolverSettings settings) {

  std::ofstream out(m_path);

  auto [xx, yy, zz] = settings.geometry.axes;
  out << std::endl;
  out << "  geometry.is_periodic = " << xx.periodic << " " << yy.periodic << " "
      << zz.periodic << std::endl;
  ;
  out << "  geometry.prob_lo     = " << xx.low << " " << yy.low << " " << zz.low
      << std::endl;
  ;
  out << "  geometry.prob_hi     = " << xx.high << " " << yy.high << " "
      << zz.high;
  ;
  out.close();
}

} // namespace inputs_file
+2 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
#include <iostream>
#include <sstream>

#include "inputs.hpp"
#include "solver.hpp"

std::string read_file(std::string inputs_file) {
  std::ifstream in_stream;
@@ -20,7 +20,7 @@ int main(int argc, char *argv[]) {
  }
  std::string fname(argv[1]);
  auto inputs_str = read_file(fname);
  auto maybe_success = parser::parse_inputs(inputs_str);
  auto maybe_success = solver::parse_inputs(inputs_str);
  if (maybe_success.has_value()) {
    return 0;
  }
+0 −1
Original line number Diff line number Diff line
lib_parser = static_library('mfix-parser',
                            'inputs_file.cpp',
                            'parser.cpp',
                            'solver.cpp',
                            include_directories: tao_inc,
+4 −4
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
#include <tao/pegtl.hpp>

// includes
#include "inputs.hpp"
#include "solver.hpp"

using namespace tao::pegtl;

@@ -17,7 +17,7 @@ struct parser_state {
  std::variant<std::vector<double>, std::vector<std::string>> current_value;
  std::vector<double> current_num_vec;
  std::vector<std::string> current_str_vec;
  parser::InputInfo info;
  solver::InputInfo info;
};

} // namespace
@@ -144,9 +144,9 @@ std::optional<parser_state> do_parse(std::string str) {

} // namespace

namespace parser {
namespace solver {

std::optional<parser::InputInfo> parse_inputs(std::string str) {
std::optional<solver::InputInfo> parse_inputs(std::string str) {
  auto maybe_state = do_parse(str);
  if (!maybe_state.has_value()) {
    return std::nullopt;
Loading