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 char mat_sinp_legii_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sinp_legii.C,v 1.4 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*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.4 2014/10/13 08:53:14 j_novak Exp $
65  * $Log: mat_sinp_legii.C,v $
66  * Revision 1.4 2014/10/13 08:53:14 j_novak
67  * Lorene classes and functions now belong to the namespace Lorene.
68  *
69  * Revision 1.3 2014/10/06 15:16:03 j_novak
70  * Modified #include directives to use c++ syntax.
71  *
72  * Revision 1.2 2005/02/18 13:14:15 j_novak
73  * Changing of malloc/free to new/delete + suppression of some unused variables
74  * (trying to avoid compilation warnings).
75  *
76  * Revision 1.1 2003/09/16 08:58:01 j_novak
77  * New functions for the T_LEG_II base
78  *
79  *
80  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sinp_legii.C,v 1.4 2014/10/13 08:53:14 j_novak Exp $
81  *
82  */
83 
84 // headers du C
85 #include <cstdlib>
86 #include <cmath>
87 #include <cassert>
88 
89 // Prototypage
90 #include "headcpp.h"
91 #include "proto.h"
92 
93 // Variable de loch
94 int loch_mat_sinp_legii = 0 ;
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 // #pragma critical (loch_mat_sinp_legii)
112  {
113 
114  // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
115  indice = -1 ;
116  for ( i=0 ; i < nb_dejafait ; i++ ) {
117  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
118  }
119 
120 
121 // Si le calcul n'a pas deja ete fait, il faut le faire :
122  if (indice == -1) {
123  if ( nb_dejafait >= NMAX ) {
124  cout << "mat_sinp_legii: nb_dejafait >= NMAX : "
125  << nb_dejafait << " <-> " << NMAX << endl ;
126  abort () ;
127  exit(-1) ;
128  }
129  indice = nb_dejafait ;
130  nb_dejafait++ ;
131  np_dejafait[indice] = np ;
132  nt_dejafait[indice] = nt ;
133 
134  tab[indice] = new double[(np/2+1)*nt*nt] ;//(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
135 
136 //-----------------------
137 // Preparation du calcul
138 //-----------------------
139 
140 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
141  int nt2 = 2*nt - 1 ;
142  int nt2m1 = nt2 - 1 ;
143 
144  int deg[3] ;
145  deg[0] = 1 ;
146  deg[1] = 1 ;
147  deg[2] = nt2 ;
148 
149 // Tableaux de travail
150  double* yy = new double[nt2] ;//(double*)( malloc( nt2*sizeof(double) ) ) ;
151  double* sint = new double[nt*nt2];//(double*)( malloc( nt*nt2*sizeof(double) ) ) ;
152 
153 // Calcul des sin( 2j theta) aux points de collocation
154 // de l'echantillonnage double :
155 
156  double dt = M_PI / double(2*(nt2-1)) ;
157  for (j=0; j<nt-1; j++) {
158  for (j2=0; j2<nt2; j2++) {
159  double theta = j2*dt ;
160  sint[nt2*j + j2] = sin( 2*j * theta ) ;
161  }
162  }
163 
164 
165 //-------------------
166 // Boucle sur m
167 //-------------------
168 
169  int m_max = (np == 1) ? 1 : np-1 ;
170 
171  for (m=1; m <= m_max ; m+=2) {
172 
173  // Recherche des fonctions de Legendre associees d'ordre m :
174 
175  double* leg = legendre_norm(m, nt) ;
176 
177  for (l=(m+1)/2; l<nt-1; l++) { // boucle sur les P_{2l}^m
178 
179  int ll = 2*l ; // degre des fonctions de Legendre
180 
181  for (j=0; j<nt-1; j++) { // boucle sur les sin((2j+1)theta)
182 
183  //... produit scalaire de sin(2j theta) par
184  // P_{2l}^m(cos(theta))
185 
186  for (j2=0; j2<nt2; j2++) {
187  yy[nt2m1-j2] = sint[nt2*j + j2]
188  * leg[nt2* (ll-m) + j2] ;
189  }
190 
191 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
192 // l'integrale (routine int1d_chebp) :
193  cfrchebp(deg, deg, yy, deg, yy) ;
194  tab[indice][ nt*nt* ((m-1)/2) + nt*l + j] =
195  2.*int1d_chebp(nt2, yy) ;
196 
197 
198  } // fin de la boucle sur j (indice de sin((2j)theta) )
199 
200  } // fin de la boucle sur l (indice de P_{2l}^m)
201 
202  delete [] leg ;
203 
204  } // fin de la boucle sur m
205 
206 // Liberation espace memoire
207 // -------------------------
208 
209  delete [] yy ;
210  delete [] sint ;
211 
212  } // fin du cas ou le calcul etait necessaire
213 
214  } //Fin de zone critique
215 
216  return tab[indice] ;
217 
218 }
219 
220 
221 }
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:69
Lorene prototypes.
Definition: app_hor.h:64