1#include <gsl/gsl_sf_bessel.h>
14static void custom_bessel(
int lmax,
double x,
double* result) {
17 for (
int l = 1; l <=
lmax; ++l) {
22 gsl_sf_bessel_jl_array(
lmax, x, result);
24 const double x_inv = 1.0 / x;
25 const double sin_x = std::sin(x);
26 result[0] = sin_x * x_inv;
29 result[1] = sin_x * x_inv * x_inv - std::cos(x) * x_inv;
32 for (
int l = 2; l <=
lmax; ++l) {
33 result[l] = (2 * (l - 1) + 1) / x * result[l - 1] - result[l - 2];
39 std::vector<double> ref_result(
lmax + 1);
40 gsl_sf_bessel_jl_array(
lmax, x, ref_result.data());
41 for(
int l = 0; l <=
lmax; ++l) {
42 assert(std::abs(result[l] - ref_result[l]) < 1e-6);
47Spherical_Bessel_functions::Spherical_Bessel_functions(
int lmax__,
55 sbessel_ = std::vector<Spline<double>>(lmax__ + 2);
56 for (
int l = 0; l <= lmax__ + 1; l++) {
60 std::vector<double> jl(lmax__ + 2);
61 for (
int ir = 0; ir < rgrid__.
num_points(); ir++) {
62 double t = rgrid__[ir] * q__;
63 custom_bessel(lmax__ + 1, t, &jl[0]);
64 for (
int l = 0; l <= lmax__ + 1; l++) {
65 sbessel_[l](ir) = jl[l];
69 for (
int l = 0; l <= lmax__ + 1; l++) {
70 sbessel_[l].interpolate();
75Spherical_Bessel_functions::sbessel(
int lmax__,
double t__,
double* jl__)
77 gsl_sf_bessel_jl_array(lmax__, t__, jl__);
81Spherical_Bessel_functions::sbessel_deriv_q(
int lmax__,
double q__,
double x__,
double* jl_dq__)
83 std::vector<double> jl(lmax__ + 2);
85 sbessel(lmax__ + 1, x__ * q__, &jl[0]);
87 for (
int l = 0; l <= lmax__; l++) {
89 jl_dq__[l] = (l / q__) * jl[l] - x__ * jl[l + 1];
101Spherical_Bessel_functions::operator[](
int l__)
const
103 return sbessel_[l__];
112 for (
int ir = 0; ir < rgrid_->
num_points(); ir++) {
113 s(ir) = (l__ / q_) * sbessel_[l__](ir) - (*rgrid_)[ir] * sbessel_[l__ + 1](ir);
117 for (
int ir = 0; ir < rgrid_->
num_points(); ir++) {
118 s(ir) = (*rgrid_)[ir] / 3;
int num_points() const
Number of grid points.
Spline< T, U > & interpolate()
Spline< double > deriv_q(int l__)
Derivative of Bessel function with respect to q.
int lmax(int lmmax__)
Get maximum orbital quantum number by the maximum lm index.
Namespace of the SIRIUS library.
Contains implementation of sirius::Spherical_Bessel_functions class.