00001 /* 00002 * Copyright (c) 2003-2009 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_legmi_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sin_legmi.C,v 1.1 2009/10/23 12:54:47 j_novak Exp $" ; 00024 00025 /* 00026 * Fournit la matrice de passage pour la transformation des coefficients du 00027 * developpement en sin(j*theta) dans les coefficients du developpement en 00028 * fonctions associees de Legendre P_l^m(cos(theta)) avec m impair. 00029 * 00030 * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas 00031 * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment 00032 * calculee. 00033 * 00034 * Entree: 00035 * ------- 00036 * int np : Nombre de degres de liberte en phi 00037 * int nt : Nombre de degres de liberte en theta 00038 * 00039 * Sortie (valeur de retour) : 00040 * --------------------------- 00041 * double* mat_sin_legmi : pointeur sur le tableau contenant l'ensemble 00042 * (pour les np/2 valeurs de m: m=1,3,...,np-1) des 00043 * matrices de passage. 00044 * La dimension du tableau est (np/2+1)*nt^2 00045 * Le stokage est le suivant: 00046 * 00047 * mat_sin_legmi[ nt*nt* m + nt*l + j] = A_{mlj} 00048 * 00049 * ou A_{mlj} est defini par 00050 * 00051 * sin(j*theta) = som_{l=m}^{nt-2} A_{mlj} P_l^m( cos(theta) ) 00052 * pour 1 <= j <= nt-2 00053 * 00054 * ou P_n^m(x) represente la fonction de Legendre associee de degre n et 00055 * d'ordre m normalisee de facon a ce que 00056 * 00057 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1 00058 * 00059 * 00060 */ 00061 00062 /* 00063 * $Id: mat_sin_legmi.C,v 1.1 2009/10/23 12:54:47 j_novak Exp $ 00064 * $Log: mat_sin_legmi.C,v $ 00065 * Revision 1.1 2009/10/23 12:54:47 j_novak 00066 * New base T_LEG_MI 00067 * 00068 * 00069 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_sin_legmi.C,v 1.1 2009/10/23 12:54:47 j_novak Exp $ 00070 * 00071 */ 00072 00073 // headers du C 00074 #include <stdlib.h> 00075 #include <math.h> 00076 #include <assert.h> 00077 00078 // Prototypage 00079 #include "headcpp.h" 00080 #include "proto.h" 00081 00082 //****************************************************************************** 00083 00084 double* mat_sin_legmi(int np, int nt) { 00085 00086 #define NMAX 30 // Nombre maximun de couples(np,nt) differents 00087 static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 00088 static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises 00089 static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00090 // calcul a deja ete fait 00091 static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le 00092 // calcul a deja ete fait 00093 00094 int i, indice, j, j2, m, l ; 00095 00096 // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ? 00097 indice = -1 ; 00098 for ( i=0 ; i < nb_dejafait ; i++ ) { 00099 if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ; 00100 } 00101 00102 00103 // Si le calcul n'a pas deja ete fait, il faut le faire : 00104 if (indice == -1) { 00105 if ( nb_dejafait >= NMAX ) { 00106 cout << "mat_sinp_legii: nb_dejafait >= NMAX : " 00107 << nb_dejafait << " <-> " << NMAX << endl ; 00108 abort () ; 00109 exit(-1) ; 00110 } 00111 indice = nb_dejafait ; 00112 nb_dejafait++ ; 00113 np_dejafait[indice] = np ; 00114 nt_dejafait[indice] = nt ; 00115 00116 tab[indice] = new double[(np/2+1)*nt*nt] ; 00117 for (int qq=0; qq<nt*nt*(np/2+1); qq++) 00118 tab[indice][qq] = -1.34 ; 00119 00120 //----------------------- 00121 // Preparation du calcul 00122 //----------------------- 00123 00124 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing: 00125 int nt2 = 2*nt - 1 ; 00126 int nt2m1 = nt2 - 1 ; 00127 00128 int deg[3] ; 00129 deg[0] = 1 ; 00130 deg[1] = 1 ; 00131 deg[2] = nt2 ; 00132 00133 // Tableaux de travail 00134 double* yy = new double[nt2] ; 00135 double* sint = new double[nt*nt2]; 00136 00137 // Calcul des sin( j theta) aux points de collocation 00138 // de l'echantillonnage double : 00139 00140 double dt = M_PI / double(nt2-1) ; 00141 for (j=0; j<nt-1; j++) { 00142 for (j2=0; j2<nt2; j2++) { 00143 double theta = j2*dt ; 00144 sint[nt2*j + j2] = sin( j * theta ) ; 00145 } 00146 } 00147 00148 00149 //------------------- 00150 // Boucle sur m 00151 //------------------- 00152 00153 int m_max = (np == 1) ? 1 : np-1 ; 00154 00155 for (m=1; m <= m_max ; m+=2) { 00156 00157 // Recherche des fonctions de Legendre associees d'ordre m : 00158 00159 double* leg = legendre_norm(m, nt) ; 00160 00161 for (l=m; l<nt-1; l++) { // boucle sur les P_l^m 00162 00163 int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2 00164 00165 for (j=0; j<nt-1; j++) { // boucle sur les sin(j theta) 00166 00167 //... produit scalaire de sin(j theta) par 00168 // P_l^m(cos(theta)) 00169 00170 for (j2=0; j2<nt; j2++) { 00171 yy[nt2m1-j2] = sint[nt2*j + j2] * 00172 leg[nt2* (l-m) + 2*j2] ; 00173 00174 } 00175 00176 for (j2=nt; j2<nt2; j2++) { 00177 yy[nt2m1-j2] = sint[nt2*j + j2] * 00178 parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ; 00179 00180 } 00181 00182 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer 00183 // l'integrale (routine int1d_cheb) : 00184 cfrcheb(deg, deg, yy, deg, yy) ; 00185 // for (int o=0; o<nt2; o++) 00186 // cout << yy[o] << endl ; 00187 00188 tab[indice][ nt*nt* ((m-1)/2) + nt*l + j] = 00189 int1d_cheb(nt2, yy) ; 00190 00191 } // fin de la boucle sur j (indice de sin(j theta) ) 00192 00193 } // fin de la boucle sur l (indice de P_l^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 return tab[indice] ; 00208 00209 } 00210 00211
1.4.6