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 char chb_cosi_legip_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cosi_legip.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+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.7 2014/10/13 08:53:10 j_novak Exp $
87  * $Log: chb_cosi_legip.C,v $
88  * Revision 1.7 2014/10/13 08:53:10 j_novak
89  * Lorene classes and functions now belong to the namespace Lorene.
90  *
91  * Revision 1.6 2014/10/06 15:15:59 j_novak
92  * Modified #include directives to use c++ syntax.
93  *
94  * Revision 1.5 2005/02/18 13:14:10 j_novak
95  * Changing of malloc/free to new/delete + suppression of some unused variables
96  * (trying to avoid compilation warnings).
97  *
98  * Revision 1.4 2003/12/19 16:21:46 j_novak
99  * Shadow hunt
100  *
101  * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
102  * Suppressed the directive #include <malloc.h> for malloc is defined
103  * in <stdlib.h>
104  *
105  * Revision 1.2 2002/10/16 14:36:52 j_novak
106  * Reorganization of #include instructions of standard C++, in order to
107  * use experimental version 3 of gcc.
108  *
109  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
110  * LORENE
111  *
112  * Revision 2.1 2000/09/29 16:05:49 eric
113  * *** empty log message ***
114  *
115  * Revision 2.0 2000/09/28 10:02:00 eric
116  * *** empty log message ***
117  *
118  *
119  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cosi_legip.C,v 1.7 2014/10/13 08:53:10 j_novak Exp $
120  *
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_cosi_legip(const int* deg , const double* cfi, double* cfo) {
136 
137 int k2, l, jmin, j, i, m ;
138 
139  // Nombres de degres de liberte en phi et theta :
140  int np = deg[0] ;
141  int nt = deg[1] ;
142  int nr = deg[2] ;
143 
144  assert(np < 4*nt) ;
145  assert( cfi != cfo ) ;
146 
147  // Tableau de travail
148  double* som = new double[nr] ;
149 
150  // Recherche de la matrice de passage cos --> Legendre
151  double* aa = mat_cosi_legip(np, nt) ;
152 
153  // Increment en m pour la matrice aa :
154  int maa = nt * nt ;
155 
156  // Pointeurs de travail :
157  double* resu = cfo ;
158  const double* cc = cfi ;
159 
160  // Increment en phi :
161  int ntnr = nt * nr ;
162 
163  // Indice courant en phi :
164  int k = 0 ;
165 
166  //----------------------------------------------------------------
167  // Cas axisymetrique
168  //----------------------------------------------------------------
169 
170  if (np == 1) {
171 
172  m = 0 ;
173 
174  // Boucle sur l'indice l du developpement en Legendre
175 
176  // ... produit matriciel (parallelise sur r)
177  for (l=m/2; l<nt-1; l++) {
178  for (i=0; i<nr; i++) {
179  som[i] = 0 ;
180  }
181 
182  //## jmin = l ; // pour m=0, aa_lj = 0 pour j<l
183  jmin = 0 ;
184  for (j=jmin; j<nt-1; 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  //... l = nt-1 : a_l = 0
199  for (i=0; i<nr; i++) {
200  *resu = 0 ;
201  resu++ ;
202  }
203 
204  // Mise a zero des coefficients k=1 et k=2 :
205  // ---------------------------------------
206 
207  for (i=ntnr; i<3*ntnr; i++) {
208  cfo[i] = 0 ;
209  }
210 
211 
212  // on sort
213  delete [] som ;
214  return ;
215 
216  } // fin du cas np=1
217 
218 
219 //----------------------------------------------------------------
220 // Cas 3-D
221 //----------------------------------------------------------------
222 
223 
224 // Boucle sur phi :
225 
226 
227  for (m=0; m < np + 1 ; m+=2) {
228 
229  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
230 
231  if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
232  // et sin( np phi) a zero
233  for (l=0; l<nt; l++) {
234  for (i=0; i<nr; i++) {
235  *resu = 0 ;
236  resu++ ;
237  }
238  }
239  }
240  else {
241 
242 // Boucle sur l'indice l du developpement en Legendre
243 
244  //... 0 <= l <= m/2 - 1 : a_l = 0
245  for (l=0; l<m/2; l++) {
246  for (i=0; i<nr; i++) {
247  *resu = 0 ;
248  resu++ ;
249  }
250  }
251  // ... m/2 <= l <= nt-2 : produit matriciel (parallelise sur r)
252  for (l=m/2; l<nt-1; l++) {
253  for (i=0; i<nr; i++) {
254  som[i] = 0 ;
255  }
256 
257  //## jmin = ( m == 0 ) ? l : 0 ; // pour m=0, aa_lj = 0 pour j<l
258  jmin = 0 ;
259  for (j=jmin; j<nt-1; j++) {
260  double amlj = aa[nt*l + j] ;
261  for (i=0; i<nr; i++) {
262  som[i] += amlj * cc[nr*j + i] ;
263  }
264  }
265 
266  for (i=0; i<nr; i++) {
267  *resu = som[i] ;
268  resu++ ;
269  }
270 
271  } // fin de la boucle sur l
272 
273  //... l = nt-1 : a_l = 0
274  for (i=0; i<nr; i++) {
275  *resu = 0 ;
276  resu++ ;
277  }
278 
279  } // fin du cas k != 1 et k!=np+1
280 
281 // On passe au phi suivant :
282  cc = cc + ntnr ;
283  k++ ;
284 
285  } // fin de la boucle sur k2
286 
287 // On passe a l'harmonique en phi suivante :
288 
289  aa += maa ; // pointeur sur la nouvelle matrice de passage
290 
291  } // fin de la boucle (m) sur phi
292 
293 //## verif :
294  assert(resu == cfo + (np+2)*ntnr) ;
295 
296  // Menage
297  delete [] som ;
298 
299 }
300 }
Lorene prototypes.
Definition: app_hor.h:64