LORENE
mat_leg_cossinc.C
1 /*
2  * Copyright (c) 2004 Michael Forot
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_leg_cossinc_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_leg_cossinc.C,v 1.5 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 fonctions associees de Legendre
28  * P_l^m(cos(theta))
29  * dans les coefficients du developpement
30  * en cos(j*theta) [m pair] / sin( 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_leg_cossinc : 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_legp_cossinc[ nt*nt* m + nt*j + l] = B_{mjl}
50  *
51  * ou B_{mjl} est defini par
52  *
53  * pour m pair :
54  * P_{l}^m( cos(theta) ) = som_{j=0}^{nt2-1} B_{mjl} cos(j*theta)
55  *
56  * pour m impair :
57  * P_{l}^m( cos(theta) ) = som_{j=0}^{nt2-2} B_{mjl} sin(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_leg_cossinc.C,v 1.5 2014/10/13 08:53:13 j_novak Exp $
69  * $Log: mat_leg_cossinc.C,v $
70  * Revision 1.5 2014/10/13 08:53:13 j_novak
71  * Lorene classes and functions now belong to the namespace Lorene.
72  *
73  * Revision 1.4 2014/10/06 15:16:03 j_novak
74  * Modified #include directives to use c++ syntax.
75  *
76  * Revision 1.3 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.2 2004/12/17 15:42:02 e_gourgoulhon
81  * l_max = nt instead of nt2.
82  *
83  * Revision 1.1 2004/11/23 15:13:50 m_forot
84  * Added the bases for the cases without any equatorial symmetry
85  * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
86  *
87  *
88  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_leg_cossinc.C,v 1.5 2014/10/13 08:53:13 j_novak Exp $
89  *
90  */
91 
92 // headers du C
93 #include <cstdlib>
94 #include <cmath>
95 
96 // Prototypage
97 #include "headcpp.h"
98 #include "proto.h"
99 
100 // Variable de loch
101 int loch_mat_leg_cossinc = 0 ;
102 
103 namespace Lorene {
104 //******************************************************************************
105 
106 double* mat_leg_cossinc(int np, int nt) {
107 
108 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
109 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
110 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
111 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
112  // calcul a deja ete fait
113 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
114  // calcul a deja ete fait
115 
116 int i, indice, j, j2, m, l ;
117 
118 // #pragma critical (loch_mat_leg_cossinc)
119  {
120  // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ?
121  indice = -1 ;
122  for ( i=0 ; i < nb_dejafait ; i++ ) {
123  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
124  }
125 
126 
127 // Si le calcul n'a pas deja ete fait, il faut le faire :
128  if (indice == -1) {
129  if ( nb_dejafait >= NMAX ) {
130  cout << "mat_legp_cossinc: nb_dejafait >= NMAX : "
131  << nb_dejafait << " <-> " << NMAX << endl ;
132  abort () ;
133  exit(-1) ;
134  }
135  indice = nb_dejafait ;
136  nb_dejafait++ ;
137  np_dejafait[indice] = np ;
138  nt_dejafait[indice] = nt ;
139 
140  tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
141 
142 //-----------------------
143 // Preparation du calcul
144 //-----------------------
145 
146 // Sur-echantillonnage :
147  int nt2 = 2*nt - 1 ;
148 
149  int deg[3] ;
150  deg[0] = 1 ;
151  deg[1] = nt2 ;
152  deg[2] = 1 ;
153 
154 // Tableaux de travail
155  double* yy = new double[nt2] ; //(double*)( malloc( nt2*sizeof(double) ) ) ;
156 
157 
158 //-------------------
159 // Boucle sur m
160 //-------------------
161 
162  for (m=0; m < np/2+1 ; m++) {
163 
164 // Recherche des fonctions de Legendre associees d'ordre m :
165 
166  double* leg = legendre_norm(m, nt) ;
167 
168  if (m%2==0) {
169 // Cas m pair
170 //-----------
171  for (l=m; l<nt; l++) { // boucle sur les P_{l}^m
172 
173  int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
174 
175  for (j2=0; j2<nt; j2++) {
176  yy[j2] = leg[nt2* (l-m) + 2*j2] ;
177  }
178 
179  for (j2=nt; j2<nt2; j2++) {
180  yy[j2] = parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ;
181  }
182 
183 //....... transformation en cos(j*theta) :
184 
185  cftcos(deg, deg, yy, deg, yy) ;
186 
187 //....... le resultat fournit les elements de matrice :
188  for (j=0; j<nt; j++) {
189  tab[indice][ nt*nt* m + nt*j + l] = yy[j] ;
190  }
191 
192  } // fin de la boucle sur l (indice de P_{l}^m)
193 
194 
195  } // fin du cas m pair
196  else {
197 
198 // Cas m impair
199 //-------------
200 
201  for (l=m; l<nt; l++) { // boucle sur les P_{l}^m
202 
203  int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
204 
205  for (j2=0; j2<nt; j2++) {
206  yy[j2] = leg[nt2* (l-m) + 2*j2] ;
207  }
208 
209  for (j2=nt; j2<nt2; j2++) {
210  yy[j2] = parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ;
211  }
212 
213 
214 //....... transformation en sin(j*theta) :
215 
216  cftsin(deg, deg, yy, deg, yy) ;
217 
218 //....... le resultat fournit les elements de matrice :
219  for (j=0; j<nt-1; j++) {
220  tab[indice][ nt*nt* m + nt*j + l] = yy[j] ;
221  }
222 
223  } // fin de la boucle sur l (indice de P_{2l+1}^m)
224 
225 
226  } // fin du cas m impair
227 
228  delete [] leg ;
229 
230  } // fin de la boucle sur m
231 
232 // Liberation espace memoire
233 // -------------------------
234 
235  delete [] yy ;
236 
237  } // fin du cas ou le calcul etait necessaire
238 
239  } // Fin de zone critique
240 
241  return tab[indice] ;
242 
243 }
244 
245 
246 }
Lorene
Lorene prototypes.
Definition: app_hor.h:64