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