Skip to content

Commit

Permalink
Merge branch 'feature/runtime_generator' into dox/readme
Browse files Browse the repository at this point in the history
  • Loading branch information
wavefunction91 committed Nov 6, 2023
2 parents 89335ce + 5f98bca commit acac7e6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 17 deletions.
10 changes: 7 additions & 3 deletions include/integratorxx/generators/spherical_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum class RadialQuad : uint32_t {
};

template <typename RadQuadType>
RadialQuad rad_from_type() {
RadialQuad radial_from_type() {
if constexpr (detail::is_becke_v<RadQuadType>) return RadialQuad::Becke;
if constexpr (detail::is_mk_v<RadQuadType> ) return RadialQuad::MuraKnowles;
if constexpr (detail::is_mhl_v<RadQuadType>) return RadialQuad::MurrayHandyLaming;
Expand All @@ -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,
Expand All @@ -36,7 +38,7 @@ enum class AngularQuad : uint32_t {
};

template <typename AngQuadType>
AngularQuad ang_from_type() {
AngularQuad angular_from_type() {
if constexpr (detail::is_ahrens_beyklin_v<AngQuadType>) return AngularQuad::AhrensBeylkin;
if constexpr (detail::is_delley_v<AngQuadType> ) return AngularQuad::Delley;
if constexpr (detail::is_lebedev_laikov_v<AngQuadType>) return AngularQuad::LebedevLaikov;
Expand All @@ -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
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/spherical_factory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,38 @@
#include <integratorxx/quadratures/radial.hpp>
#include <integratorxx/quadratures/s2.hpp>

#include <algorithm>

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<double,double>;
Expand Down
51 changes: 37 additions & 14 deletions test/spherical_generator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
#include <integratorxx/composite_quadratures/pruned_spherical_quadrature.hpp>
#include <integratorxx/generators/spherical_factory.hpp>

using bk_type = IntegratorXX::Becke<double,double>;
using mk_type = IntegratorXX::MuraKnowles<double,double>;
using mhl_type = IntegratorXX::MurrayHandyLaming<double,double>;
using ta_type = IntegratorXX::TreutlerAhlrichs<double,double>;

using ah_type = IntegratorXX::AhrensBeylkin<double>;
using de_type = IntegratorXX::Delley<double>;
using ll_type = IntegratorXX::LebedevLaikov<double>;
using wo_type = IntegratorXX::Womersley<double>;

std::ostream& operator<<( std::ostream& out, IntegratorXX::PruningRegion p) {

using namespace IntegratorXX;
Expand Down Expand Up @@ -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<bk_type>() == radial_from_string("Becke"));
REQUIRE(radial_from_type<mk_type>() == radial_from_string("MuraKnowles"));
REQUIRE(radial_from_type<mk_type>() == radial_from_string("MK"));
REQUIRE(radial_from_type<mhl_type>() == radial_from_string("MurrayHandyLaming"));
REQUIRE(radial_from_type<mhl_type>() == radial_from_string("MHL"));
REQUIRE(radial_from_type<ta_type>() == radial_from_string("TreutlerAhlrichs"));
REQUIRE(radial_from_type<ta_type>() == radial_from_string("TA"));
}

SECTION("Angular") {
REQUIRE(angular_from_type<ah_type>() == angular_from_string("AhrensBeylkin"));
REQUIRE(angular_from_type<ah_type>() == angular_from_string("AB"));
REQUIRE(angular_from_type<de_type>() == angular_from_string("Delley"));
REQUIRE(angular_from_type<ll_type>() == angular_from_string("LebedevLaikov"));
REQUIRE(angular_from_type<ll_type>() == angular_from_string("Lebedev"));
REQUIRE(angular_from_type<ll_type>() == angular_from_string("LL"));
REQUIRE(angular_from_type<wo_type>() == angular_from_string("Womersley"));
}
}

TEST_CASE( "Pruning Schemes", "[sph-gen]" ) {

using namespace IntegratorXX;
Expand Down Expand Up @@ -193,16 +226,6 @@ TEST_CASE( "Pruning Schemes", "[sph-gen]" ) {

}

using bk_type = IntegratorXX::Becke<double,double>;
using mk_type = IntegratorXX::MuraKnowles<double,double>;
using mhl_type = IntegratorXX::MurrayHandyLaming<double,double>;
using ta_type = IntegratorXX::TreutlerAhlrichs<double,double>;

using ah_type = IntegratorXX::AhrensBeylkin<double>;
using de_type = IntegratorXX::Delley<double>;
using ll_type = IntegratorXX::LebedevLaikov<double>;
using wo_type = IntegratorXX::Womersley<double>;

using sph_test_types = std::tuple<
std::tuple<bk_type, ah_type>,
std::tuple<bk_type, de_type>,
Expand Down Expand Up @@ -247,8 +270,8 @@ TEMPLATE_LIST_TEST_CASE("Unpruned", "[sph-gen]", sph_test_types) {

// Generate via runtime API
UnprunedSphericalGridSpecification unp{
rad_from_type<radial_type>(), nrad, 1.0,
ang_from_type<angular_type>(), nang
radial_from_type<radial_type>(), nrad, 1.0,
angular_from_type<angular_type>(), nang
};

auto sph = SphericalGridFactory::generate_grid(unp);
Expand Down Expand Up @@ -285,8 +308,8 @@ TEMPLATE_LIST_TEST_CASE("Pruned", "[sph-gen]", sph_test_types) {

// Generate pruning scheme
UnprunedSphericalGridSpecification unp{
rad_from_type<radial_type>(), nrad, 1.0,
ang_from_type<angular_type>(), nang
radial_from_type<radial_type>(), nrad, 1.0,
angular_from_type<angular_type>(), nang
};

auto pruning_spec = robust_psi4_pruning_scheme(unp);
Expand Down

0 comments on commit acac7e6

Please sign in to comment.