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

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