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_legp_cossincp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legp_cossincp.C,v 1.4 2005/02/18 13:14:10 j_novak Exp $" ; 00024 00025 /* 00026 * Calcule les coefficients du developpement (suivant theta) 00027 * en cos(2*j*theta) [m pair] / sin( (2*j+1) * theta) [m impair] 00028 * a partir des coefficients du developpement en fonctions 00029 * associees de Legendre P_l^m(cos(theta)) 00030 * pour une une fonction 3-D symetrique 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: 00043 * 00044 * pour m pair: f(theta) = 00045 * som_{l=m/2}^{nt-1} a_l P_{2l}^m( cos(theta) ) 00046 * 00047 * pour m impair: f(theta) = 00048 * som_{l=(m-1)/2}^{nt-2} a_l P_{2l+1}^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 et l < m/2, a_l = 0 00064 * pour m impair et l < (m-1)/2, a_l = 0 00065 00066 00067 00068 * 00069 * Sortie: 00070 * ------- 00071 * double* cfo : tableau des coefficients c_j du develop. en cos/sin definis 00072 * comme suit (a r et phi fixes) : 00073 * 00074 * pour m pair: f(theta) = som_{j=0}^{nt-1} c_j cos( 2 j theta ) 00075 * 00076 * pour m impair: f(theta) = som_{j=0}^{nt-2} c_j sin( (2 j+1) theta ) 00077 * 00078 * L'espace memoire correspondant au pointeur cfo doit etre 00079 * nr*nt*(np+2) et doit avoir ete alloue avant 00080 * l'appel a la routine. 00081 * Le coefficient c_j (0 <= j <= nt-1) est stoke dans le 00082 * tableau cfo comme suit 00083 * c_j = cfo[ nr*nt* k + i + nr* j ] 00084 * ou k et i sont les indices correspondant a 00085 * phi et r respectivement: m = k/2. 00086 * Pour m impair, c_0 = c_{nt-1} = 0. 00087 00088 * 00089 * NB: 00090 * --- 00091 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi. 00092 */ 00093 00094 /* 00095 * $Id: chb_legp_cossincp.C,v 1.4 2005/02/18 13:14:10 j_novak Exp $ 00096 * $Log: chb_legp_cossincp.C,v $ 00097 * Revision 1.4 2005/02/18 13:14:10 j_novak 00098 * Changing of malloc/free to new/delete + suppression of some unused variables 00099 * (trying to avoid compilation warnings). 00100 * 00101 * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon 00102 * Suppressed the directive #include <malloc.h> for malloc is defined 00103 * in <stdlib.h> 00104 * 00105 * Revision 1.2 2002/10/16 14:36:52 j_novak 00106 * Reorganization of #include instructions of standard C++, in order to 00107 * use experimental version 3 of gcc. 00108 * 00109 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon 00110 * LORENE 00111 * 00112 * Revision 2.0 1999/02/22 15:45:03 hyc 00113 * *** empty log message *** 00114 * 00115 * 00116 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legp_cossincp.C,v 1.4 2005/02/18 13:14:10 j_novak Exp $ 00117 * 00118 */ 00119 00120 00121 // headers du C 00122 #include <assert.h> 00123 #include <stdlib.h> 00124 00125 // Prototypage 00126 #include "headcpp.h" 00127 #include "proto.h" 00128 00129 //****************************************************************************** 00130 00131 void chb_legp_cossincp(const int* deg , const double* cfi, double* cfo) { 00132 00133 int ip, k2, l, j, i, m ; 00134 00135 // Nombres de degres de liberte en phi et theta : 00136 int np = deg[0] ; 00137 int nt = deg[1] ; 00138 int nr = deg[2] ; 00139 00140 assert(np < 4*nt) ; 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_legp_cossincp(np, nt) ; 00147 00148 // Increment en m pour la matrice bb : 00149 int mbb = nt * nt ; 00150 00151 //## Test 00152 // double* bbt = bb ; 00153 // cout << "chb_legp_cossincp: matrice de passage : " << endl ; 00154 // for ( m=0; m < np/2+1 ; m++) { 00155 // cout << "---------------------------------------" << endl ; 00156 // cout << " m = " << m << endl ; 00157 // cout << " " << endl ; 00158 // 00159 // for (j=0; j<nt; j++) { 00160 // cout << " j = " << j << " : " ; 00161 // for (l=m/2; l<nt; l++) { 00162 // cout << bbt[nt*j + l] << " " ; 00163 // } 00164 // cout << endl ; 00165 // } 00166 // arrete() ; 00167 // bbt += mbb ; // pointeur sur la nouvelle matrice de passage 00168 // } 00169 //## 00170 00171 // Pointeurs de travail : 00172 double* resu = cfo ; 00173 const double* cc = cfi ; 00174 00175 // Increment en phi : 00176 int ntnr = nt * nr ; 00177 00178 // Indice courant en phi : 00179 int k = 0 ; 00180 00181 // Ordre des harmoniques du developpement de Fourier en phi : 00182 m = 0 ; 00183 00184 // -------------- 00185 // Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3 00186 // -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1 00187 // k2 = 0 1 0 1 00188 00189 for (ip=0; ip < np/4 + 1 ; ip++) { 00190 00191 //-------------------------------- 00192 // Partie m pair 00193 //-------------------------------- 00194 00195 00196 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi) 00197 00198 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi) 00199 // et sin( np/2 phi) a zero 00200 for (j=0; j<nt; j++) { 00201 for (i=0; i<nr; i++) { 00202 *resu = 0 ; 00203 resu++ ; 00204 } 00205 } 00206 } 00207 else { 00208 00209 // Boucle sur l'indice j du developpement en cos(2 j theta) 00210 00211 for (j=0; j<nt; j++) { 00212 00213 // ... produit matriciel (parallelise sur r) 00214 for (i=0; i<nr; i++) { 00215 som[i] = 0 ; 00216 } 00217 00218 for (l=m/2; l<nt; l++) { 00219 00220 double bmjl = bb[nt*j + l] ; 00221 for (i=0; i<nr; i++) { 00222 som[i] += bmjl * cc[nr*l + i] ; 00223 } 00224 } 00225 00226 for (i=0; i<nr; i++) { 00227 *resu = som[i] ; 00228 resu++ ; 00229 } 00230 00231 } // fin de la boucle sur j 00232 00233 } // fin du cas k != 1 00234 00235 // On passe au phi suivant : 00236 cc = cc + ntnr ; 00237 k++ ; 00238 00239 } // fin de la boucle sur k2 00240 00241 // On passe a l'harmonique en phi suivante : 00242 m++ ; 00243 bb += mbb ; // pointeur sur la nouvelle matrice de passage 00244 00245 //-------------------------------- 00246 // Partie m impair 00247 //-------------------------------- 00248 00249 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi) 00250 00251 if ( k == np+1 ) { // On met les coef de 00252 // sin( np/2 phi) a zero 00253 for (j=0; j<nt; j++) { 00254 for (i=0; i<nr; i++) { 00255 *resu = 0 ; 00256 resu++ ; 00257 } 00258 } 00259 } 00260 00261 if (k < np+1) { 00262 00263 // Boucle sur l'indice j du developpement en sin( (2j+1) theta) 00264 00265 for (j=0; j<nt-1; j++) { 00266 00267 // ... produit matriciel (parallelise sur r) 00268 for (i=0; i<nr; i++) { 00269 som[i] = 0 ; 00270 } 00271 00272 for (l=(m-1)/2; l<nt-1; l++) { 00273 double bmjl = bb[nt*j + l] ; 00274 for (i=0; i<nr; i++) { 00275 som[i] += bmjl * cc[nr*l + i] ; 00276 } 00277 } 00278 00279 for (i=0; i<nr; i++) { 00280 *resu = som[i] ; 00281 resu++ ; 00282 } 00283 00284 } // fin de la boucle sur j 00285 00286 // Dernier coef en j=nt-1 mis a zero pour le cas m impair : 00287 for (i=0; i<nr; i++) { 00288 *resu = 0 ; 00289 resu++ ; 00290 } 00291 00292 // On passe au phi suivant : 00293 cc = cc + ntnr ; 00294 k++ ; 00295 00296 } // fin du cas k < np+1 00297 00298 } // fin de la boucle sur k2 00299 00300 00301 // On passe a l'harmonique en phi suivante : 00302 m++ ; 00303 bb += mbb ; // pointeur sur la nouvelle matrice de passage 00304 00305 } // fin de la boucle (ip) sur phi 00306 00307 // Mise a zero des coefficients de sin( np/2 phi ) (k=np+1) 00308 00309 //## verif : 00310 // assert(resu == cfo + (np+2)*ntnr) ; 00311 00312 // Menage 00313 delete [] som ; 00314 00315 }
1.4.6