diff --git a/source/module_base/math_sphbes.cpp b/source/module_base/math_sphbes.cpp index e3f0d8edcb7..20a40315e26 100644 --- a/source/module_base/math_sphbes.cpp +++ b/source/module_base/math_sphbes.cpp @@ -369,7 +369,7 @@ void Sphbes::Spherical_Bessel_Roots Sphbes::Spherical_Bessel(msh, r, 1, l, jl); int n=0; - for (int i=0; i epsilon) { - double *rad = new double[100]; - double *jl_new = new double[100]; - // if not enough accurate, divide again. - const double delta2 = (x_2 - x_1)/99.0; - for (int j=0;j<100;j++) + const double delta2 = (x_2 - x_1)/(grid-1); + for (int j=0;j= 0." << std::endl; exit(0); } - + double djl0 = 0; if(l == 1) { djl0 = 1.0/3.0; } - + if(l == 0 ) { for (int ir = 0;ir < msh; ir++) @@ -658,7 +659,7 @@ void Sphbes::dSpherical_Bessel_dx { djl[ir] = (x1 * std::cos(x1) - std::sin(x1)) / (x1*x1); } - + } } else @@ -669,7 +670,7 @@ void Sphbes::dSpherical_Bessel_dx for (int ir = 0;ir < msh; ir++) { double x1 = q * r[ir]; - if(x1 < 1e-8) + if(x1 < 1e-8) { djl[ir] = djl0; } @@ -687,7 +688,7 @@ void Sphbes::dSpherical_Bessel_dx double Sphbes::_sphbesj_ascending_recurrence(int l, double x) { // should be used when x > l && l > 0 - + double invx = 1.0 / x; double j0 = std::sin(x) * invx; double j1 = ( j0 - std::cos(x) ) * invx; @@ -753,21 +754,21 @@ double Sphbes::sphbesj(const int l, const double x) case 0: return std::sin(x) * invx; case 1: - return ( std::sin(x) * invx - std::cos(x) ) * invx; + return ( std::sin(x) * invx - std::cos(x) ) * invx; // NOTE: the following explicit expressions are not necessarily faster than ascending recurrence, // but we keep them just in case we need them in the future. //case 2: // return ( (3.0 * invx - x) * std::sin(x) - 3.0 * std::cos(x) ) * (invx * invx); //case 3: - // return ( std::sin(x) * (15.0 * invx - 6.0 * x) + std::cos(x) * (x * x - 15.0) ) * std::pow(invx, 3); + // return ( std::sin(x) * (15.0 * invx - 6.0 * x) + std::cos(x) * (x * x - 15.0) ) * std::pow(invx, 3); //case 4: - // return ( std::sin(x) * (std::pow(x,3) - 45.0 * x + 105.0 * invx) + // return ( std::sin(x) * (std::pow(x,3) - 45.0 * x + 105.0 * invx) // + std::cos(x) * (10.0 * x * x - 105.0) ) * std::pow(invx, 4); //case 5: - // return ( std::sin(x) * (15.0 * std::pow(x,3) - 420.0 * x + 945.0 * invx) + // return ( std::sin(x) * (15.0 * std::pow(x,3) - 420.0 * x + 945.0 * invx) // + std::cos(x) * (-std::pow(x, 4) + 105.0 * x * x - 945.0) ) * std::pow(invx, 5); //case 6: - // return ( std::sin(x) * (-std::pow(x, 5) + 210.0 * std::pow(x, 3) - 4725.0 * x + 10395.0 * invx) + // return ( std::sin(x) * (-std::pow(x, 5) + 210.0 * std::pow(x, 3) - 4725.0 * x + 10395.0 * invx) // + std::cos(x) * (-21.0 * std::pow(x, 4) + 1260.0 * x * x - 10395.0) ) * std::pow(invx, 6); default: return _sphbesj_ascending_recurrence(l, x);