| 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 mat_cossinci_legi_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossinci_legi.C,v 1.5 2014/10/13 08:53:13 j_novak Exp $" ; |
| 24 |
|
| 25 |
/* |
| 26 |
* Fournit la matrice de passage pour la transformation des coefficients du |
| 27 |
* developpement en cos((2*j+1)*theta) [m pair] / sin( 2*j * theta) [m impair] |
| 28 |
* dans les coefficients du developpement en fonctions associees de Legendre |
| 29 |
* P_l^m(cos(theta)) impaires (i.e. telles que l-m est impair). |
| 30 |
* |
| 31 |
* Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas |
| 32 |
* deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment |
| 33 |
* calculee. |
| 34 |
* |
| 35 |
* Entree: |
| 36 |
* ------- |
| 37 |
* int np : Nombre de degres de liberte en phi |
| 38 |
* int nt : Nombre de degres de liberte en theta |
| 39 |
* |
| 40 |
* Sortie (valeur de retour) : |
| 41 |
* --------------------------- |
| 42 |
* double* mat_cossinci_legi : pointeur sur le tableau contenant l'ensemble |
| 43 |
* (pour les np/2+1 valeurs de m) des |
| 44 |
* matrices de passage. |
| 45 |
* La dimension du tableau est (np/2+1)*nt^2 |
| 46 |
* Le stokage est le suivant: |
| 47 |
* |
| 48 |
* mat_cossinci_legi[ nt*nt* m + nt*l + j] = A_{mlj} |
| 49 |
* |
| 50 |
* ou A_{mlj} est defini par |
| 51 |
* |
| 52 |
* pour m pair : |
| 53 |
* cos((2*j+1)*theta) = som_{l=m/2}^{nt-2} A_{mlj} P_{2l+1}^m( cos(theta) ) |
| 54 |
* pour 0 <= j <= nt-2 |
| 55 |
* |
| 56 |
* pour m impair : |
| 57 |
* sin(2*j*theta) = som_{l=(m+1)/2}^{nt-2} A_{mlj} P_{2l}^m( cos(theta) ) |
| 58 |
* pour 1 <= j <= nt-2 |
| 59 |
* |
| 60 |
* ou P_n^m(x) represente la fonction de Legendre associee de degre n et |
| 61 |
* d'ordre m normalisee de facon a ce que |
| 62 |
* |
| 63 |
* int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1 |
| 64 |
* |
| 65 |
* |
| 66 |
*/ |
| 67 |
|
| 68 |
/* |
| 69 |
* $Id: mat_cossinci_legi.C,v 1.5 2014/10/13 08:53:13 j_novak Exp $ |
| 70 |
* $Log: mat_cossinci_legi.C,v $ |
| 71 |
* Revision 1.5 2014/10/13 08:53:13 j_novak |
| 72 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 73 |
* |
| 74 |
* Revision 1.4 2014/10/06 15:16:02 j_novak |
| 75 |
* Modified #include directives to use c++ syntax. |
| 76 |
* |
| 77 |
* Revision 1.3 2005/02/18 13:14:14 j_novak |
| 78 |
* Changing of malloc/free to new/delete + suppression of some unused variables |
| 79 |
* (trying to avoid compilation warnings). |
| 80 |
* |
| 81 |
* Revision 1.2 2002/10/16 14:36:54 j_novak |
| 82 |
* Reorganization of #include instructions of standard C++, in order to |
| 83 |
* use experimental version 3 of gcc. |
| 84 |
* |
| 85 |
* Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon |
| 86 |
* LORENE |
| 87 |
* |
| 88 |
* Revision 2.0 1999/02/22 15:35:09 hyc |
| 89 |
* *** empty log message *** |
| 90 |
* |
| 91 |
* |
| 92 |
* $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cossinci_legi.C,v 1.5 2014/10/13 08:53:13 j_novak Exp $ |
| 93 |
* |
| 94 |
*/ |
| 95 |
|
| 96 |
// headers du C |
| 97 |
#include <cstdlib> |
| 98 |
#include <cmath> |
| 99 |
|
| 100 |
// Prototypage |
| 101 |
#include "headcpp.h" |
| 102 |
#include "proto.h" |
| 103 |
|
| 104 |
// Variable de loch |
| 105 |
int loch_mat_cossinci_legi = 0 ; |
| 106 |
|
| 107 |
namespace Lorene { |
| 108 |
//****************************************************************************** |
| 109 |
|
| 110 |
double* mat_cossinci_legi(int np, int nt) { |
| 111 |
|
| 112 |
#define NMAX 30 // Nombre maximun de couples(np,nt) differents |
| 113 |
static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux |
| 114 |
static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises |
| 115 |
static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le |
| 116 |
// calcul a deja ete fait |
| 117 |
static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le |
| 118 |
// calcul a deja ete fait |
| 119 |
|
| 120 |
int i, indice, j, j2, m, l ; |
| 121 |
|
| 122 |
// #pragma critical (loch_mat_cossinci_legi) |
| 123 |
{ |
| 124 |
|
| 125 |
// Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ? |
| 126 |
indice = -1 ; |
| 127 |
for ( i=0 ; i < nb_dejafait ; i++ ) { |
| 128 |
if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
// Si le calcul n'a pas deja ete fait, il faut le faire : |
| 133 |
if (indice == -1) { |
| 134 |
if ( nb_dejafait >= NMAX ) { |
| 135 |
cout << "mat_cossinci_legi: nb_dejafait >= NMAX : " |
| 136 |
<< nb_dejafait << " <-> " << NMAX << endl ; |
| 137 |
abort () ; |
| 138 |
exit(-1) ; |
| 139 |
} |
| 140 |
indice = nb_dejafait ; |
| 141 |
nb_dejafait++ ; |
| 142 |
np_dejafait[indice] = np ; |
| 143 |
nt_dejafait[indice] = nt ; |
| 144 |
|
| 145 |
tab[indice] = new double[(np/2+1)*nt*nt] ; |
| 146 |
|
| 147 |
//----------------------- |
| 148 |
// Preparation du calcul |
| 149 |
//----------------------- |
| 150 |
|
| 151 |
// Sur-echantillonnage pour calculer les produits scalaires sans aliasing: |
| 152 |
int nt2 = 2*nt - 1 ; |
| 153 |
int nt2m1 = nt2 - 1 ; |
| 154 |
|
| 155 |
int deg[3] ; |
| 156 |
deg[0] = 1 ; |
| 157 |
deg[1] = 1 ; |
| 158 |
deg[2] = nt2 ; |
| 159 |
|
| 160 |
// Tableaux de travail |
| 161 |
double* yy = new double[nt2] ; |
| 162 |
double* cost = new double[nt*nt2] ; |
| 163 |
double* sint = new double[nt*nt2] ; |
| 164 |
|
| 165 |
// Calcul des cos(2*j*theta) / sin( (2*j+1)*theta ) aux points de collocation |
| 166 |
// de l'echantillonnage double : |
| 167 |
|
| 168 |
double dt = M_PI / double(2*(nt2-1)) ; |
| 169 |
for (j=0; j<nt-1; j++) { |
| 170 |
for (j2=0; j2<nt2; j2++) { |
| 171 |
double theta = j2*dt ; |
| 172 |
cost[nt2*j + j2] = cos( (2*j+1) * theta ) ; |
| 173 |
sint[nt2*j + j2] = sin( 2*j * theta ) ; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
//------------------- |
| 179 |
// Boucle sur m |
| 180 |
//------------------- |
| 181 |
|
| 182 |
for (m=0; m < np/2+1 ; m++) { |
| 183 |
|
| 184 |
// Recherche des fonctions de Legendre associees d'ordre m : |
| 185 |
|
| 186 |
double* leg = legendre_norm(m, nt) ; |
| 187 |
|
| 188 |
if (m%2==0) { |
| 189 |
// Cas m pair |
| 190 |
//----------- |
| 191 |
for (l=m/2; l<nt-1; l++) { // boucle sur les P_{2l+1}^m |
| 192 |
|
| 193 |
int ll = 2*l+1 ; // degre des fonctions de Legendre |
| 194 |
|
| 195 |
for (j=0; j<nt-1; j++) { // boucle sur les cos((2j+1) theta) |
| 196 |
|
| 197 |
//... produit scalaire de cos((2j+1) theta) par P_{2l+1}^m(cos(theta)) |
| 198 |
|
| 199 |
for (j2=0; j2<nt2; j2++) { |
| 200 |
yy[nt2m1-j2] = cost[nt2*j + j2] * |
| 201 |
leg[nt2* (ll-m) + j2] ; |
| 202 |
} |
| 203 |
|
| 204 |
//....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer |
| 205 |
// l'integrale (routine int1d_chebp) : |
| 206 |
cfrchebp(deg, deg, yy, deg, yy) ; |
| 207 |
tab[indice][ nt*nt* m + nt*l + j] = |
| 208 |
2.*int1d_chebp(nt2, yy) ; |
| 209 |
|
| 210 |
} // fin de la boucle sur j (indice de cos((2j+1) theta) ) |
| 211 |
|
| 212 |
} // fin de la boucle sur l (indice de P_{2l+1}^m) |
| 213 |
|
| 214 |
|
| 215 |
} // fin du cas m pair |
| 216 |
else { |
| 217 |
|
| 218 |
// Cas m impair |
| 219 |
//------------- |
| 220 |
|
| 221 |
for (l=(m+1)/2; l<nt-1; l++) { // boucle sur les P_{2l}^m |
| 222 |
|
| 223 |
int ll = 2*l ; // degre des fonctions de Legendre |
| 224 |
|
| 225 |
for (j=0; j<nt-1; j++) { // boucle sur les sin(2j theta) |
| 226 |
|
| 227 |
//... produit scalaire de sin((2j+1) theta) par P_{2l+1}^m(cos(theta)) |
| 228 |
|
| 229 |
for (j2=0; j2<nt2; j2++) { |
| 230 |
yy[nt2m1-j2] = sint[nt2*j + j2] * |
| 231 |
leg[nt2* (ll-m) + j2] ; |
| 232 |
} |
| 233 |
|
| 234 |
//....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer |
| 235 |
// l'integrale (routine int1d_chebp) : |
| 236 |
cfrchebp(deg, deg, yy, deg, yy) ; |
| 237 |
tab[indice][ nt*nt* m + nt*l + j] = |
| 238 |
2.*int1d_chebp(nt2, yy) ; |
| 239 |
|
| 240 |
} // fin de la boucle sur j (indice de sin(2j theta) ) |
| 241 |
|
| 242 |
} // fin de la boucle sur l (indice de P_{2l}^m) |
| 243 |
|
| 244 |
|
| 245 |
} // fin du cas m impair |
| 246 |
|
| 247 |
delete [] leg ; |
| 248 |
|
| 249 |
} // fin de la boucle sur m |
| 250 |
|
| 251 |
// Liberation espace memoire |
| 252 |
// ------------------------- |
| 253 |
|
| 254 |
delete [] yy ; |
| 255 |
delete [] cost ; |
| 256 |
delete [] sint ; |
| 257 |
|
| 258 |
} // fin du cas ou le calcul etait necessaire |
| 259 |
|
| 260 |
} // Fin de zone critique |
| 261 |
|
| 262 |
return tab[indice] ; |
| 263 |
|
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
} |