LORENE
mat_sin_legmi.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 sin(j*theta) dans les coefficients du developpement en
28  * fonctions associees de Legendre P_l^m(cos(theta)) avec m impair.
29  *
30  * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas
31  * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment
32  * calculee.
33  *
34  * Entree:
35  * -------
36  * int np : Nombre de degres de liberte en phi
37  * int nt : Nombre de degres de liberte en theta
38  *
39  * Sortie (valeur de retour) :
40  * ---------------------------
41  * double* mat_sin_legmi : pointeur sur le tableau contenant l'ensemble
42  * (pour les np/2 valeurs de m: m=1,3,...,np-1) des
43  * matrices de passage.
44  * La dimension du tableau est (np/2+1)*nt^2
45  * Le stokage est le suivant:
46  *
47  * mat_sin_legmi[ nt*nt* m + nt*l + j] = A_{mlj}
48  *
49  * ou A_{mlj} est defini par
50  *
51  * sin(j*theta) = som_{l=m}^{nt-2} A_{mlj} P_l^m( cos(theta) )
52  * pour 1 <= j <= nt-2
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_sin_legmi.C,v 1.4 2016/12/05 16:18:02 j_novak Exp $
64  * $Log: mat_sin_legmi.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_sin_legmi.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 #include <cassert>
86 
87 // Prototypage
88 #include "headcpp.h"
89 #include "proto.h"
90 
91 namespace Lorene {
92 //******************************************************************************
93 
94 double* mat_sin_legmi(int np, int nt) {
95 
96 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
97  static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
98  static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
99  static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
100  // calcul a deja ete fait
101  static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
102  // calcul a deja ete fait
103 
104  int i, indice, j, j2, m, l ;
105 
106  // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
107  indice = -1 ;
108  for ( i=0 ; i < nb_dejafait ; i++ ) {
109  if ( (np_dejafait[i] == np) && (nt_dejafait[i] == nt) ) indice = i ;
110  }
111 
112 
113 // Si le calcul n'a pas deja ete fait, il faut le faire :
114  if (indice == -1) {
115  if ( nb_dejafait >= NMAX ) {
116  cout << "mat_sinp_legii: nb_dejafait >= NMAX : "
117  << nb_dejafait << " <-> " << NMAX << endl ;
118  abort () ;
119  exit(-1) ;
120  }
121  indice = nb_dejafait ;
122  nb_dejafait++ ;
123  np_dejafait[indice] = np ;
124  nt_dejafait[indice] = nt ;
125 
126  tab[indice] = new double[(np/2+1)*nt*nt] ;
127  for (int qq=0; qq<nt*nt*(np/2+1); qq++)
128  tab[indice][qq] = -1.34 ;
129 
130 //-----------------------
131 // Preparation du calcul
132 //-----------------------
133 
134 // Sur-echantillonnage pour calculer les produits scalaires sans aliasing:
135  int nt2 = 2*nt - 1 ;
136  int nt2m1 = nt2 - 1 ;
137 
138  int deg[3] ;
139  deg[0] = 1 ;
140  deg[1] = 1 ;
141  deg[2] = nt2 ;
142 
143 // Tableaux de travail
144  double* yy = new double[nt2] ;
145  double* sint = new double[nt*nt2];
146 
147 // Calcul des sin( j theta) aux points de collocation
148 // de l'echantillonnage double :
149 
150  double dt = M_PI / double(nt2-1) ;
151  for (j=0; j<nt-1; j++) {
152  for (j2=0; j2<nt2; j2++) {
153  double theta = j2*dt ;
154  sint[nt2*j + j2] = sin( j * theta ) ;
155  }
156  }
157 
158 
159 //-------------------
160 // Boucle sur m
161 //-------------------
162 
163  int m_max = (np == 1) ? 1 : np-1 ;
164 
165  for (m=1; m <= m_max ; m+=2) {
166 
167  // Recherche des fonctions de Legendre associees d'ordre m :
168 
169  double* leg = legendre_norm(m, nt) ;
170 
171  for (l=m; l<nt-1; l++) { // boucle sur les P_l^m
172 
173  int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
174 
175  for (j=0; j<nt-1; j++) { // boucle sur les sin(j theta)
176 
177  //... produit scalaire de sin(j theta) par
178  // P_l^m(cos(theta))
179 
180  for (j2=0; j2<nt; j2++) {
181  yy[nt2m1-j2] = sint[nt2*j + j2] *
182  leg[nt2* (l-m) + 2*j2] ;
183 
184  }
185 
186  for (j2=nt; j2<nt2; j2++) {
187  yy[nt2m1-j2] = sint[nt2*j + j2] *
188  parite * leg[nt2* (l-m) + 2*nt2 -2 - 2*j2] ;
189 
190  }
191 
192 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
193 // l'integrale (routine int1d_cheb) :
194  cfrcheb(deg, deg, yy, deg, yy) ;
195 // for (int o=0; o<nt2; o++)
196 // cout << yy[o] << endl ;
197 
198  tab[indice][ nt*nt* ((m-1)/2) + nt*l + j] =
199  int1d_cheb(nt2, yy) ;
200 
201  } // fin de la boucle sur j (indice de sin(j theta) )
202 
203  } // fin de la boucle sur l (indice de P_l^m)
204 
205  delete [] leg ;
206 
207  } // fin de la boucle sur m
208 
209 // Liberation espace memoire
210 // -------------------------
211 
212  delete [] yy ;
213  delete [] sint ;
214 
215  } // fin du cas ou le calcul etait necessaire
216 
217  return tab[indice] ;
218 
219 }
220 
221 
222 }
Lorene prototypes.
Definition: app_hor.h:67
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:72