Loading .gitlab-ci.yml +2 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ test:all: - cmake --build build --target unit_tests - ./build/src/tests/unit_tests - cmake --build build --target mfix-parser - find -name inputs - find -name inputs |xargs -l ./build/mfix-parser # - find -name inputs # - find -name inputs |xargs -l ./build/mfix-parser tags: - mfix-exa src/CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -3,7 +3,9 @@ ################################################################################ add_library(parser inputs_file.cpp parser.cpp solver.cpp ) target_include_directories(parser PRIVATE Loading src/double.hppdeleted 100644 → 0 +0 −44 Original line number Diff line number Diff line // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_DOUBLE_HPP #define TAO_PEGTL_SRC_EXAMPLES_PEGTL_DOUBLE_HPP #include <tao/pegtl.hpp> namespace double_ { // A grammar for doubles suitable for std::stod without locale support. // See also: http://en.cppreference.com/w/cpp/string/basic_string/stof using namespace TAO_PEGTL_NAMESPACE; // clang-format off struct plus_minus : opt< one< '+', '-' > > {}; struct dot : one< '.' > {}; struct inf : seq< istring< 'i', 'n', 'f' >, opt< istring< 'i', 'n', 'i', 't', 'y' > > > {}; struct nan : seq< istring< 'n', 'a', 'n' >, opt< one< '(' >, plus< alnum >, one< ')' > > > {}; template< typename D > struct number : if_then_else< dot, plus< D >, seq< plus< D >, opt< dot, star< D > > > > {}; struct e : one< 'e', 'E' > {}; struct p : one< 'p', 'P' > {}; struct exponent : seq< plus_minus, plus< digit > > {}; struct decimal : seq< number< digit >, opt< e, exponent > > {}; struct hexadecimal : seq< one< '0' >, one< 'x', 'X' >, number< xdigit >, opt< p, exponent > > {}; struct grammar : seq< plus_minus, sor< hexadecimal, decimal, inf, nan > > {}; // clang-format on } // namespace double_ #endif src/inputs.hpp +33 −3 Original line number Diff line number Diff line Loading @@ -10,12 +10,42 @@ namespace parser { using InputArray = std::vector<double>; using InputValue = std::variant<std::string, InputArray>; using InputInfo = std::map<std::string, InputValue>; using NumberArray = std::vector<double>; using StringArray = std::vector<std::string>; using InputInfo = std::map<std::string, std::variant<NumberArray, StringArray>>; std::optional<InputInfo> parse_inputs(std::string); } // namespace parser namespace solver_settings { struct GeometryAxis { double low; double high; bool periodic; }; struct GeometrySettings { std::tuple<GeometryAxis, GeometryAxis, GeometryAxis> axes; }; struct SolverSettings { GeometrySettings geometry; }; std::optional<SolverSettings> make_solver(parser::InputInfo); } // namespace solver_settings namespace inputs_file { class InputsFile { public: InputsFile(std::string inputs_path) : m_path(inputs_path) {} solver_settings::SolverSettings load(); void save(solver_settings::SolverSettings); protected: std::string m_path; }; } // namespace inputs_file #endif src/inputs_file.cpp 0 → 100644 +65 −0 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); std::stringstream buffer; buffer << infile.rdbuf(); infile.close(); auto maybe_inputinfo = parser::parse_inputs(buffer.str()); assert(maybe_inputinfo.has_value()); auto inputinfo = maybe_inputinfo.value(); // for (auto it = inputinfo.begin(); it != inputinfo.end(); ++it) { // std::visit( // overloaded{ // [](std::string ss) { std::cout << ss << std::endl; }, // [](parser::NumberArray aa) { std::cout << aa.size() << std::endl; // }, // [](parser::StringArray aa) { std::cout << aa.size() << std::endl; // }, // }, // it->second); // } auto maybe_solversettings = solver_settings::make_solver(inputinfo); assert(maybe_solversettings.has_value()); return maybe_solversettings.value(); solver_settings::SolverSettings ss; return ss; }; 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 Loading
.gitlab-ci.yml +2 −2 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ test:all: - cmake --build build --target unit_tests - ./build/src/tests/unit_tests - cmake --build build --target mfix-parser - find -name inputs - find -name inputs |xargs -l ./build/mfix-parser # - find -name inputs # - find -name inputs |xargs -l ./build/mfix-parser tags: - mfix-exa
src/CMakeLists.txt +2 −0 Original line number Diff line number Diff line Loading @@ -3,7 +3,9 @@ ################################################################################ add_library(parser inputs_file.cpp parser.cpp solver.cpp ) target_include_directories(parser PRIVATE Loading
src/double.hppdeleted 100644 → 0 +0 −44 Original line number Diff line number Diff line // Copyright (c) 2014-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_SRC_EXAMPLES_PEGTL_DOUBLE_HPP #define TAO_PEGTL_SRC_EXAMPLES_PEGTL_DOUBLE_HPP #include <tao/pegtl.hpp> namespace double_ { // A grammar for doubles suitable for std::stod without locale support. // See also: http://en.cppreference.com/w/cpp/string/basic_string/stof using namespace TAO_PEGTL_NAMESPACE; // clang-format off struct plus_minus : opt< one< '+', '-' > > {}; struct dot : one< '.' > {}; struct inf : seq< istring< 'i', 'n', 'f' >, opt< istring< 'i', 'n', 'i', 't', 'y' > > > {}; struct nan : seq< istring< 'n', 'a', 'n' >, opt< one< '(' >, plus< alnum >, one< ')' > > > {}; template< typename D > struct number : if_then_else< dot, plus< D >, seq< plus< D >, opt< dot, star< D > > > > {}; struct e : one< 'e', 'E' > {}; struct p : one< 'p', 'P' > {}; struct exponent : seq< plus_minus, plus< digit > > {}; struct decimal : seq< number< digit >, opt< e, exponent > > {}; struct hexadecimal : seq< one< '0' >, one< 'x', 'X' >, number< xdigit >, opt< p, exponent > > {}; struct grammar : seq< plus_minus, sor< hexadecimal, decimal, inf, nan > > {}; // clang-format on } // namespace double_ #endif
src/inputs.hpp +33 −3 Original line number Diff line number Diff line Loading @@ -10,12 +10,42 @@ namespace parser { using InputArray = std::vector<double>; using InputValue = std::variant<std::string, InputArray>; using InputInfo = std::map<std::string, InputValue>; using NumberArray = std::vector<double>; using StringArray = std::vector<std::string>; using InputInfo = std::map<std::string, std::variant<NumberArray, StringArray>>; std::optional<InputInfo> parse_inputs(std::string); } // namespace parser namespace solver_settings { struct GeometryAxis { double low; double high; bool periodic; }; struct GeometrySettings { std::tuple<GeometryAxis, GeometryAxis, GeometryAxis> axes; }; struct SolverSettings { GeometrySettings geometry; }; std::optional<SolverSettings> make_solver(parser::InputInfo); } // namespace solver_settings namespace inputs_file { class InputsFile { public: InputsFile(std::string inputs_path) : m_path(inputs_path) {} solver_settings::SolverSettings load(); void save(solver_settings::SolverSettings); protected: std::string m_path; }; } // namespace inputs_file #endif
src/inputs_file.cpp 0 → 100644 +65 −0 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); std::stringstream buffer; buffer << infile.rdbuf(); infile.close(); auto maybe_inputinfo = parser::parse_inputs(buffer.str()); assert(maybe_inputinfo.has_value()); auto inputinfo = maybe_inputinfo.value(); // for (auto it = inputinfo.begin(); it != inputinfo.end(); ++it) { // std::visit( // overloaded{ // [](std::string ss) { std::cout << ss << std::endl; }, // [](parser::NumberArray aa) { std::cout << aa.size() << std::endl; // }, // [](parser::StringArray aa) { std::cout << aa.size() << std::endl; // }, // }, // it->second); // } auto maybe_solversettings = solver_settings::make_solver(inputinfo); assert(maybe_solversettings.has_value()); return maybe_solversettings.value(); solver_settings::SolverSettings ss; return ss; }; 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