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
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.7 2016/12/05 16:18:02 j_novak Exp $
64 * $Log: mat_sini_legpi.C,v $
65 * Revision 1.7 2016/12/05 16:18:02 j_novak
66 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
67 *
68 * Revision 1.6 2014/10/13 08:53:14 j_novak
69 * Lorene classes and functions now belong to the namespace Lorene.
70 *
71 * Revision 1.5 2014/10/06 15:16:03 j_novak
72 * Modified #include directives to use c++ syntax.
73 *
74 * Revision 1.4 2005/02/18 13:14:15 j_novak
75 * Changing of malloc/free to new/delete + suppression of some unused variables
76 * (trying to avoid compilation warnings).
77 *
78 * Revision 1.3 2003/01/31 10:31:24 e_gourgoulhon
79 * Suppressed the directive #include <malloc.h> for malloc is defined
80 * in <stdlib.h>
81 *
82 * Revision 1.2 2002/10/16 14:36:57 j_novak
83 * Reorganization of #include instructions of standard C++, in order to
84 * use experimental version 3 of gcc.
85 *
86 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
87 * LORENE
88 *
89 * Revision 2.1 2000/11/14 15:12:47 eric
90 * Traitement du cas np=1
91 *
92 * Revision 2.0 2000/09/29 16:09:49 eric
93 * *** empty log message ***
94 *
95 *
96 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sini_legpi.C,v 1.7 2016/12/05 16:18:02 j_novak Exp $
97 *
98 */
99
100// headers du C
101#include <cstdlib>
102#include <cmath>
103#include <cassert>
104
105// Prototypage
106#include "headcpp.h"
107#include "proto.h"
108
109namespace Lorene {
110//******************************************************************************
111
112double* mat_sini_legpi(int np, int nt) {
113
114#define NMAX 30 // Nombre maximun de couples(np,nt) differents
115static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
116static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
117static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
118 // calcul a deja ete fait
119static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
120 // calcul a deja ete fait
121
122int i, indice, j, j2, m, l ;
123
124 {
125
126 // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
127 indice = -1 ;
128 for ( i=0 ; i < nb_dejafait ; i++ ) {
129 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
130 }
131
132
133// Si le calcul n'a pas deja ete fait, il faut le faire :
134 if (indice == -1) {
135 if ( nb_dejafait >= NMAX ) {
136 cout << "mat_cosp_legpp: nb_dejafait >= NMAX : "
137 << nb_dejafait << " <-> " << NMAX << endl ;
138 abort () ;
139 exit(-1) ;
140 }
141 indice = nb_dejafait ;
142 nb_dejafait++ ;
143 np_dejafait[indice] = np ;
144 nt_dejafait[indice] = nt ;
145
146 tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
147
148//-----------------------
149// Preparation du calcul
150//-----------------------
151
152// Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
153 int nt2 = 2*nt - 1 ;
154 int nt2m1 = nt2 - 1 ;
155
156 int deg[3] ;
157 deg[0] = 1 ;
158 deg[1] = 1 ;
159 deg[2] = nt2 ;
160
161// Tableaux de travail
162 double* yy = new double[nt2] ;//(double*)( malloc( nt2*sizeof(double) ) ) ;
163 double* sint = new double[nt*nt2] ; //(double*)( malloc( nt*nt2*sizeof(double) ) ) ;
164
165// Calcul des sin( (2j+1) theta) aux points de collocation
166// de l'echantillonnage double :
167
168 double dt = M_PI / double(2*(nt2-1)) ;
169 for (j=0; j<nt-1; j++) {
170 for (j2=0; j2<nt2; j2++) {
171 double theta = j2*dt ;
172 sint[nt2*j + j2] = sin( (2*j+1) * theta ) ;
173 }
174 }
175
176
177//-------------------
178// Boucle sur m
179//-------------------
180
181 int m_max = (np == 1) ? 1 : np-1 ;
182
183 for (m=1; m <= m_max ; m+=2) {
184
185 // Recherche des fonctions de Legendre associees d'ordre m :
186
187 double* leg = legendre_norm(m, nt) ;
188
189 for (l=(m-1)/2; l<nt-1; l++) { // boucle sur les P_{2l+1}^m
190
191 int ll = 2*l+1 ; // degre des fonctions de Legendre
192
193 for (j=0; j<nt-1; j++) { // boucle sur les sin((2j+1)theta)
194
195 //... produit scalaire de sin((2j+1) theta) par
196 // P_{2l+1}^m(cos(theta))
197
198 for (j2=0; j2<nt2; j2++) {
199 yy[nt2m1-j2] = sint[nt2*j + j2]
200 * leg[nt2* (ll-m) + j2] ;
201 }
202
203//....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
204// l'integrale (routine int1d_chebp) :
205 cfrchebp(deg, deg, yy, deg, yy) ;
206 tab[indice][ nt*nt* ((m-1)/2) + nt*l + j] =
207 2.*int1d_chebp(nt2, yy) ;
208
209
210 } // fin de la boucle sur j (indice de sin((2j+1)theta) )
211
212 } // fin de la boucle sur l (indice de P_{2l+1}^m)
213
214 delete [] leg ;
215
216 } // fin de la boucle sur m
217
218// Liberation espace memoire
219// -------------------------
220
221 delete [] yy ;
222 delete [] sint ;
223
224 } // fin du cas ou le calcul etait necessaire
225
226 } //Fin de zone critique
227
228 return tab[indice] ;
229
230}
231
232
233}
Cmp sin(const Cmp &)
Sine.
Definition cmp_math.C:72
Lorene prototypes.
Definition app_hor.h:67
Coord sint
Definition map.h:733