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