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