From 2cfaddb8ed00bc2acff345ef7d4dab0adfb42efe Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Tue, 21 Apr 2020 18:51:02 -0400 Subject: [PATCH 1/2] Consolidate --- src/geometry.cpp | 3 --- src/inputs.hpp | 17 +++++++++++++++++ src/mesh.cpp | 2 -- src/solver.hpp | 2 ++ src/time.cpp | 8 -------- tests/solver.t.cpp | 14 +------------- 6 files changed, 20 insertions(+), 26 deletions(-) create mode 100644 src/inputs.hpp diff --git a/src/geometry.cpp b/src/geometry.cpp index 222de13..10d723d 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -6,9 +6,6 @@ namespace solver { std::optional make_geometry(solver::InputInfo ii) { solver::GeometrySettings geo; - 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; diff --git a/src/inputs.hpp b/src/inputs.hpp new file mode 100644 index 0000000..a4dde5f --- /dev/null +++ b/src/inputs.hpp @@ -0,0 +1,17 @@ +#ifndef INPUTS_H_ +#define INPUTS_H_ + +static const std::string BLOCKING_FACTOR("amr.blocking_factor"); +static const std::string DT_MAX("mfix.dt_max"); +static const std::string DT_MIN("mfix.dt_min"); +static const std::string MAXSTEP("mfix.max_step"); +static const std::string N_CELL("amr.n_cell"); +static const std::string PERIODIC("geometry.is_periodic"); +static const std::string PROB_HI("geometry.prob_hi"); +static const std::string PROB_LO("geometry.prob_lo"); +static const std::string TSTOP("mfix.stop_time"); +static const std::string FIXED_DT("mfix.fixed_dt"); +static const std::string CFL("mfix.cfl"); +static const std::string TCOLL_RATIO("mfix.tcoll_ratio"); + +#endif diff --git a/src/mesh.cpp b/src/mesh.cpp index 89a758e..6b35b60 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -6,8 +6,6 @@ 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; diff --git a/src/solver.hpp b/src/solver.hpp index 2ac9e2e..3cb0ac7 100644 --- a/src/solver.hpp +++ b/src/solver.hpp @@ -8,6 +8,8 @@ #include #include +#include + namespace solver { using NumberArray = std::vector; diff --git a/src/time.cpp b/src/time.cpp index 3f98139..6fda63a 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -7,14 +7,6 @@ namespace solver { std::optional make_time(solver::InputInfo ii) { solver::TimeSettings time; - std::string DT_MAX("mfix.dt_max"); - std::string DT_MIN("mfix.dt_min"); - std::string MAXSTEP("mfix.max_step"); - std::string TSTOP("mfix.stop_time"); - std::string FIXED_DT("mfix.fixed_dt"); - std::string CFL("mfix.cfl"); - std::string TCOLL_RATIO("mfix.tcoll_ratio"); - auto dt_max = std::get(ii[DT_MAX]); if (dt_max.size() != 1) { std::cout << "dt_max is a scalar: " << dt_max.size() << std::endl; diff --git a/tests/solver.t.cpp b/tests/solver.t.cpp index 758d1f0..78ed063 100644 --- a/tests/solver.t.cpp +++ b/tests/solver.t.cpp @@ -2,21 +2,9 @@ #include "catch2/catch.hpp" +#include #include -std::string BLOCKING_FACTOR("amr.blocking_factor"); -std::string DT_MAX("mfix.dt_max"); -std::string DT_MIN("mfix.dt_min"); -std::string MAXSTEP("mfix.max_step"); -std::string N_CELL("amr.n_cell"); -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 FIXED_DT("mfix.fixed_dt"); -std::string CFL("mfix.cfl"); -std::string TCOLL_RATIO("mfix.tcoll_ratio"); - TEST_CASE("empty (invalid) map", "[]") { solver::InputInfo ii; auto maybe_sv = solver::make_solver(ii); -- GitLab From 9d80835b497c2cf833a49a86d032668459b6a6da Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Wed, 22 Apr 2020 11:41:58 -0400 Subject: [PATCH 2/2] Add remaining Mesh fields --- src/inputs.hpp | 21 +++++++-- src/mesh.cpp | 65 +++++++++++++++++++++----- src/solver.hpp | 4 ++ src/time.cpp | 1 - tests/solver.t.cpp | 114 +++++++++++++++++++++------------------------ 5 files changed, 127 insertions(+), 78 deletions(-) diff --git a/src/inputs.hpp b/src/inputs.hpp index a4dde5f..f69fc4c 100644 --- a/src/inputs.hpp +++ b/src/inputs.hpp @@ -1,17 +1,28 @@ #ifndef INPUTS_H_ #define INPUTS_H_ -static const std::string BLOCKING_FACTOR("amr.blocking_factor"); +// Geometry static const std::string DT_MAX("mfix.dt_max"); static const std::string DT_MIN("mfix.dt_min"); -static const std::string MAXSTEP("mfix.max_step"); -static const std::string N_CELL("amr.n_cell"); static const std::string PERIODIC("geometry.is_periodic"); static const std::string PROB_HI("geometry.prob_hi"); static const std::string PROB_LO("geometry.prob_lo"); -static const std::string TSTOP("mfix.stop_time"); -static const std::string FIXED_DT("mfix.fixed_dt"); + +// Mesh +static const std::string SMALL_VOLFRAC("eb2.small_volfrac"); +static const std::string BLOCKING_FACTOR("amr.blocking_factor"); +static const std::string FABARRAY_TILE_SZ("fabarray.mfiter_tile_size"); +static const std::string GRID_SIZE_X("amr.max_grid_size_x"); +static const std::string GRID_SIZE_Y("amr.max_grid_size_y"); +static const std::string GRID_SIZE_Z("amr.max_grid_size_z"); +static const std::string N_CELL("amr.n_cell"); +static const std::string PARTICLE_TILE_SZ("particles.tile_size"); + +// Time static const std::string CFL("mfix.cfl"); +static const std::string FIXED_DT("mfix.fixed_dt"); +static const std::string MAXSTEP("mfix.max_step"); static const std::string TCOLL_RATIO("mfix.tcoll_ratio"); +static const std::string TSTOP("mfix.stop_time"); #endif diff --git a/src/mesh.cpp b/src/mesh.cpp index 6b35b60..1432b7e 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -6,33 +6,76 @@ namespace solver { std::optional make_mesh(solver::InputInfo ii) { solver::MeshSettings mesh; - 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; + 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 [mx, my, mz] = mesh.axes; + mx.n_cell = n_cell[0]; + my.n_cell = n_cell[1]; + mz.n_cell = n_cell[2]; + + auto fabarray_size = std::get(ii[FABARRAY_TILE_SZ]); + if (fabarray_size.size() != 3) { + std::cout << FABARRAY_TILE_SZ << " needs 3 elements " << std::endl; + } else { + mx.fab_tile_size = fabarray_size[0]; + my.fab_tile_size = fabarray_size[1]; + mz.fab_tile_size = fabarray_size[2]; + } + + auto part_grid_size = std::get(ii[PARTICLE_TILE_SZ]); + if (part_grid_size.size() != 3) { + std::cout << PARTICLE_TILE_SZ << " needs 3 elements " << std::endl; + } else { + mx.particle_tile_size = part_grid_size[0]; + my.particle_tile_size = part_grid_size[1]; + mz.particle_tile_size = part_grid_size[2]; + } + + auto grid_size_x = std::get(ii[GRID_SIZE_X]); + if (grid_size_x.size() != 1) { + std::cout << GRID_SIZE_X << " is a scalar " << std::endl; + } else { + mx.grid_size = grid_size_x[0]; + } + auto grid_size_y = std::get(ii[GRID_SIZE_Y]); + if (grid_size_y.size() != 1) { + std::cout << GRID_SIZE_Y << " is a scalar " << std::endl; + } else { + my.grid_size = grid_size_y[0]; + } + auto grid_size_z = std::get(ii[GRID_SIZE_Z]); + if (grid_size_z.size() != 1) { + std::cout << GRID_SIZE_Z << " is a scalar " << std::endl; + } else { + mz.grid_size = grid_size_z[0]; + } auto bf = std::get(ii[BLOCKING_FACTOR]); if (bf.size() != 1) { - std::cout << "amr.blocking_factor is a scalar" << std::endl; + std::cout << BLOCKING_FACTOR << " is a scalar" << std::endl; } else { mesh.blocking_factor = bf[0]; } + auto volfrac = std::get(ii[SMALL_VOLFRAC]); + if (volfrac.size() != 1) { + std::cout << SMALL_VOLFRAC << " is a scalar" << std::endl; + } else { + mesh.small_volfrac = volfrac[0]; + } + + mesh.axes[0] = mx; + mesh.axes[1] = my; + mesh.axes[2] = mz; + return mesh; } } // namespace solver diff --git a/src/solver.hpp b/src/solver.hpp index 3cb0ac7..ebce3dc 100644 --- a/src/solver.hpp +++ b/src/solver.hpp @@ -28,11 +28,15 @@ struct GeometrySettings { }; struct MeshAxis { + unsigned int fab_tile_size; + unsigned int grid_size; unsigned int n_cell; + unsigned int particle_tile_size; }; struct MeshSettings { int blocking_factor; + double small_volfrac; std::array axes; }; struct TimeSettings { diff --git a/src/time.cpp b/src/time.cpp index 6fda63a..483a001 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -60,7 +60,6 @@ std::optional make_time(solver::InputInfo ii) { time.tcoll_ratio = tcoll_ratio[0]; } - return time; } } // namespace solver diff --git a/tests/solver.t.cpp b/tests/solver.t.cpp index 78ed063..168b846 100644 --- a/tests/solver.t.cpp +++ b/tests/solver.t.cpp @@ -13,81 +13,73 @@ TEST_CASE("empty (invalid) map", "[]") { TEST_CASE("from_origin", "[]") { solver::InputInfo ii; - ii[PROB_LO] = solver::NumberArray({0, 0, 0}); + + // Geometry + ii[PROB_LO] = std::vector({-4, -5, -6}); ii[PROB_HI] = solver::NumberArray({0.004, 0.001, 0.001}); ii[PERIODIC] = solver::NumberArray({0, 0, 0}); + + // Mesh ii[N_CELL] = solver::NumberArray({11, 22, 33}); + ii[BLOCKING_FACTOR] = solver::NumberArray({222}); + ii[SMALL_VOLFRAC] = solver::NumberArray({0.000999}); + ii[FABARRAY_TILE_SZ] = solver::NumberArray({1234, 4567, 7890}); + ii[PARTICLE_TILE_SZ] = solver::NumberArray({333, 444, 555}); + ii[GRID_SIZE_X] = solver::NumberArray({24}); + ii[GRID_SIZE_Y] = solver::NumberArray({25}); + ii[GRID_SIZE_Z] = solver::NumberArray({26}); + + // Time ii[DT_MAX] = solver::NumberArray({99.99}); ii[DT_MIN] = solver::NumberArray({0.001}); ii[MAXSTEP] = solver::NumberArray({39}); ii[TSTOP] = solver::NumberArray({3.14}); - ii[BLOCKING_FACTOR] = solver::NumberArray({222}); ii[FIXED_DT] = solver::NumberArray({1}); ii[CFL] = solver::NumberArray({0.77}); ii[TCOLL_RATIO] = solver::NumberArray({49.2}); - CHECK(ii.count(PROB_LO)); - CHECK(ii.count(PROB_HI)); - CHECK(ii.count(PERIODIC)); - CHECK(ii.count(N_CELL)); - auto maybe_sv = solver::make_solver(ii); - - 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); - CHECK(yy.low == 0); - CHECK(zz.high == 0.001); - CHECK(zz.low == 0); - CHECK_FALSE(xx.periodic); - CHECK_FALSE(yy.periodic); - CHECK_FALSE(zz.periodic); - 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); - CHECK(sv.time.fixed_dt); - CHECK(sv.time.cfl == 0.77); - CHECK(sv.time.tcoll_ratio == 49.2); -} - -TEST_CASE("negative_positive", "[]") { - solver::InputInfo ii; - ii[PROB_LO] = std::vector({-4, -5, -6}); - ii[PROB_HI] = std::vector({11.1, 22.2, 33.3}); - ii[PERIODIC] = solver::NumberArray({1, 0, 1}); - ii[N_CELL] = solver::NumberArray({11, 22, 33}); - ii[DT_MAX] = solver::NumberArray({99.99}); - ii[DT_MIN] = solver::NumberArray({0.001}); - ii[MAXSTEP] = solver::NumberArray({39}); - ii[TSTOP] = solver::NumberArray({3.14}); auto maybe_sv = solver::make_solver(ii); - REQUIRE(maybe_sv.has_value()); auto sv = maybe_sv.value(); - auto [xx, yy, zz] = sv.geometry.axes; - CHECK(xx.high == 11.1); - CHECK(xx.low == -4); - CHECK(xx.periodic); - CHECK(yy.high == 22.2); - CHECK(yy.low == -5); - CHECK(zz.high == 33.3); - CHECK(zz.low == -6); - CHECK(zz.periodic); - CHECK_FALSE(yy.periodic); - - auto [mx, my, mz] = sv.mesh.axes; - CHECK(mx.n_cell == 11); - CHECK(my.n_cell == 22); - CHECK(mz.n_cell == 33); + + SECTION(" Geometry fields ") { + auto [xx, yy, zz] = sv.geometry.axes; + CHECK(xx.high == 0.004); + CHECK(xx.low == -4); + CHECK(yy.high == 0.001); + CHECK(yy.low == -5); + CHECK(zz.high == 0.001); + CHECK(zz.low == -6); + CHECK_FALSE(xx.periodic); + CHECK_FALSE(yy.periodic); + CHECK_FALSE(zz.periodic); + } + SECTION(" Mesh fields ") { + CHECK(sv.mesh.blocking_factor == 222); + auto [mx, my, mz] = sv.mesh.axes; + CHECK(mx.n_cell == 11); + CHECK(my.n_cell == 22); + CHECK(mz.n_cell == 33); + CHECK(mx.grid_size == 24); + CHECK(my.grid_size == 25); + CHECK(mz.grid_size == 26); + CHECK(mx.particle_tile_size == 333); + CHECK(my.particle_tile_size == 444); + CHECK(mz.particle_tile_size == 555); + CHECK(mx.fab_tile_size == 1234); + CHECK(my.fab_tile_size == 4567); + CHECK(mz.fab_tile_size == 7890); + } + + SECTION(" Time fields ") { + 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.time.fixed_dt); + CHECK(sv.time.cfl == 0.77); + CHECK(sv.time.tcoll_ratio == 49.2); + } } TEST_CASE("serialize", "[]") { -- GitLab