LORENE
mat_legmp_cos.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/*
28 * Fournit la matrice de passage pour la transformation des coefficients du
29 * developpement en fonctions associees de Legendre
30 * P_l^m(cos(theta)) avec m pair dans les coefficients du developpement
31 * en cos(j*theta).
32 *
33 * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas
34 * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment
35 * calculee.
36 *
37 * Entree:
38 * -------
39 * int np : Nombre de degres de liberte en phi
40 * int nt : Nombre de degres de liberte en theta
41 *
42 * Sortie (valeur de retour) :
43 * ---------------------------
44 * double* mat_lemp_cos : pointeur sur le tableau contenant l'ensemble
45 * (pour les np/2+1 valeurs de m: m=0,2,...,np)) des
46 * matrices de passage.
47 * La dimension du tableau est (np/2+1)*nt^2
48 * Le stokage est le suivant:
49 *
50 * mat_legpp_cosp[ nt*nt* m/2 + nt*j + l] = B_{mjl}
51 *
52 * ou B_{mjl} (m pair) est defini par
53 *
54 * P_l^m( cos(theta) ) = som_{j=0}^{nt-1} B_{mjl} cos(j*theta)
55 *
56 * ou P_n^m(x) represente la fonction de Legendre associee de degre n et
57 * d'ordre m normalisee de facon a ce que
58 *
59 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
60 *
61 *
62 */
63
64/*
65 * $Id: mat_legmp_cos.C,v 1.4 2016/12/05 16:18:02 j_novak Exp $
66 * $Log: mat_legmp_cos.C,v $
67 * Revision 1.4 2016/12/05 16:18:02 j_novak
68 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
69 *
70 * Revision 1.3 2014/10/13 08:53:14 j_novak
71 * Lorene classes and functions now belong to the namespace Lorene.
72 *
73 * Revision 1.2 2014/10/06 15:16:03 j_novak
74 * Modified #include directives to use c++ syntax.
75 *
76 * Revision 1.1 2009/10/13 13:49:36 j_novak
77 * New base T_LEG_MP.
78 *
79 *
80 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legmp_cos.C,v 1.4 2016/12/05 16:18:02 j_novak Exp $
81 *
82 */
83
84
85// headers du C
86#include <cstdlib>
87#include <cmath>
88
89// Prototypage
90#include "headcpp.h"
91#include "proto.h"
92
93namespace Lorene {
94//******************************************************************************
95
96double* mat_legmp_cos(int np, int nt) {
97
98#define NMAX 30 // Nombre maximun de couples(np,nt) differents
99 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
100 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
101 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
102 // calcul a deja ete fait
103 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
104 // calcul a deja ete fait
105
106 int i, indice, j, j2, m, l ;
107
108// Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ?
109
110 indice = -1 ;
111 for ( i=0 ; i < nb_dejafait ; i++ ) {
112 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
113 }
114
115
116// Si le calcul n'a pas deja ete fait, il faut le faire :
117 if (indice == -1) {
118 if ( nb_dejafait >= NMAX ) {
119 cout << "mat_legpp_cosp: nb_dejafait >= NMAX : "
120 << nb_dejafait << " <-> " << NMAX << endl ;
121 abort () ;
122 exit(-1) ;
123 }
124 indice = nb_dejafait ;
125 nb_dejafait++ ;
126 np_dejafait[indice] = np ;
127 nt_dejafait[indice] = nt ;
128
129 tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
130
131//-----------------------
132// Preparation du calcul
133//-----------------------
134
135// Sur-echantillonnage :
136 int nt2 = 2*nt - 1 ;
137
138 int deg[3] ;
139 deg[0] = 1 ;
140 deg[1] = nt2 ;
141 deg[2] = 1 ;
142
143// Tableaux de travail
144 double* yy = new double[nt2] ;//(double*)( malloc( nt2*sizeof(double) ) ) ;
145
146
147//-------------------
148// Boucle sur m
149//-------------------
150
151 int m_max = np ;
152 if (np == 1) m_max = 0 ;
153
154 for (m=0; m <= m_max ; m+=2) {
155
156// Recherche des fonctions de Legendre associees d'ordre m :
157
158 double* leg = legendre_norm(m, nt) ;
159
160 for (l=m; l<nt; l++) { // boucle sur les P_l^m
161
162 int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
163
164 for (j2=0; j2<nt; j2++) {
165 yy[j2] = leg[nt2* (l-m) + 2*j2] ;
166 }
167
168 for (j2=nt; j2<nt2; j2++) {
169 yy[j2] = parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ;
170 }
171
172//....... transformation en cos(j*theta) :
173
174 cftcos(deg, deg, yy, deg, yy) ;
175
176//....... le resultat fournit les elements de matrice :
177 for (j=0; j<nt; j++) {
178 tab[indice][ nt*nt* m/2 + nt*j + l] = yy[j] ;
179 }
180
181 } // fin de la boucle sur l (indice de P_l^m)
182
183 delete [] leg ;
184
185 } // fin de la boucle sur m
186
187// Liberation espace memoire
188// -------------------------
189
190 delete [] yy ;
191
192 } // fin du cas ou le calcul etait necessaire
193
194 return tab[indice] ;
195
196}
197
198
199}
Lorene prototypes.
Definition app_hor.h:67