LORENE
mat_cos_legmp.C
1/*
2 * Copyright (c) 1999-2001 Eric Gourgoulhon
3 * 2009 Jerome Novak
4 *
5 * This file is part of LORENE.
6 *
7 * LORENE is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * LORENE is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with LORENE; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23
24
25
26/*
27 * Fournit la matrice de passage pour la transformation des coefficients du
28 * developpement en cos(j*theta)
29 * dans les coefficients du developpement en fonctions associees de Legendre
30 * P_l^m(cos(theta)) telles que m est pair.
31 *
32 * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas
33 * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment
34 * calculee.
35 *
36 * Entree:
37 * -------
38 * int np : Nombre de degres de liberte en phi
39 * int nt : Nombre de degres de liberte en theta
40 *
41 * Sortie (valeur de retour) :
42 * ---------------------------
43 * double* mat_cos_legmp : pointeur sur le tableau contenant l'ensemble
44 * (pour les np/2+1 valeurs de m: m=0,2,...,np) des
45 * matrices de passage.
46 * La dimension du tableau est (np/2+1)*nt^2
47 * Le stokage est le suivant:
48 *
49 * mat_cos_legmp[ nt*nt* m/2 + nt*l + j] = A_{mlj}
50 *
51 * ou A_{mlj} est defini par
52 *
53 * cos(j*theta) = som_{l=m}^{nt-1} A_{mlj} P_l^m( cos(theta) )
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_cos_legmp.C,v 1.4 2016/12/05 16:18:02 j_novak Exp $
65 * $Log: mat_cos_legmp.C,v $
66 * Revision 1.4 2016/12/05 16:18:02 j_novak
67 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
68 *
69 * Revision 1.3 2014/10/13 08:53:13 j_novak
70 * Lorene classes and functions now belong to the namespace Lorene.
71 *
72 * Revision 1.2 2014/10/06 15:16:02 j_novak
73 * Modified #include directives to use c++ syntax.
74 *
75 * Revision 1.1 2009/10/13 13:49:36 j_novak
76 * New base T_LEG_MP.
77 *
78 *
79 *
80 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cos_legmp.C,v 1.4 2016/12/05 16:18:02 j_novak Exp $
81 *
82 */
83
84// headers du C
85#include <cstdlib>
86#include <cmath>
87
88// Prototypage
89#include "headcpp.h"
90#include "proto.h"
91
92namespace Lorene {
93//******************************************************************************
94
95double* mat_cos_legmp(int np, int nt) {
96
97#define NMAX 30 // Nombre maximun de couples(np,nt) differents
98 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
99 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
100 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
101 // calcul a deja ete fait
102 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
103 // calcul a deja ete fait
104
105 int i, indice, j, j2, m, l ;
106
107
108 // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
109 indice = -1 ;
110 for ( i=0 ; i < nb_dejafait ; i++ ) {
111 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
112 }
113
114
115// Si le calcul n'a pas deja ete fait, il faut le faire :
116 if (indice == -1) {
117 if ( nb_dejafait >= NMAX ) {
118 cout << "mat_cos_legmp: nb_dejafait >= NMAX : "
119 << nb_dejafait << " <-> " << NMAX << endl ;
120 abort () ;
121 exit(-1) ;
122 }
123 indice = nb_dejafait ;
124 nb_dejafait++ ;
125 np_dejafait[indice] = np ;
126 nt_dejafait[indice] = nt ;
127
128 tab[indice] = new double[(np/2+1)*nt*nt] ;
129
130//-----------------------
131// Preparation du calcul
132//-----------------------
133
134// Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
135 int nt2 = 2*nt - 1 ;
136 int nt2m1 = nt2 - 1 ;
137
138 int deg[3] ;
139 deg[0] = 1 ;
140 deg[1] = 1 ;
141 deg[2] = nt2 ;
142
143// Tableaux de travail
144 double* yy = new double[nt2] ;
145 double* cost = new double[nt*nt2] ;
146
147// Calcul des cos(j*theta) aux points de collocation
148// de l'echantillonnage double :
149
150 double dt = M_PI / double(nt2-1) ;
151 for (j=0; j<nt; j++) {
152 for (j2=0; j2<nt2; j2++) {
153 double theta = j2*dt ;
154 cost[nt2*j + j2] = cos( j * theta ) ;
155 }
156 }
157
158
159//-------------------
160// Boucle sur m
161//-------------------
162
163 int m_max = np ;
164 if (np == 1) m_max = 0 ;
165
166 for (m=0; m <= m_max ; m+=2) {
167
168// Recherche des fonctions de Legendre associees d'ordre m :
169
170 double* leg = legendre_norm(m, nt) ;
171
172 for (l=m; l<nt; l++) { // boucle sur les P_l^m
173
174 int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
175 for (j=0; j<nt; j++) { // boucle sur les cos(j theta)
176
177//... produit scalaire de cos(j theta) par P_l^m(cos(theta))
178
179 for (j2=0; j2<nt; j2++) {
180 yy[nt2m1-j2] = cost[nt2*j + j2] *
181 leg[nt2* (l-m) + 2*j2] ;
182 }
183
184 for (j2 = nt; j2<nt2; j2++) {
185 yy[nt2m1-j2] = cost[nt2*j + j2] *
186 parite * leg[nt2* (l-m) + 2*nt2 -2 -2*j2] ;
187 }
188
189//....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
190// l'integrale (routine int1d_cheb) :
191 cfrcheb(deg, deg, yy, deg, yy) ;
192 tab[indice][ nt*nt* m/2 + nt*l + j] =
193 int1d_cheb(nt2, yy) ;
194
195 } // fin de la boucle sur j (indice de cos(j theta) )
196
197 } // fin de la boucle sur l (indice de P_l^m)
198
199 delete [] leg ;
200
201 } // fin de la boucle sur m
202
203// Liberation espace memoire
204// -------------------------
205
206 delete [] yy ;
207 delete [] cost ;
208
209 } // fin du cas ou le calcul etait necessaire
210
211 return tab[indice] ;
212
213}
214
215
216}
Cmp cos(const Cmp &)
Cosine.
Definition cmp_math.C:97
Lorene prototypes.
Definition app_hor.h:67
Coord cost
Definition map.h:734