diff --git a/README.md b/README.md index fccc9c2a89ea5fa5b9d873e6473e28fe3064c1fb..81046b767abc8c0de65832b7e4dc0cc07299c668 100644 --- a/README.md +++ b/README.md @@ -9,18 +9,14 @@ This has the MFIX-Exa repo as a submodule in order to test against existing ``in ## Build -> python3 pip install cmake # if CMake not installed -> cmake -S. -Bbuild -> cmake --build build -> cd build -> ctest +> python3 pip install meson ninja +> meson build +> ninja -C build ## Run Tests -> cmake --build build --target unit_tests -> ./build/src/tests/unit_tests +> meson test -C build ## Run on inputs file -> cmake --build build --target mfix-parser -> ./build/mfix-parser subprojects/mfix/benchmarks/01-HCS/Size0001/inputs && echo "Parsing succeeded." +> ./build/src/mfix-parser subprojects/mfix/benchmarks/01-HCS/Size0001/inputs && echo "Parsing succeeded." diff --git a/src/inputs_file.cpp b/src/inputs_file.cpp index 4117db3766058ed2d399feff2a063deaa5777fd6..95f50d5ee5e284cce387078c2521ba5ac2cae4c3 100644 --- a/src/inputs_file.cpp +++ b/src/inputs_file.cpp @@ -27,10 +27,9 @@ solver_settings::SolverSettings InputsFile::load() { // 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; + // [it](parser::NumberArray aa) { std::cout << it->first << " nums " << aa.size() << std::endl; // }, - // [](parser::StringArray aa) { std::cout << aa.size() << std::endl; + // [it](parser::StringArray aa) { std::cout << it->first << " strings " << aa.size() << std::endl; // }, // }, // it->second); diff --git a/src/solver.cpp b/src/solver.cpp index a95db811ee0d998268ac3bfb3c1455f38ee3ce51..3b11fcb9857b12ed335cbdd5a5ffed464aa17928 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -5,21 +5,44 @@ namespace { -void require(parser::InputInfo ii, std::string key) { - if (!ii.count(key)) { +void require(std::string key) { std::cout << "missing required key: " << key << std::endl; - } } std::optional do_make_solver(parser::InputInfo ii) { solver_settings::SolverSettings ss; - require(ii, "geometry.prob_lo"); - require(ii, "geometry.prob_hi"); - require(ii, "geometry.is_periodic"); - auto lows = std::get(ii["geometry.prob_lo"]); - auto highs = std::get(ii["geometry.prob_hi"]); - auto is_periodic = std::get(ii["geometry.is_periodic"]); + std::string PROB_LO("geometry.prob_lo"); + std::string PROB_HI("geometry.prob_hi"); + std::string PERIODIC("geometry.is_periodic"); + if (!ii.count(PROB_LO)) { + require(PROB_LO); + return std::nullopt; + } + if (!ii.count(PROB_HI)) { + require(PROB_HI); + return std::nullopt; + } + if (!ii.count(PERIODIC)) { + require(PERIODIC); + return std::nullopt; + } + auto lows = std::get(ii[PROB_LO]); + auto highs = std::get(ii[PROB_HI]); + auto is_periodic = std::get(ii[PERIODIC]); + if (lows.size() != 3) { + std::cout << "prob_lo needs 3 elements " << std::endl; + return std::nullopt; + } + if (highs.size() != 3) { + std::cout << "prob_hi needs 3 elements " << std::endl; + return std::nullopt; + } + if (is_periodic.size() != 3) { + std::cout << "periodic 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]; diff --git a/tests/meson.build b/tests/meson.build index f0b783875204036a25a326edfc9ee1980d8b539b..71787c4c824433dd1f3e51911f9de489d5723072 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,10 +1,17 @@ unit_exe = executable('unit_tests', - 'inputs.t.cpp', 'parser.t.cpp', 'solver.t.cpp', 'main.cpp', include_directories: [parser_inc, catch2_inc], link_with: lib_parser ) - test('unit_test', unit_exe) + + +functional_test = executable('functional_tests', + 'inputs.t.cpp', + 'main.cpp', + include_directories: [parser_inc, catch2_inc], + link_with: lib_parser + ) +test('functional_test', functional_test) diff --git a/tests/solver.t.cpp b/tests/solver.t.cpp index 104110b20ca2bca73d9a84539b2a02aecf662fa4..53421740dcd1dae77373a1a18ca1895041034837 100644 --- a/tests/solver.t.cpp +++ b/tests/solver.t.cpp @@ -4,11 +4,24 @@ #include +std::string PROB_LO("geometry.prob_lo"); +std::string PROB_HI("geometry.prob_hi"); +std::string PERIODIC("geometry.is_periodic"); + +TEST_CASE("empty (invalid) map", "[]") { + parser::InputInfo ii; + auto maybe_sv = solver_settings::make_solver(ii); + CHECK_FALSE(maybe_sv.has_value()); +} + TEST_CASE("from_origin", "[]") { parser::InputInfo ii; - ii["geometry.prob_lo"] = parser::NumberArray({0, 0, 0}); - ii["geometry.prob_hi"] = parser::NumberArray({0.004, 0.001, 0.001}); - ii["geometry.is_periodic"] = parser::NumberArray({0, 0, 0}); + ii[PROB_LO] = parser::NumberArray({0, 0, 0}); + ii[PROB_HI] = parser::NumberArray({0.004, 0.001, 0.001}); + ii[PERIODIC] = parser::NumberArray({0, 0, 0}); + CHECK(ii.count(PROB_LO)); + CHECK(ii.count(PROB_HI)); + CHECK(ii.count(PERIODIC)); auto maybe_sv = solver_settings::make_solver(ii); REQUIRE(maybe_sv.has_value()); @@ -27,9 +40,9 @@ TEST_CASE("from_origin", "[]") { TEST_CASE("negative_positive", "[]") { parser::InputInfo ii; - ii["geometry.prob_lo"] = std::vector({-4, -5, -6}); - ii["geometry.prob_hi"] = std::vector({11.1, 22.2, 33.3}); - ii["geometry.is_periodic"] = parser::NumberArray({1, 0, 1}); + ii[PROB_LO] = std::vector({-4, -5, -6}); + ii[PROB_HI] = std::vector({11.1, 22.2, 33.3}); + ii[PERIODIC] = parser::NumberArray({1, 0, 1}); auto maybe_sv = solver_settings::make_solver(ii);