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_legi_cosi_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legip_cosi.C,v 1.4 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)) avec l impair et m pair 00029 * dans les coefficients du developpement 00030 * en cos( (2j+1) theta ). 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_legpp_cosp : pointeur sur le tableau contenant l'ensemble 00044 * (pour les np/2+1 valeurs de m: m=0,2,...,np)) 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_legpp_cosp[ nt*nt* m/2 + nt*j + l] = B_{mjl} 00050 * 00051 * ou B_{mjl} (m pair) est defini par 00052 * 00053 * P_{2l+1}^m( cos(theta) ) = som_{j=0}^{nt-2} B_{mjl} cos( (2j+1) theta ) 00054 * 00055 * ou P_n^m(x) represente la fonction de Legendre associee de degre n et 00056 * d'ordre m normalisee de facon a ce que 00057 * 00058 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1 00059 * 00060 * 00061 */ 00062 00063 /* 00064 * $Id: mat_legip_cosi.C,v 1.4 2005/02/18 13:14:15 j_novak Exp $ 00065 * $Log: mat_legip_cosi.C,v $ 00066 * Revision 1.4 2005/02/18 13:14:15 j_novak 00067 * Changing of malloc/free to new/delete + suppression of some unused variables 00068 * (trying to avoid compilation warnings). 00069 * 00070 * Revision 1.3 2003/01/31 10:31:24 e_gourgoulhon 00071 * Suppressed the directive #include <malloc.h> for malloc is defined 00072 * in <stdlib.h> 00073 * 00074 * Revision 1.2 2002/10/16 14:36:55 j_novak 00075 * Reorganization of #include instructions of standard C++, in order to 00076 * use experimental version 3 of gcc. 00077 * 00078 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon 00079 * LORENE 00080 * 00081 * Revision 2.0 2000/09/28 10:02:29 eric 00082 * *** empty log message *** 00083 * 00084 * 00085 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legip_cosi.C,v 1.4 2005/02/18 13:14:15 j_novak Exp $ 00086 * 00087 */ 00088 00089 // headers du C 00090 #include <stdlib.h> 00091 #include <math.h> 00092 00093 // Headers Lorene 00094 #include "headcpp.h" 00095 #include "proto.h" 00096 00097 // Variable de loch 00098 int loch_mat_legip_cosi = 0 ; 00099 00100 //****************************************************************************** 00101 00102 double* mat_legip_cosi(int np, int nt) { 00103 00104 #define NMAX 30 // Nombre maximun de couples(np,nt) differents 00105 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 00106 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises 00107 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00108 // calcul a deja ete fait 00109 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00110 // calcul a deja ete fait 00111 00112 int i, indice, j, j2, m, l ; 00113 00114 // #pragma critical (loch_mat_legip_cosi) 00115 { 00116 // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ? 00117 00118 indice = -1 ; 00119 for ( i=0 ; i < nb_dejafait ; i++ ) { 00120 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ; 00121 } 00122 00123 00124 // Si le calcul n'a pas deja ete fait, il faut le faire : 00125 if (indice == -1) { 00126 if ( nb_dejafait >= NMAX ) { 00127 cout << "mat_legpp_cosp: nb_dejafait >= NMAX : " 00128 << nb_dejafait << " <-> " << NMAX << endl ; 00129 abort () ; 00130 exit(-1) ; 00131 } 00132 indice = nb_dejafait ; 00133 nb_dejafait++ ; 00134 np_dejafait[indice] = np ; 00135 nt_dejafait[indice] = nt ; 00136 00137 tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ; 00138 00139 //----------------------- 00140 // Preparation du calcul 00141 //----------------------- 00142 00143 // Sur-echantillonnage : 00144 int nt2 = 2*nt - 1 ; 00145 00146 int deg[3] ; 00147 deg[0] = 1 ; 00148 deg[1] = nt2 ; 00149 deg[2] = 1 ; 00150 00151 // Tableaux de travail 00152 double* yy = new double[nt2] ; //(double*)( malloc( nt2*sizeof(double) ) ) ; 00153 00154 00155 //------------------- 00156 // Boucle sur m 00157 //------------------- 00158 00159 int m_max = np ; 00160 if (np == 1) m_max = 0 ; 00161 00162 for (m=0; m <= m_max ; m+=2) { 00163 00164 // Recherche des fonctions de Legendre associees d'ordre m : 00165 00166 double* leg = legendre_norm(m, nt) ; 00167 00168 for (l=m/2; l<nt-1; l++) { // boucle sur les P_{2l+1}^m 00169 00170 int ll = 2*l+1 ; // degre des fonctions de Legendre 00171 00172 for (j2=0; j2<nt2; j2++) { 00173 yy[j2] = leg[nt2* (ll-m) + j2] ; 00174 } 00175 00176 //....... transformation en cos( (2j+1) theta ) : 00177 00178 cftcosi(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/2 + nt*j + l] = yy[j] ; 00183 } 00184 00185 } // fin de la boucle sur l (indice de P_{2l}^m) 00186 00187 delete [] leg ; 00188 00189 } // fin de la boucle sur m 00190 00191 // Liberation espace memoire 00192 // ------------------------- 00193 00194 delete [] yy ; 00195 00196 } // fin du cas ou le calcul etait necessaire 00197 00198 } // Fin de zone critique 00199 00200 return tab[indice] ; 00201 00202 } 00203 00204
1.4.6