LORENE
chb_cossinci_legi.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_cossinci_legi_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cossinci_legi.C,v 1.5 2014/10/13 08:53:10 j_novak Exp $" ;
24 
25 /*
26  * Calcule les coefficients du developpement (suivant theta) en fonctions
27  * associees de Legendre P_l^m(cos(theta)) (l-m impair) a partir des
28  * coefficients du developpement en
29  * cos[(2*j+1)*theta] [m pair] / sin(2*j* theta) [m impair]
30  * representant une fonction 3-D antisymetrique par rapport au plan equatorial
31  * z = 0.
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 c_j du develop. en cos/sin definis
42  * comme suit (a r et phi fixes)
43  *
44  * pour m pair: f(theta) = som_{j=0}^{nt-2} c_j cos( (2 j+1) theta )
45  *
46  * pour m impair: f(theta) = som_{j=1}^{nt-2} c_j sin( 2j theta )
47  *
48  * L'espace memoire correspondant au pointeur cfi doit etre
49  * nr*nt*(np+2) et doit avoir ete alloue avant
50  * l'appel a la routine.
51  * Le coefficient c_j (0 <= j <= nt-1) doit etre stoke dans le
52  * tableau cfi comme suit
53  * c_j = cfi[ nr*nt* k + i + nr* j ]
54  * ou k et i sont les indices correspondant a
55  * phi et r respectivement: m = k/2.
56  * Pour m pair, c_{nt-1} = 0.
57  * Pour m impair, c_0 = c_{nt-1} = 0.
58  *
59  * Sortie:
60  * -------
61  * double* cfo : tableau des coefficients a_l du develop. en fonctions de
62  * Legendre associees P_n^m impaires:
63  *
64  * pour m pair: f(theta) =
65  * som_{l=m/2}^{nt-2} a_l P_{2l+1}^m( cos(theta) )
66  *
67  * pour m impair: f(theta) =
68  * som_{l=(m+1)/2}^{nt-2} a_l P_{2l}^m( cos(theta) )
69  *
70  * ou P_n^m(x) represente la fonction de Legendre associee
71  * de degre n et d'ordre m normalisee de facon a ce que
72  *
73  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
74  *
75  * L'espace memoire correspondant au pointeur cfo doit etre
76  * nr*nt*(np+2) et doit avoir ete alloue avant
77  * l'appel a la routine.
78  * Le coefficient a_l (0 <= l <= nt-1) est stoke dans le
79  * tableau cfo comme suit
80  * a_l = cfo[ nr*nt* k + i + nr* l ]
81  * ou k et i sont les indices correspondant a phi et r
82  * respectivement: m = k/2.
83  * NB: pour m pair: si l < m/2 ou l = nt-1, a_l = 0
84  * pour m impair: si l < (m+1)/2 ou l = nt-1, a_l = 0
85  *
86  * NB:
87  * ---
88  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
89  */
90 
91 /*
92  * $Id: chb_cossinci_legi.C,v 1.5 2014/10/13 08:53:10 j_novak Exp $
93  * $Log: chb_cossinci_legi.C,v $
94  * Revision 1.5 2014/10/13 08:53:10 j_novak
95  * Lorene classes and functions now belong to the namespace Lorene.
96  *
97  * Revision 1.4 2014/10/06 15:16:00 j_novak
98  * Modified #include directives to use c++ syntax.
99  *
100  * Revision 1.3 2005/02/18 13:14:10 j_novak
101  * Changing of malloc/free to new/delete + suppression of some unused variables
102  * (trying to avoid compilation warnings).
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.0 1999/02/22 15:45:41 hyc
112  * *** empty log message ***
113  *
114  *
115  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cossinci_legi.C,v 1.5 2014/10/13 08:53:10 j_novak Exp $
116  *
117  */
118 
119 
120 // headers du C
121 #include <cassert>
122 #include <cstdlib>
123 
124 // Prototypage
125 #include "headcpp.h"
126 #include "proto.h"
127 
128 namespace Lorene {
129 //******************************************************************************
130 
131 void chb_cossinci_legi(const int* deg , const double* cfi, double* cfo) {
132 
133 // Espace de travail realloue eventuellement a chaque appel :
134 
135 int ip, 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 
144  // Tableau de travail
145  double* som = new double[nr] ;
146 
147 // Recherche de la matrice de passage cos/sin --> Legendre
148  double* aa = mat_cossinci_legi(np, nt) ;
149 
150 // Increment en m pour la matrice aa :
151  int maa = nt * nt ;
152 
153 // Pointeurs de travail :
154  double* resu = cfo ;
155  const double* cc = cfi ;
156 
157 // Increment en phi :
158  int ntnr = nt * nr ;
159 
160 // Indice courant en phi :
161  int k = 0 ;
162 
163 // Ordre des harmoniques du developpement de Fourier en phi :
164  m = 0 ;
165 
166 // --------------
167 // Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3
168 // -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1
169 // k2 = 0 1 0 1
170 
171  for (ip=0; ip < np/4 + 1 ; ip++) {
172 
173 //--------------------------------
174 // Partie m pair
175 //--------------------------------
176 
177 
178  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
179 
180  if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
181  // et sin( np/2 phi) a zero
182  for (l=0; l<nt; l++) {
183  for (i=0; i<nr; i++) {
184  *resu = 0 ;
185  resu++ ;
186  }
187  }
188  }
189  else {
190 
191 // Boucle sur l'indice l du developpement en Legendre
192 
193  //... 0 <= l <= m/2 - 1 : a_l = 0
194  for (l=0; l<m/2; l++) {
195  for (i=0; i<nr; i++) {
196  *resu = 0 ;
197  resu++ ;
198  }
199  }
200 
201  //... m/2 <= l <= nt-2 : produit matriciel (parallelise sur r)
202  for (l=m/2; l<nt-1; l++) {
203  for (i=0; i<nr; i++) {
204  som[i] = 0 ;
205  }
206 
207  //## jmin = ( m == 0 ) ? l : 0 ; // pour m=0, aa_lj = 0 pour j<l
208  jmin = 0 ;
209  for (j=jmin; j<nt-1; j++) {
210  double amlj = aa[nt*l + j] ;
211  for (i=0; i<nr; i++) {
212  som[i] += amlj * cc[nr*j + i] ;
213  }
214  }
215 
216  for (i=0; i<nr; i++) {
217  *resu = som[i] ;
218  resu++ ;
219  }
220 
221  } // fin de la boucle sur l
222 
223 
224  //... l = nt-1 : a_l = 0
225  for (i=0; i<nr; i++) {
226  *resu = 0 ;
227  resu++ ;
228  }
229 
230  } // fin du cas k != 1
231 
232 // On passe au phi suivant :
233  cc = cc + ntnr ;
234  k++ ;
235 
236  } // fin de la boucle sur k2
237 
238 // On passe a l'harmonique en phi suivante :
239  m++ ;
240  aa += maa ; // pointeur sur la nouvelle matrice de passage
241 
242 //--------------------------------
243 // Partie m impair
244 //--------------------------------
245 
246  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
247 
248  if ( k == np+1 ) { // On met les coef de
249  // sin( np/2 phi) a zero
250  for (l=0; l<nt; l++) {
251  for (i=0; i<nr; i++) {
252  *resu = 0 ;
253  resu++ ;
254  }
255  }
256  }
257 
258  if (k < np+1) {
259 
260 // Boucle sur l'indice l du developpement en Legendre
261 
262  //... 0 <= l <= (m-1)/2 : a_l = 0
263 
264  for (l=0; l<(m+1)/2; l++) {
265  for (i=0; i<nr; i++) {
266  *resu = 0 ;
267  resu++ ;
268  }
269  }
270 
271  //... (m+1)/2 <= l <= nt-2 : produit matriciel (parallelise sur r)
272  for (l=(m+1)/2; l<nt-1; l++) {
273  for (i=0; i<nr; i++) {
274  som[i] = 0 ;
275  }
276 
277  //## jmin = ( m == 1 ) ? l : 0 ; // pour m=1, aa_lj = 0 pour j<l
278  jmin = 1 ; // pour j=0, sin(2*j*theta)=0
279 
280  for (j=jmin; j<nt-1; j++) {
281  double amlj = aa[nt*l + j] ;
282  for (i=0; i<nr; i++) {
283  som[i] += amlj * cc[nr*j + 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 l
293 
294  //... l = nt-1 : a_l = 0
295  for (i=0; i<nr; i++) {
296  *resu = 0 ;
297  resu++ ;
298  }
299 
300 
301 // On passe au phi suivant :
302  cc = cc + ntnr ;
303  k++ ;
304 
305  } // fin du cas k < np+1
306 
307  } // fin de la boucle sur k2
308 
309 
310 // On passe a l'harmonique en phi suivante :
311  m++ ;
312  aa += maa ; // pointeur sur la nouvelle matrice de passage
313 
314  } // fin de la boucle (ip) sur phi
315 
316 // Mise a zero des coefficients de sin( np/2 phi ) (k=np+1)
317 
318 //## verif :
319  assert(resu == cfo + (np+2)*ntnr) ;
320 
321  // Menage
322  delete [] som ;
323 
324 }
325 }
Lorene prototypes.
Definition: app_hor.h:64