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

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