LORENE
mat_cossincp_legp.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*theta) [m pair] / sin( (2*j+1) * theta) [m impair]
28  * dans les coefficients du developpement en fonctions associees de Legendre
29  * P_l^m(cos(theta)) paires (i.e. telles que l-m est pair).
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_cossincp_legp : 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_cossincp_legp[ 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*theta) = som_{l=m/2}^{nt-1} A_{mlj} P_{2l}^m( cos(theta) )
54  *
55  * pour m impair :
56  * sin((2*j+1)*theta) = som_{l=(m-1)/2}^{nt-2} A_{mlj} P_{2l+1}^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_cossincp_legp.C,v 1.7 2016/12/05 16:18:02 j_novak Exp $
68  * $Log: mat_cossincp_legp.C,v $
69  * Revision 1.7 2016/12/05 16:18:02 j_novak
70  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
71  *
72  * Revision 1.6 2014/10/13 08:53:13 j_novak
73  * Lorene classes and functions now belong to the namespace Lorene.
74  *
75  * Revision 1.5 2014/10/06 15:16:02 j_novak
76  * Modified #include directives to use c++ syntax.
77  *
78  * Revision 1.4 2005/02/18 13:14:14 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 2003/01/31 10:31:24 e_gourgoulhon
83  * Suppressed the directive #include <malloc.h> for malloc is defined
84  * in <stdlib.h>
85  *
86  * Revision 1.2 2002/10/16 14:36:54 j_novak
87  * Reorganization of #include instructions of standard C++, in order to
88  * use experimental version 3 of gcc.
89  *
90  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
91  * LORENE
92  *
93  * Revision 2.0 1999/02/22 15:34:45 hyc
94  * *** empty log message ***
95  *
96  *
97  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossincp_legp.C,v 1.7 2016/12/05 16:18:02 j_novak Exp $
98  *
99  */
100 
101 // headers du C
102 #include <cstdlib>
103 #include <cmath>
104 
105 // Prototypage
106 #include "headcpp.h"
107 #include "proto.h"
108 
109 namespace Lorene {
110 //******************************************************************************
111 
112 double* mat_cossincp_legp(int np, int nt) {
113 
114 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
115 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
116 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
117 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
118  // calcul a deja ete fait
119 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
120  // calcul a deja ete fait
121 
122 int i, indice, j, j2, m, l ;
123 
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_cossincp_legp: 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(2*j*theta) / sin( (2*j+1)*theta ) aux points de collocation
167 // de l'echantillonnage double :
168 
169  double dt = M_PI / double(2*(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( 2*j * theta ) ;
174  sint[nt2*j + j2] = sin( (2*j+1) * 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/2; l<nt; l++) { // boucle sur les P_{2l}^m
193 
194  int ll = 2*l ; // degre des fonctions de Legendre
195 
196  for (j=0; j<nt; j++) { // boucle sur les cos(2j theta)
197 
198 //... produit scalaire de cos(2j theta) par P_{2l}^m(cos(theta))
199 
200  for (j2=0; j2<nt2; j2++) {
201  yy[nt2m1-j2] = cost[nt2*j + j2] *
202  leg[nt2* (ll-m) + j2] ;
203  }
204 
205 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
206 // l'integrale (routine int1d_chebp) :
207  cfrchebp(deg, deg, yy, deg, yy) ;
208  tab[indice][ nt*nt* m + nt*l + j] =
209  2.*int1d_chebp(nt2, yy) ;
210 
211  } // fin de la boucle sur j (indice de cos(2j theta) )
212 
213  } // fin de la boucle sur l (indice de P_{2l}^m)
214 
215 
216  } // fin du cas m pair
217  else {
218 
219 // Cas m impair
220 //-------------
221 
222  for (l=(m-1)/2; l<nt-1; l++) { // boucle sur les P_{2l+1}^m
223 
224  int ll = 2*l+1 ; // degre des fonctions de Legendre
225 
226  for (j=0; j<nt-1; j++) { // boucle sur les sin((2j+1)theta)
227 
228 //... produit scalaire de sin((2j+1) theta) par P_{2l+1}^m(cos(theta))
229 
230  for (j2=0; j2<nt2; j2++) {
231  yy[nt2m1-j2] = sint[nt2*j + j2] *
232  leg[nt2* (ll-m) + j2] ;
233  }
234 
235 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
236 // l'integrale (routine int1d_chebp) :
237  cfrchebp(deg, deg, yy, deg, yy) ;
238  tab[indice][ nt*nt* m + nt*l + j] =
239  2.*int1d_chebp(nt2, yy) ;
240 
241  } // fin de la boucle sur j (indice de sin((2j+1)theta) )
242 
243  } // fin de la boucle sur l (indice de P_{2l+1}^m)
244 
245 
246  } // fin du cas m impair
247 
248  delete [] leg ;
249 
250  } // fin de la boucle sur m
251 
252 // Liberation espace memoire
253 // -------------------------
254 
255  delete [] yy ;
256  delete [] cost ;
257  delete [] sint ;
258 
259  } // fin du cas ou le calcul etait necessaire
260 
261  } // Fin de zone critique
262 
263  return tab[indice] ;
264 
265 }
266 
267 
268 }
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