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_sinp_legii_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sinp_legii.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 sin(2j*theta) 00028 * dans les coefficients du developpement en fonctions associees de Legendre 00029 * P_l^m(cos(theta)) avec l pair et m impair. 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_sinp_legii : pointeur sur le tableau contenant l'ensemble 00043 * (pour les np/2 valeurs de m: m=1,3,...,np-1) 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_sinp_legii[ nt*nt* m/2 + nt*l + j] = A_{mlj} 00049 * 00050 * ou A_{mlj} est defini par 00051 * 00052 * sin(2*j*theta) = som_{l=(m+1)/2}^{nt-2} A_{mlj} P_{2l}^m( cos(theta) ) 00053 * pour 1 <= j <= nt-2 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_sinp_legii.C,v 1.2 2005/02/18 13:14:15 j_novak Exp $ 00065 * $Log: mat_sinp_legii.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_sinp_legii.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 #include <assert.h> 00082 00083 // Prototypage 00084 #include "headcpp.h" 00085 #include "proto.h" 00086 00087 // Variable de loch 00088 int loch_mat_sinp_legii = 0 ; 00089 00090 //****************************************************************************** 00091 00092 double* mat_sinp_legii(int np, int nt) { 00093 00094 #define NMAX 30 // Nombre maximun de couples(np,nt) differents 00095 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 00096 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises 00097 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00098 // calcul a deja ete fait 00099 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00100 // calcul a deja ete fait 00101 00102 int i, indice, j, j2, m, l ; 00103 00104 // #pragma critical (loch_mat_sinp_legii) 00105 { 00106 00107 // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ? 00108 indice = -1 ; 00109 for ( i=0 ; i < nb_dejafait ; i++ ) { 00110 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ; 00111 } 00112 00113 00114 // Si le calcul n'a pas deja ete fait, il faut le faire : 00115 if (indice == -1) { 00116 if ( nb_dejafait >= NMAX ) { 00117 cout << "mat_sinp_legii: nb_dejafait >= NMAX : " 00118 << nb_dejafait << " <-> " << NMAX << endl ; 00119 abort () ; 00120 exit(-1) ; 00121 } 00122 indice = nb_dejafait ; 00123 nb_dejafait++ ; 00124 np_dejafait[indice] = np ; 00125 nt_dejafait[indice] = nt ; 00126 00127 tab[indice] = new double[(np/2+1)*nt*nt] ;//(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ; 00128 00129 //----------------------- 00130 // Preparation du calcul 00131 //----------------------- 00132 00133 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing: 00134 int nt2 = 2*nt - 1 ; 00135 int nt2m1 = nt2 - 1 ; 00136 00137 int deg[3] ; 00138 deg[0] = 1 ; 00139 deg[1] = 1 ; 00140 deg[2] = nt2 ; 00141 00142 // Tableaux de travail 00143 double* yy = new double[nt2] ;//(double*)( malloc( nt2*sizeof(double) ) ) ; 00144 double* sint = new double[nt*nt2];//(double*)( malloc( nt*nt2*sizeof(double) ) ) ; 00145 00146 // Calcul des sin( 2j theta) aux points de collocation 00147 // de l'echantillonnage double : 00148 00149 double dt = M_PI / double(2*(nt2-1)) ; 00150 for (j=0; j<nt-1; j++) { 00151 for (j2=0; j2<nt2; j2++) { 00152 double theta = j2*dt ; 00153 sint[nt2*j + j2] = sin( 2*j * theta ) ; 00154 } 00155 } 00156 00157 00158 //------------------- 00159 // Boucle sur m 00160 //------------------- 00161 00162 int m_max = (np == 1) ? 1 : np-1 ; 00163 00164 for (m=1; m <= m_max ; m+=2) { 00165 00166 // Recherche des fonctions de Legendre associees d'ordre m : 00167 00168 double* leg = legendre_norm(m, nt) ; 00169 00170 for (l=(m+1)/2; l<nt-1; l++) { // boucle sur les P_{2l}^m 00171 00172 int ll = 2*l ; // degre des fonctions de Legendre 00173 00174 for (j=0; j<nt-1; j++) { // boucle sur les sin((2j+1)theta) 00175 00176 //... produit scalaire de sin(2j theta) par 00177 // P_{2l}^m(cos(theta)) 00178 00179 for (j2=0; j2<nt2; j2++) { 00180 yy[nt2m1-j2] = sint[nt2*j + j2] 00181 * leg[nt2* (ll-m) + j2] ; 00182 } 00183 00184 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer 00185 // l'integrale (routine int1d_chebp) : 00186 cfrchebp(deg, deg, yy, deg, yy) ; 00187 tab[indice][ nt*nt* ((m-1)/2) + nt*l + j] = 00188 2.*int1d_chebp(nt2, yy) ; 00189 00190 00191 } // fin de la boucle sur j (indice de sin((2j)theta) ) 00192 00193 } // fin de la boucle sur l (indice de P_{2l}^m) 00194 00195 delete [] leg ; 00196 00197 } // fin de la boucle sur m 00198 00199 // Liberation espace memoire 00200 // ------------------------- 00201 00202 delete [] yy ; 00203 delete [] sint ; 00204 00205 } // fin du cas ou le calcul etait necessaire 00206 00207 } //Fin de zone critique 00208 00209 return tab[indice] ; 00210 00211 } 00212 00213
1.4.6