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 char mat_cossincp_legp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossincp_legp.C,v 1.6 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(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.6 2014/10/13 08:53:13 j_novak Exp $
68  * $Log: mat_cossincp_legp.C,v $
69  * Revision 1.6 2014/10/13 08:53:13 j_novak
70  * Lorene classes and functions now belong to the namespace Lorene.
71  *
72  * Revision 1.5 2014/10/06 15:16:02 j_novak
73  * Modified #include directives to use c++ syntax.
74  *
75  * Revision 1.4 2005/02/18 13:14:14 j_novak
76  * Changing of malloc/free to new/delete + suppression of some unused variables
77  * (trying to avoid compilation warnings).
78  *
79  * Revision 1.3 2003/01/31 10:31:24 e_gourgoulhon
80  * Suppressed the directive #include <malloc.h> for malloc is defined
81  * in <stdlib.h>
82  *
83  * Revision 1.2 2002/10/16 14:36:54 j_novak
84  * Reorganization of #include instructions of standard C++, in order to
85  * use experimental version 3 of gcc.
86  *
87  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
88  * LORENE
89  *
90  * Revision 2.0 1999/02/22 15:34:45 hyc
91  * *** empty log message ***
92  *
93  *
94  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossincp_legp.C,v 1.6 2014/10/13 08:53:13 j_novak Exp $
95  *
96  */
97 
98 // headers du C
99 #include <cstdlib>
100 #include <cmath>
101 
102 // Prototypage
103 #include "headcpp.h"
104 #include "proto.h"
105 
106 // Variable de loch
107 int loch_mat_cossincp_legp = 0 ;
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 // #pragma critical (loch_mat_cossincp_legp)
125  {
126 
127  // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
128  indice = -1 ;
129  for ( i=0 ; i < nb_dejafait ; i++ ) {
130  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
131  }
132 
133 
134  // Si le calcul n'a pas deja ete fait, il faut le faire :
135  if (indice == -1) {
136  if ( nb_dejafait >= NMAX ) {
137  cout << "mat_cossincp_legp: nb_dejafait >= NMAX : "
138  << nb_dejafait << " <-> " << NMAX << endl ;
139  abort () ;
140  exit(-1) ;
141  }
142  indice = nb_dejafait ;
143  nb_dejafait++ ;
144  np_dejafait[indice] = np ;
145  nt_dejafait[indice] = nt ;
146 
147  tab[indice] = new double[(np/2+1)*nt*nt] ;
148 
149 //-----------------------
150 // Preparation du calcul
151 //-----------------------
152 
153 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
154  int nt2 = 2*nt - 1 ;
155  int nt2m1 = nt2 - 1 ;
156 
157  int deg[3] ;
158  deg[0] = 1 ;
159  deg[1] = 1 ;
160  deg[2] = nt2 ;
161 
162 // Tableaux de travail
163  double* yy = new double[nt2] ;
164  double* cost = new double[nt*nt2] ;
165  double* sint = new double[nt*nt2] ;
166 
167 // Calcul des cos(2*j*theta) / sin( (2*j+1)*theta ) aux points de collocation
168 // de l'echantillonnage double :
169 
170  double dt = M_PI / double(2*(nt2-1)) ;
171  for (j=0; j<nt; j++) {
172  for (j2=0; j2<nt2; j2++) {
173  double theta = j2*dt ;
174  cost[nt2*j + j2] = cos( 2*j * theta ) ;
175  sint[nt2*j + j2] = sin( (2*j+1) * theta ) ;
176  }
177  }
178 
179 
180 //-------------------
181 // Boucle sur m
182 //-------------------
183 
184  for (m=0; m < np/2+1 ; m++) {
185 
186 // Recherche des fonctions de Legendre associees d'ordre m :
187 
188  double* leg = legendre_norm(m, nt) ;
189 
190  if (m%2==0) {
191 // Cas m pair
192 //-----------
193  for (l=m/2; l<nt; l++) { // boucle sur les P_{2l}^m
194 
195  int ll = 2*l ; // degre des fonctions de Legendre
196 
197  for (j=0; j<nt; j++) { // boucle sur les cos(2j theta)
198 
199 //... produit scalaire de cos(2j theta) par P_{2l}^m(cos(theta))
200 
201  for (j2=0; j2<nt2; j2++) {
202  yy[nt2m1-j2] = cost[nt2*j + j2] *
203  leg[nt2* (ll-m) + j2] ;
204  }
205 
206 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
207 // l'integrale (routine int1d_chebp) :
208  cfrchebp(deg, deg, yy, deg, yy) ;
209  tab[indice][ nt*nt* m + nt*l + j] =
210  2.*int1d_chebp(nt2, yy) ;
211 
212  } // fin de la boucle sur j (indice de cos(2j theta) )
213 
214  } // fin de la boucle sur l (indice de P_{2l}^m)
215 
216 
217  } // fin du cas m pair
218  else {
219 
220 // Cas m impair
221 //-------------
222 
223  for (l=(m-1)/2; l<nt-1; l++) { // boucle sur les P_{2l+1}^m
224 
225  int ll = 2*l+1 ; // degre des fonctions de Legendre
226 
227  for (j=0; j<nt-1; j++) { // boucle sur les sin((2j+1)theta)
228 
229 //... produit scalaire de sin((2j+1) theta) par P_{2l+1}^m(cos(theta))
230 
231  for (j2=0; j2<nt2; j2++) {
232  yy[nt2m1-j2] = sint[nt2*j + j2] *
233  leg[nt2* (ll-m) + j2] ;
234  }
235 
236 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
237 // l'integrale (routine int1d_chebp) :
238  cfrchebp(deg, deg, yy, deg, yy) ;
239  tab[indice][ nt*nt* m + nt*l + j] =
240  2.*int1d_chebp(nt2, yy) ;
241 
242  } // fin de la boucle sur j (indice de sin((2j+1)theta) )
243 
244  } // fin de la boucle sur l (indice de P_{2l+1}^m)
245 
246 
247  } // fin du cas m impair
248 
249  delete [] leg ;
250 
251  } // fin de la boucle sur m
252 
253 // Liberation espace memoire
254 // -------------------------
255 
256  delete [] yy ;
257  delete [] cost ;
258  delete [] sint ;
259 
260  } // fin du cas ou le calcul etait necessaire
261 
262  } // Fin de zone critique
263 
264  return tab[indice] ;
265 
266 }
267 
268 
269 }
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:69
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:94
Lorene prototypes.
Definition: app_hor.h:64