mat_legpp_cosp.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_legpp_cosp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legpp_cosp.C,v 1.4 2005/02/18 13:14:15 j_novak Exp $" ;
00024 
00025 
00026 /*
00027  * Fournit la matrice de passage pour la transformation des coefficients du
00028  * developpement en fonctions associees de Legendre 
00029  * P_l^m(cos(theta)) avec l pair et m pair
00030  * dans les coefficients du developpement 
00031  * en cos(2*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_legpp_cosp : 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_{2l}^m( cos(theta) ) = som_{j=0}^{nt-1} B_{mjl} cos(2*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_legpp_cosp.C,v 1.4 2005/02/18 13:14:15 j_novak Exp $
00066  * $Log: mat_legpp_cosp.C,v $
00067  * Revision 1.4  2005/02/18 13:14:15  j_novak
00068  * Changing of malloc/free to new/delete + suppression of some unused variables
00069  * (trying to avoid compilation warnings).
00070  *
00071  * Revision 1.3  2003/01/31 10:31:24  e_gourgoulhon
00072  * Suppressed the directive #include <malloc.h> for malloc is defined
00073  * in <stdlib.h>
00074  *
00075  * Revision 1.2  2002/10/16 14:36:56  j_novak
00076  * Reorganization of #include instructions of standard C++, in order to
00077  * use experimental version 3 of gcc.
00078  *
00079  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00080  * LORENE
00081  *
00082  * Revision 2.0  1999/02/22  15:33:35  hyc
00083  * *** empty log message ***
00084  *
00085  *
00086  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legpp_cosp.C,v 1.4 2005/02/18 13:14:15 j_novak Exp $
00087  *
00088  */
00089 
00090 
00091 // headers du C
00092 #include <stdlib.h>
00093 #include <math.h>
00094 
00095 // Prototypage
00096 #include "headcpp.h"
00097 #include "proto.h"
00098 
00099 // Variable de loch
00100 int loch_mat_legpp_cosp = 0 ;
00101 
00102 //******************************************************************************
00103 
00104 double* mat_legpp_cosp(int np, int nt) {
00105 
00106 #define NMAX    30      // Nombre maximun de couples(np,nt) differents 
00107 static  double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 
00108 static  int nb_dejafait = 0 ;   // Nombre de tableaux deja initialises 
00109 static  int np_dejafait[NMAX] ;    // Valeurs de np pour lesquelles le
00110                        // calcul a deja ete fait
00111 static  int nt_dejafait[NMAX] ;    // Valeurs de np pour lesquelles le
00112                        // calcul a deja ete fait
00113 
00114 int i, indice,  j,  j2,  m,  l ;
00115 
00116 //    #pragma critical (loch_mat_legpp_cosp)
00117     {
00118 // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ? 
00119 
00120     indice = -1 ;
00121     for ( i=0 ; i < nb_dejafait ; i++ ) {
00122     if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
00123     }
00124 
00125 
00126 // Si le calcul n'a pas deja ete fait, il faut le faire : 
00127     if (indice == -1) {        
00128     if ( nb_dejafait >= NMAX ) {
00129         cout << "mat_legpp_cosp: nb_dejafait >= NMAX : "
00130         << nb_dejafait << " <-> " << NMAX << endl ;
00131         abort () ;  
00132         exit(-1) ;
00133         }
00134     indice = nb_dejafait ; 
00135     nb_dejafait++ ; 
00136     np_dejafait[indice] = np ;
00137     nt_dejafait[indice] = nt ;
00138 
00139     tab[indice] = new double[(np/2+1)*nt*nt] ; //(double *) malloc( sizeof(double) * (np/2+1)*nt*nt ) ;
00140 
00141 //-----------------------
00142 // Preparation du calcul 
00143 //-----------------------
00144 
00145 // Sur-echantillonnage :
00146     int nt2 = 2*nt - 1 ; 
00147 
00148     int deg[3] ;
00149     deg[0] = 1 ;
00150     deg[1] = nt2 ;
00151     deg[2] = 1 ;
00152 
00153 // Tableaux de travail
00154     double* yy = new double[nt2] ;//(double*)( malloc( nt2*sizeof(double) ) ) ;
00155 
00156 
00157 //-------------------
00158 // Boucle sur m
00159 //-------------------
00160 
00161     int m_max = np ; 
00162     if (np == 1) m_max = 0 ; 
00163 
00164     for (m=0; 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/2; l<nt; l++) {    // boucle sur les P_{2l}^m
00171         
00172         int ll = 2*l ;  // degre des fonctions de Legendre
00173             
00174         for (j2=0; j2<nt2; j2++) {
00175             yy[j2] = leg[nt2* (ll-m) + j2] ;
00176         }
00177 
00178 //....... transformation en cos(2*j*theta) : 
00179 
00180         cftcosp(deg, deg, yy, deg, yy) ; 
00181 
00182 //....... le resultat fournit les elements de matrice : 
00183         for (j=0; j<nt; j++) {
00184             tab[indice][ nt*nt* m/2 + nt*j + l] = yy[j] ; 
00185         }
00186         
00187         }  // fin de la boucle sur l (indice de P_{2l}^m)
00188         
00189         delete [] leg ;
00190             
00191     }  // fin de la boucle sur m
00192 
00193 // Liberation espace memoire
00194 // -------------------------
00195 
00196     delete [] yy ;
00197 
00198     } // fin du cas ou le calcul etait necessaire
00199 
00200     }   // Fin de zone critique
00201     
00202     return tab[indice] ;
00203 
00204 }
00205 
00206 

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