00001 /* 00002 * Copyright (c) 2003 Jerome Novak 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_legii_sinp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legii_sinp.C,v 1.2 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 pair et m impair 00029 * dans les coefficients du developpement 00030 * en sin( 2j 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_legii_sinp : pointeur sur le tableau contenant l'ensemble 00044 * (pour les np/2 valeurs de m: m=1,3,...,np-1)) 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_legii_sinp[ nt*nt* m/2 + nt*j + l] = B_{mjl} 00050 * 00051 * ou B_{mjl} (m impair) est defini par 00052 * 00053 * P_{2l}^m( cos(theta) ) = som_{j=1}^{nt-2} B_{mjl} sin(2*j*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_legii_sinp.C,v 1.2 2005/02/18 13:14:15 j_novak Exp $ 00065 * $Log: mat_legii_sinp.C,v $ 00066 * Revision 1.2 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.1 2003/09/16 08:58:01 j_novak 00071 * New functions for the T_LEG_II base 00072 * 00073 * 00074 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legii_sinp.C,v 1.2 2005/02/18 13:14:15 j_novak Exp $ 00075 * 00076 */ 00077 00078 // headers du C 00079 #include <stdlib.h> 00080 #include <math.h> 00081 00082 // Headers Lorene 00083 #include "headcpp.h" 00084 #include "proto.h" 00085 00086 // Variable de loch 00087 int loch_mat_legii_sinp = 0 ; 00088 00089 //****************************************************************************** 00090 00091 double* mat_legii_sinp(int np, int nt) { 00092 00093 #define NMAX 30 // Nombre maximun de couples(np,nt) differents 00094 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 00095 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises 00096 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00097 // calcul a deja ete fait 00098 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00099 // calcul a deja ete fait 00100 00101 int i, indice, j, j2, m, l ; 00102 00103 // #pragma critical (loch_mat_legii_sinp) 00104 { 00105 // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ? 00106 00107 indice = -1 ; 00108 for ( i=0 ; i < nb_dejafait ; i++ ) { 00109 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ; 00110 } 00111 00112 00113 // Si le calcul n'a pas deja ete fait, il faut le faire : 00114 if (indice == -1) { 00115 if ( nb_dejafait >= NMAX ) { 00116 cout << "mat_legii_sinp: nb_dejafait >= NMAX : " 00117 << nb_dejafait << " <-> " << NMAX << endl ; 00118 abort () ; 00119 exit(-1) ; 00120 } 00121 indice = nb_dejafait ; 00122 nb_dejafait++ ; 00123 np_dejafait[indice] = np ; 00124 nt_dejafait[indice] = nt ; 00125 00126 tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ; 00127 00128 //----------------------- 00129 // Preparation du calcul 00130 //----------------------- 00131 00132 // Sur-echantillonnage : 00133 int nt2 = 2*nt - 1 ; 00134 00135 int deg[3] ; 00136 deg[0] = 1 ; 00137 deg[1] = nt2 ; 00138 deg[2] = 1 ; 00139 00140 // Tableaux de travail 00141 double* yy = new double[nt2] ; //(double*)( malloc( nt2*sizeof(double) ) ) ; 00142 00143 00144 //------------------- 00145 // Boucle sur m 00146 //------------------- 00147 00148 int m_max = (np == 1) ? 1 : np-1 ; 00149 00150 for (m=1; m <= m_max ; m+=2) { 00151 00152 // Recherche des fonctions de Legendre associees d'ordre m : 00153 00154 double* leg = legendre_norm(m, nt) ; 00155 00156 00157 for (l=(m+1)/2; l<nt-1; l++) { // boucle sur les P_{2l}^m 00158 00159 int ll = 2*l ; // degre des fonctions de Legendre 00160 00161 for (j2=0; j2<nt2; j2++) { 00162 yy[j2] = leg[nt2* (ll-m) + j2] ; 00163 } 00164 00165 //....... transformation en sin(2j*theta) : 00166 00167 cftsinp(deg, deg, yy, deg, yy) ; 00168 00169 //....... le resultat fournit les elements de matrice : 00170 for (j=0; j<nt-1; j++) { 00171 tab[indice][ nt*nt* ((m-1)/2) + nt*j + l] = yy[j] ; 00172 } 00173 00174 } // fin de la boucle sur l (indice de P_{2l}^m) 00175 00176 delete [] leg ; 00177 00178 } // fin de la boucle sur m 00179 00180 // Liberation espace memoire 00181 // ------------------------- 00182 00183 delete [] yy ; 00184 00185 } // fin du cas ou le calcul etait necessaire 00186 00187 } // Fin de zone critique 00188 00189 return tab[indice] ; 00190 00191 } 00192 00193
1.4.6