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