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 mat_cossincp_legp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossincp_legp.C,v 1.4 2005/02/18 13:14:14 j_novak Exp $" ; 00024 00025 /* 00026 * Fournit la matrice de passage pour la transformation des coefficients du 00027 * developpement en cos(2*j*theta) [m pair] / sin( (2*j+1) * theta) [m impair] 00028 * dans les coefficients du developpement en fonctions associees de Legendre 00029 * P_l^m(cos(theta)) paires (i.e. telles que l-m est pair). 00030 * 00031 * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas 00032 * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment 00033 * calculee. 00034 * 00035 * Entree: 00036 * ------- 00037 * int np : Nombre de degres de liberte en phi 00038 * int nt : Nombre de degres de liberte en theta 00039 * 00040 * Sortie (valeur de retour) : 00041 * --------------------------- 00042 * double* mat_cossincp_legp : pointeur sur le tableau contenant l'ensemble 00043 * (pour les np/2+1 valeurs de m) des 00044 * matrices de passage. 00045 * La dimension du tableau est (np/2+1)*nt^2 00046 * Le stokage est le suivant: 00047 * 00048 * mat_cossincp_legp[ nt*nt* m + nt*l + j] = A_{mlj} 00049 * 00050 * ou A_{mlj} est defini par 00051 * 00052 * pour m pair : 00053 * cos(2*j*theta) = som_{l=m/2}^{nt-1} A_{mlj} P_{2l}^m( cos(theta) ) 00054 * 00055 * pour m impair : 00056 * sin((2*j+1)*theta) = som_{l=(m-1)/2}^{nt-2} A_{mlj} P_{2l+1}^m( cos(theta) ) 00057 * 00058 * ou P_n^m(x) represente la fonction de Legendre associee de degre n et 00059 * d'ordre m normalisee de facon a ce que 00060 * 00061 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1 00062 * 00063 * 00064 */ 00065 00066 /* 00067 * $Id: mat_cossincp_legp.C,v 1.4 2005/02/18 13:14:14 j_novak Exp $ 00068 * $Log: mat_cossincp_legp.C,v $ 00069 * Revision 1.4 2005/02/18 13:14:14 j_novak 00070 * Changing of malloc/free to new/delete + suppression of some unused variables 00071 * (trying to avoid compilation warnings). 00072 * 00073 * Revision 1.3 2003/01/31 10:31:24 e_gourgoulhon 00074 * Suppressed the directive #include <malloc.h> for malloc is defined 00075 * in <stdlib.h> 00076 * 00077 * Revision 1.2 2002/10/16 14:36:54 j_novak 00078 * Reorganization of #include instructions of standard C++, in order to 00079 * use experimental version 3 of gcc. 00080 * 00081 * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon 00082 * LORENE 00083 * 00084 * Revision 2.0 1999/02/22 15:34:45 hyc 00085 * *** empty log message *** 00086 * 00087 * 00088 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossincp_legp.C,v 1.4 2005/02/18 13:14:14 j_novak Exp $ 00089 * 00090 */ 00091 00092 // headers du C 00093 #include <stdlib.h> 00094 #include <math.h> 00095 00096 // Prototypage 00097 #include "headcpp.h" 00098 #include "proto.h" 00099 00100 // Variable de loch 00101 int loch_mat_cossincp_legp = 0 ; 00102 00103 //****************************************************************************** 00104 00105 double* mat_cossincp_legp(int np, int nt) { 00106 00107 #define NMAX 30 // Nombre maximun de couples(np,nt) differents 00108 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 00109 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises 00110 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00111 // calcul a deja ete fait 00112 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00113 // calcul a deja ete fait 00114 00115 int i, indice, j, j2, m, l ; 00116 00117 // #pragma critical (loch_mat_cossincp_legp) 00118 { 00119 00120 // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ? 00121 indice = -1 ; 00122 for ( i=0 ; i < nb_dejafait ; i++ ) { 00123 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ; 00124 } 00125 00126 00127 // Si le calcul n'a pas deja ete fait, il faut le faire : 00128 if (indice == -1) { 00129 if ( nb_dejafait >= NMAX ) { 00130 cout << "mat_cossincp_legp: nb_dejafait >= NMAX : " 00131 << nb_dejafait << " <-> " << NMAX << endl ; 00132 abort () ; 00133 exit(-1) ; 00134 } 00135 indice = nb_dejafait ; 00136 nb_dejafait++ ; 00137 np_dejafait[indice] = np ; 00138 nt_dejafait[indice] = nt ; 00139 00140 tab[indice] = new double[(np/2+1)*nt*nt] ; 00141 00142 //----------------------- 00143 // Preparation du calcul 00144 //----------------------- 00145 00146 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing: 00147 int nt2 = 2*nt - 1 ; 00148 int nt2m1 = nt2 - 1 ; 00149 00150 int deg[3] ; 00151 deg[0] = 1 ; 00152 deg[1] = 1 ; 00153 deg[2] = nt2 ; 00154 00155 // Tableaux de travail 00156 double* yy = new double[nt2] ; 00157 double* cost = new double[nt*nt2] ; 00158 double* sint = new double[nt*nt2] ; 00159 00160 // Calcul des cos(2*j*theta) / sin( (2*j+1)*theta ) aux points de collocation 00161 // de l'echantillonnage double : 00162 00163 double dt = M_PI / double(2*(nt2-1)) ; 00164 for (j=0; j<nt; j++) { 00165 for (j2=0; j2<nt2; j2++) { 00166 double theta = j2*dt ; 00167 cost[nt2*j + j2] = cos( 2*j * theta ) ; 00168 sint[nt2*j + j2] = sin( (2*j+1) * theta ) ; 00169 } 00170 } 00171 00172 00173 //------------------- 00174 // Boucle sur m 00175 //------------------- 00176 00177 for (m=0; m < np/2+1 ; m++) { 00178 00179 // Recherche des fonctions de Legendre associees d'ordre m : 00180 00181 double* leg = legendre_norm(m, nt) ; 00182 00183 if (m%2==0) { 00184 // Cas m pair 00185 //----------- 00186 for (l=m/2; l<nt; l++) { // boucle sur les P_{2l}^m 00187 00188 int ll = 2*l ; // degre des fonctions de Legendre 00189 00190 for (j=0; j<nt; j++) { // boucle sur les cos(2j theta) 00191 00192 //... produit scalaire de cos(2j theta) par P_{2l}^m(cos(theta)) 00193 00194 for (j2=0; j2<nt2; j2++) { 00195 yy[nt2m1-j2] = cost[nt2*j + j2] * 00196 leg[nt2* (ll-m) + j2] ; 00197 } 00198 00199 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer 00200 // l'integrale (routine int1d_chebp) : 00201 cfrchebp(deg, deg, yy, deg, yy) ; 00202 tab[indice][ nt*nt* m + nt*l + j] = 00203 2.*int1d_chebp(nt2, yy) ; 00204 00205 } // fin de la boucle sur j (indice de cos(2j theta) ) 00206 00207 } // fin de la boucle sur l (indice de P_{2l}^m) 00208 00209 00210 } // fin du cas m pair 00211 else { 00212 00213 // Cas m impair 00214 //------------- 00215 00216 for (l=(m-1)/2; l<nt-1; l++) { // boucle sur les P_{2l+1}^m 00217 00218 int ll = 2*l+1 ; // degre des fonctions de Legendre 00219 00220 for (j=0; j<nt-1; j++) { // boucle sur les sin((2j+1)theta) 00221 00222 //... produit scalaire de sin((2j+1) theta) par P_{2l+1}^m(cos(theta)) 00223 00224 for (j2=0; j2<nt2; j2++) { 00225 yy[nt2m1-j2] = sint[nt2*j + j2] * 00226 leg[nt2* (ll-m) + j2] ; 00227 } 00228 00229 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer 00230 // l'integrale (routine int1d_chebp) : 00231 cfrchebp(deg, deg, yy, deg, yy) ; 00232 tab[indice][ nt*nt* m + nt*l + j] = 00233 2.*int1d_chebp(nt2, yy) ; 00234 00235 } // fin de la boucle sur j (indice de sin((2j+1)theta) ) 00236 00237 } // fin de la boucle sur l (indice de P_{2l+1}^m) 00238 00239 00240 } // fin du cas m impair 00241 00242 delete [] leg ; 00243 00244 } // fin de la boucle sur m 00245 00246 // Liberation espace memoire 00247 // ------------------------- 00248 00249 delete [] yy ; 00250 delete [] cost ; 00251 delete [] sint ; 00252 00253 } // fin du cas ou le calcul etait necessaire 00254 00255 } // Fin de zone critique 00256 00257 return tab[indice] ; 00258 00259 } 00260 00261
1.4.6