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