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 
)
381 {
382  //Given n and m, we only have to compute P_n^(|m|)
383  //The function will return all these P values for theta
384  std::size_t nTerms = 0.5 * (n + 1) * (n + 2);
385  NumericalVector<> polynomials(nTerms);
386 
387  size_t location_current;
388  size_t location_previous;
389  Mdouble temp;
390 
391  polynomials(0) = 1; //P_0^0 = 1;
392  for (int l = 1; l <= n; l++)
393  {
394  //first compute P_l^l
395  location_current = 0.5 * (l + 1) * (l + 2) - 1;
396  location_previous = location_current - (l + 1);
397  polynomials(location_current) = -(2.0 * (l - 1.0) + 1.0) * std::sqrt(1.0 - x * x) *
398  polynomials(location_previous); // Recursive formula from wiki
399 
400  //second, compute P_l^(l-1) based on P_(l-1)^(l-1)
401  polynomials(location_current - 1) =
402  x * (2.0 * (l - 1) + 1) * polynomials(location_previous); // Recursive formula from wiki
403  }
404 
405  //thirdly, compute other values
406  for (int l = 2; l <= n; l++)
407  {
408  for (int m = (l - 2); m >= 0; m--)
409  {
410  location_current = (0.5 * (l + 1) * (l + 2) - 1) - l + m;
411  temp = polynomials(location_current + 2) +
412  2.0 * (m + 1) * x / sqrt(1 - x * x) * polynomials(location_current + 1);
413  polynomials(location_current) = temp / ((m - l) * (l + m + 1)); // variation on greengard eqn 3.34 from wiki
414  }
415  }
416 
417 
418  return polynomials;
419 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Definition: NumericalVector.h:44
int * m
Definition: level2_cplx_impl.h:294
list x
Definition: plotDoE.py:28

References m, n, sqrt(), and plotDoE::x.

Referenced by sphericalHarmonics().

◆ computeSquaredFactorialValues()

NumericalVector sphericalHarmonics::computeSquaredFactorialValues ( int  p)
453 {
454  std::size_t nTerms = 0.5 * (p + 1) * (2 * p + 2);
455  NumericalVector<> squaredFactorials(nTerms);
456 
457  for (int n = 0; n <= p; n++)
458  {
459  for (int m = -n; m <= n; m++)
460  {
461  std::size_t location = n * n + (m + n); //(n^2 is begin of Y_n)
462  int fact1 = mathsFunc::factorial(n - m);
463  int fact2 = mathsFunc::factorial(n + m);
464  Mdouble fact = fact1 * fact2;
465  squaredFactorials(location) = std::pow(-1.0, n) / std::sqrt(fact);
466  }
467  }
468 
469  return squaredFactorials;
470 }
float * p
Definition: Tutorial_Map_using.cpp:9
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625
constexpr T factorial(const T t)
factorial function
Definition: ExtendedMath.h:135

References mathsFunc::factorial(), m, n, p, Eigen::bfloat16_impl::pow(), and sqrt().

◆ sphericalHarmonics()

NumericalVector< std::complex< Mdouble > > sphericalHarmonics::sphericalHarmonics ( int  p,
Mdouble  theta,
Mdouble  phi 
)
425 {
426  std::size_t nTerms = 0.5 * (p + 1) * (2 * p + 2);
429 
430  //Compute the spherical harmonics
431  for (int n = 0; n <= p; n++)
432  {
433  for (int mt = -n; mt <= n; mt++)
434  {
435  Mdouble m = mt;
436  Mdouble m_abs = std::abs(mt);
437  std::size_t location_current = n * n + (m + n); //n^2 is begin of Y_n^-n
438  std::size_t location_polynomial = 0.5 * n * (n + 1) + m_abs;
439  int fact1 = mathsFunc::factorial(n - m_abs);
440  int fact2 = mathsFunc::factorial(n + m_abs);
441  Mdouble fact = 1.0 * fact1 / fact2;
442  std::complex<Mdouble> value =
443  std::sqrt(fact) * polynomials(location_polynomial) * std::exp(constants::i * m * phi);
444  Y(location_current) = value;
445  }
446  }
447  return Y;
448 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
double theta
Definition: two_d_biharmonic.cc:236
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16 &a)
Definition: BFloat16.h:615
squared absolute value
Definition: GlobalFunctions.h:87
const std::complex< Mdouble > i
Definition: ExtendedMath.h:31
NumericalVector associatedLegendrePolynomials(int n, Mdouble x)
Definition: ExtendedMath.cc:380
const char Y
Definition: test/EulerAngles.cpp:32

References abs(), associatedLegendrePolynomials(), cos(), Eigen::bfloat16_impl::exp(), mathsFunc::factorial(), constants::i, m, n, p, sqrt(), BiharmonicTestFunctions2::theta, Eigen::value, and Y.

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