mat_cos_legmp.C

00001 /*
00002  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00003  *                 2009 Jerome Novak
00004  *
00005  *   This file is part of LORENE.
00006  *
00007  *   LORENE is free software; you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation; either version 2 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   LORENE is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with LORENE; if not, write to the Free Software
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 
00024 char mat_cos_legmp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cos_legmp.C,v 1.1 2009/10/13 13:49:36 j_novak Exp $" ;
00025 
00026 /*
00027  * Fournit la matrice de passage pour la transformation des coefficients du
00028  * developpement en cos(j*theta) 
00029  * dans les coefficients du developpement en fonctions associees de Legendre 
00030  * P_l^m(cos(theta)) telles que m est pair.
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_cos_legmp :     pointeur sur le tableau contenant l'ensemble
00044  *                  (pour les np/2+1 valeurs de m: m=0,2,...,np) 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_cos_legmp[ nt*nt* m/2 + nt*l + j] = A_{mlj}
00050  *              
00051  *              ou A_{mlj} est defini par
00052  *
00053  *   cos(j*theta) = som_{l=m}^{nt-1} A_{mlj} P_l^m( cos(theta) )
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_cos_legmp.C,v 1.1 2009/10/13 13:49:36 j_novak Exp $
00065  * $Log: mat_cos_legmp.C,v $
00066  * Revision 1.1  2009/10/13 13:49:36  j_novak
00067  * New base T_LEG_MP.
00068  *
00069  *
00070  *
00071  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cos_legmp.C,v 1.1 2009/10/13 13:49:36 j_novak Exp $
00072  *
00073  */
00074 
00075 // headers du C
00076 #include <stdlib.h>
00077 #include <math.h>
00078 
00079 // Prototypage
00080 #include "headcpp.h"
00081 #include "proto.h"
00082 
00083 //******************************************************************************
00084 
00085 double* mat_cos_legmp(int np, int nt) {
00086 
00087 #define NMAX    30      // Nombre maximun de couples(np,nt) differents 
00088     static  double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux 
00089     static  int nb_dejafait = 0 ;      // Nombre de tableaux deja initialises 
00090     static  int np_dejafait[NMAX] ;    // Valeurs de np pour lesquelles le
00091                                                // calcul a deja ete fait
00092     static  int nt_dejafait[NMAX] ;    // Valeurs de np pour lesquelles le
00093                                                // calcul a deja ete fait
00094 
00095     int i, indice,  j,  j2,  m,  l ;
00096     
00097     
00098     // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ? 
00099     indice = -1 ;
00100     for ( i=0 ; i < nb_dejafait ; i++ ) {
00101     if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
00102     }
00103 
00104 
00105 // Si le calcul n'a pas deja ete fait, il faut le faire : 
00106     if (indice == -1) {        
00107     if ( nb_dejafait >= NMAX ) {
00108         cout << "mat_cos_legmp: nb_dejafait >= NMAX : "
00109          << nb_dejafait << " <-> " << NMAX << endl ;
00110         abort () ;  
00111         exit(-1) ;
00112     }
00113     indice = nb_dejafait ; 
00114     nb_dejafait++ ; 
00115     np_dejafait[indice] = np ;
00116     nt_dejafait[indice] = nt ;
00117     
00118     tab[indice] = new double[(np/2+1)*nt*nt] ;
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* cost = new double[nt*nt2] ; 
00136    
00137 // Calcul des cos(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; j++) {
00142         for (j2=0; j2<nt2; j2++) {
00143         double theta = j2*dt ;
00144         cost[nt2*j + j2] = cos( j * theta ) ;
00145         }
00146     }   
00147 
00148 
00149 //-------------------
00150 // Boucle sur m
00151 //-------------------
00152 
00153     int m_max = np ; 
00154     if (np == 1) m_max = 0 ; 
00155 
00156     for (m=0; m <= m_max ; m+=2) {
00157 
00158 // Recherche des fonctions de Legendre associees d'ordre m :
00159 
00160         double* leg = legendre_norm(m, nt) ;    
00161     
00162         for (l=m; l<nt; l++) {  // boucle sur les P_l^m
00163         
00164           int parite = 1 - 2*((l-m)%2) ;  // parite du P_l^m par rapport au plan theta=pi/2
00165         for (j=0; j<nt; j++) {  // boucle sur les cos(j theta)
00166             
00167 //... produit scalaire de cos(j theta) par P_l^m(cos(theta)) 
00168 
00169             for (j2=0; j2<nt; j2++) {
00170             yy[nt2m1-j2] = cost[nt2*j + j2] *
00171                        leg[nt2* (l-m) + 2*j2] ;
00172             }
00173 
00174             for (j2 = nt; j2<nt2; j2++) {
00175             yy[nt2m1-j2] = cost[nt2*j + j2] *
00176                 parite * leg[nt2* (l-m) + 2*nt2 -2 -2*j2] ;
00177             }
00178 
00179 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
00180 //      l'integrale (routine int1d_cheb) :      
00181             cfrcheb(deg, deg, yy, deg, yy) ;
00182             tab[indice][ nt*nt* m/2 + nt*l + j] = 
00183                         int1d_cheb(nt2, yy) ;
00184 
00185         }   // fin de la boucle sur j  (indice de cos(j theta) )
00186         
00187         }  // fin de la boucle sur l (indice de P_l^m)
00188                 
00189     delete [] leg ; 
00190             
00191     }  // fin de la boucle sur m
00192 
00193 // Liberation espace memoire
00194 // -------------------------
00195 
00196     delete [] yy ;
00197     delete [] cost ;
00198 
00199     } // fin du cas ou le calcul etait necessaire
00200     
00201     return tab[indice] ;
00202 
00203 }
00204 
00205 

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