1#ifndef VIENNASHE_MATH_SPHERICAL_HARMONICS_HPP
2#define VIENNASHE_MATH_SPHERICAL_HARMONICS_HPP
45 for (
long i=n; i>1; --i)
74 log::info<log_AssocLegendre>() <<
"AssocLegendre() with n=" << n_ <<
", m=" << m_ << std::endl;
77 return doublefactorial(2*n_ - 1) * pow(sqrt(1.0 - x*x), n_) * ( (n_ % 2 == 0) ? 1.0 : -1.0);
78 else if (m_ == (n_ - 1))
82 log::error() <<
"Error in AssocLegendre: n<m" << std::endl;
87 - (n_ + m_ - 1.0) *
AssocLegendre(n_ - 2, m_)(x) ) / (n_ - m_);
103 const double pi = 3.1415926535897932384626433832795;
104 normalisation = sqrt( (2.0*n_ + 1.0) *
factorial(n_ - abs(m_)) / (2.0 * pi *
factorial(n_ + abs(m_))));
110 return normalisation *
AssocLegendre(n_, m_)(cos(theta)) * cos(m_ * phi);
112 return normalisation *
AssocLegendre(n_, 0)(cos(theta)) / sqrt(2.0);
114 return normalisation *
AssocLegendre(n_, -m_)(cos(theta)) * sin(m_ * phi);
118 double normalisation;
138 double sum1 = n_ * cos(theta) * Y_n_m(theta, phi);
139 double sum2 = sqrt( (n_*n_ - m_*m_) * (2.0*n_ + 1.0) / (2.0*n_ - 1.0) ) * Y_n_1_m(theta, phi);
142 return ( sum1 - sum2 ) / sin(theta);
166 const double pi = 3.1415926535897932384626433832795;
167 double normalisation = sqrt( (2.0*n_ + 1.0) *
factorial(n_ - abs(m_)) / (2.0 * pi *
factorial(n_ + abs(m_))));
169 double dP_dtheta = n_ * cos(theta) *
AssocLegendre(n_, abs(m_))(cos(theta)) ;
171 dP_dtheta -= (n_ + abs(m_)) *
AssocLegendre(n_-1, abs(m_))(cos(theta));
172 dP_dtheta /= sin(theta);
175 return normalisation * dP_dtheta * cos(m_ * phi);
177 return normalisation * dP_dtheta / sqrt(2.0);
179 return normalisation * dP_dtheta * sin(m_ * phi);
220 iter_type_(it_type) {}
Associated Legendre polynomial.
double operator()(double x) const
AssocLegendre(long n, long m)
Derivative of a spherical harmonic with respect to phi.
SphericalHarmonic_dPhi(int n, int m)
double operator()(double theta, double phi) const
Derivative of a spherical harmonic with respect to theta, alternative evaluation of theta-derivative.
double operator()(double theta, double phi) const
SphericalHarmonic_dTheta_2(int n, int m)
Derivative of a spherical harmonic with respect to theta.
SphericalHarmonic_dTheta(int n, int m)
double operator()(double theta, double phi) const
SphericalHarmonic(int n, int m)
double operator()(double theta, double phi) const
Iteration over all spherical harmonics indices up to order L, with increasing indices l and m.
spherical_harmonics_iterator(long Lmax, harmonics_iteration_type it_type)
Contains forward declarations and definition of small classes that must be defined at an early stage.
A logging facility providing fine-grained control over logging in ViennaSHE.
logger< true > error()
Used to log errors. The logging level is logERROR.
harmonics_iteration_type
An enumeration of spherical harmonics types (all, even, odd) ViennaSHE supports.
@ ALL_HARMONICS_ITERATION_ID
@ EVEN_HARMONICS_ITERATION_ID
@ ODD_HARMONICS_ITERATION_ID
double factorial(long n)
Compute the factorial.
double doublefactorial(long n)
Compute the double factorial, i.e. n(n-2)(n-4)...
The main ViennaSHE namespace. All functionality resides inside this namespace.
Defines the log keys used within the viennashe::math namespace.