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

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