LORENE
mat_cosp_legpp.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_cosp_legpp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cosp_legpp.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)
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) avec m 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_cosp_legpp : pointeur sur le tableau contenant l'ensemble
43  * (pour les np/2+1 valeurs de m: m=0,2,...,np) 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_cosp_legpp[ nt*nt* m/2 + nt*l + j] = A_{mlj}
49  *
50  * ou A_{mlj} est defini par
51  *
52  * cos(2*j*theta) = som_{l=m/2}^{nt-1} A_{mlj} P_{2l}^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_cosp_legpp.C,v 1.6 2014/10/13 08:53:13 j_novak Exp $
64  * $Log: mat_cosp_legpp.C,v $
65  * Revision 1.6 2014/10/13 08:53:13 j_novak
66  * Lorene classes and functions now belong to the namespace Lorene.
67  *
68  * Revision 1.5 2014/10/06 15:16:02 j_novak
69  * Modified #include directives to use c++ syntax.
70  *
71  * Revision 1.4 2005/02/18 13:14:13 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:54 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:28 e_gourgoulhon
84  * LORENE
85  *
86  * Revision 2.0 1999/02/22 15:35:27 hyc
87  * *** empty log message ***
88  *
89  *
90  *
91  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cosp_legpp.C,v 1.6 2014/10/13 08:53:13 j_novak Exp $
92  *
93  */
94 
95 // headers du C
96 #include <cstdlib>
97 #include <cmath>
98 
99 // Prototypage
100 #include "headcpp.h"
101 #include "proto.h"
102 
103 // Variable de loch
104 int loch_mat_cosp_legpp = 0 ;
105 
106 namespace Lorene {
107 //******************************************************************************
108 
109 double* mat_cosp_legpp(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 // #pragma critical (loch_mat_cosp_legpp)
122  {
123 
124  // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
125  indice = -1 ;
126  for ( i=0 ; i < nb_dejafait ; i++ ) {
127  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
128  }
129 
130 
131 // Si le calcul n'a pas deja ete fait, il faut le faire :
132  if (indice == -1) {
133  if ( nb_dejafait >= NMAX ) {
134  cout << "mat_cosp_legpp: nb_dejafait >= NMAX : "
135  << nb_dejafait << " <-> " << NMAX << endl ;
136  abort () ;
137  exit(-1) ;
138  }
139  indice = nb_dejafait ;
140  nb_dejafait++ ;
141  np_dejafait[indice] = np ;
142  nt_dejafait[indice] = nt ;
143 
144  tab[indice] = new double[(np/2+1)*nt*nt] ;
145 
146 //-----------------------
147 // Preparation du calcul
148 //-----------------------
149 
150 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
151  int nt2 = 2*nt - 1 ;
152  int nt2m1 = nt2 - 1 ;
153 
154  int deg[3] ;
155  deg[0] = 1 ;
156  deg[1] = 1 ;
157  deg[2] = nt2 ;
158 
159 // Tableaux de travail
160  double* yy = new double[nt2] ;
161  double* cost = new double[nt*nt2] ;
162 
163 // Calcul des cos(2*j*theta) aux points de collocation
164 // de l'echantillonnage double :
165 
166  double dt = M_PI / double(2*(nt2-1)) ;
167  for (j=0; j<nt; j++) {
168  for (j2=0; j2<nt2; j2++) {
169  double theta = j2*dt ;
170  cost[nt2*j + j2] = cos( 2*j * theta ) ;
171  }
172  }
173 
174 
175 //-------------------
176 // Boucle sur m
177 //-------------------
178 
179  int m_max = np ;
180  if (np == 1) m_max = 0 ;
181 
182  for (m=0; m <= m_max ; m+=2) {
183 
184 // Recherche des fonctions de Legendre associees d'ordre m :
185 
186  double* leg = legendre_norm(m, nt) ;
187 
188  for (l=m/2; l<nt; l++) { // boucle sur les P_{2l}^m
189 
190  int ll = 2*l ; // degre des fonctions de Legendre
191 
192  for (j=0; j<nt; j++) { // boucle sur les cos(2j theta)
193 
194 //... produit scalaire de cos(2j theta) par P_{2l}^m(cos(theta))
195 
196  for (j2=0; j2<nt2; j2++) {
197  yy[nt2m1-j2] = cost[nt2*j + j2] *
198  leg[nt2* (ll-m) + j2] ;
199  }
200 
201 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
202 // l'integrale (routine int1d_chebp) :
203  cfrchebp(deg, deg, yy, deg, yy) ;
204  tab[indice][ nt*nt* m/2 + nt*l + j] =
205  2.*int1d_chebp(nt2, yy) ;
206 
207  } // fin de la boucle sur j (indice de cos(2j theta) )
208 
209  } // fin de la boucle sur l (indice de P_{2l}^m)
210 
211  delete [] leg ;
212 
213  } // fin de la boucle sur m
214 
215 // Liberation espace memoire
216 // -------------------------
217 
218  delete [] yy ;
219  delete [] cost ;
220 
221  } // fin du cas ou le calcul etait necessaire
222 
223  } //Fin de zone critique
224 
225  return tab[indice] ;
226 
227 }
228 
229 
230 }
Lorene
Lorene prototypes.
Definition: app_hor.h:64
Lorene::cos
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:94