From b04176c5f0795735d75b88ca33e3ec1a65098aef Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Wed, 29 Apr 2020 15:28:12 -0400 Subject: [PATCH 1/6] Add csg::Tree to solver::GeometrySettings --- meson.build | 4 ++++ src/inputs/meson.build | 5 ++++- src/inputs/solver.hpp | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 7c6e889..da9d68d 100644 --- a/meson.build +++ b/meson.build @@ -8,6 +8,10 @@ parser_inc = include_directories( 'src/csg', 'src/csg/impl', 'src/inputs') +csg_inc = include_directories( + 'src/csg', + 'src/csg/impl', +) subdir('src/csg') subdir('src/inputs') diff --git a/src/inputs/meson.build b/src/inputs/meson.build index a435c0a..33e8467 100644 --- a/src/inputs/meson.build +++ b/src/inputs/meson.build @@ -5,7 +5,10 @@ lib_inputs_parser = static_library( 'parser.cpp', 'solver.cpp', 'time.cpp', - include_directories: tao_inc, + include_directories: [ + csg_inc, + tao_inc, + ], install : true) subdir('tests') diff --git a/src/inputs/solver.hpp b/src/inputs/solver.hpp index 868f515..051084e 100644 --- a/src/inputs/solver.hpp +++ b/src/inputs/solver.hpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace solver { @@ -26,6 +27,7 @@ struct GeometryAxis { }; struct GeometrySettings { std::array axes; + csg::Tree tree; }; struct MeshAxis { -- GitLab From 2ba3ce98682acc02b6cb315521011c60efb085ef Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Wed, 29 Apr 2020 17:12:49 -0400 Subject: [PATCH 2/6] Add csg::Tree to GeometrySettings --- src/csg/csg.hpp | 1 + src/csg/impl/csg.cpp | 9 ++++++--- src/inputs/geometry.cpp | 18 ++++++++++++++++++ src/inputs/inputs.hpp | 1 + src/inputs/meson.build | 1 + 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/csg/csg.hpp b/src/csg/csg.hpp index 7bce194..e29b857 100644 --- a/src/csg/csg.hpp +++ b/src/csg/csg.hpp @@ -47,6 +47,7 @@ private: std::unique_ptr m_pimpl; }; +std::shared_ptr get_csgtree_from_filename(std::string); std::unique_ptr get_csgif_from_filename(std::string geom_file); } // namespace csg diff --git a/src/csg/impl/csg.cpp b/src/csg/impl/csg.cpp index 7ea6c38..99b104b 100644 --- a/src/csg/impl/csg.cpp +++ b/src/csg/impl/csg.cpp @@ -54,14 +54,17 @@ double CsgIF::operator()(double xx, double yy, double zz) const noexcept { return m_pimpl->call_signed_distance(m_state, xx, yy, zz); } -std::unique_ptr get_csgif_from_filename(std::string geom_file) { - +std::shared_ptr get_csgtree_from_filename(std::string geom_file) { auto csg_str = read_csg(geom_file); if (!csg_str) { std::cout << "Unable to read .csg file: " << geom_file << std::endl; return nullptr; } - auto csg_obj = csg::parse_csg(csg_str.value()); + return csg::parse_csg(csg_str.value()); +} + +std::unique_ptr get_csgif_from_filename(std::string geom_file) { + auto csg_obj = get_csgtree_from_filename(geom_file); if (!csg_obj) { std::cout << "Failed to parse .csg file: " << geom_file << std::endl; diff --git a/src/inputs/geometry.cpp b/src/inputs/geometry.cpp index 10d723d..5a45551 100644 --- a/src/inputs/geometry.cpp +++ b/src/inputs/geometry.cpp @@ -1,11 +1,29 @@ #include +#include "csg.hpp" #include "solver.hpp" namespace solver { std::optional make_geometry(solver::InputInfo ii) { solver::GeometrySettings geo; + + if (!ii.count(CSG_FILENAME)) { + require(CSG_FILENAME); + return std::nullopt; + } + auto csg_filename = std::get(ii[CSG_FILENAME]); + if (csg_filename.size() != 1) { + std::cout << CSG_FILENAME << " should only have 1 element" << std::endl; + return std::nullopt; + } + auto csg = csg::get_csgtree_from_filename(csg_filename[0]); + if (!csg) { + std::cout << "Unable to load .csg file: " << csg_filename[0] << std::endl; + return std::nullopt; + } + geo.tree = *csg; + if (!ii.count(PROB_LO)) { require(PROB_LO); return std::nullopt; diff --git a/src/inputs/inputs.hpp b/src/inputs/inputs.hpp index 7959503..7129f67 100644 --- a/src/inputs/inputs.hpp +++ b/src/inputs/inputs.hpp @@ -7,6 +7,7 @@ static const std::string DT_MIN("mfix.dt_min"); 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 CSG_FILENAME("mfix.geometry_filename"); // Mesh static const std::string BLOCKING_FACTOR("amr.blocking_factor"); diff --git a/src/inputs/meson.build b/src/inputs/meson.build index 33e8467..2bf4ee3 100644 --- a/src/inputs/meson.build +++ b/src/inputs/meson.build @@ -9,6 +9,7 @@ lib_inputs_parser = static_library( csg_inc, tao_inc, ], + link_with: lib_csg_parser, install : true) subdir('tests') -- GitLab From 24e837e51034454db909b2147bd280edf846a361 Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Wed, 29 Apr 2020 18:34:58 -0400 Subject: [PATCH 3/6] Revert --- src/inputs/geometry.cpp | 7 +------ src/inputs/solver.hpp | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/inputs/geometry.cpp b/src/inputs/geometry.cpp index 5a45551..ff1e060 100644 --- a/src/inputs/geometry.cpp +++ b/src/inputs/geometry.cpp @@ -17,12 +17,7 @@ std::optional make_geometry(solver::InputInfo ii) { std::cout << CSG_FILENAME << " should only have 1 element" << std::endl; return std::nullopt; } - auto csg = csg::get_csgtree_from_filename(csg_filename[0]); - if (!csg) { - std::cout << "Unable to load .csg file: " << csg_filename[0] << std::endl; - return std::nullopt; - } - geo.tree = *csg; + geo.csg_filename = csg_filename[0]; if (!ii.count(PROB_LO)) { require(PROB_LO); diff --git a/src/inputs/solver.hpp b/src/inputs/solver.hpp index 051084e..0f3793b 100644 --- a/src/inputs/solver.hpp +++ b/src/inputs/solver.hpp @@ -27,7 +27,7 @@ struct GeometryAxis { }; struct GeometrySettings { std::array axes; - csg::Tree tree; + std::string csg_filename; }; struct MeshAxis { -- GitLab From 5869864e87702649d5d0794097bfc2d9391de25b Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Wed, 29 Apr 2020 18:42:00 -0400 Subject: [PATCH 4/6] revert --- meson.build | 4 ---- src/inputs/geometry.cpp | 1 - src/inputs/meson.build | 6 +----- src/inputs/solver.hpp | 1 - 4 files changed, 1 insertion(+), 11 deletions(-) diff --git a/meson.build b/meson.build index da9d68d..7c6e889 100644 --- a/meson.build +++ b/meson.build @@ -8,10 +8,6 @@ parser_inc = include_directories( 'src/csg', 'src/csg/impl', 'src/inputs') -csg_inc = include_directories( - 'src/csg', - 'src/csg/impl', -) subdir('src/csg') subdir('src/inputs') diff --git a/src/inputs/geometry.cpp b/src/inputs/geometry.cpp index ff1e060..b417e2b 100644 --- a/src/inputs/geometry.cpp +++ b/src/inputs/geometry.cpp @@ -1,6 +1,5 @@ #include -#include "csg.hpp" #include "solver.hpp" namespace solver { diff --git a/src/inputs/meson.build b/src/inputs/meson.build index 2bf4ee3..a435c0a 100644 --- a/src/inputs/meson.build +++ b/src/inputs/meson.build @@ -5,11 +5,7 @@ lib_inputs_parser = static_library( 'parser.cpp', 'solver.cpp', 'time.cpp', - include_directories: [ - csg_inc, - tao_inc, - ], - link_with: lib_csg_parser, + include_directories: tao_inc, install : true) subdir('tests') diff --git a/src/inputs/solver.hpp b/src/inputs/solver.hpp index 0f3793b..8136360 100644 --- a/src/inputs/solver.hpp +++ b/src/inputs/solver.hpp @@ -9,7 +9,6 @@ #include #include -#include #include namespace solver { -- GitLab From 26e2b61496ecacd08511a752e4a0e4b5701afb8d Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Wed, 29 Apr 2020 18:45:39 -0400 Subject: [PATCH 5/6] reorg --- src/inputs/geometry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inputs/geometry.cpp b/src/inputs/geometry.cpp index b417e2b..7f48246 100644 --- a/src/inputs/geometry.cpp +++ b/src/inputs/geometry.cpp @@ -16,7 +16,6 @@ std::optional make_geometry(solver::InputInfo ii) { std::cout << CSG_FILENAME << " should only have 1 element" << std::endl; return std::nullopt; } - geo.csg_filename = csg_filename[0]; if (!ii.count(PROB_LO)) { require(PROB_LO); @@ -46,6 +45,7 @@ std::optional make_geometry(solver::InputInfo ii) { return std::nullopt; } + geo.csg_filename = csg_filename[0]; 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]; -- GitLab From d6590e2f3fe091f9ef981ef510b197d2eb6ea20c Mon Sep 17 00:00:00 2001 From: Mark Meredith Date: Wed, 29 Apr 2020 18:50:29 -0400 Subject: [PATCH 6/6] Fix --- src/inputs/tests/solver.t.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/inputs/tests/solver.t.cpp b/src/inputs/tests/solver.t.cpp index d26a67e..f160a05 100644 --- a/src/inputs/tests/solver.t.cpp +++ b/src/inputs/tests/solver.t.cpp @@ -18,6 +18,7 @@ TEST_CASE("from_origin", "[]") { 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}); + ii[CSG_FILENAME] = solver::StringArray({"geometry.csg",}); // Mesh ii[N_CELL] = solver::NumberArray({11, 22, 33}); -- GitLab