33 #ifndef MADNESS_MRA_ADQUAD_H__INCLUDED
34 #define MADNESS_MRA_ADQUAD_H__INCLUDED
47 double norm(
const Tensor<T>& t) {
52 template <
typename funcT>
53 typename funcT::returnT
do_adq(
double lo,
double hi,
const funcT&
func,
54 int n,
const double* x,
const double* w) {
56 double range = (hi-lo);
57 typename funcT::returnT
sum =
func(lo + range*x[0])*w[0];
58 for (
int i=1; i<n; ++i) sum +=
func(lo + range*x[i])*w[i];
63 template <
typename funcT>
64 typename funcT::returnT
adq1(
double lo,
double hi,
const funcT&
func,
double thresh,
65 int n,
const double* x,
const double* w,
int level) {
66 static const int MAX_LEVEL=14;
69 typename funcT::returnT full =
do_adq(lo, hi, func, n, x, w);
70 typename funcT::returnT half =
do_adq(lo, lo+d, func, n, x, w) +
do_adq(lo+d, hi, func, n, x, w);
74 double relerr = (norm==0.0) ? 0.0 : abserr/
norm;
78 bool converged = (relerr < 1e-14) || (abserr<thresh && relerr<0.01);
83 if (level == MAX_LEVEL) {
88 return adq1(lo, lo+d, func, thresh*0.5, n, x, w, level+1) +
89 adq1(lo+d, hi, func, thresh*0.5, n, x, w, level+1);
94 template <
typename funcT>
95 typename funcT::returnT
adq(
double lo,
double hi,
const funcT&
func,
double thresh) {
100 return adq1(lo, hi, func, thresh, n, x, y, 0);
108 return exp(-x*x)*
cos(3*x);
112 const double pi = 3.1415926535897932384;
118 return std::abs(test-
exact())<1e-14;
125 #endif // MADNESS_MRA_ADQUAD_H__INCLUDED
funcT::returnT do_adq(double lo, double hi, const funcT &func, int n, const double *x, const double *w)
Definition: adquad.h:53
double norm(const T &t)
Definition: adquad.h:42
const mpreal exp(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2234
T norm(Vector< T, N > v)
Compute norm of a Vector.
Definition: array.h:447
std::complex< double > func(int n, int t1, int t2, int t3, double xx, double yy, double zz)
Definition: wannier.cc:98
static bool runtest()
Definition: adquad.h:116
const mpreal cos(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2255
double returnT
Definition: adquad.h:105
funcT::returnT adq1(double lo, double hi, const funcT &func, double thresh, int n, const double *x, const double *w, int level)
Definition: adquad.h:64
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
static double exact()
Definition: adquad.h:111
const double pi
Definition: navstokes_cosines.cc:91
bool gauss_legendre(int n, double xlo, double xhi, double *x, double *w)
Definition: legendre.cc:231
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
double operator()(double x) const
Definition: adquad.h:106
funcT::returnT adq(double lo, double hi, const funcT &func, double thresh)
Definition: adquad.h:95
const mpreal sum(const mpreal tab[], unsigned long int n, mp_rnd_t rnd_mode)
Definition: mpreal.cc:241
void test(World &world, bool doloadbal=false)
Definition: dataloadbal.cc:225
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45