LORENE
mat_sinp_legii.C
1 /*
2  * Copyright (c) 2003 Jerome Novak
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 sin(2j*theta)
28  * dans les coefficients du developpement en fonctions associees de Legendre
29  * P_l^m(cos(theta)) avec l pair 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_sinp_legii : 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_sinp_legii[ nt*nt* m/2 + nt*l + j] = A_{mlj}
49  *
50  * ou A_{mlj} est defini par
51  *
52  * sin(2*j*theta) = som_{l=(m+1)/2}^{nt-2} A_{mlj} P_{2l}^m( cos(theta) )
53  * pour 1 <= j <= nt-2
54  *
55  * ou P_n^m(x) represente la fonction de Legendre associee de degre n et
56  * d'ordre m normalisee de facon a ce que
57  *
58  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
59  *
60  *
61  */
62 
63 /*
64  * $Id: mat_sinp_legii.C,v 1.5 2016/12/05 16:18:02 j_novak Exp $
65  * $Log: mat_sinp_legii.C,v $
66  * Revision 1.5 2016/12/05 16:18:02 j_novak
67  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
68  *
69  * Revision 1.4 2014/10/13 08:53:14 j_novak
70  * Lorene classes and functions now belong to the namespace Lorene.
71  *
72  * Revision 1.3 2014/10/06 15:16:03 j_novak
73  * Modified #include directives to use c++ syntax.
74  *
75  * Revision 1.2 2005/02/18 13:14:15 j_novak
76  * Changing of malloc/free to new/delete + suppression of some unused variables
77  * (trying to avoid compilation warnings).
78  *
79  * Revision 1.1 2003/09/16 08:58:01 j_novak
80  * New functions for the T_LEG_II base
81  *
82  *
83  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sinp_legii.C,v 1.5 2016/12/05 16:18:02 j_novak Exp $
84  *
85  */
86 
87 // headers du C
88 #include <cstdlib>
89 #include <cmath>
90 #include <cassert>
91 
92 // Prototypage
93 #include "headcpp.h"
94 #include "proto.h"
95 
96 namespace Lorene {
97 //******************************************************************************
98 
99 double* mat_sinp_legii(int np, int nt) {
100 
101 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
102 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
103 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
104 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
105  // calcul a deja ete fait
106 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
107  // calcul a deja ete fait
108 
109 int i, indice, j, j2, m, l ;
110 
111  {
112 
113  // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
114  indice = -1 ;
115  for ( i=0 ; i < nb_dejafait ; i++ ) {
116  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
117  }
118 
119 
120 // Si le calcul n'a pas deja ete fait, il faut le faire :
121  if (indice == -1) {
122  if ( nb_dejafait >= NMAX ) {
123  cout << "mat_sinp_legii: nb_dejafait >= NMAX : "
124  << nb_dejafait << " <-> " << NMAX << endl ;
125  abort () ;
126  exit(-1) ;
127  }
128  indice = nb_dejafait ;
129  nb_dejafait++ ;
130  np_dejafait[indice] = np ;
131  nt_dejafait[indice] = nt ;
132 
133  tab[indice] = new double[(np/2+1)*nt*nt] ;//(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
134 
135 //-----------------------
136 // Preparation du calcul
137 //-----------------------
138 
139 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
140  int nt2 = 2*nt - 1 ;
141  int nt2m1 = nt2 - 1 ;
142 
143  int deg[3] ;
144  deg[0] = 1 ;
145  deg[1] = 1 ;
146  deg[2] = nt2 ;
147 
148 // Tableaux de travail
149  double* yy = new double[nt2] ;//(double*)( malloc( nt2*sizeof(double) ) ) ;
150  double* sint = new double[nt*nt2];//(double*)( malloc( nt*nt2*sizeof(double) ) ) ;
151 
152 // Calcul des sin( 2j theta) aux points de collocation
153 // de l'echantillonnage double :
154 
155  double dt = M_PI / double(2*(nt2-1)) ;
156  for (j=0; j<nt-1; j++) {
157  for (j2=0; j2<nt2; j2++) {
158  double theta = j2*dt ;
159  sint[nt2*j + j2] = sin( 2*j * theta ) ;
160  }
161  }
162 
163 
164 //-------------------
165 // Boucle sur m
166 //-------------------
167 
168  int m_max = (np == 1) ? 1 : np-1 ;
169 
170  for (m=1; 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+1)/2; l<nt-1; l++) { // boucle sur les P_{2l}^m
177 
178  int ll = 2*l ; // degre des fonctions de Legendre
179 
180  for (j=0; j<nt-1; j++) { // boucle sur les sin((2j+1)theta)
181 
182  //... produit scalaire de sin(2j theta) par
183  // P_{2l}^m(cos(theta))
184 
185  for (j2=0; j2<nt2; j2++) {
186  yy[nt2m1-j2] = sint[nt2*j + j2]
187  * leg[nt2* (ll-m) + j2] ;
188  }
189 
190 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
191 // l'integrale (routine int1d_chebp) :
192  cfrchebp(deg, deg, yy, deg, yy) ;
193  tab[indice][ nt*nt* ((m-1)/2) + nt*l + j] =
194  2.*int1d_chebp(nt2, yy) ;
195 
196 
197  } // fin de la boucle sur j (indice de sin((2j)theta) )
198 
199  } // fin de la boucle sur l (indice de P_{2l}^m)
200 
201  delete [] leg ;
202 
203  } // fin de la boucle sur m
204 
205 // Liberation espace memoire
206 // -------------------------
207 
208  delete [] yy ;
209  delete [] sint ;
210 
211  } // fin du cas ou le calcul etait necessaire
212 
213  } //Fin de zone critique
214 
215  return tab[indice] ;
216 
217 }
218 
219 
220 }
Lorene prototypes.
Definition: app_hor.h:67
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:72