| 1 |
/* |
| 2 |
* Copyright (c) 1999-2001 Eric Gourgoulhon |
| 3 |
* |
| 4 |
* This file is part of LORENE. |
| 5 |
* |
| 6 |
* LORENE is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* LORENE is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with LORENE; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
|
| 23 |
char chb_leg_cossinc_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_leg_cossinc.C,v 1.4 2014/10/13 08:53:10 j_novak Exp $" ; |
| 24 |
|
| 25 |
/* |
| 26 |
* Calcule les coefficients du developpement (suivant theta) |
| 27 |
* en cos(j*theta) [m pair] / sin(j*theta) [m impair] |
| 28 |
* a partir des coefficients du developpement en fonctions |
| 29 |
* associees de Legendre P_l^m(cos(theta)) |
| 30 |
* pour une une fonction 3-D symetrique par rapport au plan equatorial |
| 31 |
* z = 0. |
| 32 |
* |
| 33 |
* Entree: |
| 34 |
* ------- |
| 35 |
* const int* deg : tableau du nombre effectif de degres de liberte dans chacune |
| 36 |
* des 3 dimensions: |
| 37 |
* deg[0] = np : nombre de points de collocation en phi |
| 38 |
* deg[1] = nt : nombre de points de collocation en theta |
| 39 |
* deg[2] = nr : nombre de points de collocation en r |
| 40 |
* |
| 41 |
* const double* cfi : tableau des coefficients a_l du develop. en fonctions de |
| 42 |
* Legendre associees P_n^m: |
| 43 |
* |
| 44 |
* pour m pair: f(theta) = |
| 45 |
* som_{l=m}^{nt-1} a_l P_{l}^m( cos(theta) ) |
| 46 |
* |
| 47 |
* pour m impair: f(theta) = |
| 48 |
* som_{l=m}^{nt-1} a_l P_{l}^m( cos(theta) ) |
| 49 |
* |
| 50 |
* ou P_n^m(x) represente la fonction de Legendre associee |
| 51 |
* de degre n et d'ordre m normalisee de facon a ce que |
| 52 |
* |
| 53 |
* int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1 |
| 54 |
* |
| 55 |
* L'espace memoire correspondant au pointeur cfi doit etre |
| 56 |
* nr*nt*(np+2) et doit avoir ete alloue avant |
| 57 |
* l'appel a la routine. |
| 58 |
* Le coefficient a_l (0 <= l <= nt-1) doit etre stoke dans le |
| 59 |
* tableau cfi comme suit |
| 60 |
* a_l = cfi[ nr*nt* k + i + nr* l ] |
| 61 |
* ou k et i sont les indices correspondant a phi et r |
| 62 |
* respectivement: m = k/2. |
| 63 |
* NB: pour m pair et l < m, a_l = 0 |
| 64 |
* pour m impair et l < m, a_l = 0 |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
* |
| 69 |
* Sortie: |
| 70 |
* ------- |
| 71 |
* double* cfo : tableau des coefficients c_j du develop. en cos/sin definis |
| 72 |
* comme suit (a r et phi fixes) : |
| 73 |
* |
| 74 |
* pour m pair: f(theta) = som_{j=0}^{nt-1} c_j cos( j theta ) |
| 75 |
* |
| 76 |
* pour m impair: f(theta) = som_{j=0}^{nt-2} c_j sin( j theta ) |
| 77 |
* |
| 78 |
* L'espace memoire correspondant au pointeur cfo doit etre |
| 79 |
* nr*nt*(np+2) et doit avoir ete alloue avant |
| 80 |
* l'appel a la routine. |
| 81 |
* Le coefficient c_j (0 <= j <= nt-1) est stoke dans le |
| 82 |
* tableau cfo comme suit |
| 83 |
* c_j = cfo[ nr*nt* k + i + nr* j ] |
| 84 |
* ou k et i sont les indices correspondant a |
| 85 |
* phi et r respectivement: m = k/2. |
| 86 |
* Pour m impair, c_0 = c_{nt-1} = 0. |
| 87 |
|
| 88 |
* |
| 89 |
* NB: |
| 90 |
* --- |
| 91 |
* Il n'est pas possible d'avoir le pointeur cfo egal a cfi. |
| 92 |
*/ |
| 93 |
|
| 94 |
/* |
| 95 |
* $Id: chb_leg_cossinc.C,v 1.4 2014/10/13 08:53:10 j_novak Exp $ |
| 96 |
* $Log: chb_leg_cossinc.C,v $ |
| 97 |
* Revision 1.4 2014/10/13 08:53:10 j_novak |
| 98 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 99 |
* |
| 100 |
* Revision 1.3 2014/10/06 15:16:00 j_novak |
| 101 |
* Modified #include directives to use c++ syntax. |
| 102 |
* |
| 103 |
* Revision 1.2 2005/02/18 13:14:10 j_novak |
| 104 |
* Changing of malloc/free to new/delete + suppression of some unused variables |
| 105 |
* (trying to avoid compilation warnings). |
| 106 |
* |
| 107 |
* Revision 1.1 2004/11/23 15:13:50 m_forot |
| 108 |
* Added the bases for the cases without any equatorial symmetry |
| 109 |
* (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I). |
| 110 |
* |
| 111 |
* |
| 112 |
* $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_leg_cossinc.C,v 1.4 2014/10/13 08:53:10 j_novak Exp $ |
| 113 |
* |
| 114 |
*/ |
| 115 |
|
| 116 |
|
| 117 |
// headers du C |
| 118 |
#include <cassert> |
| 119 |
#include <cstdlib> |
| 120 |
|
| 121 |
// Prototypage |
| 122 |
#include "headcpp.h" |
| 123 |
#include "proto.h" |
| 124 |
|
| 125 |
namespace Lorene { |
| 126 |
//****************************************************************************** |
| 127 |
|
| 128 |
void chb_leg_cossinc(const int* deg , const double* cfi, double* cfo) { |
| 129 |
|
| 130 |
int ip, k2, l, j, i, m ; |
| 131 |
|
| 132 |
// Nombres de degres de liberte en phi et theta : |
| 133 |
int np = deg[0] ; |
| 134 |
int nt = deg[1] ; |
| 135 |
int nr = deg[2] ; |
| 136 |
|
| 137 |
assert(np < 4*nt) ; |
| 138 |
|
| 139 |
// Tableau de travail |
| 140 |
double* som = new double[nr] ; |
| 141 |
|
| 142 |
// Recherche de la matrice de passage Legendre --> cos/sin |
| 143 |
double* bb = mat_leg_cossinc(np, nt) ; |
| 144 |
|
| 145 |
// Increment en m pour la matrice bb : |
| 146 |
int mbb = nt * nt ; |
| 147 |
|
| 148 |
//## Test |
| 149 |
// double* bbt = bb ; |
| 150 |
// cout << "chb_leg_cossinc: matrice de passage : " << endl ; |
| 151 |
// for ( m=0; m < np/2+1 ; m++) { |
| 152 |
// cout << "---------------------------------------" << endl ; |
| 153 |
// cout << " m = " << m << endl ; |
| 154 |
// cout << " " << endl ; |
| 155 |
// |
| 156 |
// for (j=0; j<nt; j++) { |
| 157 |
// cout << " j = " << j << " : " ; |
| 158 |
// for (l=m/2; l<nt; l++) { |
| 159 |
// cout << bbt[nt*j + l] << " " ; |
| 160 |
// } |
| 161 |
// cout << endl ; |
| 162 |
// } |
| 163 |
// arrete() ; |
| 164 |
// bbt += mbb ; // pointeur sur la nouvelle matrice de passage |
| 165 |
// } |
| 166 |
//## |
| 167 |
|
| 168 |
// Pointeurs de travail : |
| 169 |
double* resu = cfo ; |
| 170 |
const double* cc = cfi ; |
| 171 |
|
| 172 |
// Increment en phi : |
| 173 |
int ntnr = nt * nr ; |
| 174 |
|
| 175 |
// Indice courant en phi : |
| 176 |
int k = 0 ; |
| 177 |
|
| 178 |
// Ordre des harmoniques du developpement de Fourier en phi : |
| 179 |
m = 0 ; |
| 180 |
|
| 181 |
// -------------- |
| 182 |
// Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3 |
| 183 |
// -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1 |
| 184 |
// k2 = 0 1 0 1 |
| 185 |
|
| 186 |
for (ip=0; ip < np/4 + 1 ; ip++) { |
| 187 |
|
| 188 |
//-------------------------------- |
| 189 |
// Partie m pair |
| 190 |
//-------------------------------- |
| 191 |
|
| 192 |
|
| 193 |
for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi) |
| 194 |
|
| 195 |
if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi) |
| 196 |
// et sin( np/2 phi) a zero |
| 197 |
for (j=0; j<nt; j++) { |
| 198 |
for (i=0; i<nr; i++) { |
| 199 |
*resu = 0 ; |
| 200 |
resu++ ; |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
else { |
| 205 |
|
| 206 |
// Boucle sur l'indice j du developpement en cos(j theta) |
| 207 |
|
| 208 |
for (j=0; j<nt; j++) { |
| 209 |
|
| 210 |
// ... produit matriciel (parallelise sur r) |
| 211 |
for (i=0; i<nr; i++) { |
| 212 |
som[i] = 0 ; |
| 213 |
} |
| 214 |
|
| 215 |
for (l=m; l<nt; l++) { |
| 216 |
|
| 217 |
double bmjl = bb[nt*j + l] ; |
| 218 |
for (i=0; i<nr; i++) { |
| 219 |
som[i] += bmjl * cc[nr*l + i] ; |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
for (i=0; i<nr; i++) { |
| 224 |
*resu = som[i] ; |
| 225 |
resu++ ; |
| 226 |
} |
| 227 |
|
| 228 |
} // fin de la boucle sur j |
| 229 |
|
| 230 |
} // fin du cas k != 1 |
| 231 |
|
| 232 |
// On passe au phi suivant : |
| 233 |
cc = cc + ntnr ; |
| 234 |
k++ ; |
| 235 |
|
| 236 |
} // fin de la boucle sur k2 |
| 237 |
|
| 238 |
// On passe a l'harmonique en phi suivante : |
| 239 |
m++ ; |
| 240 |
bb += mbb ; // pointeur sur la nouvelle matrice de passage |
| 241 |
|
| 242 |
//-------------------------------- |
| 243 |
// Partie m impair |
| 244 |
//-------------------------------- |
| 245 |
|
| 246 |
for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi) |
| 247 |
|
| 248 |
if ( k == np+1 ) { // On met les coef de |
| 249 |
// sin( np/2 phi) a zero |
| 250 |
for (j=0; j<nt; j++) { |
| 251 |
for (i=0; i<nr; i++) { |
| 252 |
*resu = 0 ; |
| 253 |
resu++ ; |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
if (k < np+1) { |
| 259 |
|
| 260 |
// Boucle sur l'indice j du developpement en sin( j theta) |
| 261 |
|
| 262 |
for (j=0; j<nt-1; j++) { |
| 263 |
|
| 264 |
// ... produit matriciel (parallelise sur r) |
| 265 |
for (i=0; i<nr; i++) { |
| 266 |
som[i] = 0 ; |
| 267 |
} |
| 268 |
|
| 269 |
for (l=m; l<nt-1; l++) { |
| 270 |
double bmjl = bb[nt*j + l] ; |
| 271 |
for (i=0; i<nr; i++) { |
| 272 |
som[i] += bmjl * cc[nr*l + i] ; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
for (i=0; i<nr; i++) { |
| 277 |
*resu = som[i] ; |
| 278 |
resu++ ; |
| 279 |
} |
| 280 |
|
| 281 |
} // fin de la boucle sur j |
| 282 |
|
| 283 |
// Dernier coef en j=nt-1 mis a zero pour le cas m impair : |
| 284 |
for (i=0; i<nr; i++) { |
| 285 |
*resu = 0 ; |
| 286 |
resu++ ; |
| 287 |
} |
| 288 |
|
| 289 |
// On passe au phi suivant : |
| 290 |
cc = cc + ntnr ; |
| 291 |
k++ ; |
| 292 |
|
| 293 |
} // fin du cas k < np+1 |
| 294 |
|
| 295 |
} // fin de la boucle sur k2 |
| 296 |
|
| 297 |
|
| 298 |
// On passe a l'harmonique en phi suivante : |
| 299 |
m++ ; |
| 300 |
bb += mbb ; // pointeur sur la nouvelle matrice de passage |
| 301 |
|
| 302 |
} // fin de la boucle (ip) sur phi |
| 303 |
|
| 304 |
// Mise a zero des coefficients de sin( np/2 phi ) (k=np+1) |
| 305 |
|
| 306 |
//## verif : |
| 307 |
// assert(resu == cfo + (np+2)*ntnr) ; |
| 308 |
|
| 309 |
// Menage |
| 310 |
delete [] som ; |
| 311 |
|
| 312 |
} |
| 313 |
} |