source: Sophya/trunk/SophyaLib/Samba/lambdaBuilder.cc@ 1371

Last change on this file since 1371 was 1218, checked in by ansari, 25 years ago

doc dans .cc

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