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_legi_cossinci_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legi_cossinci.C,v 1.3 2005/02/18 13:14:10 j_novak Exp $" ; 00024 00025 /* 00026 * Calcule les coefficients du developpement (suivant theta) 00027 * en cos((2*j+1)*theta) [m pair] / sin( 2*j * theta) [m impair] 00028 * a partir des coefficients du developpement en fonctions 00029 * associees de Legendre P_l^m(cos(theta)) impaires 00030 * pour une une fonction 3-D antisymetrique par rapport au plan equatorial 00031 * z = 0. 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 impaires: 00043 * 00044 * pour m pair: f(theta) = 00045 * som_{l=m/2}^{nt-2} a_l P_{2l+1}^m( cos(theta) ) 00046 * 00047 * pour m impair: f(theta) = 00048 * som_{l=(m+1)/2}^{nt-2} a_l P_{2l}^m( cos(theta) ) 00049 * 00050 * ou P_n^m(x) represente la fonction de Legendre associee 00051 * de degre n et d'ordre m normalisee de facon a ce que 00052 * 00053 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1 00054 * 00055 * L'espace memoire correspondant au pointeur cfi doit etre 00056 * nr*nt*(np+2) et doit avoir ete alloue avant 00057 * l'appel a la routine. 00058 * Le coefficient a_l (0 <= l <= nt-1) doit etre stoke dans le 00059 * tableau cfi comme suit 00060 * a_l = cfi[ nr*nt* k + i + nr* l ] 00061 * ou k et i sont les indices correspondant a phi et r 00062 * respectivement: m = k/2. 00063 * NB: pour m pair: si l < m/2 ou l = nt-1, a_l = 0 00064 * pour m impair: si l < (m+1)/2 ou l = nt-1, a_l = 0 00065 * 00066 * Sortie: 00067 * ------- 00068 * double* cfo : tableau des coefficients c_j du develop. en cos/sin definis 00069 * comme suit (a r et phi fixes) : 00070 * 00071 * pour m pair: f(theta) = som_{j=0}^{nt-2} c_j cos( (2j+1) theta ) 00072 * 00073 * pour m impair: f(theta) = som_{j=1}^{nt-2} c_j sin( 2j theta ) 00074 * 00075 * L'espace memoire correspondant au pointeur cfo doit etre 00076 * nr*nt*(np+2) et doit avoir ete alloue avant 00077 * l'appel a la routine. 00078 * Le coefficient c_j (0 <= j <= nt-1) est stoke dans le 00079 * tableau cfo comme suit 00080 * c_j = cfo[ nr*nt* k + i + nr* j ] 00081 * ou k et i sont les indices correspondant a 00082 * phi et r respectivement: m = k/2. 00083 * Pour m pair, c_{nt-1} = 0. 00084 * Pour m impair, c_0 = c_{nt-1} = 0. 00085 * 00086 * NB: 00087 * --- 00088 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi. 00089 */ 00090 00091 /* 00092 * $Id: chb_legi_cossinci.C,v 1.3 2005/02/18 13:14:10 j_novak Exp $ 00093 * $Log: chb_legi_cossinci.C,v $ 00094 * Revision 1.3 2005/02/18 13:14:10 j_novak 00095 * Changing of malloc/free to new/delete + suppression of some unused variables 00096 * (trying to avoid compilation warnings). 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.0 1999/02/22 15:45:13 hyc 00106 * *** empty log message *** 00107 * 00108 * 00109 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legi_cossinci.C,v 1.3 2005/02/18 13:14:10 j_novak Exp $ 00110 * 00111 */ 00112 00113 // headers du C 00114 #include <assert.h> 00115 #include <stdlib.h> 00116 00117 // Prototypage 00118 #include "headcpp.h" 00119 #include "proto.h" 00120 00121 //****************************************************************************** 00122 00123 void chb_legi_cossinci(const int* deg , const double* cfi, double* cfo) { 00124 00125 int ip, k2, l, j, i, m ; 00126 00127 // Nombres de degres de liberte en phi et theta : 00128 int np = deg[0] ; 00129 int nt = deg[1] ; 00130 int nr = deg[2] ; 00131 00132 assert(np < 4*nt) ; 00133 00134 // Tableau de travail 00135 double* som = new double[nr] ; 00136 00137 // Recherche de la matrice de passage Legendre --> cos/sin 00138 double* bb = mat_legi_cossinci(np, nt) ; 00139 00140 // Increment en m pour la matrice bb : 00141 int mbb = nt * nt ; 00142 00143 // Pointeurs de travail : 00144 double* resu = cfo ; 00145 const double* cc = cfi ; 00146 00147 // Increment en phi : 00148 int ntnr = nt * nr ; 00149 00150 // Indice courant en phi : 00151 int k = 0 ; 00152 00153 // Ordre des harmoniques du developpement de Fourier en phi : 00154 m = 0 ; 00155 00156 // -------------- 00157 // Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3 00158 // -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1 00159 // k2 = 0 1 0 1 00160 00161 for (ip=0; ip < np/4 + 1 ; ip++) { 00162 00163 //-------------------------------- 00164 // Partie m pair 00165 //-------------------------------- 00166 00167 00168 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi) 00169 00170 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi) 00171 // et sin( np/2 phi) a zero 00172 for (j=0; j<nt; j++) { 00173 for (i=0; i<nr; i++) { 00174 *resu = 0 ; 00175 resu++ ; 00176 } 00177 } 00178 } 00179 else { 00180 00181 // Boucle sur l'indice j du developpement en cos((2 j+1) theta) 00182 00183 //... produit matriciel (parallelise sur r) 00184 for (j=0; j<nt-1; j++) { 00185 00186 for (i=0; i<nr; i++) { 00187 som[i] = 0 ; 00188 } 00189 00190 for (l=m/2; l<nt-1; l++) { 00191 00192 double bmjl = bb[nt*j + l] ; 00193 for (i=0; i<nr; i++) { 00194 som[i] += bmjl * cc[nr*l + i] ; 00195 } 00196 } 00197 00198 for (i=0; i<nr; i++) { 00199 *resu = som[i] ; 00200 resu++ ; 00201 } 00202 00203 } // fin de la boucle sur j 00204 00205 //... dernier coef en j=nt-1 mis a zero: 00206 for (i=0; i<nr; i++) { 00207 *resu = 0 ; 00208 resu++ ; 00209 } 00210 00211 } // fin du cas k != 1 00212 00213 // On passe au phi suivant : 00214 cc = cc + ntnr ; 00215 k++ ; 00216 00217 } // fin de la boucle sur k2 00218 00219 // On passe a l'harmonique en phi suivante : 00220 m++ ; 00221 bb += mbb ; // pointeur sur la nouvelle matrice de passage 00222 00223 //-------------------------------- 00224 // Partie m impair 00225 //-------------------------------- 00226 00227 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi) 00228 00229 if ( k == np+1 ) { // On met les coef de 00230 // sin( np/2 phi) a zero 00231 for (j=0; j<nt; j++) { 00232 for (i=0; i<nr; i++) { 00233 *resu = 0 ; 00234 resu++ ; 00235 } 00236 } 00237 } 00238 00239 if (k < np+1) { 00240 00241 // Boucle sur l'indice j du developpement en sin( 2j theta) 00242 00243 //... premier coef en j=0 mis a zero: 00244 for (i=0; i<nr; i++) { 00245 *resu = 0 ; 00246 resu++ ; 00247 } 00248 00249 //... produit matriciel (parallelise sur r) 00250 00251 for (j=1; j<nt-1; j++) { 00252 00253 for (i=0; i<nr; i++) { 00254 som[i] = 0 ; 00255 } 00256 00257 for (l=(m+1)/2; l<nt-1; l++) { 00258 double bmjl = bb[nt*j + l] ; 00259 for (i=0; i<nr; i++) { 00260 som[i] += bmjl * cc[nr*l + i] ; 00261 } 00262 } 00263 00264 for (i=0; i<nr; i++) { 00265 *resu = som[i] ; 00266 resu++ ; 00267 } 00268 00269 } // fin de la boucle sur j 00270 00271 //... dernier coef en j=nt-1 mis a zero : 00272 for (i=0; i<nr; i++) { 00273 *resu = 0 ; 00274 resu++ ; 00275 } 00276 00277 // On passe au phi suivant : 00278 cc = cc + ntnr ; 00279 k++ ; 00280 00281 } // fin du cas k < np+1 00282 00283 } // fin de la boucle sur k2 00284 00285 00286 // On passe a l'harmonique en phi suivante : 00287 m++ ; 00288 bb += mbb ; // pointeur sur la nouvelle matrice de passage 00289 00290 } // fin de la boucle (ip) sur phi 00291 00292 // Mise a zero des coefficients de sin( np/2 phi ) (k=np+1) 00293 00294 //## verif : 00295 assert(resu == cfo + (np+2)*ntnr) ; 00296 00297 // Menage 00298 delete [] som ; 00299 00300 }
1.4.6