00001 /* 00002 * Copyright (c) 1999-2001 Eric Gourgoulhon 00003 * 00004 * This file is part of LORENE. 00005 * 00006 * LORENE is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * LORENE is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with LORENE; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 00023 char legendre_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/legendre.C,v 1.4 2005/02/18 13:14:13 j_novak Exp $" ; 00024 00025 /* 00026 * Calcule les valeurs des fonctions de Legendre associees 00027 * P_l^m(cos(theta)) / (2m-1)!! 00028 * aux points 00029 * theta_j = pi/2 j/(nt-1) 0 <= j <= nt-1 00030 * qui echantillonnent uniformement l'intervalle [0, pi/2]. 00031 * 00032 * 00033 * Entree: 00034 * ------- 00035 * int m : ordre de la fonction de Legendre associee P_l^m 00036 * int nt : nombre de points en theta 00037 * 00038 * Sortie (valeur de retour) : 00039 * ------------------------- 00040 * double* legendre : ensemble des (nt-m)*nt valeurs 00041 * P_l^m(cos(theta))/(2m-1)!! 00042 * stokees comme suit: 00043 * 00044 * legendre[nt* (l-m) + j] = P_l^m( cos(theta_j) ) / (2m-1)!! 00045 * 00046 * avec m <= l <= nt-1. 00047 * 00048 * NB: Cette routine effectue le calcul a chaque appel et ne renvoie pas 00049 * un pointeur sur des valeurs precedemment calculees. 00050 */ 00051 00052 00053 /* 00054 * $Id: legendre.C,v 1.4 2005/02/18 13:14:13 j_novak Exp $ 00055 * $Log: legendre.C,v $ 00056 * Revision 1.4 2005/02/18 13:14:13 j_novak 00057 * Changing of malloc/free to new/delete + suppression of some unused variables 00058 * (trying to avoid compilation warnings). 00059 * 00060 * Revision 1.3 2003/01/31 10:31:24 e_gourgoulhon 00061 * Suppressed the directive #include <malloc.h> for malloc is defined 00062 * in <stdlib.h> 00063 * 00064 * Revision 1.2 2002/10/16 14:36:54 j_novak 00065 * Reorganization of #include instructions of standard C++, in order to 00066 * use experimental version 3 of gcc. 00067 * 00068 * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon 00069 * LORENE 00070 * 00071 * Revision 2.0 1999/02/22 15:37:13 hyc 00072 * *** empty log message *** 00073 * 00074 * 00075 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/legendre.C,v 1.4 2005/02/18 13:14:13 j_novak Exp $ 00076 * 00077 */ 00078 00079 // headers du C 00080 #include <stdlib.h> 00081 #include <assert.h> 00082 #include <math.h> 00083 00084 #include "headcpp.h" 00085 00086 //****************************************************************************** 00087 00088 double* legendre(int m, int nt) { 00089 00090 int i, j, l ; 00091 00092 int lmax = nt - 1 ; 00093 assert(m >= 0) ; 00094 assert(m <= lmax) ; 00095 00096 double dt = M_PI / double(2*(nt-1)) ; 00097 00098 // Allocation memoire pour le tableau resultat 00099 //-------------------------------------------- 00100 00101 double* resu = new double[(lmax-m+1)*nt] ; //(double *)(malloc( (lmax-m+1)*nt * sizeof(double) )) ; 00102 00103 // Tableau de travail 00104 double* cost = new double[nt] ; //(double*)( malloc( nt*sizeof(double) ) ) ; 00105 00106 //----------------------- 00107 // 1/ Calcul de P_m^m 00108 //----------------------- 00109 00110 if (m==0) { 00111 for (j=0; j<nt; j++) { 00112 resu[j] = 1. ; // P_0^0(x) = 1. 00113 } 00114 } 00115 else { 00116 00117 //... P_m^m(x) = (-1)^m (1-x^2)^{m/2} <--- cette formule donne un P_m^m 00118 // plus petit par un facteur 00119 // (2m-1)!! que celui de la litterature 00120 00121 for (j=0; j<nt; j++) { 00122 double y = 1. ; 00123 double s = sin(j*dt) ; 00124 for (i=1 ; i<2*m; i+=2) { 00125 y *= - s ; 00126 // NB: Pour obtenir le P_m^m de la litterature, il faudrait remplacer la ligne 00127 // ci-dessus par : y *= - i*s ; 00128 } 00129 resu[j] = y ; 00130 //## resu[j] = pow(-s, double(m)) ; 00131 } 00132 } // fin du cas m != 0 00133 00134 if (lmax==m) { 00135 delete [] cost ; 00136 return resu ; 00137 } 00138 else { 00139 00140 //----------------------- 00141 // 2/ Calcul de P_{m+1}^m 00142 //----------------------- 00143 00144 //... Calcul des cos( theta_j ) : 00145 for (j=0; j<nt; j++) { 00146 cost[j] = cos(j*dt) ; 00147 } 00148 00149 for (j=0; j<nt; j++) { 00150 resu[nt+j] = cost[j] * (2.*m+1) * resu[j] ; 00151 } 00152 00153 //----------------------- 00154 // 3/ Calcul de P_l^m pour m+2 <= l <= lmax 00155 //----------------------- 00156 00157 for (l=m+2; l < lmax+1 ; l++) { 00158 int i_l = nt*(l-m) ; 00159 int i_lm1 = nt*(l-1-m) ; 00160 int i_lm2 = nt*(l-2-m) ; 00161 int a = 2*l - 1 ; 00162 int b = l + m - 1 ; 00163 int c = l - m ; 00164 00165 for (j=0; j<nt; j++) { 00166 resu[i_l+j] = ( cost[j] * a * resu[i_lm1+j] 00167 - b * resu[i_lm2+j] ) / c ; 00168 } 00169 } 00170 00171 delete [] cost ; //free (cost) ; 00172 return resu ; 00173 00174 } // fin du cas lmax > m 00175 00176 } 00177 00178 00179
1.4.6