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