LORENE
mat_legmi_sin.C
1 /*
2  * Copyright (c) 2003-2009 Jerome Novak
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 
24 
25 /*
26  * Fournit la matrice de passage pour la transformation des coefficients du
27  * developpement en fonctions associees de Legendre
28  * P_l^m(cos(theta)) avec m impair dans les coefficients du developpement
29  * en sin( j theta ).
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_legmi_sin : pointeur sur le tableau contenant l'ensemble
43  * (pour les np/2 valeurs de m: m=1,3,...,np-1)) 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_legmi_sin[ nt*nt* m + nt*j + l] = B_{mjl}
49  *
50  * ou B_{mjl} (m impair) est defini par
51  *
52  * P_l^m( cos(theta) ) = som_{j=1}^{nt-2} B_{mjl} sin(j*theta)
53  *
54  * ou P_n^m(x) represente la fonction de Legendre associee de degre n et
55  * d'ordre m normalisee de facon a ce que
56  *
57  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
58  *
59  *
60  */
61 
62 /*
63  * $Id: mat_legmi_sin.C,v 1.4 2016/12/05 16:18:02 j_novak Exp $
64  * $Log: mat_legmi_sin.C,v $
65  * Revision 1.4 2016/12/05 16:18:02 j_novak
66  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
67  *
68  * Revision 1.3 2014/10/13 08:53:14 j_novak
69  * Lorene classes and functions now belong to the namespace Lorene.
70  *
71  * Revision 1.2 2014/10/06 15:16:03 j_novak
72  * Modified #include directives to use c++ syntax.
73  *
74  * Revision 1.1 2009/10/23 12:54:47 j_novak
75  * New base T_LEG_MI
76  *
77  *
78  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_legmi_sin.C,v 1.4 2016/12/05 16:18:02 j_novak Exp $
79  *
80  */
81 
82 // headers du C
83 #include <cstdlib>
84 #include <cmath>
85 
86 // Headers Lorene
87 #include "headcpp.h"
88 #include "proto.h"
89 
90 namespace Lorene {
91 //******************************************************************************
92 
93 double* mat_legmi_sin(int np, int nt) {
94 
95 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
96  static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
97  static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
98  static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
99  // calcul a deja ete fait
100  static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
101  // calcul a deja ete fait
102  int i, indice, j, j2, m, l ;
103 
104 // Les matrices B_{mjl} pour ce couple (np,nt) ont-elles deja ete calculees ?
105 
106  indice = -1 ;
107  for ( i=0 ; i < nb_dejafait ; i++ ) {
108  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
109  }
110 
111 
112 // Si le calcul n'a pas deja ete fait, il faut le faire :
113  if (indice == -1) {
114  if ( nb_dejafait >= NMAX ) {
115  cout << "mat_legii_sinp: nb_dejafait >= NMAX : "
116  << nb_dejafait << " <-> " << NMAX << endl ;
117  abort () ;
118  exit(-1) ;
119  }
120  indice = nb_dejafait ;
121  nb_dejafait++ ;
122  np_dejafait[indice] = np ;
123  nt_dejafait[indice] = nt ;
124 
125  tab[indice] = new double[(np/2+1)*nt*nt] ;
126 
127 //-----------------------
128 // Preparation du calcul
129 //-----------------------
130 
131 // Sur-echantillonnage :
132  int nt2 = 2*nt - 1 ;
133 
134  int deg[3] ;
135  deg[0] = 1 ;
136  deg[1] = nt2 ;
137  deg[2] = 1 ;
138 
139 // Tableaux de travail
140  double* yy = new double[nt2] ;
141 
142 
143 //-------------------
144 // Boucle sur m
145 //-------------------
146 
147  int m_max = (np == 1) ? 1 : np-1 ;
148 
149  for (m=1; m <= m_max ; m+=2) {
150 
151  // Recherche des fonctions de Legendre associees d'ordre m :
152 
153  double* leg = legendre_norm(m, nt) ;
154 
155 
156  for (l=m; l<nt-1; l++) { // boucle sur les P_l^m
157 
158  int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
159 
160  for (j2=0; j2<nt; j2++) {
161  yy[j2] = leg[nt2* (l-m) + 2*j2] ;
162  }
163 
164  for (j2=nt; j2<nt2; j2++) {
165  yy[j2] = parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ;
166  }
167 
168  //....... transformation en sin(j*theta) :
169 
170  cftsin(deg, deg, yy, deg, yy) ;
171 
172  //....... le resultat fournit les elements de matrice :
173  for (j=0; j<nt-1; j++) {
174  tab[indice][ nt*nt*((m-1)/2) + nt*j + l] = yy[j] ;
175  }
176 
177  } // fin de la boucle sur l (indice de P_l^m)
178 
179  delete [] leg ;
180 
181  } // fin de la boucle sur m
182 
183 // Liberation espace memoire
184 // -------------------------
185 
186  delete [] yy ;
187 
188  } // fin du cas ou le calcul etait necessaire
189 
190  return tab[indice] ;
191 
192 }
193 
194 
195 }
Lorene prototypes.
Definition: app_hor.h:67