LORENE
legendre_norm.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  * Calcule les valeurs des fonctions de Legendre associees
27  * P_l^m(cos(theta)) normalisees de facon a ce que
28  *
29  * int_0^pi [ P_l^m(cos(theta)) ]^2 sin(theta) dtheta = 1
30  *
31  * NB: Cette normalisation est differente de celle de la litterature
32  *
33  * Le calcul est effectue aux 2*nt-1 points
34  * theta_j = pi/2 j/(2*nt-2) 0 <= j <= 2*nt-2
35  * qui echantillonnent uniformement l'intervalle [0, pi/2].
36  *
37  *
38  * Entree:
39  * -------
40  * int m : ordre de la fonction de Legendre associee P_l^m
41  * int nt : nombre de points en theta
42  *
43  * Sortie (valeur de retour) :
44  * -------------------------
45  * double* legendre_norm : ensemble des (2*nt-1-m)*(2*nt-1) valeurs
46  * P_l^m(cos(theta))
47  * stokees comme suit:
48  *
49  * legendre_norm[(2*nt-1)* (l-m) + j] = P_l^m( cos(theta_j) )
50  *
51  * avec m <= l <= 2*nt-2.
52  *
53  * NB: Cette routine effectue le calcul a chaque appel et ne renvoie pas
54  * un pointeur sur des valeurs precedemment calculees.
55  */
56 
57 
58 /*
59  * $Id: legendre_norm.C,v 1.7 2016/12/05 16:18:02 j_novak Exp $
60  * $Log: legendre_norm.C,v $
61  * Revision 1.7 2016/12/05 16:18:02 j_novak
62  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
63  *
64  * Revision 1.6 2014/10/13 08:53:13 j_novak
65  * Lorene classes and functions now belong to the namespace Lorene.
66  *
67  * Revision 1.5 2014/10/06 15:16:02 j_novak
68  * Modified #include directives to use c++ syntax.
69  *
70  * Revision 1.4 2005/02/18 13:14:13 j_novak
71  * Changing of malloc/free to new/delete + suppression of some unused variables
72  * (trying to avoid compilation warnings).
73  *
74  * Revision 1.3 2003/01/31 10:31:24 e_gourgoulhon
75  * Suppressed the directive #include <malloc.h> for malloc is defined
76  * in <stdlib.h>
77  *
78  * Revision 1.2 2002/10/16 14:36:54 j_novak
79  * Reorganization of #include instructions of standard C++, in order to
80  * use experimental version 3 of gcc.
81  *
82  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
83  * LORENE
84  *
85  * Revision 2.0 1999/02/22 15:37:00 hyc
86  * *** empty log message ***
87  *
88  *
89  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/legendre_norm.C,v 1.7 2016/12/05 16:18:02 j_novak Exp $
90  *
91  */
92 
93 // headers du C
94 #include <cstdlib>
95 #include <cassert>
96 #include <cmath>
97 
98 // Prototypage
99 #include "headcpp.h"
100 #include "proto.h"
101 
102 namespace Lorene {
103 //******************************************************************************
104 
105 double* legendre_norm(int m, int nt) {
106 
107 int l, j ;
108 
109  int lmax = 2*nt - 2 ;
110 
111 // Sur-echantillonnage pour calculer les carres sans aliasing:
112  int nt2 = 2*nt - 1 ;
113  int nt2m1 = nt2 - 1 ;
114 
115  int deg[3] ;
116  deg[0] = 1 ;
117  deg[1] = 1 ;
118  deg[2] = nt2 ;
119 
120 // Tableau de travail
121  double* yy = new double[nt2] ; //(double*)( malloc( nt2*sizeof(double) ) ) ;
122 
123 // Recherche des fonctions de legendre associees non normalisees
124 // -------------------------------------------------------------
125 // (NB: elles different de celles de la litterature par un facteur (2m-1)!!) :
126 
127  double* leg = legendre(m, nt2) ;
128 
129 // Normalisation
130 // -------------
131  for (l=m; l<lmax+1; l++) {
132 
133  int ml = (m+1)*(l+1) ;
134 
135 // On divise les fonctions de Legendre par (m+1)*(l+1)
136 // pour obtenir des nombres pas trop grands:
137 
138  for (j=0; j<nt2; j++) {
139  leg[nt2*(l-m)+j] /= ml ;
140  }
141 
142 // Carre :
143  for (j=0; j<nt2; j++) {
144  double w = leg[nt2*(l-m)+j] ;
145  yy[nt2m1-j] = w * w ; // le rangement est celui qui convient
146  // a cfrchebp
147  }
148 
149 // Developpement en polynomes de Tchebyshev pairs (x=cos(theta)) :
150 
151  cfrchebp(deg, deg, yy, deg, yy) ;
152 
153 // Integrale sur [0,Pi] = 2 fois l'integrale sur [0,1] pour x = cos(theta) :
154  double integ = 2.*int1d_chebp(nt2, yy) ;
155 
156 // Facteur de normalisation
157  double fact = 1. / sqrt(integ) ;
158 
159 /* Test: Comparaison avec le resultat analytique
160  *
161  * double fact_test = ml* factorielle2(2*m-1) * sqrt( double(2*l+1)/2.
162  * * factorielle(l-m) / factorielle(l+m) ) ;
163  * double diff = (fact - fact_test) / fact_test ;
164  *
165  * cout << "m, l : "<< m << " " << l << " : " << fact << " " << fact_test
166  * << " " << diff << endl ;
167  */
168 
169  for (j=0; j<nt2; j++) {
170  leg[nt2*(l-m)+j] *= fact ;
171  }
172 
173  } // fin de la boucle sur l
174 
175 // Liberation espace memoire :
176  delete [] yy ;
177 
178  return leg ;
179 
180 }
181 
182 
183 
184 }
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
Lorene prototypes.
Definition: app_hor.h:67