13 #ifndef HEX_DIOPHANTINE
14 #define HEX_DIOPHANTINE
19 #include <gsl/gsl_sf.h>
24 template <
class Functor,
class Integrator>
44 : Q_(f), f_(f), result_(0), ok_(true), status_(),
45 epsabs_(1
e-8), epsrel_(1
e-6), limit_(1000) {}
47 double result ()
const {
return result_; }
48 bool ok ()
const {
return ok_; }
49 std::string
const &
status ()
const {
return status_; }
51 double epsabs ()
const {
return epsabs_; }
54 double epsrel ()
const {
return epsrel_; }
57 int limit ()
const {
return limit_; }
60 virtual double nthNode (
int n)
const = 0;
75 if (rt != 0 and a < rt)
80 double quotient = 0.75;
81 for (
int samples = 8; ; samples *= 2)
88 if ((
int)log2(samples) == limit_)
92 "Cannot integrate classically forbidden region - reached maximal number of iterations."
104 if (estimate == 0 and result_ == 0)
122 for (
int inode = 1; inode < limit_; inode++)
141 if (not Q_.integrate(rmin,rmax))
144 status_ =
format(
"Node integrator failed on <%g,%g>: %s", rmin, rmax, Q_.status().c_str());
149 result_ += Q_.result();
161 template <
class Functor,
class Integrator>
172 int err = gsl_sf_bessel_zero_Jnu_e(l_+0.5,n,&res);
173 if (err != GSL_SUCCESS)
177 "Cannot find %d-th root of the Bessel function j[%d](%g r) -- %s.",
178 n, l_, k_, gsl_strerror(err)
195 template <
class Functor,
class Integrator>
201 :
NodeIntegrator<Functor,Integrator>(f), k_(k), l_(l), nzeros_(0), zeros_(nullptr) {}
205 if (zeros_ !=
nullptr)
218 if (zeros_ !=
nullptr)
225 zeros_ =
new double [nzeros_];
230 return zeros_[n-1] / k_;
235 return (
std::sqrt(1 + l_*(l_+1)*k_*k_) - 1) / (k_*k_);
244 mutable double * zeros_;
247 template <
class Functor,
class Integrator>
253 :
NodeIntegrator<Functor,Integrator>(f), zeros_(zeros), rt_(rt) {}
260 if (n <= (
int)zeros_.
size())
double epsrel() const
Definition: nodeintegrate.h:54
Array view.
Definition: arrays.h:186
Definition: nodeintegrate.h:248
std::string const & status() const
Definition: nodeintegrate.h:49
virtual double nthNode(int n) const
Definition: nodeintegrate.h:209
CoulombNodeIntegrator(Functor f, double k, int l)
Definition: nodeintegrate.h:200
T trapz(double h, NumberArray< T > const &y)
Uniform trapezoidal integration.
Definition: special.h:78
A comfortable number array class.
Definition: arrays.h:171
T min(const ArrayView< T > a)
Minimal element of array.
Definition: arrays.h:1663
virtual double turningPoint() const
Definition: nodeintegrate.h:233
FixedNodeIntegrator(Functor f, const rArrayView zeros, double rt=0)
Definition: nodeintegrate.h:252
int limit() const
Definition: nodeintegrate.h:57
void setEpsRel(double eps)
Definition: nodeintegrate.h:55
virtual double turningPoint() const
Definition: nodeintegrate.h:184
const double e
Definition: special.h:44
void eval(TFunctor f, TArray grid, TArray &vals)
Definition: arrays.h:1844
double epsabs() const
Definition: nodeintegrate.h:51
~CoulombNodeIntegrator()
Definition: nodeintegrate.h:203
auto transform(Functor f) const -> NumberArray< decltype(f(T(0)))>
Apply a user transformation.
Definition: arrays.h:990
class NodeIntegrator exception
const double Inf
Definition: special.h:67
Definition: nodeintegrate.h:25
char const * format(Params...p)
printf-like formatting.
Definition: misc.h:233
bool integrate(double a, double b)
Definition: nodeintegrate.h:63
double result() const
Definition: nodeintegrate.h:47
int coulomb_zeros(double eta, int L, int nzeros, double *zeros, double epsrel=1e-8)
Get zeros of the Coulomb wave function .
Definition: special.cpp:60
void setLimit(double n)
Definition: nodeintegrate.h:58
virtual double nthNode(int n) const
Definition: nodeintegrate.h:255
void setEpsAbs(double eps)
Definition: nodeintegrate.h:52
bool ok() const
Definition: nodeintegrate.h:48
virtual double nthNode(int n) const
Definition: nodeintegrate.h:169
NumberArray< T > geomspace(T x0, T x1, size_t samples, double q)
Generate geometric grid.
Definition: arrays.h:1505
BesselNodeIntegrator(Functor f, double k, int l)
Definition: nodeintegrate.h:166
Definition: nodeintegrate.h:162
NumberArray< T > sqrt(NumberArray< T > const &A)
Return per-element square root.
Definition: arrays.h:1711
rArray abs(const cArrayView u)
Definition: arrays.cpp:19
virtual double turningPoint() const
Definition: nodeintegrate.h:61
virtual double nthNode(int n) const =0
virtual double turningPoint() const
Definition: nodeintegrate.h:266
T max(const ArrayView< T > a)
Maximal element of array.
Definition: arrays.h:1673
NodeIntegrator(Functor f)
Definition: nodeintegrate.h:43
size_t size() const
Item count.
Definition: arrays.h:673
Definition: nodeintegrate.h:196