LORENE
chb_legpi_sini.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 char chb_legpi_sini_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legpi_sini.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $" ;
24 
25 /*
26  * Calcule les coefficients du developpement (suivant theta)
27  * en sin((2j+1) theta)
28  * a partir des coefficients du developpement en fonctions
29  * associees de Legendre P_l^m(cos(theta)) (l impair et m impair)
30  * pour une une fonction 3-D symetrique par rapport au plan equatorial
31  * z = 0 et antisymetrique par le retournement (x, y, z) --> (-x, -y, z).
32  *
33  * Entree:
34  * -------
35  * const int* deg : tableau du nombre effectif de degres de liberte dans chacune
36  * des 3 dimensions:
37  * deg[0] = np : nombre de points de collocation en phi
38  * deg[1] = nt : nombre de points de collocation en theta
39  * deg[2] = nr : nombre de points de collocation en r
40  *
41  * const double* cfi : tableau des coefficients a_j du develop. en fonctions de
42  * Legendre associees P_n^m:
43  *
44  * f(theta) =
45  * som_{l=(m-1)/2}^{nt-2} a_j P_{2j+1}^m( cos(theta) )
46  *
47  * (m impair)
48  *
49  * ou P_l^m(x) represente la fonction de Legendre associee
50  * de degre l et d'ordre m normalisee de facon a ce que
51  *
52  * int_0^pi [ P_l^m(cos(theta)) ]^2 sin(theta) dtheta = 1
53  *
54  * L'espace memoire correspondant au pointeur cfi doit etre
55  * nr*nt*(np+2) et doit avoir ete alloue avant
56  * l'appel a la routine.
57  * Le coefficient a_j (0 <= j <= nt-1) doit etre stoke dans le
58  * tableau cfi comme suit
59  * a_j = cfi[ nr*nt* k + i + nr* j ]
60  * ou k et i sont les indices correspondant a phi et r
61  * respectivement: m = 2 (k/2).
62  * NB: pour j<(m-1)/2, a_j = 0
63  *
64  * Sortie:
65  * -------
66  * double* cfo : tableau des coefficients c_j du develop. en sin definis
67  * comme suit (a r et phi fixes) :
68  *
69  * f(theta) = som_{j=0}^{nt-2} c_j sin( (2j+1) theta )
70  *
71  * L'espace memoire correspondant au pointeur cfo doit etre
72  * nr*nt*(np+2) et doit avoir ete alloue avant
73  * l'appel a la routine.
74  * Le coefficient c_j (0 <= j <= nt-1) est stoke dans le
75  * tableau cfo comme suit
76  * c_j = cfo[ nr*nt* k + i + nr* j ]
77  * ou k et i sont les indices correspondant a
78  * phi et r respectivement.
79  * NB: c_{nt-1} = 0.
80  *
81  *
82  * NB:
83  * ---
84  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
85  */
86 
87 /*
88  * $Id: chb_legpi_sini.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $
89  * $Log: chb_legpi_sini.C,v $
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:00 j_novak
94  * Modified #include directives to use c++ syntax.
95  *
96  * Revision 1.4 2005/02/18 13:14:11 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:52 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:29 e_gourgoulhon
109  * LORENE
110  *
111  * Revision 2.1 2000/11/14 15:12:11 eric
112  * Traitement du cas np=1
113  *
114  * Revision 2.0 2000/09/29 16:07:35 eric
115  * *** empty log message ***
116  *
117  *
118  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legpi_sini.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $
119  *
120  */
121 
122 // headers du C
123 #include <cstdlib>
124 #include <cassert>
125 
126 // Headers Lorene
127 #include "headcpp.h"
128 #include "proto.h"
129 
130 namespace Lorene {
131 //******************************************************************************
132 
133 void chb_legpi_sini(const int* deg , const double* cfi, double* cfo) {
134 
135 int k2, l, 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 Legendre --> cos/sin
149  double* bb = mat_legpi_sini(np, nt) ;
150 
151 // Increment en m pour la matrice bb :
152  int mbb = 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  // Boucle sur l'indice j du developpement en sin( (2j+1) theta)
168 
169  for (j=0; j<nt-1; j++) {
170 
171  // ... produit matriciel (parallelise sur r)
172  for (i=0; i<nr; i++) {
173  som[i] = 0 ;
174  }
175 
176  for (l=0; l<nt-1; l++) {
177  double bmjl = bb[nt*j + l] ;
178  for (i=0; i<nr; i++) {
179  som[i] += bmjl * cc[nr*l + i] ;
180  }
181  }
182 
183  for (i=0; i<nr; i++) {
184  *resu = som[i] ;
185  resu++ ;
186  }
187 
188  } // fin de la boucle sur j
189 
190  // Dernier coef en j=nt-1 mis a zero pour le cas m impair :
191  for (i=0; i<nr; i++) {
192  *resu = 0 ;
193  resu++ ;
194  }
195 
196  // Special case np=1 (axisymmetry)
197  // -------------------------------
198  if (np==1) {
199  for (i=0; i<2*ntnr; i++) {
200  *resu = 0 ;
201  resu++ ;
202  }
203  delete [] som ;
204  return ;
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  // Boucle sur l'indice j du developpement en sin( (2j+1) theta)
229 
230  for (j=0; j<nt-1; j++) {
231 
232  // ... produit matriciel (parallelise sur r)
233  for (i=0; i<nr; i++) {
234  som[i] = 0 ;
235  }
236 
237  for (l=0; l<nt-1; l++) {
238  double bmjl = bb[nt*j + l] ;
239  for (i=0; i<nr; i++) {
240  som[i] += bmjl * cc[nr*l + i] ;
241  }
242  }
243 
244  for (i=0; i<nr; i++) {
245  *resu = som[i] ;
246  resu++ ;
247  }
248 
249  } // fin de la boucle sur j
250 
251  // Dernier coef en j=nt-1 mis a zero pour le cas m impair :
252  for (i=0; i<nr; i++) {
253  *resu = 0 ;
254  resu++ ;
255  }
256 
257  // On passe au phi suivant :
258  cc = cc + ntnr ;
259  k++ ;
260 
261  // On passe au m suivant :
262  bb += mbb ; // pointeur sur la nouvelle matrice de passage
263 
264  // Cas k >= 3
265  // ----------
266 
267  for (m=3; m < np ; m+=2) {
268 
269  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
270 
271  // Boucle sur l'indice j du developpement en sin( (2j+1) theta)
272 
273  for (j=0; j<nt-1; j++) {
274 
275  // ... produit matriciel (parallelise sur r)
276  for (i=0; i<nr; i++) {
277  som[i] = 0 ;
278  }
279 
280  for (l=(m-1)/2; l<nt-1; l++) {
281  double bmjl = bb[nt*j + l] ;
282  for (i=0; i<nr; i++) {
283  som[i] += bmjl * cc[nr*l + i] ;
284  }
285  }
286 
287  for (i=0; i<nr; i++) {
288  *resu = som[i] ;
289  resu++ ;
290  }
291 
292  } // fin de la boucle sur j
293 
294  // Dernier coef en j=nt-1 mis a zero pour le cas m impair :
295  for (i=0; i<nr; i++) {
296  *resu = 0 ;
297  resu++ ;
298  }
299 
300  // On passe au phi suivant :
301  cc = cc + ntnr ;
302  k++ ;
303 
304  } // fin de la boucle sur k2
305 
306  // On passe a l'harmonique en phi suivante :
307  bb += mbb ; // pointeur sur la nouvelle matrice de passage
308 
309  } // fin de la boucle (m) sur phi
310 
311 
312  // Cas k=np+1 : tout est mis a zero
313  // --------------------------------
314 
315  for (l=0; l<nt; l++) {
316  for (i=0; i<nr; i++) {
317  *resu = 0 ;
318  resu++ ;
319  }
320  }
321 
322 
323 //## verif :
324  assert(resu == cfo + (np+2)*ntnr) ;
325 
326  // Menage
327  delete [] som ;
328 
329 }
330 }
Lorene prototypes.
Definition: app_hor.h:64