00001 /* 00002 * Copyright (c) 2004 Michael Forot 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_leg_cossinc_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_leg_cossinc.C,v 1.3 2005/02/18 13:14:15 j_novak Exp $" ; 00024 00025 /* 00026 * Fournit la matrice de passage pour la transformation des coefficients du 00027 * developpement en fonctions associees de Legendre 00028 * P_l^m(cos(theta)) 00029 * dans les coefficients du developpement 00030 * en cos(j*theta) [m pair] / sin( j * theta) [m impair] 00031 * 00032 * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas 00033 * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment 00034 * calculee. 00035 * 00036 * Entree: 00037 * ------- 00038 * int np : Nombre de degres de liberte en phi 00039 * int nt : Nombre de degres de liberte en theta 00040 * 00041 * Sortie (valeur de retour) : 00042 * --------------------------- 00043 * double* mat_leg_cossinc : pointeur sur le tableau contenant l'ensemble 00044 * (pour les np/2+1 valeurs de m) des 00045 * matrices de passage. 00046 * La dimension du tableau est (np/2+1)*nt^2 00047 * Le stokage est le suivant: 00048 * 00049 * mat_legp_cossinc[ nt*nt* m + nt*j + l] = B_{mjl} 00050 * 00051 * ou B_{mjl} est defini par 00052 * 00053 * pour m pair : 00054 * P_{l}^m( cos(theta) ) = som_{j=0}^{nt2-1} B_{mjl} cos(j*theta) 00055 * 00056 * pour m impair : 00057 * P_{l}^m( cos(theta) ) = som_{j=0}^{nt2-2} B_{mjl} sin(j*theta) 00058 * 00059 * ou P_n^m(x) represente la fonction de Legendre associee de degre n et 00060 * d'ordre m normalisee de facon a ce que 00061 * 00062 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1 00063 * 00064 * 00065 */ 00066 00067 /* 00068 * $Id: mat_leg_cossinc.C,v 1.3 2005/02/18 13:14:15 j_novak Exp $ 00069 * $Log: mat_leg_cossinc.C,v $ 00070 * Revision 1.3 2005/02/18 13:14:15 j_novak 00071 * Changing of malloc/free to new/delete + suppression of some unused variables 00072 * (trying to avoid compilation warnings). 00073 * 00074 * Revision 1.2 2004/12/17 15:42:02 e_gourgoulhon 00075 * l_max = nt instead of nt2. 00076 * 00077 * Revision 1.1 2004/11/23 15:13:50 m_forot 00078 * Added the bases for the cases without any equatorial symmetry 00079 * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I). 00080 * 00081 * 00082 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_leg_cossinc.C,v 1.3 2005/02/18 13:14:15 j_novak Exp $ 00083 * 00084 */ 00085 00086 // headers du C 00087 #include <stdlib.h> 00088 #include <math.h> 00089 00090 // Prototypage 00091 #include "headcpp.h" 00092 #include "proto.h" 00093 00094 // Variable de loch 00095 int loch_mat_leg_cossinc = 0 ; 00096 00097 //****************************************************************************** 00098 00099 double* mat_leg_cossinc(int np, int nt) { 00100 00101 #define NMAX 30 // Nombre maximun de couples(np,nt) differents 00102 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 00103 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises 00104 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00105 // calcul a deja ete fait 00106 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00107 // calcul a deja ete fait 00108 00109 int i, indice, j, j2, m, l ; 00110 00111 // #pragma critical (loch_mat_leg_cossinc) 00112 { 00113 // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ? 00114 indice = -1 ; 00115 for ( i=0 ; i < nb_dejafait ; i++ ) { 00116 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ; 00117 } 00118 00119 00120 // Si le calcul n'a pas deja ete fait, il faut le faire : 00121 if (indice == -1) { 00122 if ( nb_dejafait >= NMAX ) { 00123 cout << "mat_legp_cossinc: nb_dejafait >= NMAX : " 00124 << nb_dejafait << " <-> " << NMAX << endl ; 00125 abort () ; 00126 exit(-1) ; 00127 } 00128 indice = nb_dejafait ; 00129 nb_dejafait++ ; 00130 np_dejafait[indice] = np ; 00131 nt_dejafait[indice] = nt ; 00132 00133 tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ; 00134 00135 //----------------------- 00136 // Preparation du calcul 00137 //----------------------- 00138 00139 // Sur-echantillonnage : 00140 int nt2 = 2*nt - 1 ; 00141 00142 int deg[3] ; 00143 deg[0] = 1 ; 00144 deg[1] = nt2 ; 00145 deg[2] = 1 ; 00146 00147 // Tableaux de travail 00148 double* yy = new double[nt2] ; //(double*)( malloc( nt2*sizeof(double) ) ) ; 00149 00150 00151 //------------------- 00152 // Boucle sur m 00153 //------------------- 00154 00155 for (m=0; m < np/2+1 ; m++) { 00156 00157 // Recherche des fonctions de Legendre associees d'ordre m : 00158 00159 double* leg = legendre_norm(m, nt) ; 00160 00161 if (m%2==0) { 00162 // Cas m pair 00163 //----------- 00164 for (l=m; l<nt; l++) { // boucle sur les P_{l}^m 00165 00166 int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2 00167 00168 for (j2=0; j2<nt; j2++) { 00169 yy[j2] = leg[nt2* (l-m) + 2*j2] ; 00170 } 00171 00172 for (j2=nt; j2<nt2; j2++) { 00173 yy[j2] = parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ; 00174 } 00175 00176 //....... transformation en cos(j*theta) : 00177 00178 cftcos(deg, deg, yy, deg, yy) ; 00179 00180 //....... le resultat fournit les elements de matrice : 00181 for (j=0; j<nt; j++) { 00182 tab[indice][ nt*nt* m + nt*j + l] = yy[j] ; 00183 } 00184 00185 } // fin de la boucle sur l (indice de P_{l}^m) 00186 00187 00188 } // fin du cas m pair 00189 else { 00190 00191 // Cas m impair 00192 //------------- 00193 00194 for (l=m; l<nt; l++) { // boucle sur les P_{l}^m 00195 00196 int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2 00197 00198 for (j2=0; j2<nt; j2++) { 00199 yy[j2] = leg[nt2* (l-m) + 2*j2] ; 00200 } 00201 00202 for (j2=nt; j2<nt2; j2++) { 00203 yy[j2] = parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ; 00204 } 00205 00206 00207 //....... transformation en sin(j*theta) : 00208 00209 cftsin(deg, deg, yy, deg, yy) ; 00210 00211 //....... le resultat fournit les elements de matrice : 00212 for (j=0; j<nt-1; j++) { 00213 tab[indice][ nt*nt* m + nt*j + l] = yy[j] ; 00214 } 00215 00216 } // fin de la boucle sur l (indice de P_{2l+1}^m) 00217 00218 00219 } // fin du cas m impair 00220 00221 delete [] leg ; 00222 00223 } // fin de la boucle sur m 00224 00225 // Liberation espace memoire 00226 // ------------------------- 00227 00228 delete [] yy ; 00229 00230 } // fin du cas ou le calcul etait necessaire 00231 00232 } // Fin de zone critique 00233 00234 return tab[indice] ; 00235 00236 } 00237 00238
1.4.6