00001 /* 00002 * Copyright (c) 1999-2001 Eric Gourgoulhon 00003 * Copyright (c) 2009 Jerome Novak 00004 * 00005 * This file is part of LORENE. 00006 * 00007 * LORENE is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * LORENE is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with LORENE; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 */ 00022 00023 00024 char chb_legmi_sin_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legmi_sin.C,v 1.1 2009/10/23 12:54:47 j_novak Exp $" ; 00025 00026 /* 00027 * Calcule les coefficients du developpement (suivant theta) 00028 * en sin(j theta) 00029 * a partir des coefficients du developpement en fonctions 00030 * associees de Legendre P_l^m(cos(theta)) (m impair) 00031 * pour une une fonction 3-D antisymetrique par le retournement 00032 * (x, y, z) --> (-x, -y, z). 00033 * 00034 * Entree: 00035 * ------- 00036 * const int* deg : tableau du nombre effectif de degres de liberte dans chacune 00037 * des 3 dimensions: 00038 * deg[0] = np : nombre de points de collocation en phi 00039 * deg[1] = nt : nombre de points de collocation en theta 00040 * deg[2] = nr : nombre de points de collocation en r 00041 * 00042 * const double* cfi : tableau des coefficients a_j du develop. en fonctions de 00043 * Legendre associees P_n^m: 00044 * 00045 * f(theta) = 00046 * som_{l=m}^{nt-2} a_j P_j^m( cos(theta) ) 00047 * 00048 * (m impair) 00049 * 00050 * ou P_l^m(x) represente la fonction de Legendre associee 00051 * de degre l et d'ordre m normalisee de facon a ce que 00052 * 00053 * int_0^pi [ P_l^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_j (0 <= j <= nt-1) doit etre stoke dans le 00059 * tableau cfi comme suit 00060 * a_j = cfi[ nr*nt* k + i + nr* j ] 00061 * ou k et i sont les indices correspondant a phi et r 00062 * respectivement: m = 2 (k/2). 00063 * NB: pour j<m, a_j = 0 00064 * 00065 * Sortie: 00066 * ------- 00067 * double* cfo : tableau des coefficients c_j du develop. en sin definis 00068 * comme suit (a r et phi fixes) : 00069 * 00070 * f(theta) = som_{j=0}^{nt-2} c_j sin( j theta ) 00071 * 00072 * L'espace memoire correspondant au pointeur cfo doit etre 00073 * nr*nt*(np+2) et doit avoir ete alloue avant 00074 * l'appel a la routine. 00075 * Le coefficient c_j (0 <= j <= nt-1) est stoke dans le 00076 * tableau cfo comme suit 00077 * c_j = cfo[ nr*nt* k + i + nr* j ] 00078 * ou k et i sont les indices correspondant a 00079 * phi et r respectivement. 00080 * NB: c_{nt-1} = 0. 00081 * 00082 * 00083 * NB: 00084 * --- 00085 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi. 00086 */ 00087 00088 /* 00089 * $Id: chb_legmi_sin.C,v 1.1 2009/10/23 12:54:47 j_novak Exp $ 00090 * $Log: chb_legmi_sin.C,v $ 00091 * Revision 1.1 2009/10/23 12:54:47 j_novak 00092 * New base T_LEG_MI 00093 * 00094 * 00095 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legmi_sin.C,v 1.1 2009/10/23 12:54:47 j_novak Exp $ 00096 * 00097 */ 00098 00099 // headers du C 00100 #include <stdlib.h> 00101 #include <assert.h> 00102 00103 // Headers Lorene 00104 #include "headcpp.h" 00105 #include "proto.h" 00106 00107 //****************************************************************************** 00108 00109 void chb_legmi_sin(const int* deg , const double* cfi, double* cfo) { 00110 00111 int k2, l, 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 Legendre --> cos/sin 00125 double* bb = mat_legmi_sin(np, nt) ; 00126 00127 // Increment en m pour la matrice bb : 00128 int mbb = 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 //... premier coef en j=0 mis a zero: 00144 for (i=0; i<nr; i++) { 00145 *resu = 0 ; 00146 resu++ ; 00147 } 00148 00149 // Boucle sur l'indice j du developpement en sin( j theta) 00150 00151 for (j=1; j<nt-1; j++) { 00152 00153 // ... produit matriciel 00154 for (i=0; i<nr; i++) { 00155 som[i] = 0 ; 00156 } 00157 00158 for (l=1; l<nt-1; l++) { 00159 double bmjl = bb[nt*j + l] ; 00160 for (i=0; i<nr; i++) { 00161 som[i] += bmjl * cc[nr*l + 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 j 00171 00172 // Dernier coef en j=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 // On passe au phi suivant : 00190 cc = cc + ntnr ; 00191 k++ ; 00192 00193 // Cas k=1 : tout est mis a zero 00194 // ----------------------------- 00195 00196 for (l=0; l<nt; l++) { 00197 for (i=0; i<nr; i++) { 00198 *resu = 0 ; 00199 resu++ ; 00200 } 00201 } 00202 00203 // On passe au phi suivant : 00204 cc = cc + ntnr ; 00205 k++ ; 00206 00207 // Cas k=2 (m=1 : sin(phi)) 00208 // ------------------------ 00209 00210 //... premier coef en j=0 mis a zero: 00211 for (i=0; i<nr; i++) { 00212 *resu = 0 ; 00213 resu++ ; 00214 } 00215 00216 // Boucle sur l'indice j du developpement en sin( j theta) 00217 00218 for (j=1; j<nt-1; j++) { 00219 00220 // ... produit matriciel 00221 for (i=0; i<nr; i++) { 00222 som[i] = 0 ; 00223 } 00224 00225 for (l=1; l<nt-1; l++) { 00226 double bmjl = bb[nt*j + l] ; 00227 for (i=0; i<nr; i++) { 00228 som[i] += bmjl * cc[nr*l + 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 j 00238 00239 // Dernier coef en j=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 bb += mbb ; // 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 // Boucle sur l'indice j du developpement en sin( (2j+1) theta) 00260 00261 //... premier coef en j=0 mis a zero: 00262 for (i=0; i<nr; i++) { 00263 *resu = 0 ; 00264 resu++ ; 00265 } 00266 00267 for (j=1; j<nt-1; j++) { 00268 00269 // ... produit matriciel 00270 for (i=0; i<nr; i++) { 00271 som[i] = 0 ; 00272 } 00273 00274 for (l=m; l<nt-1; l++) { 00275 double bmjl = bb[nt*j + l] ; 00276 for (i=0; i<nr; i++) { 00277 som[i] += bmjl * cc[nr*l + 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 j 00287 00288 // Dernier coef en j=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 bb += mbb ; // pointeur sur la nouvelle matrice de passage 00302 00303 } // fin de la boucle (m) sur phi 00304 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