From ae3454e1cfa4ef2a6340cbd893291e75b694cb2f Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Tue, 21 Apr 2020 16:51:36 -0400 Subject: [PATCH] Add amr.blocking_factor --- src/geometry.cpp | 13 ------------- src/mesh.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/meson.build | 1 + src/solver.cpp | 12 ++++++++++-- src/solver.hpp | 12 +++++++++++- tests/solver.t.cpp | 24 +++++++++++++++--------- 6 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 src/mesh.cpp diff --git a/src/geometry.cpp b/src/geometry.cpp index cdf2bd2..222de13 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -9,7 +9,6 @@ std::optional make_geometry(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; @@ -22,14 +21,9 @@ std::optional make_geometry(solver::InputInfo ii) { require(PERIODIC); return std::nullopt; } - if (!ii.count(N_CELL)) { - require(N_CELL); - return std::nullopt; - } auto lows = std::get(ii[PROB_LO]); auto highs = std::get(ii[PROB_HI]); auto is_periodic = std::get(ii[PERIODIC]); - auto n_cell = std::get(ii[N_CELL]); if (lows.size() != 3) { std::cout << "prob_lo needs 3 elements " << std::endl; return std::nullopt; @@ -42,23 +36,16 @@ std::optional make_geometry(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>(geo.axes).high = highs[0]; std::get<0>(geo.axes).low = lows[0]; std::get<0>(geo.axes).periodic = is_periodic[0]; - std::get<0>(geo.axes).n_cell = n_cell[0]; std::get<1>(geo.axes).high = highs[1]; std::get<1>(geo.axes).low = lows[1]; std::get<1>(geo.axes).periodic = is_periodic[1]; - std::get<1>(geo.axes).n_cell = n_cell[1]; std::get<2>(geo.axes).high = highs[2]; std::get<2>(geo.axes).low = lows[2]; std::get<2>(geo.axes).periodic = is_periodic[2]; - std::get<2>(geo.axes).n_cell = n_cell[2]; return geo; } } // namespace solver diff --git a/src/mesh.cpp b/src/mesh.cpp new file mode 100644 index 0000000..89a758e --- /dev/null +++ b/src/mesh.cpp @@ -0,0 +1,40 @@ +#include + +#include "solver.hpp" + +namespace solver { + +std::optional make_mesh(solver::InputInfo ii) { + solver::MeshSettings mesh; + std::string N_CELL("amr.n_cell"); + std::string BLOCKING_FACTOR("amr.blocking_factor"); + if (!ii.count(N_CELL)) { + require(N_CELL); + return std::nullopt; + } + + if (!ii.count(N_CELL)) { + require(N_CELL); + return std::nullopt; + } + auto n_cell = std::get(ii[N_CELL]); + + if (n_cell.size() != 3) { + std::cout << "n_cell needs 3 elements " << std::endl; + return std::nullopt; + } + + std::get<0>(mesh.axes).n_cell = n_cell[0]; + std::get<1>(mesh.axes).n_cell = n_cell[1]; + std::get<2>(mesh.axes).n_cell = n_cell[2]; + + auto bf = std::get(ii[BLOCKING_FACTOR]); + if (bf.size() != 1) { + std::cout << "amr.blocking_factor is a scalar" << std::endl; + } else { + mesh.blocking_factor = bf[0]; + } + + return mesh; +} +} // namespace solver diff --git a/src/meson.build b/src/meson.build index fc2c2cd..abe80e4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,5 +1,6 @@ lib_parser = static_library('mfix-parser', 'geometry.cpp', + 'mesh.cpp', 'parser.cpp', 'solver.cpp', 'time.cpp', diff --git a/src/solver.cpp b/src/solver.cpp index 9a441d4..02a506d 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -17,6 +17,11 @@ std::optional do_make_solver(solver::InputInfo ii) { std::cout << "Problem making geometry" << std::endl; return std::nullopt; } + auto new_mesh = make_mesh(ii); + if (!new_mesh.has_value()) { + std::cout << "Problem making mesh" << std::endl; + return std::nullopt; + } auto new_time = make_time(ii); if (!new_time.has_value()) { std::cout << "Problem making time" << std::endl; @@ -24,6 +29,7 @@ std::optional do_make_solver(solver::InputInfo ii) { } ss.geometry = new_geo.value(); ss.time = new_time.value(); + ss.mesh = new_mesh.value(); return ss; } @@ -47,8 +53,10 @@ std::string serialize(solver::SolverSettings settings) { << zz.low << std::endl; buffer << " geometry.prob_hi = " << xx.high << " " << yy.high << " " << zz.high << std::endl; - buffer << " amr.n_cell = " << xx.n_cell << " " << yy.n_cell << " " - << zz.n_cell; + + auto [mx, my, mz] = settings.mesh.axes; + buffer << " amr.n_cell = " << mx.n_cell << " " << my.n_cell << " " + << mz.n_cell; return buffer.str(); } diff --git a/src/solver.hpp b/src/solver.hpp index f70a1f8..63549b2 100644 --- a/src/solver.hpp +++ b/src/solver.hpp @@ -20,11 +20,19 @@ struct GeometryAxis { double low; double high; bool periodic; - unsigned int n_cell; }; struct GeometrySettings { std::array axes; }; + +struct MeshAxis { + unsigned int n_cell; +}; + +struct MeshSettings { + int blocking_factor; + std::array axes; +}; struct TimeSettings { unsigned int max_step; double dt_max; @@ -33,11 +41,13 @@ struct TimeSettings { }; struct SolverSettings { GeometrySettings geometry; + MeshSettings mesh; TimeSettings time; }; std::optional make_solver(solver::InputInfo); std::optional make_geometry(solver::InputInfo); +std::optional make_mesh(solver::InputInfo); std::optional make_time(solver::InputInfo); std::string serialize(solver::SolverSettings); diff --git a/tests/solver.t.cpp b/tests/solver.t.cpp index 839780f..40559ba 100644 --- a/tests/solver.t.cpp +++ b/tests/solver.t.cpp @@ -12,6 +12,7 @@ std::string PERIODIC("geometry.is_periodic"); std::string PROB_HI("geometry.prob_hi"); std::string PROB_LO("geometry.prob_lo"); std::string TSTOP("mfix.stop_time"); +std::string BLOCKING_FACTOR("amr.blocking_factor"); TEST_CASE("empty (invalid) map", "[]") { solver::InputInfo ii; @@ -29,6 +30,7 @@ TEST_CASE("from_origin", "[]") { ii[DT_MIN] = solver::NumberArray({0.001}); ii[MAXSTEP] = solver::NumberArray({39}); ii[TSTOP] = solver::NumberArray({3.14}); + ii[BLOCKING_FACTOR] = solver::NumberArray({222}); CHECK(ii.count(PROB_LO)); CHECK(ii.count(PROB_HI)); CHECK(ii.count(PERIODIC)); @@ -38,6 +40,7 @@ TEST_CASE("from_origin", "[]") { REQUIRE(maybe_sv.has_value()); auto sv = maybe_sv.value(); auto [xx, yy, zz] = sv.geometry.axes; + auto [mx, my, mz] = sv.mesh.axes; CHECK(xx.high == 0.004); CHECK(xx.low == 0); CHECK(yy.high == 0.001); @@ -47,14 +50,15 @@ 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); + CHECK(mx.n_cell == 11); + CHECK(my.n_cell == 22); + CHECK(mz.n_cell == 33); CHECK(sv.time.dt_max == 99.99); CHECK(sv.time.dt_min == 0.001); CHECK(sv.time.max_step == 39); CHECK(sv.time.tstop == 3.14); + CHECK(sv.mesh.blocking_factor == 222); } TEST_CASE("negative_positive", "[]") { @@ -82,9 +86,11 @@ 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); + + auto [mx, my, mz] = sv.mesh.axes; + CHECK(mx.n_cell == 11); + CHECK(my.n_cell == 22); + CHECK(mz.n_cell == 33); } TEST_CASE("serialize", "[]") { @@ -102,9 +108,9 @@ 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; + std::get<0>(ss.mesh.axes).n_cell = 11; + std::get<1>(ss.mesh.axes).n_cell = 22; + std::get<2>(ss.mesh.axes).n_cell = 33; auto inputs_str = serialize(ss); -- GitLab