LORENE
mat_cos_legmp.C
1 /*
2  * Copyright (c) 1999-2001 Eric Gourgoulhon
3  * 2009 Jerome Novak
4  *
5  * This file is part of LORENE.
6  *
7  * LORENE is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * LORENE is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with LORENE; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22 
23 
24 char mat_cos_legmp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cos_legmp.C,v 1.3 2014/10/13 08:53:13 j_novak Exp $" ;
25 
26 /*
27  * Fournit la matrice de passage pour la transformation des coefficients du
28  * developpement en cos(j*theta)
29  * dans les coefficients du developpement en fonctions associees de Legendre
30  * P_l^m(cos(theta)) telles que m est pair.
31  *
32  * Cette routine n'effectue le calcul de la matrice que si celui-ci n'a pas
33  * deja ete fait, sinon elle renvoie le pointeur sur une valeur precedemment
34  * calculee.
35  *
36  * Entree:
37  * -------
38  * int np : Nombre de degres de liberte en phi
39  * int nt : Nombre de degres de liberte en theta
40  *
41  * Sortie (valeur de retour) :
42  * ---------------------------
43  * double* mat_cos_legmp : pointeur sur le tableau contenant l'ensemble
44  * (pour les np/2+1 valeurs de m: m=0,2,...,np) des
45  * matrices de passage.
46  * La dimension du tableau est (np/2+1)*nt^2
47  * Le stokage est le suivant:
48  *
49  * mat_cos_legmp[ nt*nt* m/2 + nt*l + j] = A_{mlj}
50  *
51  * ou A_{mlj} est defini par
52  *
53  * cos(j*theta) = som_{l=m}^{nt-1} A_{mlj} P_l^m( cos(theta) )
54  *
55  * ou P_n^m(x) represente la fonction de Legendre associee de degre n et
56  * d'ordre m normalisee de facon a ce que
57  *
58  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
59  *
60  *
61  */
62 
63 /*
64  * $Id: mat_cos_legmp.C,v 1.3 2014/10/13 08:53:13 j_novak Exp $
65  * $Log: mat_cos_legmp.C,v $
66  * Revision 1.3 2014/10/13 08:53:13 j_novak
67  * Lorene classes and functions now belong to the namespace Lorene.
68  *
69  * Revision 1.2 2014/10/06 15:16:02 j_novak
70  * Modified #include directives to use c++ syntax.
71  *
72  * Revision 1.1 2009/10/13 13:49:36 j_novak
73  * New base T_LEG_MP.
74  *
75  *
76  *
77  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/mat_cos_legmp.C,v 1.3 2014/10/13 08:53:13 j_novak Exp $
78  *
79  */
80 
81 // headers du C
82 #include <cstdlib>
83 #include <cmath>
84 
85 // Prototypage
86 #include "headcpp.h"
87 #include "proto.h"
88 
89 namespace Lorene {
90 //******************************************************************************
91 
92 double* mat_cos_legmp(int np, int nt) {
93 
94 #define NMAX 30 // Nombre maximun de couples(np,nt) differents
95  static double* tab[NMAX] ; // Tableau des pointeurs sur les tableaux
96  static int nb_dejafait = 0 ; // Nombre de tableaux deja initialises
97  static int np_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
98  // calcul a deja ete fait
99  static int nt_dejafait[NMAX] ; // Valeurs de np pour lesquelles le
100  // calcul a deja ete fait
101 
102  int i, indice, j, j2, m, l ;
103 
104 
105  // Les matrices A_{mlj} pour ce couple (np,nt) ont-elles deja ete calculees ?
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_cos_legmp: 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 pour calculer les produits scalaires sans aliasing:
132  int nt2 = 2*nt - 1 ;
133  int nt2m1 = nt2 - 1 ;
134 
135  int deg[3] ;
136  deg[0] = 1 ;
137  deg[1] = 1 ;
138  deg[2] = nt2 ;
139 
140 // Tableaux de travail
141  double* yy = new double[nt2] ;
142  double* cost = new double[nt*nt2] ;
143 
144 // Calcul des cos(j*theta) aux points de collocation
145 // de l'echantillonnage double :
146 
147  double dt = M_PI / double(nt2-1) ;
148  for (j=0; j<nt; j++) {
149  for (j2=0; j2<nt2; j2++) {
150  double theta = j2*dt ;
151  cost[nt2*j + j2] = cos( j * theta ) ;
152  }
153  }
154 
155 
156 //-------------------
157 // Boucle sur m
158 //-------------------
159 
160  int m_max = np ;
161  if (np == 1) m_max = 0 ;
162 
163  for (m=0; m <= m_max ; m+=2) {
164 
165 // Recherche des fonctions de Legendre associees d'ordre m :
166 
167  double* leg = legendre_norm(m, nt) ;
168 
169  for (l=m; l<nt; l++) { // boucle sur les P_l^m
170 
171  int parite = 1 - 2*((l-m)%2) ; // parite du P_l^m par rapport au plan theta=pi/2
172  for (j=0; j<nt; j++) { // boucle sur les cos(j theta)
173 
174 //... produit scalaire de cos(j theta) par P_l^m(cos(theta))
175 
176  for (j2=0; j2<nt; j2++) {
177  yy[nt2m1-j2] = cost[nt2*j + j2] *
178  leg[nt2* (l-m) + 2*j2] ;
179  }
180 
181  for (j2 = nt; j2<nt2; j2++) {
182  yy[nt2m1-j2] = cost[nt2*j + j2] *
183  parite * leg[nt2* (l-m) + 2*nt2 -2 -2*j2] ;
184  }
185 
186 //....... on passe en Tchebyshev vis-a-vis de x=cos(theta) pour calculer
187 // l'integrale (routine int1d_cheb) :
188  cfrcheb(deg, deg, yy, deg, yy) ;
189  tab[indice][ nt*nt* m/2 + nt*l + j] =
190  int1d_cheb(nt2, yy) ;
191 
192  } // fin de la boucle sur j (indice de cos(j theta) )
193 
194  } // fin de la boucle sur l (indice de P_l^m)
195 
196  delete [] leg ;
197 
198  } // fin de la boucle sur m
199 
200 // Liberation espace memoire
201 // -------------------------
202 
203  delete [] yy ;
204  delete [] cost ;
205 
206  } // fin du cas ou le calcul etait necessaire
207 
208  return tab[indice] ;
209 
210 }
211 
212 
213 }
Lorene
Lorene prototypes.
Definition: app_hor.h:64
Lorene::cos
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:94