10 #include <gsl/gsl_sf.h>
13 std::complex<double> StHbtYlm::Ceiphi(
double phi)
15 return ( std::complex<double>( cos(phi), sin(phi) ) );
18 double StHbtYlm::Legendre(
int ell,
double ctheta)
20 return ( gsl_sf_legendre_Pl(ell, ctheta) );
23 std::complex<double> StHbtYlm::Ylm(
int ell,
int m,
double theta,
double phi)
26 std::complex<double> answer;
27 std::complex<double> ci(0.0, 1.0);
29 answer = gsl_sf_legendre_sphPlm(ell, abs(m), ctheta) * Ceiphi(m * phi);
31 if (abs(m) % 2) answer *= -1.0;
36 std::complex<double> StHbtYlm::Ylm(
int ell,
int m,
double x,
double y,
double z)
38 std::complex<double> answer;
40 double r = sqrt(x * x + y * y + z * z);
41 if ( r < 1e-10 || fabs(z) < 1e-10 ) ctheta = 0.0;
44 answer = gsl_sf_legendre_sphPlm(ell, abs(m), ctheta) * Ceiphi(m * phi);
46 if (abs(m) % 2) answer *= -1.0;
51 void StHbtYlm::YlmUpToL(
int lmax,
double x,
double y,
double z, std::complex<double>* ylms)
53 std::complex<double> answer;
61 double r = sqrt(x * x + y * y + z * z);
62 if ( r < 1e-10 || fabs(z) < 1e-10 ) ctheta = 0.0;
66 for (
int iter = 1; iter <= lmax; iter++) {
67 coss[iter - 1] = cos(iter * phi);
68 sins[iter - 1] = sin(iter * phi);
70 ylms[lcur++] = gsl_sf_legendre_sphPlm(0, 0, ctheta) * std::complex<double>(1, 0);
72 for (
int il = 1; il <= lmax; il++) {
73 for (
int im = 0; im <= il; im++) {
74 lpol = gsl_sf_legendre_sphPlm(il, im, ctheta);
76 ylms[lcur + il + im] = lpol * std::complex<double>(coss[im - 1], sins[im - 1]);
78 ylms[lcur + il - im] = -lpol* std::complex<double>(coss[im - 1], -sins[im - 1]);
80 ylms[lcur + il - im] = lpol * std::complex<double>(coss[im - 1], -sins[im - 1]);
83 ylms[lcur + il] = lpol * std::complex<double>(1, 0);
90 void StHbtYlm::YlmUpToL(
int lmax,
double ctheta,
double phi, std::complex<double>* ylms)
98 for (
int iter = 1; iter <= lmax; iter++) {
99 coss[iter - 1] = cos(iter * phi);
100 sins[iter - 1] = sin(iter * phi);
102 ylms[lcur++] = gsl_sf_legendre_sphPlm(0, 0, ctheta) * std::complex<double>(1, 0);
104 for (
int il = 1; il <= lmax; il++) {
105 for (
int im = 0; im <= il; im++) {
106 lpol = gsl_sf_legendre_sphPlm(il, im, ctheta);
108 ylms[lcur + il + im] = lpol * std::complex<double>(coss[im - 1], sins[im - 1]);
110 ylms[lcur + il - im] = -lpol* std::complex<double>(coss[im - 1], -sins[im - 1]);
112 ylms[lcur + il - im] = lpol * std::complex<double>(coss[im - 1], -sins[im - 1]);
115 ylms[lcur + il] = lpol * std::complex<double>(1, 0);
122 double StHbtYlm::ReYlm(
int ell,
int m,
double theta,
double phi)
124 return ( real( StHbtYlm::Ylm(ell, m, theta, phi) ) );
127 double StHbtYlm::ImYlm(
int ell,
int m,
double theta,
double phi)
129 return ( imag( StHbtYlm::Ylm(ell, m, theta, phi) ) );
132 double StHbtYlm::ReYlm(
int ell,
int m,
double x,
double y,
double z)
134 return ( real( StHbtYlm::Ylm(ell, m, x, y, z) ) );
137 double StHbtYlm::ImYlm(
int ell,
int m,
double x,
double y,
double z)
139 return ( imag( StHbtYlm::Ylm(ell, m, x, y, z) ) );