00001 /* 00002 * Copyright (c) 2003 Jerome Novak 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_legii_sinp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legii_sinp.C,v 1.2 2005/02/18 13:14:10 j_novak Exp $" ; 00024 00025 /* 00026 * Calcule les coefficients du developpement (suivant theta) 00027 * en sin(2j theta) 00028 * a partir des coefficients du developpement en fonctions 00029 * associees de Legendre P_l^m(cos(theta)) (l pair et m impair) 00030 * pour une une fonction 3-D antisymetrique par rapport au plan equatorial 00031 * z = 0 et antisymetrique 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_{l=(m+1)/2}^{nt-2} a_j P_{2j}^m( cos(theta) ) 00046 * 00047 * (m impair) 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+1)/2, a_j = 0 00063 * 00064 * Sortie: 00065 * ------- 00066 * double* cfo : tableau des coefficients c_j du develop. en sin definis 00067 * comme suit (a r et phi fixes) : 00068 * 00069 * f(theta) = som_{j=1}^{nt-2} c_j sin( 2j 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. 00079 * NB: c_0 = 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_legii_sinp.C,v 1.2 2005/02/18 13:14:10 j_novak Exp $ 00089 * $Log: chb_legii_sinp.C,v $ 00090 * Revision 1.2 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.1 2003/09/16 08:58:01 j_novak 00095 * New functions for the T_LEG_II base 00096 * 00097 * 00098 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legii_sinp.C,v 1.2 2005/02/18 13:14:10 j_novak Exp $ 00099 * 00100 */ 00101 00102 // headers du C 00103 #include <stdlib.h> 00104 #include <assert.h> 00105 00106 // Headers Lorene 00107 #include "headcpp.h" 00108 #include "proto.h" 00109 00110 //****************************************************************************** 00111 00112 void chb_legii_sinp(const int* deg , const double* cfi, double* cfo) { 00113 00114 int k2, l, j, i, m ; 00115 00116 // Nombres de degres de liberte en phi et theta : 00117 int np = deg[0] ; 00118 int nt = deg[1] ; 00119 int nr = deg[2] ; 00120 00121 assert(np < 4*nt) ; 00122 assert( cfi != cfo ) ; 00123 00124 // Tableau de travail 00125 double* som = new double[nr] ; 00126 // Recherche de la matrice de passage Legendre --> cos/sin 00127 double* bb = mat_legii_sinp(np, nt) ; 00128 00129 // Increment en m pour la matrice bb : 00130 int mbb = nt * nt ; 00131 00132 // Pointeurs de travail : 00133 double* resu = cfo ; 00134 const double* cc = cfi ; 00135 00136 // Increment en phi : 00137 int ntnr = nt * nr ; 00138 00139 // Indice courant en phi : 00140 int k = 0 ; 00141 00142 // Cas k=0 (m=1 : cos(phi)) 00143 // ------------------------ 00144 00145 //... premier coef en j=0 mis a zero: 00146 for (i=0; i<nr; i++) { 00147 *resu = 0 ; 00148 resu++ ; 00149 } 00150 00151 // Boucle sur l'indice j du developpement en sin( 2j theta) 00152 00153 for (j=1; j<nt-1; j++) { 00154 00155 // ... produit matriciel (parallelise sur r) 00156 for (i=0; i<nr; i++) { 00157 som[i] = 0 ; 00158 } 00159 00160 for (l=1; l<nt-1; l++) { 00161 double bmjl = bb[nt*j + l] ; 00162 for (i=0; i<nr; i++) { 00163 som[i] += bmjl * cc[nr*l + i] ; 00164 } 00165 } 00166 00167 for (i=0; i<nr; i++) { 00168 *resu = som[i] ; 00169 resu++ ; 00170 } 00171 00172 } // fin de la boucle sur j 00173 00174 // Dernier coef en j=nt-1 mis a zero pour le cas m impair : 00175 for (i=0; i<nr; i++) { 00176 *resu = 0 ; 00177 resu++ ; 00178 } 00179 00180 // Special case np=1 (axisymmetry) 00181 // ------------------------------- 00182 if (np==1) { 00183 for (i=0; i<2*ntnr; i++) { 00184 *resu = 0 ; 00185 resu++ ; 00186 } 00187 delete [] som ; 00188 return ; 00189 } 00190 00191 // On passe au phi suivant : 00192 cc = cc + ntnr ; 00193 k++ ; 00194 00195 // Cas k=1 : tout est mis a zero 00196 // ----------------------------- 00197 00198 for (l=0; l<nt; l++) { 00199 for (i=0; i<nr; i++) { 00200 *resu = 0 ; 00201 resu++ ; 00202 } 00203 } 00204 00205 // On passe au phi suivant : 00206 cc = cc + ntnr ; 00207 k++ ; 00208 00209 // Cas k=2 (m=1 : sin(phi)) 00210 // ------------------------ 00211 00212 //... premier coef en j=0 mis a zero: 00213 for (i=0; i<nr; i++) { 00214 *resu = 0 ; 00215 resu++ ; 00216 } 00217 00218 // Boucle sur l'indice j du developpement en sin( 2j theta) 00219 00220 for (j=1; j<nt-1; j++) { 00221 00222 // ... produit matriciel (parallelise sur r) 00223 for (i=0; i<nr; i++) { 00224 som[i] = 0 ; 00225 } 00226 00227 for (l=1; l<nt-1; l++) { 00228 double bmjl = bb[nt*j + l] ; 00229 for (i=0; i<nr; i++) { 00230 som[i] += bmjl * cc[nr*l + i] ; 00231 } 00232 } 00233 00234 for (i=0; i<nr; i++) { 00235 *resu = som[i] ; 00236 resu++ ; 00237 } 00238 00239 } // fin de la boucle sur j 00240 00241 // Dernier coef en j=nt-1 mis a zero pour le cas m impair : 00242 for (i=0; i<nr; i++) { 00243 *resu = 0 ; 00244 resu++ ; 00245 } 00246 00247 // On passe au phi suivant : 00248 cc = cc + ntnr ; 00249 k++ ; 00250 00251 // On passe au m suivant : 00252 bb += mbb ; // pointeur sur la nouvelle matrice de passage 00253 00254 // Cas k >= 3 00255 // ---------- 00256 00257 for (m=3; m < np ; m+=2) { 00258 00259 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi) 00260 00261 // Boucle sur l'indice j du developpement en sin( 2j theta) 00262 00263 //... premier coef en j=0 mis a zero: 00264 for (i=0; i<nr; i++) { 00265 *resu = 0 ; 00266 resu++ ; 00267 } 00268 00269 for (j=1; j<nt-1; j++) { 00270 00271 for (i=0; i<nr; i++) { 00272 som[i] = 0 ; 00273 } 00274 00275 for (l=(m+1)/2; l<nt-1; l++) { 00276 double bmjl = bb[nt*j + l] ; 00277 for (i=0; i<nr; i++) { 00278 som[i] += bmjl * cc[nr*l + i] ; 00279 } 00280 } 00281 00282 for (i=0; i<nr; i++) { 00283 *resu = som[i] ; 00284 resu++ ; 00285 } 00286 00287 } // fin de la boucle sur j 00288 00289 // Dernier coef en j=nt-1 mis a zero pour le cas m impair : 00290 for (i=0; i<nr; i++) { 00291 *resu = 0 ; 00292 resu++ ; 00293 } 00294 00295 // On passe au phi suivant : 00296 cc = cc + ntnr ; 00297 k++ ; 00298 00299 } // fin de la boucle sur k2 00300 00301 // On passe a l'harmonique en phi suivante : 00302 bb += mbb ; // pointeur sur la nouvelle matrice de passage 00303 00304 } // fin de la boucle (m) sur phi 00305 00306 00307 // Cas k=np+1 : tout est mis a zero 00308 // -------------------------------- 00309 00310 for (l=0; l<nt; l++) { 00311 for (i=0; i<nr; i++) { 00312 *resu = 0 ; 00313 resu++ ; 00314 } 00315 } 00316 00317 00318 //## verif : 00319 assert(resu == cfo + (np+2)*ntnr) ; 00320 00321 // Menage 00322 delete [] som ; 00323 00324 }
1.4.6