diff --git a/include/integratorxx/generators/spherical_factory.hpp b/include/integratorxx/generators/spherical_factory.hpp index 077e1d9..f4722ed 100644 --- a/include/integratorxx/generators/spherical_factory.hpp +++ b/include/integratorxx/generators/spherical_factory.hpp @@ -18,7 +18,7 @@ enum class RadialQuad : uint32_t { }; template -RadialQuad rad_from_type() { +RadialQuad radial_from_type() { if constexpr (detail::is_becke_v) return RadialQuad::Becke; if constexpr (detail::is_mk_v ) return RadialQuad::MuraKnowles; if constexpr (detail::is_mhl_v) return RadialQuad::MurrayHandyLaming; @@ -27,6 +27,8 @@ RadialQuad rad_from_type() { throw std::runtime_error("Unrecognized Radial Quadrature"); }; +RadialQuad radial_from_string(std::string name); + /// High-level specification of angular quadratures enum class AngularQuad : uint32_t { AhrensBeylkin = 0x0100, @@ -36,7 +38,7 @@ enum class AngularQuad : uint32_t { }; template -AngularQuad ang_from_type() { +AngularQuad angular_from_type() { if constexpr (detail::is_ahrens_beyklin_v) return AngularQuad::AhrensBeylkin; if constexpr (detail::is_delley_v ) return AngularQuad::Delley; if constexpr (detail::is_lebedev_laikov_v) return AngularQuad::LebedevLaikov; @@ -45,6 +47,8 @@ AngularQuad ang_from_type() { throw std::runtime_error("Unrecognized Angular Quadrature"); }; +AngularQuad angular_from_string(std::string name); + /// High-level specification of pruning schemes for spherical quadratures enum class PruningScheme { Unpruned, /// Unpruned quadrature @@ -69,7 +73,7 @@ struct UnprunedSphericalGridSpecification { }; -/// Speficiation of a pruned region of an spierical quadrature +/// Specification of a pruned region of an spherical quadrature struct PruningRegion { size_t idx_st; ///< Starting radial index for pruned region size_t idx_en; ///< Ending radial index (exclusive) for the pruned region diff --git a/src/spherical_factory.cxx b/src/spherical_factory.cxx index 3bf0c04..c270866 100644 --- a/src/spherical_factory.cxx +++ b/src/spherical_factory.cxx @@ -2,9 +2,38 @@ #include #include +#include namespace IntegratorXX { + +RadialQuad radial_from_string(std::string name) { + std::transform(name.begin(), name.end(), name.begin(), ::toupper); + if(name == "BECKE") return RadialQuad::Becke; + if(name == "MURAKNOWLES") return RadialQuad::MuraKnowles; + if(name == "MK") return RadialQuad::MuraKnowles; + if(name == "MURRAYHANDYLAMING") return RadialQuad::MurrayHandyLaming; + if(name == "MHL") return RadialQuad::MurrayHandyLaming; + if(name == "TREUTLERAHLRICHS") return RadialQuad::TreutlerAhlrichs; + if(name == "TA") return RadialQuad::TreutlerAhlrichs; + + throw std::runtime_error("Unrecognized Radial Quadrature"); +} + +AngularQuad angular_from_string(std::string name) { + std::transform(name.begin(), name.end(), name.begin(), ::toupper); + if(name == "AHRENSBEYLKIN") return AngularQuad::AhrensBeylkin; + if(name == "AB") return AngularQuad::AhrensBeylkin; + if(name == "DELLEY") return AngularQuad::Delley; + if(name == "LEBEDEVLAIKOV") return AngularQuad::LebedevLaikov; + if(name == "LEBEDEV") return AngularQuad::LebedevLaikov; + if(name == "LL") return AngularQuad::LebedevLaikov; + if(name == "WOMERSLEY") return AngularQuad::Womersley; + + throw std::runtime_error("Unrecognized Angular Quadrature"); +} + + using spherical_grid_ptr = SphericalGridFactory::spherical_grid_ptr; using bk_type = Becke; diff --git a/test/spherical_generator.cxx b/test/spherical_generator.cxx index 5cde799..650a766 100644 --- a/test/spherical_generator.cxx +++ b/test/spherical_generator.cxx @@ -7,6 +7,16 @@ #include #include +using bk_type = IntegratorXX::Becke; +using mk_type = IntegratorXX::MuraKnowles; +using mhl_type = IntegratorXX::MurrayHandyLaming; +using ta_type = IntegratorXX::TreutlerAhlrichs; + +using ah_type = IntegratorXX::AhrensBeylkin; +using de_type = IntegratorXX::Delley; +using ll_type = IntegratorXX::LebedevLaikov; +using wo_type = IntegratorXX::Womersley; + std::ostream& operator<<( std::ostream& out, IntegratorXX::PruningRegion p) { using namespace IntegratorXX; @@ -43,6 +53,29 @@ std::ostream& operator<<( std::ostream& out, return out; } +TEST_CASE( "String Getter", "[sph-gen]" ) { + using namespace IntegratorXX; + SECTION("Radial") { + REQUIRE(radial_from_type() == radial_from_string("Becke")); + REQUIRE(radial_from_type() == radial_from_string("MuraKnowles")); + REQUIRE(radial_from_type() == radial_from_string("MK")); + REQUIRE(radial_from_type() == radial_from_string("MurrayHandyLaming")); + REQUIRE(radial_from_type() == radial_from_string("MHL")); + REQUIRE(radial_from_type() == radial_from_string("TreutlerAhlrichs")); + REQUIRE(radial_from_type() == radial_from_string("TA")); + } + + SECTION("Angular") { + REQUIRE(angular_from_type() == angular_from_string("AhrensBeylkin")); + REQUIRE(angular_from_type() == angular_from_string("AB")); + REQUIRE(angular_from_type() == angular_from_string("Delley")); + REQUIRE(angular_from_type() == angular_from_string("LebedevLaikov")); + REQUIRE(angular_from_type() == angular_from_string("Lebedev")); + REQUIRE(angular_from_type() == angular_from_string("LL")); + REQUIRE(angular_from_type() == angular_from_string("Womersley")); + } +} + TEST_CASE( "Pruning Schemes", "[sph-gen]" ) { using namespace IntegratorXX; @@ -193,16 +226,6 @@ TEST_CASE( "Pruning Schemes", "[sph-gen]" ) { } -using bk_type = IntegratorXX::Becke; -using mk_type = IntegratorXX::MuraKnowles; -using mhl_type = IntegratorXX::MurrayHandyLaming; -using ta_type = IntegratorXX::TreutlerAhlrichs; - -using ah_type = IntegratorXX::AhrensBeylkin; -using de_type = IntegratorXX::Delley; -using ll_type = IntegratorXX::LebedevLaikov; -using wo_type = IntegratorXX::Womersley; - using sph_test_types = std::tuple< std::tuple, std::tuple, @@ -247,8 +270,8 @@ TEMPLATE_LIST_TEST_CASE("Unpruned", "[sph-gen]", sph_test_types) { // Generate via runtime API UnprunedSphericalGridSpecification unp{ - rad_from_type(), nrad, 1.0, - ang_from_type(), nang + radial_from_type(), nrad, 1.0, + angular_from_type(), nang }; auto sph = SphericalGridFactory::generate_grid(unp); @@ -285,8 +308,8 @@ TEMPLATE_LIST_TEST_CASE("Pruned", "[sph-gen]", sph_test_types) { // Generate pruning scheme UnprunedSphericalGridSpecification unp{ - rad_from_type(), nrad, 1.0, - ang_from_type(), nang + radial_from_type(), nrad, 1.0, + angular_from_type(), nang }; auto pruning_spec = robust_psi4_pruning_scheme(unp);