[729] | 1 | #include "lambdaBuilder.h"
|
---|
| 2 | #include "nbconst.h"
|
---|
| 3 |
|
---|
| 4 |
|
---|
[1218] | 5 | /*!
|
---|
| 6 | \class SOPHYA::Legendre
|
---|
| 7 | generate Legendre polynomials : use in two steps :
|
---|
| 8 |
|
---|
| 9 | a) instanciate Legendre(\f$x\f$, \f$lmax\f$) ; \f$x\f$ is the value for wich Legendre polynomials will be required (usually equal to \f$\cos \theta\f$) and \f$lmax\f$ is the MAXIMUM value of the order of polynomials wich will be required in the following code (all polynomials, from \f$l=0 to lmax\f$, are computed once for all by an iterative formula).
|
---|
| 10 |
|
---|
| 11 | b) get the value of Legendre polynomial for a particular value of \f$l\f$ by calling the method getPl.
|
---|
| 12 |
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 |
|
---|
[729] | 16 | Legendre::Legendre(r_8 x, int_4 lmax)
|
---|
| 17 | {
|
---|
[1428] | 18 | if (fabs(x) > 1. )
|
---|
[729] | 19 | {
|
---|
| 20 | throw RangeCheckError("variable for Legendre polynomials must have modules inferior to 1" );
|
---|
| 21 | }
|
---|
| 22 | x_ = x;
|
---|
| 23 | array_init(lmax);
|
---|
| 24 | }
|
---|
[1218] | 25 |
|
---|
| 26 | /*! \fn void SOPHYA::Legendre::array_init(int_4 lmax)
|
---|
| 27 |
|
---|
| 28 | compute all \f$P_l(x,l_{max})\f$ for \f$l=1,l_{max}\f$
|
---|
| 29 | */
|
---|
[729] | 30 | void Legendre::array_init(int_4 lmax)
|
---|
| 31 | {
|
---|
| 32 | lmax_ = lmax;
|
---|
| 33 | Pl_.ReSize(lmax_+1);
|
---|
| 34 | Pl_(0)=1.;
|
---|
| 35 | Pl_(1)=x_;
|
---|
| 36 | for (int k=2; k<Pl_.NElts(); k++)
|
---|
| 37 | {
|
---|
| 38 | Pl_(k) = ( (2.*k-1)*x_*Pl_(k-1)-(k-1)*Pl_(k-2) )/k;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[1756] | 42 | TriangularMatrix<r_8> LambdaLMBuilder::a_recurrence_ = TriangularMatrix<r_8>();
|
---|
| 43 | TriangularMatrix<r_8> LambdaLMBuilder::lam_fact_ = TriangularMatrix<r_8>();
|
---|
[729] | 44 | TVector<r_8>* LambdaLMBuilder::normal_l_ = NULL;
|
---|
| 45 |
|
---|
[1218] | 46 |
|
---|
| 47 |
|
---|
| 48 | /*! \class SOPHYA::LambdaLMBuilder
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | This class generate the coefficients :
|
---|
| 52 | \f[
|
---|
| 53 | \lambda_l^m=\sqrt{\frac{2l+1}{4\pi}\frac{(l-m)!}{(l+m)!}}
|
---|
| 54 | P_l^m(\cos{\theta})
|
---|
| 55 | \f]
|
---|
| 56 | where \f$P_l^m\f$ are the associated Legendre polynomials. The above coefficients contain the theta-dependance of spheric harmonics :
|
---|
| 57 | \f[
|
---|
| 58 | Y_{lm}(\cos{\theta})=\lambda_l^m(\cos{\theta}) e^{im\phi}.
|
---|
| 59 | \f]
|
---|
| 60 |
|
---|
| 61 | Each object has a fixed theta (radians), and maximum l and m to be calculated
|
---|
| 62 | (lmax and mmax).
|
---|
| 63 | use the class in two steps :
|
---|
| 64 | a) instanciate LambdaLMBuilder(\f$\theta\f$, \f$lmax\f$, \f$mmax\f$) ; \f$lmax\f$ and \f$mmax\f$ are MAXIMUM values for which \f$\lambda_l^m\f$ will be required in the following code (all coefficients, from \f$l=0 to lmax\f$, are computed once for all by an iterative formula).
|
---|
| 65 | b) get the values of coefficients for particular values of \f$l\f$ and \f$m\f$ by calling the method lamlm.
|
---|
| 66 | */
|
---|
| 67 |
|
---|
| 68 |
|
---|
[729] | 69 | LambdaLMBuilder::LambdaLMBuilder(r_8 theta,int_4 lmax, int_4 mmax)
|
---|
| 70 | {
|
---|
| 71 | cth_=cos(theta);
|
---|
| 72 | sth_=sin(theta);
|
---|
| 73 | array_init(lmax, mmax);
|
---|
| 74 | }
|
---|
[1683] | 75 | LambdaLMBuilder::LambdaLMBuilder(r_8 costet, r_8 sintet,int_4 lmax, int_4 mmax)
|
---|
| 76 | {
|
---|
| 77 | cth_=costet;
|
---|
| 78 | sth_=sintet;
|
---|
| 79 | array_init(lmax, mmax);
|
---|
| 80 | }
|
---|
[729] | 81 | void LambdaLMBuilder::array_init(int lmax, int mmax)
|
---|
| 82 | {
|
---|
[1756] | 83 | if (a_recurrence_.Size() == 0)
|
---|
[729] | 84 | {
|
---|
[1756] | 85 | // a_recurrence_ = new TriangularMatrix<r_8>;
|
---|
[729] | 86 | updateArrayRecurrence(lmax);
|
---|
| 87 | }
|
---|
| 88 | else
|
---|
[1756] | 89 | if ( lmax > (a_recurrence_).rowNumber()-1 )
|
---|
[729] | 90 | {
|
---|
| 91 | cout << " WARNING : The classes LambdaXXBuilder will be more efficient if instanciated with parameter lmax = maximum value of l index which will be needed in the whole application (arrays not recomputed) " << endl;
|
---|
[1756] | 92 | cout << "lmax= " << lmax << " previous instanciation with lmax= " << (a_recurrence_).rowNumber() << endl;
|
---|
[729] | 93 | updateArrayRecurrence(lmax);
|
---|
| 94 | }
|
---|
| 95 | lmax_=lmax;
|
---|
| 96 | mmax_=mmax;
|
---|
| 97 | r_8 bignorm2 = 1.e268; // = 1e-20*1.d288
|
---|
| 98 |
|
---|
| 99 | lambda_.ReSizeRow(lmax_+1);
|
---|
| 100 |
|
---|
| 101 | r_8 lam_mm = 1. / sqrt(4.*Pi) *bignorm2;
|
---|
| 102 |
|
---|
| 103 | for (int m=0; m<=mmax_;m++)
|
---|
| 104 | {
|
---|
| 105 |
|
---|
| 106 |
|
---|
| 107 | lambda_(m,m)= lam_mm / bignorm2;
|
---|
| 108 |
|
---|
| 109 | r_8 lam_0=0.;
|
---|
| 110 | r_8 lam_1=1. /bignorm2 ;
|
---|
| 111 | // r_8 a_rec = LWK->a_recurr(m,m);
|
---|
[1756] | 112 | r_8 a_rec = a_recurrence_(m,m);
|
---|
[729] | 113 | r_8 b_rec = 0.;
|
---|
| 114 | for (int l=m+1; l<=lmax_; l++)
|
---|
| 115 | {
|
---|
| 116 | r_8 lam_2 = (cth_*lam_1-b_rec*lam_0)*a_rec;
|
---|
| 117 | lambda_(l,m) = lam_2*lam_mm;
|
---|
| 118 | b_rec=1./a_rec;
|
---|
| 119 | // a_rec= LWK->a_recurr(l,m);
|
---|
[1756] | 120 | a_rec= a_recurrence_(l,m);
|
---|
[729] | 121 | lam_0 = lam_1;
|
---|
| 122 | lam_1 = lam_2;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | lam_mm = -lam_mm*sth_* sqrt( (2.*m+3.)/ (2.*m+2.) );
|
---|
| 126 |
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 |
|
---|
[1218] | 131 | /*! \fn void SOPHYA::LambdaLMBuilder::updateArrayRecurrence(int_4 lmax)
|
---|
| 132 |
|
---|
| 133 | compute a static array of coefficients independant from theta (common to all instances of the LambdaBuilder Class
|
---|
| 134 | */
|
---|
[729] | 135 | void LambdaLMBuilder::updateArrayRecurrence(int_4 lmax)
|
---|
| 136 | {
|
---|
[1756] | 137 | a_recurrence_.ReSizeRow(lmax+1);
|
---|
[729] | 138 | for (int m=0; m<=lmax;m++)
|
---|
| 139 | {
|
---|
[1756] | 140 | a_recurrence_(m,m) = sqrt( 2.*m +3.);
|
---|
[729] | 141 | for (int l=m+1; l<=lmax; l++)
|
---|
| 142 | {
|
---|
| 143 | r_8 fl2 = (l+1.)*(l+1.);
|
---|
[1756] | 144 | a_recurrence_(l,m)=sqrt( (4.*fl2-1.)/(fl2-m*m) );
|
---|
[729] | 145 | }
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[1218] | 149 | /*! \fn void SOPHYA::LambdaLMBuilder::updateArrayLamNorm()
|
---|
[729] | 150 |
|
---|
[1218] | 151 | compute static arrays of coefficients independant from theta (common to all instances of the derived classes
|
---|
| 152 | */
|
---|
[729] | 153 | void LambdaLMBuilder::updateArrayLamNorm()
|
---|
| 154 | {
|
---|
[1756] | 155 | lam_fact_.ReSizeRow(lmax_+1);
|
---|
[729] | 156 | for(int m = 0;m<= lmax_; m++)
|
---|
| 157 | {
|
---|
| 158 | for (int l=m; l<=lmax_; l++)
|
---|
| 159 | {
|
---|
[1756] | 160 | lam_fact_(l,m) =2.*(r_8)sqrt( (2.*l+1)*(l+m)*(l-m)/(2.*l-1) );
|
---|
[729] | 161 | }
|
---|
| 162 | }
|
---|
| 163 | (*normal_l_).ReSize(lmax_+1);
|
---|
| 164 | (*normal_l_)(0)=0.;
|
---|
| 165 | (*normal_l_)(1)=0.;
|
---|
| 166 | for (int l=2; l< (*normal_l_).NElts(); l++)
|
---|
| 167 | {
|
---|
| 168 | (*normal_l_)(l) =(r_8)sqrt( 2./( (l+2)*(l+1)*l*(l-1) ) );
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 |
|
---|
[1218] | 173 | /*! \class SOPHYA::LambdaWXBuilder
|
---|
[729] | 174 |
|
---|
[1218] | 175 | This class generates the coefficients :
|
---|
| 176 | \f[
|
---|
| 177 | _{w}\lambda_l^m=-2\sqrt{\frac{2(l-2)!}{(l+2)!}\frac{(2l+1)}{4\pi}\frac{(l-m)!}{(l+m)!}} G^+_{lm}
|
---|
| 178 | \f]
|
---|
| 179 | \f[
|
---|
| 180 | _{x}\lambda_l^m=-2\sqrt{\frac{2(l-2)!}{(l+2)!}\frac{(2l+1)}{4\pi}\frac{(l-m)!}{(l+m)!}}G^-_{lm}
|
---|
| 181 | \f]
|
---|
| 182 | where
|
---|
| 183 | \f[G^+_{lm}(\cos{\theta})=-\left( \frac{l-m^2}{\sin^2{\theta}}+\frac{1}{2}l\left(l-1\right)\right)P_l^m(\cos{\theta})+\left(l+m\right)\frac{\cos{\theta}}{\sin^2{\theta}}P^m_{l-1}(\cos{\theta})
|
---|
| 184 | \f]
|
---|
| 185 | and
|
---|
| 186 | \f[G^-_{lm}(\cos{\theta})=\frac{m}{\sin^2{\theta}}\left(\left(l-1\right)\cos{\theta}P^m_l(\cos{\theta})-\left(l+m\right)P^m_{l-1}(\cos{\theta})\right)
|
---|
| 187 | \f]
|
---|
| 188 | \f$P_l^m\f$ are the associated Legendre polynomials.
|
---|
[729] | 189 |
|
---|
[1218] | 190 | The coefficients express the theta-dependance of the \f$W_{lm}(\cos{\theta})\f$ and \f$X_{lm}(\cos{\theta})\f$ functions :
|
---|
| 191 | \f[W_{lm}(\cos{\theta}) = \sqrt{\frac{(l+2)!}{2(l-2)!}}_w\lambda_l^m(\cos{\theta})e^{im\phi}
|
---|
| 192 | \f]
|
---|
| 193 | \f[X_{lm}(\cos{\theta}) = -i\sqrt{\frac{(l+2)!}{2(l-2)!}}_x\lambda_l^m(\cos{\theta})e^{im\phi}
|
---|
| 194 | \f]
|
---|
| 195 | where \f$W_{lm}(\cos{\theta})\f$ and \f$X_{lm}(\cos{\theta})\f$ are defined as :
|
---|
| 196 |
|
---|
| 197 | \f[
|
---|
| 198 | W_{lm}(\cos{\theta})=-\frac{1}{2}\sqrt{\frac{(l+2)!}{(l-2)!}}\left(
|
---|
| 199 | _{+2}Y_l^m(\cos{\theta})+_{-2}Y_l^m(\cos{\theta})\right)
|
---|
| 200 | \f]
|
---|
| 201 | \f[X_{lm}(\cos{\theta})=-\frac{i}{2}\sqrt{\frac{(l+2)!}{(l-2)!}}\left(
|
---|
| 202 | _{+2}Y_l^m(\cos{\theta})-_{-2}Y_l^m(\cos{\theta})\right)
|
---|
| 203 | \f]
|
---|
| 204 |
|
---|
| 205 | */
|
---|
| 206 |
|
---|
| 207 |
|
---|
[729] | 208 | LambdaWXBuilder::LambdaWXBuilder(r_8 theta, int_4 lmax, int_4 mmax) : LambdaLMBuilder(theta, lmax, mmax)
|
---|
| 209 | {
|
---|
| 210 | array_init();
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 |
|
---|
| 214 | void LambdaWXBuilder::array_init()
|
---|
| 215 | {
|
---|
[1756] | 216 | if (lam_fact_.Size() < 1 || normal_l_ == NULL)
|
---|
[729] | 217 | {
|
---|
[1756] | 218 | // lam_fact_ = new TriangularMatrix<r_8>;
|
---|
[729] | 219 | normal_l_ = new TVector<r_8>;
|
---|
| 220 | updateArrayLamNorm();
|
---|
| 221 | }
|
---|
| 222 | else
|
---|
[1756] | 223 | if ( lmax_ > lam_fact_.rowNumber()-1 || lmax_ > (*normal_l_).NElts()-1 )
|
---|
[729] | 224 | {
|
---|
| 225 | updateArrayLamNorm();
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | r_8 one_on_s2 = 1. / (sth_*sth_) ; // 1/sin^2
|
---|
| 229 | r_8 c_on_s2 = cth_*one_on_s2;
|
---|
| 230 | lamWlm_.ReSizeRow(lmax_+1);
|
---|
| 231 | lamXlm_.ReSizeRow(lmax_+1);
|
---|
| 232 |
|
---|
| 233 | // calcul des lambda
|
---|
| 234 | for(int m = 0;m<= mmax_; m++)
|
---|
| 235 | {
|
---|
| 236 | for (int l=m; l<=lmax_; l++)
|
---|
| 237 | {
|
---|
| 238 | lamWlm_(l,m) = 0.;
|
---|
| 239 | lamXlm_(l,m) = 0.;
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
| 242 | for(int l = 2;l<= lmax_; l++)
|
---|
| 243 | {
|
---|
| 244 | r_8 normal_l = (*normal_l_)(l);
|
---|
| 245 | for (int m=0; m<=l; m++)
|
---|
| 246 | {
|
---|
| 247 | r_8 lam_lm1m = LambdaLMBuilder::lamlm(l-1,m);
|
---|
| 248 | r_8 lam_lm = LambdaLMBuilder::lamlm(l,m);
|
---|
[1756] | 249 | r_8 lam_fact_l_m = lam_fact_(l,m);
|
---|
[729] | 250 | r_8 a_w = 2. * (l - m*m) * one_on_s2 + l*(l-1.);
|
---|
| 251 | r_8 b_w = c_on_s2 * lam_fact_l_m;
|
---|
| 252 | r_8 a_x = 2. * cth_ * (l-1.);
|
---|
| 253 | lamWlm_(l,m) = normal_l * ( a_w * lam_lm - b_w * lam_lm1m );
|
---|
| 254 | lamXlm_(l,m) = - normal_l * m* one_on_s2* ( a_x * lam_lm - lam_fact_l_m * lam_lm1m );
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | }
|
---|
| 259 |
|
---|
[1218] | 260 | /*! \class SOPHYA::LambdaPMBuilder
|
---|
[729] | 261 |
|
---|
[1218] | 262 | This class generates the coefficients
|
---|
| 263 | \f[
|
---|
| 264 | _{\pm}\lambda_l^m=2\sqrt{\frac{(l-2)!}{(l+2)!}\frac{(2l+1)}{4\pi}\frac{(l-m)!}{(l+m)!}}\left( G^+_{lm} \mp G^-_{lm}\right)
|
---|
| 265 | \f]
|
---|
| 266 | where
|
---|
| 267 | \f[G^+_{lm}(\cos{\theta})=-\left( \frac{l-m^2}{\sin^2{\theta}}+\frac{1}{2}l\left(l-1\right)\right)P_l^m(\cos{\theta})+\left(l+m\right)\frac{\cos{\theta}}{\sin^2{\theta}}P^m_{l-1}(\cos{\theta})
|
---|
| 268 | \f]
|
---|
| 269 | and
|
---|
| 270 | \f[G^-_{lm}(\cos{\theta})=\frac{m}{\sin^2{\theta}}\left(\left(l-1\right)\cos{\theta}P^m_l(\cos{\theta})-\left(l+m\right)P^m_{l-1}(\cos{\theta})\right)
|
---|
| 271 | \f]
|
---|
| 272 | and \f$P_l^m\f$ are the associated Legendre polynomials.
|
---|
| 273 | The coefficients express the theta-dependance of the spin-2 spherical harmonics :
|
---|
| 274 | \f[_{\pm2}Y_l^m(\cos{\theta})=_\pm\lambda_l^m(\cos{\theta})e^{im\phi}
|
---|
| 275 | \f]
|
---|
| 276 | */
|
---|
| 277 |
|
---|
[729] | 278 | LambdaPMBuilder::LambdaPMBuilder(r_8 theta, int_4 lmax, int_4 mmax) : LambdaLMBuilder(theta, lmax, mmax)
|
---|
| 279 | {
|
---|
| 280 | array_init();
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 |
|
---|
| 284 | void LambdaPMBuilder::array_init()
|
---|
| 285 | {
|
---|
[1756] | 286 | if (lam_fact_.Size() < 1 || normal_l_ == NULL)
|
---|
[729] | 287 | {
|
---|
[1756] | 288 | // lam_fact_ = new TriangularMatrix<r_8>;
|
---|
[729] | 289 | normal_l_ = new TVector<r_8>;
|
---|
| 290 | updateArrayLamNorm();
|
---|
| 291 | }
|
---|
| 292 | else
|
---|
[1756] | 293 | if ( lmax_ > lam_fact_.rowNumber()-1 || lmax_ > (*normal_l_).NElts()-1 )
|
---|
[729] | 294 | {
|
---|
| 295 | updateArrayLamNorm();
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | r_8 one_on_s2 = 1. / (sth_*sth_) ;
|
---|
| 299 | r_8 c_on_s2 = cth_*one_on_s2;
|
---|
| 300 | lamPlm_.ReSizeRow(lmax_+1);
|
---|
| 301 | lamMlm_.ReSizeRow(lmax_+1);
|
---|
| 302 |
|
---|
| 303 | // calcul des lambda
|
---|
| 304 | for(int m = 0;m<= mmax_; m++)
|
---|
| 305 | {
|
---|
| 306 | for (int l=m; l<=lmax_; l++)
|
---|
| 307 | {
|
---|
| 308 | lamPlm_(l,m) = 0.;
|
---|
| 309 | lamMlm_(l,m) = 0.;
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | for(int l = 2;l<= lmax_; l++)
|
---|
| 314 | {
|
---|
| 315 | r_8 normal_l = (*normal_l_)(l);
|
---|
| 316 | for (int m=0; m<=l; m++)
|
---|
| 317 | {
|
---|
| 318 | r_8 lam_lm1m = LambdaLMBuilder::lamlm(l-1,m);
|
---|
| 319 | r_8 lam_lm = LambdaLMBuilder::lamlm(l,m);
|
---|
[1756] | 320 | r_8 lam_fact_l_m = lam_fact_(l,m);
|
---|
[729] | 321 | r_8 a_w = 2. * (l - m*m) * one_on_s2 + l*(l-1.);
|
---|
| 322 | r_8 f_w = lam_fact_l_m/(sth_*sth_);
|
---|
| 323 | r_8 c_w = 2*m*(l-1.) * c_on_s2;
|
---|
| 324 |
|
---|
| 325 | lamPlm_(l,m) = normal_l * ( -(a_w+c_w) * lam_lm + f_w*( cth_ + m) * lam_lm1m )/Rac2;
|
---|
| 326 | lamMlm_(l,m) = normal_l * ( -(a_w-c_w) * lam_lm + f_w*( cth_ - m) * lam_lm1m )/Rac2;
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 |
|
---|