00001 #ifndef SCOTTUTILS_YLM_CC__
00002 #define SCOTTUTILS_YLM_CC__
00003 #include "sf.h"
00004 #include "utils.h"
00005
00006 using namespace std;
00007
00008 double SpherHarmonics::legendre(int ell,double ctheta){
00009 double answer;
00010
00011 if(ctheta>1.0) ctheta=1.0;
00012 if(ctheta<-1.0) ctheta=-1.0;
00013 return gsl_sf_legendre_Pl(ell,ctheta);
00014 }
00015
00016 complex<double> SpherHarmonics::Ylm(int ell, int m, double theta, double phi){
00017 double ctheta;
00018 complex<double> answer;
00019 complex<double> ci(0.0,1.0);
00020 ctheta=cos(theta);
00021 answer=gsl_sf_legendre_sphPlm(ell,abs(m),ctheta)*Misc::ceiphi(static_cast<double>(m)*phi);
00022 if(m<0) answer *= NEGONE_TO_THE(abs(m));
00023 return answer;
00024 }
00025
00026 complex<double> SpherHarmonics::Ylm(int ell, int m, double x, double y, double z){
00027 complex<double> answer;
00028 double ctheta,phi;
00029 double r = sqrt(x*x+y*y+z*z);
00030 if ( r < 1e-10 || fabs(z) < 1e-10 ) ctheta = 0.0;
00031 else ctheta=z/r;
00032 phi=atan2(y,x);
00033 answer=gsl_sf_legendre_sphPlm(ell,abs(m),ctheta)*Misc::ceiphi(static_cast<double>(m)*phi);
00034 if(m<0) answer *= NEGONE_TO_THE(abs(m));
00035 return answer;
00036 }
00037
00038 double SpherHarmonics::ReYlm(int ell, int m, double theta, double phi){
00039 return real(SpherHarmonics::Ylm(ell,m,theta,phi));
00040 }
00041
00042 double SpherHarmonics::ImYlm(int ell, int m, double theta, double phi){
00043 return imag(SpherHarmonics::Ylm(ell,m,theta,phi));
00044 }
00045
00046 double SpherHarmonics::ReYlm(int ell, int m, double x,double y,double z){
00047 return real(SpherHarmonics::Ylm(ell,m,x,y,z));
00048 }
00049
00050 double SpherHarmonics::ImYlm(int ell, int m, double x,double y,double z){
00051 return imag(SpherHarmonics::Ylm(ell,m,x,y,z));
00052 }
00053
00054 #endif