LORENE
chb_cosi_legip.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+1)*theta)
29  * representant une fonction 3-D antisymetrique par rapport au plan equatorial
30  * z = 0 et symetrique par le retournement (x, y, z) --> (-x, -y, z).
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 defini
41  * comme suit (a r et phi fixes)
42  *
43  * f(theta) = som_{j=0}^{nt-2} c_j cos( (2j+1) theta )
44  *
45  * L'espace memoire correspondant au pointeur cfi doit etre
46  * nr*nt*(np+2) et doit avoir ete alloue avant
47  * l'appel a la routine.
48  * Le coefficient c_j (0 <= j <= nt-1) doit etre stoke dans le
49  * tableau cfi comme suit
50  * c_j = cfi[ nr*nt* k + i + nr* j ]
51  * ou k et i sont les indices correspondant a
52  * phi et r respectivement.
53  *
54  * Sortie:
55  * -------
56  * double* cfo : tableau des coefficients a_j du develop. en fonctions de
57  * Legendre associees P_l^m (l impair, m pair)
58  *
59  * f(theta) =
60  * som_{j=m/2}^{nt-2} a_j P_{2j+1}^m( cos(theta) )
61  *
62  *
63  * avec m pair : m = 0, 2, ..., np.
64  *
65  * P_l^m(x) represente la fonction de Legendre associee
66  * de degre l et d'ordre m normalisee de facon a ce que
67  *
68  * int_0^pi [ P_l^m(cos(theta)) ]^2 sin(theta) dtheta = 1
69  *
70  * L'espace memoire correspondant au pointeur cfo doit etre
71  * nr*nt*(np+2) et doit avoir ete alloue avant
72  * l'appel a la routine.
73  * Le coefficient a_j (0 <= j <= nt-1) est stoke dans le
74  * tableau cfo comme suit
75  * a_j = cfo[ nr*nt* k + i + nr* j ]
76  * ou k et i sont les indices correspondant a phi et r
77  * respectivement: m = 2( k/2 ).
78  * NB: pour j < m/2 ou j = nt-1, a_j = 0
79  *
80  * NB:
81  * ---
82  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
83  */
84 
85 /*
86  * $Id: chb_cosi_legip.C,v 1.8 2016/12/05 16:18:00 j_novak Exp $
87  * $Log: chb_cosi_legip.C,v $
88  * Revision 1.8 2016/12/05 16:18:00 j_novak
89  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
90  *
91  * Revision 1.7 2014/10/13 08:53:10 j_novak
92  * Lorene classes and functions now belong to the namespace Lorene.
93  *
94  * Revision 1.6 2014/10/06 15:15:59 j_novak
95  * Modified #include directives to use c++ syntax.
96  *
97  * Revision 1.5 2005/02/18 13:14:10 j_novak
98  * Changing of malloc/free to new/delete + suppression of some unused variables
99  * (trying to avoid compilation warnings).
100  *
101  * Revision 1.4 2003/12/19 16:21:46 j_novak
102  * Shadow hunt
103  *
104  * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
105  * Suppressed the directive #include <malloc.h> for malloc is defined
106  * in <stdlib.h>
107  *
108  * Revision 1.2 2002/10/16 14:36:52 j_novak
109  * Reorganization of #include instructions of standard C++, in order to
110  * use experimental version 3 of gcc.
111  *
112  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
113  * LORENE
114  *
115  * Revision 2.1 2000/09/29 16:05:49 eric
116  * *** empty log message ***
117  *
118  * Revision 2.0 2000/09/28 10:02:00 eric
119  * *** empty log message ***
120  *
121  *
122  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cosi_legip.C,v 1.8 2016/12/05 16:18:00 j_novak Exp $
123  *
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_cosi_legip(const int* deg , const double* cfi, double* cfo) {
139 
140 int k2, l, jmin, j, i, m ;
141 
142  // Nombres de degres de liberte en phi et theta :
143  int np = deg[0] ;
144  int nt = deg[1] ;
145  int nr = deg[2] ;
146 
147  assert(np < 4*nt) ;
148  assert( cfi != cfo ) ;
149 
150  // Tableau de travail
151  double* som = new double[nr] ;
152 
153  // Recherche de la matrice de passage cos --> Legendre
154  double* aa = mat_cosi_legip(np, nt) ;
155 
156  // Increment en m pour la matrice aa :
157  int maa = nt * nt ;
158 
159  // Pointeurs de travail :
160  double* resu = cfo ;
161  const double* cc = cfi ;
162 
163  // Increment en phi :
164  int ntnr = nt * nr ;
165 
166  // Indice courant en phi :
167  int k = 0 ;
168 
169  //----------------------------------------------------------------
170  // Cas axisymetrique
171  //----------------------------------------------------------------
172 
173  if (np == 1) {
174 
175  m = 0 ;
176 
177  // Boucle sur l'indice l du developpement en Legendre
178 
179  // ... produit matriciel (parallelise sur r)
180  for (l=m/2; l<nt-1; l++) {
181  for (i=0; i<nr; i++) {
182  som[i] = 0 ;
183  }
184 
185  //## jmin = l ; // pour m=0, aa_lj = 0 pour j<l
186  jmin = 0 ;
187  for (j=jmin; j<nt-1; 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  //... l = nt-1 : a_l = 0
202  for (i=0; i<nr; i++) {
203  *resu = 0 ;
204  resu++ ;
205  }
206 
207  // Mise a zero des coefficients k=1 et k=2 :
208  // ---------------------------------------
209 
210  for (i=ntnr; i<3*ntnr; i++) {
211  cfo[i] = 0 ;
212  }
213 
214 
215  // on sort
216  delete [] som ;
217  return ;
218 
219  } // fin du cas np=1
220 
221 
222 //----------------------------------------------------------------
223 // Cas 3-D
224 //----------------------------------------------------------------
225 
226 
227 // Boucle sur phi :
228 
229 
230  for (m=0; m < np + 1 ; m+=2) {
231 
232  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
233 
234  if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
235  // et sin( np phi) a zero
236  for (l=0; l<nt; l++) {
237  for (i=0; i<nr; i++) {
238  *resu = 0 ;
239  resu++ ;
240  }
241  }
242  }
243  else {
244 
245 // Boucle sur l'indice l du developpement en Legendre
246 
247  //... 0 <= l <= m/2 - 1 : a_l = 0
248  for (l=0; l<m/2; l++) {
249  for (i=0; i<nr; i++) {
250  *resu = 0 ;
251  resu++ ;
252  }
253  }
254  // ... m/2 <= l <= nt-2 : produit matriciel (parallelise sur r)
255  for (l=m/2; l<nt-1; 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  jmin = 0 ;
262  for (j=jmin; j<nt-1; j++) {
263  double amlj = aa[nt*l + j] ;
264  for (i=0; i<nr; i++) {
265  som[i] += amlj * cc[nr*j + i] ;
266  }
267  }
268 
269  for (i=0; i<nr; i++) {
270  *resu = som[i] ;
271  resu++ ;
272  }
273 
274  } // fin de la boucle sur l
275 
276  //... l = nt-1 : a_l = 0
277  for (i=0; i<nr; i++) {
278  *resu = 0 ;
279  resu++ ;
280  }
281 
282  } // fin du cas k != 1 et k!=np+1
283 
284 // On passe au phi suivant :
285  cc = cc + ntnr ;
286  k++ ;
287 
288  } // fin de la boucle sur k2
289 
290 // On passe a l'harmonique en phi suivante :
291 
292  aa += maa ; // pointeur sur la nouvelle matrice de passage
293 
294  } // fin de la boucle (m) sur phi
295 
296 //## verif :
297  assert(resu == cfo + (np+2)*ntnr) ;
298 
299  // Menage
300  delete [] som ;
301 
302 }
303 }
Lorene prototypes.
Definition: app_hor.h:67