sphericalHarmonics Namespace Reference

Functions

NumericalVector associatedLegendrePolynomials (int n, Mdouble x)
 
NumericalVector< std::complex< Mdouble > > sphericalHarmonics (int p, Mdouble theta, Mdouble phi)
 
NumericalVector computeSquaredFactorialValues (int p)
 

Function Documentation

◆ associatedLegendrePolynomials()

NumericalVector sphericalHarmonics::associatedLegendrePolynomials ( int  n,
Mdouble  x 
)
402 {
403  //Given n and m, we only have to compute P_n^(|m|)
404  //The function will return all these P values for theta
405  std::size_t nTerms = 0.5 * (n + 1) * (n + 2);
406  NumericalVector<> polynomials(nTerms);
407 
408  size_t location_current;
409  size_t location_previous;
410  Mdouble temp;
411 
412  polynomials(0) = 1; //P_0^0 = 1;
413  for (int l = 1; l <= n; l++)
414  {
415  //first compute P_l^l
416  location_current = 0.5 * (l + 1) * (l + 2) - 1;
417  location_previous = location_current - (l + 1);
418  polynomials(location_current) = -(2.0 * (l - 1.0) + 1.0) * std::sqrt(1.0 - x * x) *
419  polynomials(location_previous); // Recursive formula from wiki
420 
421  //second, compute P_l^(l-1) based on P_(l-1)^(l-1)
422  polynomials(location_current - 1) =
423  x * (2.0 * (l - 1) + 1) * polynomials(location_previous); // Recursive formula from wiki
424  }
425 
426  //thirdly, compute other values
427  for (int l = 2; l <= n; l++)
428  {
429  for (int m = (l - 2); m >= 0; m--)
430  {
431  location_current = (0.5 * (l + 1) * (l + 2) - 1) - l + m;
432  temp = polynomials(location_current + 2) +
433  2.0 * (m + 1) * x / sqrt(1 - x * x) * polynomials(location_current + 1);
434  polynomials(location_current) = temp / ((m - l) * (l + m + 1)); // variation on greengard eqn 3.34 from wiki
435  }
436  }
437 
438 
439  return polynomials;
440 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
double Mdouble
Definition: GeneralDefine.h:34
Definition: NumericalVector.h:64

References n.

Referenced by sphericalHarmonics().

◆ computeSquaredFactorialValues()

NumericalVector sphericalHarmonics::computeSquaredFactorialValues ( int  p)
474 {
475  std::size_t nTerms = 0.5 * (p + 1) * (2 * p + 2);
476  NumericalVector<> squaredFactorials(nTerms);
477 
478  for (int n = 0; n <= p; n++)
479  {
480  for (int m = -n; m <= n; m++)
481  {
482  std::size_t location = n * n + (m + n); //(n^2 is begin of Y_n)
483  int fact1 = mathsFunc::factorial(n - m);
484  int fact2 = mathsFunc::factorial(n + m);
485  Mdouble fact = fact1 * fact2;
486  squaredFactorials(location) = std::pow(-1.0, n) / std::sqrt(fact);
487  }
488  }
489 
490  return squaredFactorials;
491 }
constexpr T factorial(const T t)
factorial function
Definition: ExtendedMath.h:155

References mathsFunc::factorial(), and n.

◆ sphericalHarmonics()

NumericalVector< std::complex< Mdouble > > sphericalHarmonics::sphericalHarmonics ( int  p,
Mdouble  theta,
Mdouble  phi 
)
446 {
447  std::size_t nTerms = 0.5 * (p + 1) * (2 * p + 2);
450 
451  //Compute the spherical harmonics
452  for (int n = 0; n <= p; n++)
453  {
454  for (int mt = -n; mt <= n; mt++)
455  {
456  Mdouble m = mt;
457  Mdouble m_abs = std::abs(mt);
458  std::size_t location_current = n * n + (m + n); //n^2 is begin of Y_n^-n
459  std::size_t location_polynomial = 0.5 * n * (n + 1) + m_abs;
460  int fact1 = mathsFunc::factorial(n - m_abs);
461  int fact2 = mathsFunc::factorial(n + m_abs);
462  Mdouble fact = 1.0 * fact1 / fact2;
463  std::complex<Mdouble> value =
464  std::sqrt(fact) * polynomials(location_polynomial) * std::exp(constants::i * m * phi);
465  Y(location_current) = value;
466  }
467  }
468  return Y;
469 }
@ Y
Definition: StatisticsVector.h:42
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:64
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:84
NumericalVector associatedLegendrePolynomials(int n, Mdouble x)
Definition: ExtendedMath.cc:401

References associatedLegendrePolynomials(), mathsFunc::cos(), mathsFunc::exp(), mathsFunc::factorial(), constants::i, n, and Y.

Referenced by Multipole::convertMultipoleToLocal(), LocalExpansion::translateLocalExpansion(), and Multipole::TranslateMultipoleExpansionTo().