LORENE
mat_sini_legpi.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_sini_legpi_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sini_legpi.C,v 1.6 2014/10/13 08:53:14 j_novak Exp $" ;
24 
25 /*
26  * Fournit la matrice de passage pour la transformation des coefficients du
27  * developpement en sin((2j+1)*theta)
28  * dans les coefficients du developpement en fonctions associees de Legendre
29  * P_l^m(cos(theta)) avec l impair et m 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_sini_legpi : pointeur sur le tableau contenant l'ensemble
43  * (pour les np/2 valeurs de m: m=1,3,...,np-1) 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_cosi_legip[ nt*nt* m/2 + nt*l + j] = A_{mlj}
49  *
50  * ou A_{mlj} est defini par
51  *
52  * sin((2*j+1)*theta) = som_{l=(m-1)/2}^{nt-2} A_{mlj} P_{2l+1}^m( cos(theta) )
53  *
54  * ou P_n^m(x) represente la fonction de Legendre associee de degre n et
55  * d'ordre m normalisee de facon a ce que
56  *
57  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
58  *
59  *
60  */
61 
62 /*
63  * $Id: mat_sini_legpi.C,v 1.6 2014/10/13 08:53:14 j_novak Exp $
64  * $Log: mat_sini_legpi.C,v $
65  * Revision 1.6 2014/10/13 08:53:14 j_novak
66  * Lorene classes and functions now belong to the namespace Lorene.
67  *
68  * Revision 1.5 2014/10/06 15:16:03 j_novak
69  * Modified #include directives to use c++ syntax.
70  *
71  * Revision 1.4 2005/02/18 13:14:15 j_novak
72  * Changing of malloc/free to new/delete + suppression of some unused variables
73  * (trying to avoid compilation warnings).
74  *
75  * Revision 1.3 2003/01/31 10:31:24 e_gourgoulhon
76  * Suppressed the directive #include <malloc.h> for malloc is defined
77  * in <stdlib.h>
78  *
79  * Revision 1.2 2002/10/16 14:36:57 j_novak
80  * Reorganization of #include instructions of standard C++, in order to
81  * use experimental version 3 of gcc.
82  *
83  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
84  * LORENE
85  *
86  * Revision 2.1 2000/11/14 15:12:47 eric
87  * Traitement du cas np=1
88  *
89  * Revision 2.0 2000/09/29 16:09:49 eric
90  * *** empty log message ***
91  *
92  *
93  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sini_legpi.C,v 1.6 2014/10/13 08:53:14 j_novak Exp $
94  *
95  */
96 
97 // headers du C
98 #include <cstdlib>
99 #include <cmath>
100 #include <cassert>
101 
102 // Prototypage
103 #include "headcpp.h"
104 #include "proto.h"
105 
106 // Variable de loch
107 int loch_mat_sini_legpi = 0 ;
108 
109 namespace Lorene {
110 //******************************************************************************
111 
112 double* mat_sini_legpi(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_sini_legpi)
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_cosp_legpp: 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] ; //(double *) malloc( sizeof(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] ;//(double*)( malloc( nt2*sizeof(double) ) ) ;
164  double* sint = new double[nt*nt2] ; //(double*)( malloc( nt*nt2*sizeof(double) ) ) ;
165 
166 // Calcul des sin( (2j+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-1; j++) {
171  for (j2=0; j2<nt2; j2++) {
172  double theta = j2*dt ;
173  sint[nt2*j + j2] = sin( (2*j+1) * theta ) ;
174  }
175  }
176 
177 
178 //-------------------
179 // Boucle sur m
180 //-------------------
181 
182  int m_max = (np == 1) ? 1 : np-1 ;
183 
184  for (m=1; m <= m_max ; m+=2) {
185 
186  // Recherche des fonctions de Legendre associees d'ordre m :
187 
188  double* leg = legendre_norm(m, nt) ;
189 
190  for (l=(m-1)/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 sin((2j+1)theta)
195 
196  //... produit scalaire de sin((2j+1) theta) par
197  // P_{2l+1}^m(cos(theta))
198 
199  for (j2=0; j2<nt2; j2++) {
200  yy[nt2m1-j2] = sint[nt2*j + j2]
201  * leg[nt2* (ll-m) + j2] ;
202  }
203 
204 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
205 // l'integrale (routine int1d_chebp) :
206  cfrchebp(deg, deg, yy, deg, yy) ;
207  tab[indice][ nt*nt* ((m-1)/2) + nt*l + j] =
208  2.*int1d_chebp(nt2, yy) ;
209 
210 
211  } // fin de la boucle sur j (indice de sin((2j+1)theta) )
212 
213  } // fin de la boucle sur l (indice de P_{2l+1}^m)
214 
215  delete [] leg ;
216 
217  } // fin de la boucle sur m
218 
219 // Liberation espace memoire
220 // -------------------------
221 
222  delete [] yy ;
223  delete [] sint ;
224 
225  } // fin du cas ou le calcul etait necessaire
226 
227  } //Fin de zone critique
228 
229  return tab[indice] ;
230 
231 }
232 
233 
234 }
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:69
Lorene prototypes.
Definition: app_hor.h:64