2#include "LinAlg/Matrix.hpp"
3#include "qip/Maths.hpp"
4#include "qip/Vector.hpp"
17double jL(
int L,
double x);
30double yL(
int L,
double x);
33double PhiL(
int L,
double x,
bool tilde =
false);
36double PsiL(
int L,
double x,
bool tilde =
false);
243std::vector<double>
fillBesselVec(
int l,
const std::vector<double> &xvec);
245std::vector<double> fillBesselVec_kr(
int l,
double k,
246 const std::vector<double> &rvec);
248void fillBesselVec_kr(
int l,
double k,
const std::vector<double> &r,
249 std::vector<double> *jl);
262 JL_table(
int max_L,
const std::vector<double> &q,
263 const std::vector<double> &r) {
268 void fill(
int max_L,
const std::vector<double> &q,
269 const std::vector<double> &r) {
271 m_J_L_q.
resize(std::size_t(max_L + 1), q.size());
272 m_J_L_q_on_qr.
resize(std::size_t(max_L + 1), q.size());
274#pragma omp parallel for collapse(2)
275 for (
auto L = 0ul; L <= std::size_t(max_L); ++L) {
276 for (
auto iq = 0ul; iq < m_J_L_q.
cols(); ++iq) {
277 const auto tq = q[iq];
279 m_J_L_q[L][iq] = fillBesselVec_kr(
int(L), tq, r);
281 m_J_L_q_on_qr[L][iq] = m_J_L_q[L][iq] / (tq * r);
288 const std::vector<double> &
at(std::size_t L, std::size_t iq)
const {
289 return m_J_L_q.
atc(L, iq);
294 const std::vector<double> &
jL(
int L,
double q)
const {
296 const auto it = std::lower_bound(m_q.begin(), m_q.end() - 1, q);
297 const auto iq = std::size_t(std::distance(m_q.begin(), it));
298 return m_J_L_q.
atc(std::size_t(L), iq);
303 const std::vector<double> &
jL_nearest(
int L,
double q)
const {
306 if (q <= m_q.front())
307 return m_J_L_q.
atc(std::size_t(L), 0);
309 return m_J_L_q.
atc(std::size_t(L), m_q.size() - 1);
312 const auto it = std::lower_bound(m_q.begin() + 1, m_q.end() - 1, q);
313 const auto i = std::size_t(std::distance(m_q.begin(), it)) - 1;
316 const auto iq = (q - m_q[i] < m_q[i + 1] - q) ? i : i + 1;
318 return m_J_L_q.
atc(std::size_t(L), iq);
326 if (q <= m_q.front())
327 return m_J_L_q_on_qr.
atc(std::size_t(L), 0);
329 return m_J_L_q_on_qr.
atc(std::size_t(L), m_q.size() - 1);
332 const auto it = std::lower_bound(m_q.begin() + 1, m_q.end() - 1, q);
333 const auto i = std::size_t(std::distance(m_q.begin(), it)) - 1;
336 const auto iq = (q - m_q[i] < m_q[i + 1] - q) ? i : i + 1;
338 return m_J_L_q_on_qr.
atc(std::size_t(L), iq);
347 if (q <= m_q.front())
348 return m_J_L_q.
atc(std::size_t(L), 0);
350 return m_J_L_q.
atc(std::size_t(L), m_q.size() - 1);
353 const auto it = std::lower_bound(m_q.begin() + 1, m_q.end() - 1, q);
354 const auto i = std::size_t(std::distance(m_q.begin(), it)) - 1;
359 const double logq = std::log10(q);
360 const double logq0 = std::log10(m_q[i]);
361 const double logq1 = std::log10(m_q[i + 1]);
362 const double t = (logq - logq0) / (logq1 - logq0);
364 const auto &v0 = m_J_L_q.
atc(std::size_t(L), i);
365 const auto &v1 = m_J_L_q.
atc(std::size_t(L), i + 1);
368 return (1.0 - t) * v0 + t * v1;
375 std::vector<double> m_q{};
Matrix class; row-major.
Definition Matrix.hpp:39
const T & atc(std::size_t row_i, std::size_t col_j) const
const ref () index access (with range checking). (i,j) ith row, jth col
Definition Matrix.hpp:146
std::size_t cols() const
Return columns [minor index size].
Definition Matrix.hpp:114
void resize(std::size_t rows, std::size_t cols)
Resizes matrix to new dimension; all values reset to default.
Definition Matrix.hpp:96
Spherical Bessel Lookup table; in the form j_L(qr) = J[L][q][r].
Definition SphericalBessel.hpp:259
const std::vector< double > & jL_nearest(int L, double q) const
Returns jL(q_i*r) for the grid point q_i nearest to the requested q.
Definition SphericalBessel.hpp:303
const std::vector< double > & at(std::size_t L, std::size_t iq) const
Direct access to jL(q*r) for specific q grid index.
Definition SphericalBessel.hpp:288
const std::vector< double > & jL_on_qr_nearest(int L, double q) const
Returns jL(q_i*r)/(q_i*r) for the grid point q_i nearest to the requested q.
Definition SphericalBessel.hpp:323
const std::vector< double > & jL(int L, double q) const
Returns jL(q_i*r) for the first grid point q_i such that q_i >= q.
Definition SphericalBessel.hpp:294
std::vector< double > jL_interp(int L, double q) const
Returns jL(q*r) interpolated linearly between grid points. nb: assumes q grid dense enough that linea...
Definition SphericalBessel.hpp:344
void fill(int max_L, const std::vector< double > &q, const std::vector< double > &r)
If derivatives required for degree L, max_L = L+1.
Definition SphericalBessel.hpp:268
Wrappers for returning Spherical Bessel functions.
Definition SphericalBessel.cpp:7
double PsiL(int L, double x, bool tilde)
Psi_L(x) = [x^{L+1} / (2L-1)!!] * y_L(x). If tilde=true, returns 1 - Psi_L(x)
Definition SphericalBessel.cpp:253
double exactGSL_JL(int L, double x)
Spherical Bessel function of first kind via GSL.
Definition SphericalBessel.cpp:93
double PhiL(int L, double x, bool tilde)
Phi_L(x) = [(2L+1)!! / x^L] * j_L(x). If tilde=true, returns 1 - Phi_L(x)
Definition SphericalBessel.cpp:199
double yL(int L, double x)
Used for frequency-dependent Breit - more generic formula that can be used to evaluate spherical Bess...
Definition SphericalBessel.cpp:99
double exactGSL_YL(int L, double x)
Spherical Bessel functions of second kind.
Definition SphericalBessel.cpp:96
double jL(int L, double x)
Spherical Bessel function; uses low-x approximation where appropriate.
Definition SphericalBessel.cpp:10
std::vector< double > fillBesselVec(int l, const std::vector< double > &xvec)
Spherical Bessel functions of second kind.
Definition SphericalBessel.cpp:302
Operator overloads for std::vector.
Definition Vector.hpp:503