LORENE
mat_cossinci_legi.C
1 /*
2  * Copyright (c) 1999-2001 Eric Gourgoulhon
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 
24 
25 /*
26  * Fournit la matrice de passage pour la transformation des coefficients du
27  * developpement en cos((2*j+1)*theta) [m pair] / sin( 2*j * theta) [m impair]
28  * dans les coefficients du developpement en fonctions associees de Legendre
29  * P_l^m(cos(theta)) impaires (i.e. telles que l-m est impair).
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_cossinci_legi : 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_cossinci_legi[ nt*nt* m + nt*l + j] = A_{mlj}
49  *
50  * ou A_{mlj} est defini par
51  *
52  * pour m pair :
53  * cos((2*j+1)*theta) = som_{l=m/2}^{nt-2} A_{mlj} P_{2l+1}^m( cos(theta) )
54  * pour 0 <= j <= nt-2
55  *
56  * pour m impair :
57  * sin(2*j*theta) = som_{l=(m+1)/2}^{nt-2} A_{mlj} P_{2l}^m( cos(theta) )
58  * pour 1 <= j <= nt-2
59  *
60  * ou P_n^m(x) represente la fonction de Legendre associee de degre n et
61  * d'ordre m normalisee de facon a ce que
62  *
63  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
64  *
65  *
66  */
67 
68 /*
69  * $Id: mat_cossinci_legi.C,v 1.6 2016/12/05 16:18:02 j_novak Exp $
70  * $Log: mat_cossinci_legi.C,v $
71  * Revision 1.6 2016/12/05 16:18:02 j_novak
72  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
73  *
74  * Revision 1.5 2014/10/13 08:53:13 j_novak
75  * Lorene classes and functions now belong to the namespace Lorene.
76  *
77  * Revision 1.4 2014/10/06 15:16:02 j_novak
78  * Modified #include directives to use c++ syntax.
79  *
80  * Revision 1.3 2005/02/18 13:14:14 j_novak
81  * Changing of malloc/free to new/delete + suppression of some unused variables
82  * (trying to avoid compilation warnings).
83  *
84  * Revision 1.2 2002/10/16 14:36:54 j_novak
85  * Reorganization of #include instructions of standard C++, in order to
86  * use experimental version 3 of gcc.
87  *
88  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
89  * LORENE
90  *
91  * Revision 2.0 1999/02/22 15:35:09 hyc
92  * *** empty log message ***
93  *
94  *
95  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossinci_legi.C,v 1.6 2016/12/05 16:18:02 j_novak Exp $
96  *
97  */
98 
99 // headers du C
100 #include <cstdlib>
101 #include <cmath>
102 
103 // Prototypage
104 #include "headcpp.h"
105 #include "proto.h"
106 
107 namespace Lorene {
108 //******************************************************************************
109 
110 double* mat_cossinci_legi(int np, int nt) {
111 
112 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
113 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
114 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
115 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
116  // calcul a deja ete fait
117 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
118  // calcul a deja ete fait
119 
120 int i, indice, j, j2, m, l ;
121 
122  {
123 
124  // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
125  indice = -1 ;
126  for ( i=0 ; i < nb_dejafait ; i++ ) {
127  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
128  }
129 
130 
131  // Si le calcul n'a pas deja ete fait, il faut le faire :
132  if (indice == -1) {
133  if ( nb_dejafait >= NMAX ) {
134  cout << "mat_cossinci_legi: nb_dejafait >= NMAX : "
135  << nb_dejafait << " <-> " << NMAX << endl ;
136  abort () ;
137  exit(-1) ;
138  }
139  indice = nb_dejafait ;
140  nb_dejafait++ ;
141  np_dejafait[indice] = np ;
142  nt_dejafait[indice] = nt ;
143 
144  tab[indice] = new double[(np/2+1)*nt*nt] ;
145 
146 //-----------------------
147 // Preparation du calcul
148 //-----------------------
149 
150 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
151  int nt2 = 2*nt - 1 ;
152  int nt2m1 = nt2 - 1 ;
153 
154  int deg[3] ;
155  deg[0] = 1 ;
156  deg[1] = 1 ;
157  deg[2] = nt2 ;
158 
159 // Tableaux de travail
160  double* yy = new double[nt2] ;
161  double* cost = new double[nt*nt2] ;
162  double* sint = new double[nt*nt2] ;
163 
164 // Calcul des cos(2*j*theta) / sin( (2*j+1)*theta ) aux points de collocation
165 // de l'echantillonnage double :
166 
167  double dt = M_PI / double(2*(nt2-1)) ;
168  for (j=0; j<nt-1; j++) {
169  for (j2=0; j2<nt2; j2++) {
170  double theta = j2*dt ;
171  cost[nt2*j + j2] = cos( (2*j+1) * theta ) ;
172  sint[nt2*j + j2] = sin( 2*j * theta ) ;
173  }
174  }
175 
176 
177 //-------------------
178 // Boucle sur m
179 //-------------------
180 
181  for (m=0; m < np/2+1 ; m++) {
182 
183 // Recherche des fonctions de Legendre associees d'ordre m :
184 
185  double* leg = legendre_norm(m, nt) ;
186 
187  if (m%2==0) {
188 // Cas m pair
189 //-----------
190  for (l=m/2; l<nt-1; l++) { // boucle sur les P_{2l+1}^m
191 
192  int ll = 2*l+1 ; // degre des fonctions de Legendre
193 
194  for (j=0; j<nt-1; j++) { // boucle sur les cos((2j+1) theta)
195 
196 //... produit scalaire de cos((2j+1) theta) par P_{2l+1}^m(cos(theta))
197 
198  for (j2=0; j2<nt2; j2++) {
199  yy[nt2m1-j2] = cost[nt2*j + j2] *
200  leg[nt2* (ll-m) + j2] ;
201  }
202 
203 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
204 // l'integrale (routine int1d_chebp) :
205  cfrchebp(deg, deg, yy, deg, yy) ;
206  tab[indice][ nt*nt* m + nt*l + j] =
207  2.*int1d_chebp(nt2, yy) ;
208 
209  } // fin de la boucle sur j (indice de cos((2j+1) theta) )
210 
211  } // fin de la boucle sur l (indice de P_{2l+1}^m)
212 
213 
214  } // fin du cas m pair
215  else {
216 
217 // Cas m impair
218 //-------------
219 
220  for (l=(m+1)/2; l<nt-1; l++) { // boucle sur les P_{2l}^m
221 
222  int ll = 2*l ; // degre des fonctions de Legendre
223 
224  for (j=0; j<nt-1; j++) { // boucle sur les sin(2j theta)
225 
226 //... produit scalaire de sin((2j+1) theta) par P_{2l+1}^m(cos(theta))
227 
228  for (j2=0; j2<nt2; j2++) {
229  yy[nt2m1-j2] = sint[nt2*j + j2] *
230  leg[nt2* (ll-m) + j2] ;
231  }
232 
233 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
234 // l'integrale (routine int1d_chebp) :
235  cfrchebp(deg, deg, yy, deg, yy) ;
236  tab[indice][ nt*nt* m + nt*l + j] =
237  2.*int1d_chebp(nt2, yy) ;
238 
239  } // fin de la boucle sur j (indice de sin(2j theta) )
240 
241  } // fin de la boucle sur l (indice de P_{2l}^m)
242 
243 
244  } // fin du cas m impair
245 
246  delete [] leg ;
247 
248  } // fin de la boucle sur m
249 
250 // Liberation espace memoire
251 // -------------------------
252 
253  delete [] yy ;
254  delete [] cost ;
255  delete [] sint ;
256 
257  } // fin du cas ou le calcul etait necessaire
258 
259  } // Fin de zone critique
260 
261  return tab[indice] ;
262 
263 }
264 
265 
266 }
Lorene prototypes.
Definition: app_hor.h:67
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:97
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:72