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