00001 /* 00002 * Copyright (c) 1999-2001 Eric Gourgoulhon 00003 * 2009 Jerome Novak 00004 * 00005 * This file is part of LORENE. 00006 * 00007 * LORENE is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * LORENE is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with LORENE; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 */ 00022 00023 00024 char mat_legmp_cos_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legmp_cos.C,v 1.1 2009/10/13 13:49:36 j_novak Exp $" ; 00025 00026 00027 /* 00028 * Fournit la matrice de passage pour la transformation des coefficients du 00029 * developpement en fonctions associees de Legendre 00030 * P_l^m(cos(theta)) avec m pair dans les coefficients du developpement 00031 * en cos(j*theta). 00032 * 00033 * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas 00034 * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment 00035 * calculee. 00036 * 00037 * Entree: 00038 * ------- 00039 * int np : Nombre de degres de liberte en phi 00040 * int nt : Nombre de degres de liberte en theta 00041 * 00042 * Sortie (valeur de retour) : 00043 * --------------------------- 00044 * double* mat_lemp_cos : pointeur sur le tableau contenant l'ensemble 00045 * (pour les np/2+1 valeurs de m: m=0,2,...,np)) des 00046 * matrices de passage. 00047 * La dimension du tableau est (np/2+1)*nt^2 00048 * Le stokage est le suivant: 00049 * 00050 * mat_legpp_cosp[ nt*nt* m/2 + nt*j + l] = B_{mjl} 00051 * 00052 * ou B_{mjl} (m pair) est defini par 00053 * 00054 * P_l^m( cos(theta) ) = som_{j=0}^{nt-1} B_{mjl} cos(j*theta) 00055 * 00056 * ou P_n^m(x) represente la fonction de Legendre associee de degre n et 00057 * d'ordre m normalisee de facon a ce que 00058 * 00059 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1 00060 * 00061 * 00062 */ 00063 00064 /* 00065 * $Id: mat_legmp_cos.C,v 1.1 2009/10/13 13:49:36 j_novak Exp $ 00066 * $Log: mat_legmp_cos.C,v $ 00067 * Revision 1.1 2009/10/13 13:49:36 j_novak 00068 * New base T_LEG_MP. 00069 * 00070 * 00071 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legmp_cos.C,v 1.1 2009/10/13 13:49:36 j_novak Exp $ 00072 * 00073 */ 00074 00075 00076 // headers du C 00077 #include <stdlib.h> 00078 #include <math.h> 00079 00080 // Prototypage 00081 #include "headcpp.h" 00082 #include "proto.h" 00083 00084 //****************************************************************************** 00085 00086 double* mat_legmp_cos(int np, int nt) { 00087 00088 #define NMAX 30 // Nombre maximun de couples(np,nt) differents 00089 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 00090 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises 00091 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00092 // calcul a deja ete fait 00093 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00094 // calcul a deja ete fait 00095 00096 int i, indice, j, j2, m, l ; 00097 00098 // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ? 00099 00100 indice = -1 ; 00101 for ( i=0 ; i < nb_dejafait ; i++ ) { 00102 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ; 00103 } 00104 00105 00106 // Si le calcul n'a pas deja ete fait, il faut le faire : 00107 if (indice == -1) { 00108 if ( nb_dejafait >= NMAX ) { 00109 cout << "mat_legpp_cosp: nb_dejafait >= NMAX : " 00110 << nb_dejafait << " <-> " << NMAX << endl ; 00111 abort () ; 00112 exit(-1) ; 00113 } 00114 indice = nb_dejafait ; 00115 nb_dejafait++ ; 00116 np_dejafait[indice] = np ; 00117 nt_dejafait[indice] = nt ; 00118 00119 tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ; 00120 00121 //----------------------- 00122 // Preparation du calcul 00123 //----------------------- 00124 00125 // Sur-echantillonnage : 00126 int nt2 = 2*nt - 1 ; 00127 00128 int deg[3] ; 00129 deg[0] = 1 ; 00130 deg[1] = nt2 ; 00131 deg[2] = 1 ; 00132 00133 // Tableaux de travail 00134 double* yy = new double[nt2] ;//(double*)( malloc( nt2*sizeof(double) ) ) ; 00135 00136 00137 //------------------- 00138 // Boucle sur m 00139 //------------------- 00140 00141 int m_max = np ; 00142 if (np == 1) m_max = 0 ; 00143 00144 for (m=0; m <= m_max ; m+=2) { 00145 00146 // Recherche des fonctions de Legendre associees d'ordre m : 00147 00148 double* leg = legendre_norm(m, nt) ; 00149 00150 for (l=m; l<nt; l++) { // boucle sur les P_l^m 00151 00152 int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2 00153 00154 for (j2=0; j2<nt; j2++) { 00155 yy[j2] = leg[nt2* (l-m) + 2*j2] ; 00156 } 00157 00158 for (j2=nt; j2<nt2; j2++) { 00159 yy[j2] = parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ; 00160 } 00161 00162 //....... transformation en cos(j*theta) : 00163 00164 cftcos(deg, deg, yy, deg, yy) ; 00165 00166 //....... le resultat fournit les elements de matrice : 00167 for (j=0; j<nt; j++) { 00168 tab[indice][ nt*nt* m/2 + nt*j + l] = yy[j] ; 00169 } 00170 00171 } // fin de la boucle sur l (indice de P_l^m) 00172 00173 delete [] leg ; 00174 00175 } // fin de la boucle sur m 00176 00177 // Liberation espace memoire 00178 // ------------------------- 00179 00180 delete [] yy ; 00181 00182 } // fin du cas ou le calcul etait necessaire 00183 00184 return tab[indice] ; 00185 00186 } 00187 00188
1.4.6