LORENE
mat_legi_cossinci.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 fonctions associees de Legendre
28  * P_l^m(cos(theta)) impaires (i.e. telles que l-m est impair)
29  * dans les coefficients du developpement
30  * en cos((2*j+1)*theta) [m pair] / sin( 2*j * theta) [m impair]
31  *
32  * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas
33  * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment
34  * calculee.
35  *
36  * Entree:
37  * -------
38  * int np : Nombre de degres de liberte en phi
39  * int nt : Nombre de degres de liberte en theta
40  *
41  * Sortie (valeur de retour) :
42  * ---------------------------
43  * double* mat_legi_cossinci : pointeur sur le tableau contenant l'ensemble
44  * (pour les np/2+1 valeurs de m) des
45  * matrices de passage.
46  * La dimension du tableau est (np/2+1)*nt^2
47  * Le stokage est le suivant:
48  *
49  * mat_legi_cossinci[ nt*nt* m + nt*j + l] = B_{mjl}
50  *
51  * ou B_{mjl} est defini par
52  *
53  * pour m pair :
54  * P_{2l+1}^m( cos(theta) ) = som_{j=0}^{nt-2} B_{mjl} cos((2*j+1)*theta)
55  *
56  * pour m impair :
57  * P_{2l}^m( cos(theta) ) = som_{j=1}^{nt-2} B_{mjl} sin(2*j*theta)
58  *
59  * ou P_n^m(x) represente la fonction de Legendre associee de degre n et
60  * d'ordre m normalisee de facon a ce que
61  *
62  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
63  *
64  *
65  */
66 
67 /*
68  * $Id: mat_legi_cossinci.C,v 1.6 2016/12/05 16:18:02 j_novak Exp $
69  * $Log: mat_legi_cossinci.C,v $
70  * Revision 1.6 2016/12/05 16:18:02 j_novak
71  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
72  *
73  * Revision 1.5 2014/10/13 08:53:13 j_novak
74  * Lorene classes and functions now belong to the namespace Lorene.
75  *
76  * Revision 1.4 2014/10/06 15:16:03 j_novak
77  * Modified #include directives to use c++ syntax.
78  *
79  * Revision 1.3 2005/02/18 13:14:15 j_novak
80  * Changing of malloc/free to new/delete + suppression of some unused variables
81  * (trying to avoid compilation warnings).
82  *
83  * Revision 1.2 2002/10/16 14:36:55 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:21 hyc
91  * *** empty log message ***
92  *
93  *
94  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legi_cossinci.C,v 1.6 2016/12/05 16:18:02 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 namespace Lorene {
107 //******************************************************************************
108 
109 double* mat_legi_cossinci(int np, int nt) {
110 
111 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
112 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
113 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
114 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
115  // calcul a deja ete fait
116 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
117  // calcul a deja ete fait
118 
119 int i, indice, j, j2, m, l ;
120 
121  {
122  // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ?
123  indice = -1 ;
124  for ( i=0 ; i < nb_dejafait ; i++ ) {
125  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
126  }
127 
128 
129 // Si le calcul n'a pas deja ete fait, il faut le faire :
130  if (indice == -1) {
131  if ( nb_dejafait >= NMAX ) {
132  cout << "mat_legi_cossinci: nb_dejafait >= NMAX : "
133  << nb_dejafait << " <-> " << NMAX << endl ;
134  abort () ;
135  exit(-1) ;
136  }
137  indice = nb_dejafait ;
138  nb_dejafait++ ;
139  np_dejafait[indice] = np ;
140  nt_dejafait[indice] = nt ;
141 
142  tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
143 
144 //-----------------------
145 // Preparation du calcul
146 //-----------------------
147 
148 // Sur-echantillonnage :
149  int nt2 = 2*nt - 1 ;
150 
151  int deg[3] ;
152  deg[0] = 1 ;
153  deg[1] = nt2 ;
154  deg[2] = 1 ;
155 
156 // Tableaux de travail
157  double* yy = new double[nt2] ; //(double*)( malloc( nt2*sizeof(double) ) ) ;
158 
159 
160 //-------------------
161 // Boucle sur m
162 //-------------------
163 
164  for (m=0; m < np/2+1 ; m++) {
165 
166 // Recherche des fonctions de Legendre associees d'ordre m :
167 
168  double* leg = legendre_norm(m, nt) ;
169 
170  if (m%2==0) {
171 // Cas m pair
172 //-----------
173  for (l=m/2; l<nt-1; l++) { // boucle sur les P_{2l+1}^m
174 
175  int ll = 2*l+1 ; // degre des fonctions de Legendre
176 
177  for (j2=0; j2<nt2; j2++) {
178  yy[j2] = leg[nt2* (ll-m) + j2] ;
179  }
180 
181 //....... transformation en cos((2*j+1)*theta) :
182 
183  cftcosi(deg, deg, yy, deg, yy) ;
184 
185 //....... le resultat fournit les elements de matrice :
186  for (j=0; j<nt; j++) {
187  tab[indice][ nt*nt* m + nt*j + l] = yy[j] ;
188  }
189 
190  } // fin de la boucle sur l (indice de P_{2l}^m)
191 
192 
193  } // fin du cas m pair
194  else {
195 
196 // Cas m impair
197 //-------------
198 
199  for (l=(m+1)/2; l<nt-1; l++) { // boucle sur les P_{2l}^m
200 
201  int ll = 2*l ; // degre des fonctions de Legendre
202 
203 
204  for (j2=0; j2<nt2; j2++) {
205  yy[j2] = leg[nt2* (ll-m) + j2] ;
206  }
207 
208 //....... transformation en sin( 2j*theta) :
209 
210  cftsinp(deg, deg, yy, deg, yy) ;
211 
212 //....... le resultat fournit les elements de matrice :
213  for (j=0; j<nt-1; j++) {
214  tab[indice][ nt*nt* m + nt*j + l] = yy[j] ;
215  }
216 
217  } // fin de la boucle sur l (indice de P_{2l+1}^m)
218 
219 
220  } // fin du cas m impair
221 
222  delete [] leg ;
223 
224  } // fin de la boucle sur m
225 
226 // Liberation espace memoire
227 // -------------------------
228 
229  delete [] yy ;
230 
231  } // fin du cas ou le calcul etait necessaire
232 
233  } // Fin de zone critique
234 
235  return tab[indice] ;
236 
237 }
238 
239 
240 }
Lorene prototypes.
Definition: app_hor.h:67