diff --git a/src/csg/csg.hpp b/src/csg/csg.hpp index 7bce19472eeb6c2faef5594eb568050873080b8a..e29b857240b8ae461bd729c2501107525b8a7898 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 7ea6c38ee30693a6c0321b2bea4b36fda775f0eb..99b104ba0fd7dc2e039b323388de34f55f955432 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 10d723db361e324c534f73fcd787483555ab63ab..7f48246fcd61d18bc782c78ec0346015319ff010 100644 --- a/src/inputs/geometry.cpp +++ b/src/inputs/geometry.cpp @@ -6,6 +6,17 @@ 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; + } + if (!ii.count(PROB_LO)) { require(PROB_LO); return std::nullopt; @@ -34,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]; diff --git a/src/inputs/inputs.hpp b/src/inputs/inputs.hpp index 79595037d5f1eae60acf2c369e31babd88dca3d5..7129f67e799bd12e8aa6bcf91fb16e4656b92037 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/solver.hpp b/src/inputs/solver.hpp index 868f5157a69e4674db24a088a646f5527b700bfe..8136360a5354d92c8b33eac5edba343b0274c104 100644 --- a/src/inputs/solver.hpp +++ b/src/inputs/solver.hpp @@ -26,6 +26,7 @@ struct GeometryAxis { }; struct GeometrySettings { std::array axes; + std::string csg_filename; }; struct MeshAxis { diff --git a/src/inputs/tests/solver.t.cpp b/src/inputs/tests/solver.t.cpp index d26a67ed6ccd423e5c739f776bd9c7a16a52b02c..f160a05d8a3498ea5e2a5a18268e1b34d65490f4 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});