mat_cosi_legip.C

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_cosi_legip_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cosi_legip.C,v 1.4 2005/02/18 13:14:13 j_novak Exp $" ;
00024 
00025 /*
00026  * Fournit la matrice de passage pour la transformation des coefficients du
00027  * developpement en cos((2j+1)*theta) 
00028  * dans les coefficients du developpement en fonctions associees de Legendre 
00029  * P_l^m(cos(theta)) avec l impair et m pair.
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_cosi_legip : pointeur sur le tableau contenant l'ensemble
00043  *                  (pour les np/2+1 valeurs de m: m=0,2,...,np) 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_cosi_legip[ nt*nt* m/2 + nt*l + j] = A_{mlj}
00049  *              
00050  *              ou A_{mlj} est defini par
00051  *
00052  *   cos((2j+1) theta) = som_{l=m/2}^{nt-2} A_{mlj} P_{2l+1}^m( cos(theta) )
00053  *                      pour 0 <= 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_cosi_legip.C,v 1.4 2005/02/18 13:14:13 j_novak Exp $
00065  * $Log: mat_cosi_legip.C,v $
00066  * Revision 1.4  2005/02/18 13:14:13  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:54  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:28  e_gourgoulhon
00079  * LORENE
00080  *
00081  * Revision 2.0  2000/09/28  10:02:18  eric
00082  * *** empty log message ***
00083  *
00084  *
00085  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cosi_legip.C,v 1.4 2005/02/18 13:14:13 j_novak Exp $
00086  *
00087  */
00088 
00089 // headers du C
00090 #include <stdlib.h>
00091 #include <math.h>
00092 
00093 // Prototypage
00094 #include "headcpp.h"
00095 #include "proto.h"
00096 
00097 // Variable de loch
00098 int loch_mat_cosi_legip = 0 ;
00099 
00100 //******************************************************************************
00101 
00102 double* mat_cosi_legip(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_cosi_legip)
00115     {
00116     
00117     // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ? 
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_cosp_legpp: 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] ;
00138 
00139 //-----------------------
00140 // Preparation du calcul 
00141 //-----------------------
00142 
00143 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
00144     int nt2 = 2*nt - 1 ; 
00145     int nt2m1 = nt2 - 1 ; 
00146 
00147     int deg[3] ;
00148     deg[0] = 1 ;
00149     deg[1] = 1 ;
00150     deg[2] = nt2 ;
00151 
00152 // Tableaux de travail
00153     double* yy = new double[nt2] ;
00154     double* cost = new double[nt*nt2] ;
00155    
00156 // Calcul des cos(2*j*theta)  aux points de collocation
00157 //  de l'echantillonnage double : 
00158 
00159     double dt = M_PI / double(2*(nt2-1)) ;
00160     for (j=0; j<nt-1; j++) {
00161         for (j2=0; j2<nt2; j2++) {
00162         double theta = j2*dt ;
00163         cost[nt2*j + j2] = cos( (2*j+1) * theta ) ;
00164         }
00165     }   
00166 
00167 
00168 //-------------------
00169 // Boucle sur m
00170 //-------------------
00171 
00172     int m_max = np ; 
00173     if (np == 1) m_max = 0 ; 
00174 
00175     for (m=0; m <= m_max ; m+=2) {
00176 
00177 // Recherche des fonctions de Legendre associees d'ordre m :
00178 
00179         double* leg = legendre_norm(m, nt) ;    
00180     
00181         for (l=m/2; l<nt-1; l++) {  // boucle sur les P_{2l+1}^m
00182         
00183         int ll = 2*l+1 ;    // degre des fonctions de Legendre
00184             
00185             for (j=0; j<nt-1; j++) { // boucle sur les cos((2j+1) theta)
00186             
00187 //... produit scalaire de cos((2j+1) theta) par P_{2l+1}^m(cos(theta)) 
00188 
00189             for (j2=0; j2<nt2; j2++) {
00190             yy[nt2m1-j2] = cost[nt2*j + j2] *
00191                        leg[nt2* (ll-m) + j2] ;
00192             }
00193 
00194 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
00195 //      l'integrale (routine int1d_chebp) :         
00196             cfrchebp(deg, deg, yy, deg, yy) ;
00197             tab[indice][ nt*nt* m/2 + nt*l + j] = 
00198                         2.*int1d_chebp(nt2, yy) ;
00199 
00200             }   // fin de la boucle sur j  (indice de cos((2j+1) theta) )
00201         
00202         }  // fin de la boucle sur l (indice de P_{2l+1}^m)
00203                 
00204         delete [] leg ;
00205             
00206     }  // fin de la boucle sur m
00207 
00208 // Liberation espace memoire
00209 // -------------------------
00210 
00211     delete [] yy ;
00212     delete [] cost ;
00213 
00214     } // fin du cas ou le calcul etait necessaire
00215 
00216     } //Fin de zone critique
00217     
00218     return tab[indice] ;
00219 
00220 }
00221 
00222 

Generated on Tue Feb 7 01:35:18 2012 for LORENE by  doxygen 1.4.6