LORENE
chb_sini_legpi.C
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 
24 
25 /*
26  * Calcule les coefficients du developpement (suivant theta) en fonctions
27  * associees de Legendre P_l^m(cos(theta)) a partir des coefficients du
28  * developpement en sin((2j+1)*theta)
29  * representant une fonction 3-D symetrique par rapport au plan equatorial
30  * z = 0 et antisymetrique par le retournement (x, y, z) --> (-x, -y, z).
31  *
32  * Entree:
33  * -------
34  * const int* deg : tableau du nombre effectif de degres de liberte dans chacune
35  * des 3 dimensions:
36  * deg[0] = np : nombre de points de collocation en phi
37  * deg[1] = nt : nombre de points de collocation en theta
38  * deg[2] = nr : nombre de points de collocation en r
39  *
40  * const double* cfi : tableau des coefficients c_j du develop. en cos defini
41  * comme suit (a r et phi fixes)
42  *
43  * f(theta) = som_{j=0}^{nt-2} c_j sin( (2j+1) theta )
44  *
45  * L'espace memoire correspondant au pointeur cfi doit etre
46  * nr*nt*(np+2) et doit avoir ete alloue avant
47  * l'appel a la routine.
48  * Le coefficient c_j (0 <= j <= nt-2) doit etre stoke dans le
49  * tableau cfi comme suit
50  * c_j = cfi[ nr*nt* k + i + nr* j ]
51  * ou k et i sont les indices correspondant a
52  * phi et r respectivement. On a c_{nt-1} = 0.
53  *
54  * Sortie:
55  * -------
56  * double* cfo : tableau des coefficients a_j du develop. en fonctions de
57  * Legendre associees P_l^m (l impair, m impair)
58  *
59  * f(theta) =
60  * som_{l=(m-1)/2}^{nt-2} a_j P_{2j+1}^m( cos(theta) )
61  *
62  * avec m impair.
63  *
64  * P_l^m(x) represente la fonction de Legendre associee
65  * de degre l et d'ordre m normalisee de facon a ce que
66  *
67  * int_0^pi [ P_l^m(cos(theta)) ]^2 sin(theta) dtheta = 1
68  *
69  * L'espace memoire correspondant au pointeur cfo doit etre
70  * nr*nt*(np+2) et doit avoir ete alloue avant
71  * l'appel a la routine.
72  * Le coefficient a_j (0 <= j <= nt-1) est stoke dans le
73  * tableau cfo comme suit
74  * a_j = cfo[ nr*nt* k + i + nr* j ]
75  * ou k et i sont les indices correspondant a phi et r
76  * respectivement: m = 2( k/2 ).
77  * NB: pour j<(m-1)/2, a_j = 0
78  *
79  * NB:
80  * ---
81  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
82  */
83 
84 /*
85  * $Id: chb_sini_legpi.C,v 1.7 2016/12/05 16:18:01 j_novak Exp $
86  * $Log: chb_sini_legpi.C,v $
87  * Revision 1.7 2016/12/05 16:18:01 j_novak
88  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
89  *
90  * Revision 1.6 2014/10/13 08:53:11 j_novak
91  * Lorene classes and functions now belong to the namespace Lorene.
92  *
93  * Revision 1.5 2014/10/06 15:16:01 j_novak
94  * Modified #include directives to use c++ syntax.
95  *
96  * Revision 1.4 2005/02/18 13:14:12 j_novak
97  * Changing of malloc/free to new/delete + suppression of some unused variables
98  * (trying to avoid compilation warnings).
99  *
100  * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
101  * Suppressed the directive #include <malloc.h> for malloc is defined
102  * in <stdlib.h>
103  *
104  * Revision 1.2 2002/10/16 14:36:53 j_novak
105  * Reorganization of #include instructions of standard C++, in order to
106  * use experimental version 3 of gcc.
107  *
108  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
109  * LORENE
110  *
111  * Revision 2.1 2000/11/14 15:12:18 eric
112  * Traitement du cas np=1
113  *
114  * Revision 2.0 2000/09/29 16:08:39 eric
115  * *** empty log message ***
116  *
117  *
118  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_sini_legpi.C,v 1.7 2016/12/05 16:18:01 j_novak Exp $
119  *
120  */
121 
122 // headers du C
123 #include <cassert>
124 #include <cstdlib>
125 
126 // Prototypage
127 #include "headcpp.h"
128 #include "proto.h"
129 
130 namespace Lorene {
131 //******************************************************************************
132 
133 void chb_sini_legpi(const int* deg , const double* cfi, double* cfo) {
134 
135 int k2, l, jmin, j, i, m ;
136 
137  // Nombres de degres de liberte en phi et theta :
138  int np = deg[0] ;
139  int nt = deg[1] ;
140  int nr = deg[2] ;
141 
142  assert(np < 4*nt) ;
143  assert( cfi != cfo ) ;
144 
145  // Tableau de travail
146  double* som = new double[nr] ;
147 
148  // Recherche de la matrice de passage cos --> Legendre
149  double* aa = mat_sini_legpi(np, nt) ;
150 
151  // Increment en m pour la matrice aa :
152  int maa = nt * nt ;
153 
154  // Pointeurs de travail :
155  double* resu = cfo ;
156  const double* cc = cfi ;
157 
158  // Increment en phi :
159  int ntnr = nt * nr ;
160 
161  // Indice courant en phi :
162  int k = 0 ;
163 
164  // Cas k=0 (m=1 : cos(phi))
165  // ------------------------
166 
167  // ... produit matriciel (parallelise sur r)
168  for (l=0; l<nt-1; l++) {
169  for (i=0; i<nr; i++) {
170  som[i] = 0 ;
171  }
172 
173  jmin = l ; // pour m=1, aa_lj = 0 pour j<l
174 
175  for (j=jmin; j<nt-1; j++) {
176  double amlj = aa[nt*l + j] ;
177  for (i=0; i<nr; i++) {
178  som[i] += amlj * cc[nr*j + i] ;
179  }
180  }
181 
182  for (i=0; i<nr; i++) {
183  *resu = som[i] ;
184  resu++ ;
185  }
186 
187  } // fin de la boucle sur l
188 
189  // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
190  for (i=0; i<nr; i++) {
191  *resu = 0 ;
192  resu++ ;
193  }
194 
195  // Special case np=1 (axisymmetry)
196  // -------------------------------
197  if (np==1) {
198  for (i=0; i<2*ntnr; i++) {
199  *resu = 0 ;
200  resu++ ;
201  }
202  delete [] som ;
203  return ;
204  }
205 
206 
207  // On passe au phi suivant :
208  cc = cc + ntnr ;
209  k++ ;
210 
211  // Cas k=1 : tout est mis a zero
212  // -----------------------------
213 
214  for (l=0; l<nt; l++) {
215  for (i=0; i<nr; i++) {
216  *resu = 0 ;
217  resu++ ;
218  }
219  }
220 
221  // On passe au phi suivant :
222  cc = cc + ntnr ;
223  k++ ;
224 
225  // Cas k=2 (m=1 : sin(phi))
226  // ------------------------
227 
228  // ... produit matriciel (parallelise sur r)
229  for (l=0; l<nt-1; l++) {
230  for (i=0; i<nr; i++) {
231  som[i] = 0 ;
232  }
233 
234  jmin = l ; // pour m=1, aa_lj = 0 pour j<l
235 
236  for (j=jmin; j<nt-1; j++) {
237  double amlj = aa[nt*l + j] ;
238  for (i=0; i<nr; i++) {
239  som[i] += amlj * cc[nr*j + i] ;
240  }
241  }
242 
243  for (i=0; i<nr; i++) {
244  *resu = som[i] ;
245  resu++ ;
246  }
247 
248  } // fin de la boucle sur l
249 
250  // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
251  for (i=0; i<nr; i++) {
252  *resu = 0 ;
253  resu++ ;
254  }
255 
256  // On passe au phi suivant :
257  cc = cc + ntnr ;
258  k++ ;
259 
260  // On passe au m suivant
261  aa += maa ; // pointeur sur la nouvelle matrice de passage
262 
263  // Cas k >= 3
264  // ----------
265 
266  for (m=3; m < np ; m+=2) {
267 
268  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
269 
270  for (l=0; l<(m-1)/2; l++) {
271  for (i=0; i<nr; i++) {
272  *resu = 0 ;
273  resu++ ;
274  }
275  }
276 
277  // ... produit matriciel (parallelise sur r)
278  for (l=(m-1)/2; l<nt-1; l++) {
279  for (i=0; i<nr; i++) {
280  som[i] = 0 ;
281  }
282 
283  jmin = 0 ;
284 
285  for (j=jmin; j<nt-1; j++) {
286  double amlj = aa[nt*l + j] ;
287  for (i=0; i<nr; i++) {
288  som[i] += amlj * cc[nr*j + i] ;
289  }
290  }
291 
292  for (i=0; i<nr; i++) {
293  *resu = som[i] ;
294  resu++ ;
295  }
296 
297  } // fin de la boucle sur l
298 
299  // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
300  for (i=0; i<nr; i++) {
301  *resu = 0 ;
302  resu++ ;
303  }
304 
305  // On passe au phi suivant :
306  cc = cc + ntnr ;
307  k++ ;
308 
309  } // fin de la boucle sur k2
310 
311  // On passe a l'harmonique en phi suivante :
312 
313  aa += maa ; // pointeur sur la nouvelle matrice de passage
314 
315  } // fin de la boucle (m) sur phi
316 
317  // Cas k=np+1 : tout est mis a zero
318  // --------------------------------
319 
320  for (l=0; l<nt; l++) {
321  for (i=0; i<nr; i++) {
322  *resu = 0 ;
323  resu++ ;
324  }
325  }
326 
327 
328 //## verif :
329  assert(resu == cfo + (np+2)*ntnr) ;
330 
331  // Menage
332  delete [] som ;
333 
334 }
335 }
Lorene prototypes.
Definition: app_hor.h:67