LORENE
mat_legii_sinp.C
1/*
2 * Copyright (c) 2003 Jerome Novak
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_legii_sinp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legii_sinp.C,v 1.4 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 fonctions associees de Legendre
28 * P_l^m(cos(theta)) avec l pair et m impair
29 * dans les coefficients du developpement
30 * en sin( 2j theta ).
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_legii_sinp : pointeur sur le tableau contenant l'ensemble
44 * (pour les np/2 valeurs de m: m=1,3,...,np-1)) 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_legii_sinp[ nt*nt* m/2 + nt*j + l] = B_{mjl}
50 *
51 * ou B_{mjl} (m impair) est defini par
52 *
53 * P_{2l}^m( cos(theta) ) = som_{j=1}^{nt-2} B_{mjl} sin(2*j*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_legii_sinp.C,v 1.4 2014/10/13 08:53:13 j_novak Exp $
65 * $Log: mat_legii_sinp.C,v $
66 * Revision 1.4 2014/10/13 08:53:13 j_novak
67 * Lorene classes and functions now belong to the namespace Lorene.
68 *
69 * Revision 1.3 2014/10/06 15:16:03 j_novak
70 * Modified #include directives to use c++ syntax.
71 *
72 * Revision 1.2 2005/02/18 13:14:15 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.1 2003/09/16 08:58:01 j_novak
77 * New functions for the T_LEG_II base
78 *
79 *
80 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legii_sinp.C,v 1.4 2014/10/13 08:53:13 j_novak Exp $
81 *
82 */
83
84// headers du C
85#include <cstdlib>
86#include <cmath>
87
88// Headers Lorene
89#include "headcpp.h"
90#include "proto.h"
91
92// Variable de loch
93int loch_mat_legii_sinp = 0 ;
94
95namespace Lorene {
96//******************************************************************************
97
98double* mat_legii_sinp(int np, int nt) {
99
100#define NMAX 30 // Nombre maximun de couples(np,nt) differents
101static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
102static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
103static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
104 // calcul a deja ete fait
105static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
106 // calcul a deja ete fait
107
108int i, indice, j, j2, m, l ;
109
110// #pragma critical (loch_mat_legii_sinp)
111 {
112// Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ?
113
114 indice = -1 ;
115 for ( i=0 ; i < nb_dejafait ; i++ ) {
116 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
117 }
118
119
120// Si le calcul n'a pas deja ete fait, il faut le faire :
121 if (indice == -1) {
122 if ( nb_dejafait >= NMAX ) {
123 cout << "mat_legii_sinp: nb_dejafait >= NMAX : "
124 << nb_dejafait << " <-> " << NMAX << endl ;
125 abort () ;
126 exit(-1) ;
127 }
128 indice = nb_dejafait ;
129 nb_dejafait++ ;
130 np_dejafait[indice] = np ;
131 nt_dejafait[indice] = nt ;
132
133 tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
134
135//-----------------------
136// Preparation du calcul
137//-----------------------
138
139// Sur-echantillonnage :
140 int nt2 = 2*nt - 1 ;
141
142 int deg[3] ;
143 deg[0] = 1 ;
144 deg[1] = nt2 ;
145 deg[2] = 1 ;
146
147// Tableaux de travail
148 double* yy = new double[nt2] ; //(double*)( malloc( nt2*sizeof(double) ) ) ;
149
150
151//-------------------
152// Boucle sur m
153//-------------------
154
155 int m_max = (np == 1) ? 1 : np-1 ;
156
157 for (m=1; m <= m_max ; m+=2) {
158
159 // Recherche des fonctions de Legendre associees d'ordre m :
160
161 double* leg = legendre_norm(m, nt) ;
162
163
164 for (l=(m+1)/2; l<nt-1; l++) { // boucle sur les P_{2l}^m
165
166 int ll = 2*l ; // degre des fonctions de Legendre
167
168 for (j2=0; j2<nt2; j2++) {
169 yy[j2] = leg[nt2* (ll-m) + j2] ;
170 }
171
172 //....... transformation en sin(2j*theta) :
173
174 cftsinp(deg, deg, yy, deg, yy) ;
175
176 //....... le resultat fournit les elements de matrice :
177 for (j=0; j<nt-1; j++) {
178 tab[indice][ nt*nt* ((m-1)/2) + nt*j + l] = yy[j] ;
179 }
180
181 } // fin de la boucle sur l (indice de P_{2l}^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 } // Fin de zone critique
195
196 return tab[indice] ;
197
198}
199
200
201}
Lorene prototypes.
Definition app_hor.h:64