LORENE
mat_cossinc_leg.C
1 /*
2  * Copyright (c) 2004 Michael Forot
3  *
4  * This file is part of LORENE.
5  *
6  * LORENE is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * LORENE is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with LORENE; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 
23 char mat_cossinc_leg_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossinc_leg.C,v 1.7 2014/10/13 08:53:13 j_novak Exp $" ;
24 
25 /*
26  * Fournit la matrice de passage pour la transformation des coefficients du
27  * developpement en cos(j*theta) [m pair] / sin( j* theta) [m impair]
28  * dans les coefficients du developpement en fonctions associees de Legendre
29  * P_l^m(cos(theta)).
30  *
31  * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas
32  * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment
33  * calculee.
34  *
35  * Entree:
36  * -------
37  * int np : Nombre de degres de liberte en phi
38  * int nt : Nombre de degres de liberte en theta
39  *
40  * Sortie (valeur de retour) :
41  * ---------------------------
42  * double* mat_cossinc_leg : pointeur sur le tableau contenant l'ensemble
43  * (pour les np/2+1 valeurs de m) des
44  * matrices de passage.
45  * La dimension du tableau est (np/2+1)*nt^2
46  * Le stokage est le suivant:
47  *
48  * mat_cossinc_leg[ nt*nt* m + nt*l + j] = A_{mlj}
49  *
50  * ou A_{mlj} est defini par
51  *
52  * pour m pair :
53  * cos(j*theta) = som_{l=m}^{nt-1} A_{mlj} P_{l}^m( cos(theta) )
54  *
55  * pour m impair :
56  * sin(j*theta) = som_{l=m}^{nt-1} A_{mlj} P_{l}^m( cos(theta) )
57  *
58  * ou P_n^m(x) represente la fonction de Legendre associee de degre n et
59  * d'ordre m normalisee de facon a ce que
60  *
61  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
62  *
63  *
64  */
65 
66 /*
67  * $Id: mat_cossinc_leg.C,v 1.7 2014/10/13 08:53:13 j_novak Exp $
68  * $Log: mat_cossinc_leg.C,v $
69  * Revision 1.7 2014/10/13 08:53:13 j_novak
70  * Lorene classes and functions now belong to the namespace Lorene.
71  *
72  * Revision 1.6 2014/10/06 15:16:02 j_novak
73  * Modified #include directives to use c++ syntax.
74  *
75  * Revision 1.5 2009/10/13 13:49:36 j_novak
76  * New base T_LEG_MP.
77  *
78  * Revision 1.4 2005/02/18 13:14:13 j_novak
79  * Changing of malloc/free to new/delete + suppression of some unused variables
80  * (trying to avoid compilation warnings).
81  *
82  * Revision 1.3 2005/02/16 15:24:15 m_forot
83  * Replace int1d_chebp by int1d_cheb
84  *
85  * Revision 1.2 2004/12/17 15:42:02 e_gourgoulhon
86  * l_max = nt instead of nt2.
87  *
88  * Revision 1.1 2004/11/23 15:13:50 m_forot
89  * Added the bases for the cases without any equatorial symmetry
90  * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
91  *
92  *
93  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossinc_leg.C,v 1.7 2014/10/13 08:53:13 j_novak Exp $
94  *
95  */
96 
97 // headers du C
98 #include <cstdlib>
99 #include <cmath>
100 
101 // Prototypage
102 #include "headcpp.h"
103 #include "proto.h"
104 
105 // Variable de loch
106 int loch_mat_cossinc_leg = 0 ;
107 
108 namespace Lorene {
109 //******************************************************************************
110 
111 double* mat_cossinc_leg(int np, int nt) {
112 
113 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
114 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
115 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
116 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
117  // calcul a deja ete fait
118 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
119  // calcul a deja ete fait
120 
121 int i, indice, j, j2, m, l ;
122 
123 // #pragma critical (loch_mat_cossinc_leg)
124  {
125 
126  // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
127  indice = -1 ;
128  for ( i=0 ; i < nb_dejafait ; i++ ) {
129  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
130  }
131 
132 
133  // Si le calcul n'a pas deja ete fait, il faut le faire :
134  if (indice == -1) {
135  if ( nb_dejafait >= NMAX ) {
136  cout << "mat_cossinc_leg: nb_dejafait >= NMAX : "
137  << nb_dejafait << " <-> " << NMAX << endl ;
138  abort () ;
139  exit(-1) ;
140  }
141  indice = nb_dejafait ;
142  nb_dejafait++ ;
143  np_dejafait[indice] = np ;
144  nt_dejafait[indice] = nt ;
145 
146  tab[indice] = new double[(np/2+1)*nt*nt] ;
147 
148 //-----------------------
149 // Preparation du calcul
150 //-----------------------
151 
152 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
153  int nt2 = 2*nt - 1 ;
154  int nt2m1 = nt2 - 1 ;
155 
156  int deg[3] ;
157  deg[0] = 1 ;
158  deg[1] = 1 ;
159  deg[2] = nt2 ;
160 
161 // Tableaux de travail
162  double* yy = new double[nt2] ;
163  double* cost = new double[nt*nt2] ;
164  double* sint = new double[nt*nt2] ;
165 
166 // Calcul des cos(j*theta) / sin( j*theta ) aux points de collocation
167 // de l'echantillonnage double :
168 
169  double dt = M_PI / double((nt2-1)) ;
170  for (j=0; j<nt; j++) {
171  for (j2=0; j2<nt2; j2++) {
172  double theta = j2*dt ;
173  cost[nt2*j + j2] = cos( j * theta ) ;
174  sint[nt2*j + j2] = sin( j * theta ) ;
175  }
176  }
177 
178 
179 //-------------------
180 // Boucle sur m
181 //-------------------
182 
183  for (m=0; m < np/2+1 ; m++) {
184 
185 // Recherche des fonctions de Legendre associees d'ordre m :
186 
187  double* leg = legendre_norm(m, nt) ;
188 
189  if (m%2==0) {
190 // Cas m pair
191 //-----------
192  for (l=m; l<nt; l++) { // boucle sur les P_{l}^m
193 
194  int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
195 
196  for (j=0; j<nt; j++) { // boucle sur les cos(j theta)
197 
198 //... produit scalaire de cos(j theta) par P_{l}^m(cos(theta))
199 
200  for (j2=0; j2<nt; j2++) {
201  yy[nt2m1-j2] = cost[nt2*j + j2] *
202  leg[nt2* (l-m) + 2*j2] ;
203  }
204 
205  for (j2=nt; j2<nt2; j2++) {
206  yy[nt2m1-j2] = cost[nt2*j + j2] *
207  parite * leg[nt2* (l-m) + 2*nt2 -2 -2*j2] ;
208  }
209 
210 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
211 // l'integrale (routine int1d_cheb) :
212  cfrcheb(deg, deg, yy, deg, yy) ;
213  tab[indice][ nt*nt* m + nt*l + j] =
214  int1d_cheb(nt2, yy) ;
215 
216  } // fin de la boucle sur j (indice de cos(j theta) )
217 
218  } // fin de la boucle sur l (indice de P_l^m)
219 
220 
221  } // fin du cas m pair
222  else {
223 
224 // Cas m impair
225 //-------------
226 
227  for (l=m; l<nt; l++) { // boucle sur les P_{l}^m
228 
229  int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
230 
231  for (j=0; j<nt; j++) { // boucle sur les sin(j)theta)
232 
233 //... produit scalaire de sin(j) theta) par P_{l}^m(cos(theta))
234 
235  for (j2=0; j2<nt; j2++) {
236  yy[nt2m1-j2] = sint[nt2*j + j2] *
237  leg[nt2* (l-m) + 2*j2] ;
238 
239  }
240 
241  for (j2=nt; j2<nt2; j2++) {
242  yy[nt2m1-j2] = sint[nt2*j + j2] *
243  parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ;
244 
245  }
246 
247 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
248 // l'integrale (routine int1d_chebp) :
249  cfrcheb(deg, deg, yy, deg, yy) ;
250 
251  tab[indice][ nt*nt* m + nt*l + j] =
252  int1d_cheb(nt2, yy) ;
253 
254  } // fin de la boucle sur j (indice de sin(j*theta) )
255 
256  } // fin de la boucle sur l (indice de P_{l}^m)
257 
258 
259  } // fin du cas m impair
260 
261  delete [] leg ;
262 
263  } // fin de la boucle sur m
264 
265 // Liberation espace memoire
266 // -------------------------
267 
268  delete [] yy ;
269  delete [] cost ;
270  delete [] sint ;
271 
272  } // fin du cas ou le calcul etait necessaire
273 
274  } // Fin de zone critique
275 
276  return tab[indice] ;
277 
278 }
279 
280 
281 }
Lorene
Lorene prototypes.
Definition: app_hor.h:64
Lorene::cos
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:94
Lorene::sin
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:69