MADNESS  0.10.1
IntegratorXX.h
Go to the documentation of this file.
1 //
2 // Created by Florian Bischoff on 4/11/24.
3 //
4 
5 #ifndef INTEGRATORXX_H
6 #define INTEGRATORXX_H
7 
8 #include<madness/world/world.h> // for madness::print
10 
11 #ifdef MADNESS_HAS_INTEGRATORXX
12 #ifndef INTEGRATORXX_INCLUDED
13 #define INTEGRATORXX_INCLUDED
14 #include <integratorxx/generators/impl/impl.hpp>
15 #endif
16 #endif
17 
18 
19 /// Builder for a molecular integration grid, using IntegratorXX
20 ///
21 /// usage:
22 /// GridBuilder builder;
23 /// builder.set_nradial(nrad);
24 /// builder.set_origin(gridcenter);
25 /// builder.set_angular_order(order);
26 /// builder.make_grid();
27 /// std::vector<Vector<double,3>> points=builder.get_points();
28 /// see test_IntegratorXX.cc for an example
29 class GridBuilder {
30 private:
31  typedef std::array<double,3> pointT;
32  bool debug=false;
33  std::vector<pointT> points; // final grid points (after make_grid())
34  madness::Vector<double,3> origin={0,0,0}; // origin/center of the grid
35  std::size_t nradial=25; // the number of radial quadrature points
36  std::size_t nangular=0; // to be set from angular order, depending on angular_scheme
37  std::size_t angular_order=7; // a quadrature of a give order will integrate a spherical harmonic of that order exactly
38  std::string radial_scheme="TA";
39  std::string angular_scheme="LebedevLaikov";
40 #ifdef MADNESS_HAS_INTEGRATORXX
41  IntegratorXX::SphericalGridFactory::spherical_grid_ptr grid;
42 #else
43  struct dummygrid {
44  std::vector<pointT> points() const {return std::vector<pointT>();};
45  std::vector<double> weights() const {return std::vector<double>();}
46  };
47  std::shared_ptr<dummygrid> grid;
48 #endif
49 
50 public:
52 #ifndef MADNESS_HAS_INTEGRATORXX
53  madness::print("\nno GridBuilder without IntegratorXX\n");
54  MADNESS_EXCEPTION("no GridBuilder without IntegratorXX",1);
55 #endif
56  }
57 
58  /// a quadrature of a give order will integrate a spherical harmonic of that order exactly
59  void set_angular_order(const std::size_t order) {
60  angular_order=order;
61  }
62 
63  /// a quadrature of a give order will integrate a spherical harmonic of that order exactly
64  std::size_t get_angular_order() const {
65  return angular_order;
66  }
67 
68  /// number of radial gridpoints on the interval [0,\inf)
69  void set_nradial(const std::size_t nradial1) {
70  nradial=nradial1;
71  }
72 
73  /// number of radial gridpoints on the interval [0,\inf)
74  std::size_t get_nradial() const {
75  return nradial;
76  }
77 
78  /// the origin/center of the grid
80  origin=o;
81  }
82 
83  void make_grid() {
85  if (debug) {
86  madness::print("generating grid with nradial=",nradial,"nangular=",nangular,
87  "angular_order=",angular_order,"npoints=",nradial*nangular);
88  }
89 
90 #ifdef MADNESS_HAS_INTEGRATORXX
91  auto radial_quadrature=IntegratorXX::radial_from_string("MuraKnowles");
92  auto radial_traits=IntegratorXX::make_radial_traits(radial_quadrature,nradial,1.0);
93  auto angular_quadrature=IntegratorXX::angular_from_string("LebedevLaikov");
94  IntegratorXX::UnprunedSphericalGridSpecification unp{
95  radial_quadrature, *radial_traits,
96  angular_quadrature, nangular
97  };
98 
99  auto pruning_spec = IntegratorXX::robust_psi4_pruning_scheme(unp);
100  grid=IntegratorXX::SphericalGridFactory::generate_grid(pruning_spec);
101 #endif
102  }
103 
104  /// get the grid points
105  std::vector<madness::Vector<double,3>> get_points() const {
106  MADNESS_CHECK_THROW(grid.get(),"grid not initialized");
107  auto points0=grid->points();
108  std::vector<madness::Vector<double,3>> points;
109  for (auto p : points0) points.push_back(madness::Vector<double,3>(p)+origin);
110  return points;
111  }
112 
113  std::vector<double> get_weights() const {
114  MADNESS_CHECK_THROW(grid.get(),"grid not initialized");
115  return grid->weights();
116  }
117 
118 private:
119  /// number of angular gridpoints, derived from the angular order
120  void set_angular_points_from_order(const std::size_t order) {
121 #ifdef MADNESS_HAS_INTEGRATORXX
122  // this is stupid: why have a runtime switch for the angular scheme if the traits are templated???
123  if (angular_scheme=="LebedevLaikov") {
124  using traits=IntegratorXX::quadrature_traits< IntegratorXX::LebedevLaikov<double>>;
125  int nextorder=traits::next_algebraic_order(order);
126  nangular = traits::npts_by_algebraic_order(nextorder);
127  } else if (angular_scheme=="AhrensBeylkin") {
128  using traits=IntegratorXX::quadrature_traits< IntegratorXX::AhrensBeylkin<double>>;
129  int nextorder=traits::next_algebraic_order(order);
130  nangular = traits::npts_by_algebraic_order(nextorder);
131  } else {
132  MADNESS_EXCEPTION("unknown angular quadrature scheme",1);
133  }
134 #endif
135  }
136 };
137 
138 
139 
140 #endif //INTEGRATORXX_H
Definition: IntegratorXX.h:29
void set_angular_points_from_order(const std::size_t order)
number of angular gridpoints, derived from the angular order
Definition: IntegratorXX.h:120
void set_nradial(const std::size_t nradial1)
number of radial gridpoints on the interval [0,\inf)
Definition: IntegratorXX.h:69
std::size_t nangular
Definition: IntegratorXX.h:36
void set_angular_order(const std::size_t order)
a quadrature of a give order will integrate a spherical harmonic of that order exactly
Definition: IntegratorXX.h:59
std::size_t get_angular_order() const
a quadrature of a give order will integrate a spherical harmonic of that order exactly
Definition: IntegratorXX.h:64
void set_origin(const madness::Vector< double, 3 > &o)
the origin/center of the grid
Definition: IntegratorXX.h:79
std::vector< pointT > points
Definition: IntegratorXX.h:33
std::string angular_scheme
Definition: IntegratorXX.h:39
bool debug
Definition: IntegratorXX.h:32
std::size_t nradial
Definition: IntegratorXX.h:35
std::size_t get_nradial() const
number of radial gridpoints on the interval [0,\inf)
Definition: IntegratorXX.h:74
std::shared_ptr< dummygrid > grid
Definition: IntegratorXX.h:47
std::vector< double > get_weights() const
Definition: IntegratorXX.h:113
GridBuilder()
Definition: IntegratorXX.h:51
madness::Vector< double, 3 > origin
Definition: IntegratorXX.h:34
void make_grid()
Definition: IntegratorXX.h:83
std::vector< madness::Vector< double, 3 > > get_points() const
get the grid points
Definition: IntegratorXX.h:105
std::string radial_scheme
Definition: IntegratorXX.h:38
std::array< double, 3 > pointT
Definition: IntegratorXX.h:31
std::size_t angular_order
Definition: IntegratorXX.h:37
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition: derivatives.cc:72
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition: madness_exception.h:119
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition: madness_exception.h:210
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition: print.h:225
Definition: IntegratorXX.h:43
std::vector< double > weights() const
Definition: IntegratorXX.h:45
std::vector< pointT > points() const
Definition: IntegratorXX.h:44
Implement the madness:Vector class, an extension of std::array that supports some mathematical operat...
Declares the World class for the parallel runtime environment.