chb_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 chb_cosi_legip_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cosi_legip.C,v 1.5 2005/02/18 13:14:10 j_novak Exp $" ;
00024 
00025 /*
00026  *  Calcule les coefficients du developpement (suivant theta) en fonctions
00027  *  associees de Legendre P_l^m(cos(theta)) a partir des coefficients du 
00028  *  developpement en cos((2*j+1)*theta) 
00029  *  representant une fonction 3-D antisymetrique par rapport au plan equatorial
00030  *  z = 0 et symetrique par le retournement (x, y, z) --> (-x, -y, z). 
00031  * 
00032  * Entree:
00033  * -------
00034  *  const int* deg : tableau du nombre effectif de degres de liberte dans chacune 
00035  *           des 3 dimensions: 
00036  *          deg[0] = np : nombre de points de collocation en phi
00037  *          deg[1] = nt : nombre de points de collocation en theta
00038  *          deg[2] = nr : nombre de points de collocation en r
00039  *
00040  *  const double* cfi :  tableau des coefficients c_j du develop. en cos defini
00041  *            comme suit (a r et phi fixes)
00042  *
00043  *          f(theta) = som_{j=0}^{nt-2} c_j cos( (2j+1) theta ) 
00044  *
00045  *          L'espace memoire correspondant au pointeur cfi doit etre 
00046  *              nr*nt*(np+2) et doit avoir ete alloue avant 
00047  *          l'appel a la routine.    
00048  *          Le coefficient c_j (0 <= j <= nt-1) doit etre stoke dans le 
00049  *          tableau cfi comme suit
00050  *                c_j = cfi[ nr*nt* k + i + nr* j ]
00051  *          ou k et i sont les indices correspondant a
00052  *          phi et r respectivement.
00053  *
00054  * Sortie:
00055  * -------
00056  *   double* cfo :  tableau des coefficients a_j du develop. en fonctions de
00057  *          Legendre associees P_l^m (l impair, m pair)
00058  *
00059  *          f(theta) = 
00060  *              som_{j=m/2}^{nt-2} a_j P_{2j+1}^m( cos(theta) )
00061  *            
00062  *      
00063  *          avec m pair :  m = 0, 2, ..., np.         
00064  *
00065  *          P_l^m(x) represente la fonction de Legendre associee
00066  *             de degre l et d'ordre m normalisee de facon a ce que
00067  *
00068  *          int_0^pi [ P_l^m(cos(theta)) ]^2  sin(theta) dtheta = 1
00069  *
00070  *          L'espace memoire correspondant au pointeur cfo doit etre 
00071  *              nr*nt*(np+2) et doit avoir ete alloue avant 
00072  *          l'appel a la routine.    
00073  *          Le coefficient a_j (0 <= j <= nt-1) est stoke dans le 
00074  *          tableau cfo comme suit
00075  *                a_j = cfo[ nr*nt* k + i + nr* j ]
00076  *          ou k et i sont les indices correspondant a phi et r 
00077  *          respectivement: m = 2( k/2 ).
00078  *          NB: pour j < m/2 ou j = nt-1,  a_j = 0
00079  *
00080  * NB:
00081  * ---
00082  *  Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
00083  */
00084 
00085 /*
00086  * $Id: chb_cosi_legip.C,v 1.5 2005/02/18 13:14:10 j_novak Exp $
00087  * $Log: chb_cosi_legip.C,v $
00088  * Revision 1.5  2005/02/18 13:14:10  j_novak
00089  * Changing of malloc/free to new/delete + suppression of some unused variables
00090  * (trying to avoid compilation warnings).
00091  *
00092  * Revision 1.4  2003/12/19 16:21:46  j_novak
00093  * Shadow hunt
00094  *
00095  * Revision 1.3  2003/01/31 10:31:23  e_gourgoulhon
00096  * Suppressed the directive #include <malloc.h> for malloc is defined
00097  * in <stdlib.h>
00098  *
00099  * Revision 1.2  2002/10/16 14:36:52  j_novak
00100  * Reorganization of #include instructions of standard C++, in order to
00101  * use experimental version 3 of gcc.
00102  *
00103  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00104  * LORENE
00105  *
00106  * Revision 2.1  2000/09/29  16:05:49  eric
00107  * *** empty log message ***
00108  *
00109  * Revision 2.0  2000/09/28  10:02:00  eric
00110  * *** empty log message ***
00111  *
00112  *
00113  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cosi_legip.C,v 1.5 2005/02/18 13:14:10 j_novak Exp $
00114  *
00115  */
00116 
00117 
00118 // headers du C
00119 #include <assert.h>
00120 #include <stdlib.h>
00121 
00122 // Prototypage
00123 #include "headcpp.h"
00124 #include "proto.h"
00125 
00126 //******************************************************************************
00127 
00128 void chb_cosi_legip(const int* deg , const double* cfi, double* cfo) {
00129 
00130 int k2, l, jmin, j, i, m ;
00131  
00132     // Nombres de degres de liberte en phi et theta :
00133     int np = deg[0] ;
00134     int nt = deg[1] ;
00135     int nr = deg[2] ;
00136 
00137     assert(np < 4*nt) ;
00138     assert( cfi != cfo ) ; 
00139 
00140     // Tableau de travail
00141     double* som = new double[nr] ; 
00142 
00143     // Recherche de la matrice de passage  cos --> Legendre 
00144     double* aa = mat_cosi_legip(np, nt) ;
00145     
00146     // Increment en m pour la matrice aa :
00147     int maa = nt * nt  ;
00148    
00149     // Pointeurs de travail :
00150     double* resu = cfo ;
00151     const double* cc = cfi ;
00152 
00153     // Increment en phi :
00154     int ntnr = nt * nr ;
00155 
00156     // Indice courant en phi :
00157     int k = 0 ;
00158 
00159     //----------------------------------------------------------------
00160     //          Cas axisymetrique       
00161     //----------------------------------------------------------------
00162 
00163     if (np == 1) {
00164 
00165     m = 0 ; 
00166 
00167     // Boucle sur l'indice l du developpement en Legendre
00168 
00169     // ... produit matriciel (parallelise sur r)
00170         for (l=m/2; l<nt-1; l++) {
00171             for (i=0; i<nr; i++) {
00172             som[i] = 0 ; 
00173             }
00174             
00175             //##    jmin =  l  ;    // pour m=0, aa_lj = 0 pour j<l
00176             jmin = 0 ; 
00177             for (j=jmin; j<nt-1; j++) {
00178             double amlj = aa[nt*l + j] ;
00179             for (i=0; i<nr; i++) {
00180                 som[i] += amlj * cc[nr*j + i] ;
00181             }
00182             }
00183             
00184             for (i=0; i<nr; i++) {
00185             *resu = som[i]  ;
00186             resu++ ;  
00187             }
00188             
00189         }  // fin de la boucle sur l 
00190     
00191      //...  l = nt-1 : a_l = 0 
00192         for (i=0; i<nr; i++) {
00193             *resu = 0 ;
00194             resu++ ; 
00195         }
00196 
00197     // Mise a zero des coefficients k=1 et k=2 :
00198     // ---------------------------------------
00199     
00200     for (i=ntnr; i<3*ntnr; i++) {
00201         cfo[i] = 0 ;         
00202     }       
00203         
00204 
00205     // on sort
00206     delete [] som ;
00207     return ; 
00208     
00209     }   // fin du cas np=1
00210 
00211 
00212 //----------------------------------------------------------------
00213 //          Cas 3-D     
00214 //----------------------------------------------------------------
00215 
00216 
00217 // Boucle sur phi  : 
00218 
00219 
00220     for (m=0; m < np + 1 ; m+=2) {      
00221         
00222     for (k2=0; k2 < 2; k2++) {  // k2=0 : cos(m phi)  ;   k2=1 : sin(m phi)
00223 
00224         if ( (k == 1) || (k == np+1) ) {    // On met les coef de sin(0 phi)
00225                         // et sin( np phi)  a zero 
00226         for (l=0; l<nt; l++) {
00227             for (i=0; i<nr; i++) {
00228             *resu = 0 ;
00229             resu++ ; 
00230             }           
00231         }
00232         }
00233         else {
00234 
00235 // Boucle sur l'indice l du developpement en Legendre
00236 
00237      //...  0 <= l <= m/2 - 1 : a_l = 0 
00238         for (l=0; l<m/2; l++) {
00239             for (i=0; i<nr; i++) {
00240             *resu = 0 ;
00241             resu++ ; 
00242             }
00243         }       
00244     // ... m/2 <= l <= nt-2 : produit matriciel (parallelise sur r)
00245         for (l=m/2; l<nt-1; l++) {
00246             for (i=0; i<nr; i++) {
00247             som[i] = 0 ; 
00248             }
00249             
00250             //## jmin = ( m == 0 ) ? l : 0 ;  // pour m=0, aa_lj = 0 pour j<l
00251             jmin = 0 ; 
00252             for (j=jmin; j<nt-1; j++) {
00253             double amlj = aa[nt*l + j] ;
00254             for (i=0; i<nr; i++) {
00255                 som[i] += amlj * cc[nr*j + i] ;
00256             }
00257             }
00258             
00259             for (i=0; i<nr; i++) {
00260             *resu = som[i]  ;
00261             resu++ ;  
00262             }
00263             
00264         }  // fin de la boucle sur l 
00265 
00266      //...  l = nt-1 : a_l = 0 
00267         for (i=0; i<nr; i++) {
00268             *resu = 0 ;
00269             resu++ ; 
00270         }
00271 
00272         }   // fin du cas k != 1 et k!=np+1
00273         
00274 // On passe au phi suivant :
00275         cc = cc + ntnr  ; 
00276         k++ ;
00277                 
00278     }   // fin de la boucle sur k2 
00279     
00280 // On passe a l'harmonique en phi suivante :
00281 
00282     aa += maa ; // pointeur sur la nouvelle matrice de passage
00283         
00284     }   // fin de la boucle (m) sur phi  
00285 
00286 //## verif : 
00287     assert(resu == cfo + (np+2)*ntnr) ;
00288 
00289     // Menage
00290     delete [] som ;
00291     
00292 }

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