mat_legp_cossincp.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_legp_cossincp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legp_cossincp.C,v 1.4 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)) paires (i.e. telles que l-m est pair)
00029  * dans les coefficients du developpement 
00030  * en cos(2*j*theta) [m pair] / sin( (2*j+1) * theta) [m impair]
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_legp_cossincp : pointeur sur le tableau contenant l'ensemble
00044  *                  (pour les np/2+1 valeurs de m) 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_legp_cossincp[ nt*nt* m + nt*j + l] = B_{mjl}
00050  *              
00051  *              ou B_{mjl} est defini par
00052  *
00053  * pour m pair :  
00054  *   P_{2l}^m( cos(theta) ) = som_{j=0}^{nt-1} B_{mjl} cos(2*j*theta)
00055  *
00056  * pour m impair :  
00057  *   P_{2l+1}^m( cos(theta) ) = som_{j=0}^{nt-2} B_{mjl} sin((2*j+1)*theta) 
00058  *
00059  *  ou P_n^m(x) represente la fonction de Legendre associee de degre n et 
00060  *     d'ordre m normalisee de facon a ce que
00061  *
00062  *   int_0^pi [ P_n^m(cos(theta)) ]^2  sin(theta) dtheta = 1
00063  *
00064  * 
00065  */
00066 
00067 /*
00068  * $Id: mat_legp_cossincp.C,v 1.4 2005/02/18 13:14:15 j_novak Exp $
00069  * $Log: mat_legp_cossincp.C,v $
00070  * Revision 1.4  2005/02/18 13:14:15  j_novak
00071  * Changing of malloc/free to new/delete + suppression of some unused variables
00072  * (trying to avoid compilation warnings).
00073  *
00074  * Revision 1.3  2003/01/31 10:31:24  e_gourgoulhon
00075  * Suppressed the directive #include <malloc.h> for malloc is defined
00076  * in <stdlib.h>
00077  *
00078  * Revision 1.2  2002/10/16 14:36:56  j_novak
00079  * Reorganization of #include instructions of standard C++, in order to
00080  * use experimental version 3 of gcc.
00081  *
00082  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00083  * LORENE
00084  *
00085  * Revision 2.0  1999/02/22  15:33:59  hyc
00086  * *** empty log message ***
00087  *
00088  *
00089  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legp_cossincp.C,v 1.4 2005/02/18 13:14:15 j_novak Exp $
00090  *
00091  */
00092 
00093 // headers du C
00094 #include <stdlib.h>
00095 #include <math.h>
00096 
00097 // Prototypage
00098 #include "headcpp.h"
00099 #include "proto.h"
00100 
00101 // Variable de loch
00102 int loch_mat_legp_cossincp = 0 ;
00103 
00104 //******************************************************************************
00105 
00106 double* mat_legp_cossincp(int np, int nt) {
00107 
00108 #define NMAX    30      // Nombre maximun de couples(np,nt) differents 
00109 static  double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 
00110 static  int nb_dejafait = 0 ;   // Nombre de tableaux deja initialises 
00111 static  int np_dejafait[NMAX] ;    // Valeurs de np pour lesquelles le
00112                        // calcul a deja ete fait
00113 static  int nt_dejafait[NMAX] ;    // Valeurs de np pour lesquelles le
00114                        // calcul a deja ete fait
00115 
00116 int i, indice,  j,  j2,  m,  l ;
00117 
00118 //    #pragma critical (loch_mat_legp_cossincp)
00119     {
00120     // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ? 
00121     indice = -1 ;
00122     for ( i=0 ; i < nb_dejafait ; i++ ) {
00123     if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
00124     }
00125 
00126 
00127 // Si le calcul n'a pas deja ete fait, il faut le faire : 
00128     if (indice == -1) {        
00129     if ( nb_dejafait >= NMAX ) {
00130         cout << "mat_legp_cossincp: nb_dejafait >= NMAX : "
00131         << nb_dejafait << " <-> " << NMAX << endl ;
00132         abort () ;  
00133         exit(-1) ;
00134         }
00135     indice = nb_dejafait ; 
00136     nb_dejafait++ ; 
00137     np_dejafait[indice] = np ;
00138     nt_dejafait[indice] = nt ;
00139 
00140     tab[indice] = new double [(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
00141 
00142 //-----------------------
00143 // Preparation du calcul 
00144 //-----------------------
00145 
00146 // Sur-echantillonnage :
00147     int nt2 = 2*nt - 1 ; 
00148 
00149     int deg[3] ;
00150     deg[0] = 1 ;
00151     deg[1] = nt2 ;
00152     deg[2] = 1 ;
00153 
00154 // Tableaux de travail
00155     double* yy = new double[nt2];//(double*)( malloc( nt2*sizeof(double) ) ) ;
00156 
00157 
00158 //-------------------
00159 // Boucle sur m
00160 //-------------------
00161 
00162     for (m=0; m < np/2+1 ; m++) {
00163 
00164 // Recherche des fonctions de Legendre associees d'ordre m :
00165 
00166         double* leg = legendre_norm(m, nt) ;    
00167     
00168         if (m%2==0) {
00169 // Cas m pair
00170 //-----------
00171         for (l=m/2; l<nt; l++) {    // boucle sur les P_{2l}^m
00172         
00173             int ll = 2*l ;  // degre des fonctions de Legendre
00174             
00175             for (j2=0; j2<nt2; j2++) {
00176                 yy[j2] = leg[nt2* (ll-m) + j2] ;
00177             }
00178 
00179 //....... transformation en cos(2*j*theta) : 
00180 
00181             cftcosp(deg, deg, yy, deg, yy) ; 
00182 
00183 //....... le resultat fournit les elements de matrice : 
00184             for (j=0; j<nt; j++) {
00185             tab[indice][ nt*nt* m + nt*j + l] = yy[j] ; 
00186             }
00187         
00188         }  // fin de la boucle sur l (indice de P_{2l}^m)
00189         
00190         
00191         }   // fin du cas m pair
00192         else {
00193         
00194 // Cas m impair
00195 //-------------
00196 
00197         for (l=(m-1)/2; l<nt-1; l++) {  // boucle sur les P_{2l+1}^m
00198         
00199             int ll = 2*l+1 ;    // degre des fonctions de Legendre
00200             
00201             
00202             for (j2=0; j2<nt2; j2++) {
00203                 yy[j2] = leg[nt2* (ll-m) + j2] ;
00204             }
00205 
00206 //....... transformation en sin((2j+1)*theta) : 
00207 
00208             cftsini(deg, deg, yy, deg, yy) ; 
00209 
00210 //....... le resultat fournit les elements de matrice : 
00211             for (j=0; j<nt-1; j++) {
00212             tab[indice][ nt*nt* m + nt*j + l] = yy[j] ; 
00213             }
00214         
00215         }  // fin de la boucle sur l (indice de P_{2l+1}^m)
00216         
00217 
00218         } // fin du cas m impair
00219         
00220         delete [] leg ;
00221             
00222     }  // fin de la boucle sur m
00223 
00224 // Liberation espace memoire
00225 // -------------------------
00226 
00227     delete [] yy ;
00228 
00229     } // fin du cas ou le calcul etait necessaire
00230 
00231     }   // Fin de zone critique
00232     
00233     return tab[indice] ;
00234 
00235 }
00236 
00237 

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