mat_cossinc_leg.C

00001 /*
00002  *   Copyright (c) 2004 Michael Forot
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_cossinc_leg_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossinc_leg.C,v 1.5 2009/10/13 13:49:36 j_novak Exp $" ;
00024 
00025 /*
00026  * Fournit la matrice de passage pour la transformation des coefficients du
00027  * developpement en cos(j*theta) [m pair] / sin( j* theta) [m impair]
00028  * dans les coefficients du developpement en fonctions associees de Legendre 
00029  * P_l^m(cos(theta)). 
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_cossinc_leg : pointeur sur le tableau contenant l'ensemble
00043  *                  (pour les np/2+1 valeurs de m) 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_cossinc_leg[ nt*nt* m + nt*l + j] = A_{mlj}
00049  *              
00050  *              ou A_{mlj} est defini par
00051  *
00052  * pour m pair :  
00053  *   cos(j*theta) = som_{l=m}^{nt-1} A_{mlj} P_{l}^m( cos(theta) )
00054  *
00055  * pour m impair :  
00056  *   sin(j*theta) = som_{l=m}^{nt-1} A_{mlj} P_{l}^m( cos(theta) )
00057  *
00058  *  ou P_n^m(x) represente la fonction de Legendre associee de degre n et 
00059  *     d'ordre m normalisee de facon a ce que
00060  *
00061  *   int_0^pi [ P_n^m(cos(theta)) ]^2  sin(theta) dtheta = 1
00062  *
00063  * 
00064  */
00065 
00066 /*
00067  * $Id: mat_cossinc_leg.C,v 1.5 2009/10/13 13:49:36 j_novak Exp $
00068  * $Log: mat_cossinc_leg.C,v $
00069  * Revision 1.5  2009/10/13 13:49:36  j_novak
00070  * New base T_LEG_MP.
00071  *
00072  * Revision 1.4  2005/02/18 13:14:13  j_novak
00073  * Changing of malloc/free to new/delete + suppression of some unused variables
00074  * (trying to avoid compilation warnings).
00075  *
00076  * Revision 1.3  2005/02/16 15:24:15  m_forot
00077  * Replace int1d_chebp by int1d_cheb
00078  *
00079  * Revision 1.2  2004/12/17 15:42:02  e_gourgoulhon
00080  * l_max = nt instead of nt2.
00081  *
00082  * Revision 1.1  2004/11/23 15:13:50  m_forot
00083  * Added the bases for the cases without any equatorial symmetry
00084  * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
00085  *
00086  *
00087  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossinc_leg.C,v 1.5 2009/10/13 13:49:36 j_novak Exp $
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_cossinc_leg = 0 ;
00101 
00102 //******************************************************************************
00103 
00104 double* mat_cossinc_leg(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_cossinc_leg)
00117     { 
00118 
00119     // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ? 
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_cossinc_leg: 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] ; 
00140 
00141 //-----------------------
00142 // Preparation du calcul 
00143 //-----------------------
00144 
00145 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
00146     int nt2 = 2*nt - 1 ; 
00147     int nt2m1 = nt2 - 1 ; 
00148 
00149     int deg[3] ;
00150     deg[0] = 1 ;
00151     deg[1] = 1 ;
00152     deg[2] = nt2 ;
00153 
00154 // Tableaux de travail
00155     double* yy = new double[nt2] ; 
00156     double* cost = new double[nt*nt2] ; 
00157     double* sint = new double[nt*nt2] ; 
00158    
00159 // Calcul des cos(j*theta) / sin( j*theta ) aux points de collocation
00160 //  de l'echantillonnage double : 
00161 
00162     double dt = M_PI / double((nt2-1)) ;
00163     for (j=0; j<nt; j++) {
00164         for (j2=0; j2<nt2; j2++) {
00165         double theta = j2*dt ;
00166         cost[nt2*j + j2] = cos( j * theta ) ;
00167         sint[nt2*j + j2] = sin( j * theta ) ;
00168         }
00169     }   
00170 
00171 
00172 //-------------------
00173 // Boucle sur m
00174 //-------------------
00175 
00176     for (m=0; m < np/2+1 ; m++) {
00177 
00178 // Recherche des fonctions de Legendre associees d'ordre m :
00179 
00180         double* leg = legendre_norm(m, nt) ;    
00181        
00182         if (m%2==0) {
00183 // Cas m pair
00184 //-----------
00185         for (l=m; l<nt; l++) {  // boucle sur les P_{l}^m
00186         
00187           int parite = 1 - 2*((l-m)%2) ;  // parite du P_l^m par rapport au plan theta=pi/2
00188 
00189           for (j=0; j<nt; j++) {    // boucle sur les cos(j theta)
00190             
00191 //... produit scalaire de cos(j theta) par P_{l}^m(cos(theta)) 
00192 
00193             for (j2=0; j2<nt; j2++) {
00194               yy[nt2m1-j2] = cost[nt2*j + j2] *
00195                   leg[nt2* (l-m) + 2*j2] ;
00196             }
00197 
00198             for (j2=nt; j2<nt2; j2++) {
00199               yy[nt2m1-j2] = cost[nt2*j + j2] *
00200                 parite * leg[nt2* (l-m) + 2*nt2 -2 -2*j2] ;
00201             }
00202 
00203 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
00204 //      l'integrale (routine int1d_cheb) :      
00205             cfrcheb(deg, deg, yy, deg, yy) ;
00206             tab[indice][ nt*nt* m + nt*l + j] = 
00207                         int1d_cheb(nt2, yy) ;
00208 
00209             }   // fin de la boucle sur j  (indice de cos(j theta) )
00210         
00211         }  // fin de la boucle sur l (indice de P_l^m)
00212         
00213         
00214         }   // fin du cas m pair
00215         else {
00216         
00217 // Cas m impair
00218 //-------------
00219 
00220         for (l=m; l<nt; l++) {  // boucle sur les P_{l}^m
00221 
00222           int parite = 1 - 2*((l-m)%2) ;  // parite du P_l^m par rapport au plan theta=pi/2
00223         
00224           for (j=0; j<nt; j++) {  // boucle sur les sin(j)theta)
00225             
00226 //... produit scalaire de sin(j) theta) par P_{l}^m(cos(theta)) 
00227 
00228             for (j2=0; j2<nt; j2++) {
00229               yy[nt2m1-j2] = sint[nt2*j + j2] *
00230                 leg[nt2* (l-m) + 2*j2] ;
00231         
00232             }
00233 
00234             for (j2=nt; j2<nt2; j2++) {
00235               yy[nt2m1-j2] = sint[nt2*j + j2] *
00236                 parite * leg[nt2* (l-m) + 2*nt2  -2 - 2*j2] ;
00237         
00238             }
00239             
00240 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
00241 //      l'integrale (routine int1d_chebp) : 
00242             cfrcheb(deg, deg, yy, deg, yy) ;
00243             
00244             tab[indice][ nt*nt* m + nt*l + j] = 
00245                         int1d_cheb(nt2, yy) ;
00246                     
00247           } // fin de la boucle sur j  (indice de  sin(j*theta) )
00248         
00249         }  // fin de la boucle sur l (indice de P_{l}^m)
00250         
00251 
00252         } // fin du cas m impair
00253         
00254     delete [] leg ;
00255             
00256     }  // fin de la boucle sur m
00257 
00258 // Liberation espace memoire
00259 // -------------------------
00260 
00261     delete [] yy ; 
00262     delete [] cost ;
00263     delete [] sint ; 
00264 
00265     } // fin du cas ou le calcul etait necessaire
00266     
00267     } // Fin de zone critique
00268     
00269     return tab[indice] ;
00270 
00271 }
00272 
00273 

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