2#include "LinAlg/Matrix.hpp"
3#include "qip/Maths.hpp"
4#include "qip/Vector.hpp"
18double jL(
int L,
double x);
29double yL(
int L,
double x);
32double PhiL(
int L,
double x,
bool tilde =
false);
35double PsiL(
int L,
double x,
bool tilde =
false);
76std::vector<double>
fillBesselVec(
int l,
const std::vector<double> &xvec,
77 bool cell_average =
true);
98 const std::vector<double> &rvec,
99 bool cell_average =
true);
113 std::vector<double> *jl,
bool cell_average =
true);
130 const std::vector<double> &r,
bool cell_average =
true) {
131 fill(max_L, q, r, cell_average);
136 void fill(
int max_L,
const std::vector<double> &q,
137 const std::vector<double> &r,
bool cell_average =
true) {
139 m_J_L_q.
resize(std::size_t(max_L + 1), q.size());
140 m_J_L_q_on_qr.
resize(std::size_t(max_L + 1), q.size());
142#pragma omp parallel for collapse(2)
143 for (
auto L = 0ul; L <= std::size_t(max_L); ++L) {
144 for (
auto iq = 0ul; iq < m_J_L_q.
cols(); ++iq) {
145 const auto tq = q[iq];
149 m_J_L_q_on_qr[L][iq] = m_J_L_q[L][iq] / (tq * r);
156 const std::vector<double> &
at(std::size_t L, std::size_t iq)
const {
157 return m_J_L_q.
atc(L, iq);
162 const std::vector<double> &
jL(
int L,
double q)
const {
164 const auto it = std::lower_bound(m_q.begin(), m_q.end() - 1, q);
165 const auto iq = std::size_t(std::distance(m_q.begin(), it));
166 return m_J_L_q.
atc(std::size_t(L), iq);
171 const std::vector<double> &
jL_nearest(
int L,
double q)
const {
174 if (q <= m_q.front())
175 return m_J_L_q.
atc(std::size_t(L), 0);
177 return m_J_L_q.
atc(std::size_t(L), m_q.size() - 1);
180 const auto it = std::lower_bound(m_q.begin() + 1, m_q.end() - 1, q);
181 const auto i = std::size_t(std::distance(m_q.begin(), it)) - 1;
184 const auto iq = (q - m_q[i] < m_q[i + 1] - q) ? i : i + 1;
186 return m_J_L_q.
atc(std::size_t(L), iq);
194 if (q <= m_q.front())
195 return m_J_L_q_on_qr.
atc(std::size_t(L), 0);
197 return m_J_L_q_on_qr.
atc(std::size_t(L), m_q.size() - 1);
200 const auto it = std::lower_bound(m_q.begin() + 1, m_q.end() - 1, q);
201 const auto i = std::size_t(std::distance(m_q.begin(), it)) - 1;
204 const auto iq = (q - m_q[i] < m_q[i + 1] - q) ? i : i + 1;
206 return m_J_L_q_on_qr.
atc(std::size_t(L), iq);
215 if (q <= m_q.front())
216 return m_J_L_q.
atc(std::size_t(L), 0);
218 return m_J_L_q.
atc(std::size_t(L), m_q.size() - 1);
221 const auto it = std::lower_bound(m_q.begin() + 1, m_q.end() - 1, q);
222 const auto i = std::size_t(std::distance(m_q.begin(), it)) - 1;
227 const double logq = std::log10(q);
228 const double logq0 = std::log10(m_q[i]);
229 const double logq1 = std::log10(m_q[i + 1]);
230 const double t = (logq - logq0) / (logq1 - logq0);
232 const auto &v0 = m_J_L_q.
atc(std::size_t(L), i);
233 const auto &v1 = m_J_L_q.
atc(std::size_t(L), i + 1);
236 return (1.0 - t) * v0 + t * v1;
243 std::vector<double> m_q{};
Row-major dense matrix with arithmetic and linear algebra support.
Definition Matrix.hpp:209
const T & atc(std::size_t row_i, std::size_t col_j) const
at(i,j): element access with range checking, const ref
Definition Matrix.hpp:315
std::size_t cols() const
Return columns [minor index size].
Definition Matrix.hpp:284
void resize(std::size_t rows, std::size_t cols)
Resizes matrix to new dimension; all values reset to default.
Definition Matrix.hpp:266
Lookup table of spherical Bessel functions: j_L(q*r) = J[L][q][r].
Definition SphericalBessel.hpp:124
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:171
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:156
void fill(int max_L, const std::vector< double > &q, const std::vector< double > &r, bool cell_average=true)
If derivatives required for degree L, max_L = L+1. cell_average is forwarded to fillBesselVec_kr (see...
Definition SphericalBessel.hpp:136
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:191
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:162
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:212
JL_table()
Default construct empty table; must call fill() before use.
Definition SphericalBessel.hpp:127
JL_table(int max_L, const std::vector< double > &q, const std::vector< double > &r, bool cell_average=true)
Construct and fill the table; equivalent to default-construct + fill()
Definition SphericalBessel.hpp:129
Spherical Bessel functions j_L(x) and y_L(x), and related utilities.
Definition SphericalBessel.cpp:9
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:264
double exactGSL_JL(int L, double x)
Spherical Bessel function of first kind via GSL.
Definition SphericalBessel.cpp:98
std::vector< double > fillBesselVec_kr(int l, double k, const std::vector< double > &rvec, bool cell_average)
As fillBesselVec, with the argument of j_L being k*r instead of x.
Definition SphericalBessel.cpp:386
std::vector< double > fillBesselVec(int l, const std::vector< double > &xvec, bool cell_average)
Fills a vector with the spherical Bessel function j_L sampled on the supplied grid; oscillation-resol...
Definition SphericalBessel.cpp:378
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:207
double yL(int L, double x)
Spherical Bessel function of second kind, y_L(x)
Definition SphericalBessel.cpp:104
double exactGSL_YL(int L, double x)
Spherical Bessel functions of second kind.
Definition SphericalBessel.cpp:101
double jL(int L, double x)
Spherical Bessel function j_L(x); uses low-x approximation where appropriate.
Definition SphericalBessel.cpp:12
Operator overloads for std::vector.
Definition Vector.hpp:503