LORENE
chb_cosp_legpp.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)
29  * representant une fonction 3-D symetrique 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-1} c_j cos( 2 j 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_l du develop. en fonctions de
57  * Legendre associees P_n^m:
58  *
59  * f(theta) =
60  * som_{l=m/2}^{nt-1} a_l P_{2l}^m( cos(theta) )
61  *
62  * avec m pair : m = 0, 2, ..., np.
63  *
64  * P_n^m(x) represente la fonction de Legendre associee
65  * de degre n et d'ordre m normalisee de facon a ce que
66  *
67  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
68  *
69  * L'espace memoire correspondant au pointeur cfo doit etre
70  * nr*nt*(np+2) et doit avoir ete alloue avant
71  * l'appel a la routine.
72  * Le coefficient a_l (0 <= l <= nt-1) est stoke dans le
73  * tableau cfo comme suit
74  * a_l = cfo[ nr*nt* k + i + nr* l ]
75  * ou k et i sont les indices correspondant a phi et r
76  * respectivement: m = 2( k/2 ).
77  * NB: pour l < m/2, a_l = 0
78  *
79  * NB:
80  * ---
81  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
82  */
83 
84 /*
85  * $Id: chb_cosp_legpp.C,v 1.8 2016/12/05 16:18:00 j_novak Exp $
86  * $Log: chb_cosp_legpp.C,v $
87  * Revision 1.8 2016/12/05 16:18:00 j_novak
88  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
89  *
90  * Revision 1.7 2014/10/13 08:53:10 j_novak
91  * Lorene classes and functions now belong to the namespace Lorene.
92  *
93  * Revision 1.6 2014/10/06 15:16:00 j_novak
94  * Modified #include directives to use c++ syntax.
95  *
96  * Revision 1.5 2005/02/18 13:14:10 j_novak
97  * Changing of malloc/free to new/delete + suppression of some unused variables
98  * (trying to avoid compilation warnings).
99  *
100  * Revision 1.4 2003/12/19 16:21:46 j_novak
101  * Shadow hunt
102  *
103  * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
104  * Suppressed the directive #include <malloc.h> for malloc is defined
105  * in <stdlib.h>
106  *
107  * Revision 1.2 2002/10/16 14:36:52 j_novak
108  * Reorganization of #include instructions of standard C++, in order to
109  * use experimental version 3 of gcc.
110  *
111  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
112  * LORENE
113  *
114  * Revision 2.1 2000/09/29 16:06:31 eric
115  * Mise a zero des coefficients k=1 et k=2.
116  *
117  * Revision 2.0 1999/02/22 15:45:54 hyc
118  * *** empty log message ***
119  *
120  *
121  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cosp_legpp.C,v 1.8 2016/12/05 16:18:00 j_novak Exp $
122  *
123  */
124 
125 
126 // headers du C
127 #include <cassert>
128 #include <cstdlib>
129 
130 // Prototypage
131 #include "headcpp.h"
132 #include "proto.h"
133 
134 namespace Lorene {
135 //******************************************************************************
136 
137 void chb_cosp_legpp(const int* deg , const double* cfi, double* cfo) {
138 
139 int 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 --> Legendre
152  double* aa = mat_cosp_legpp(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=ntnr; i<3*ntnr; i++) {
202  cfo[i] = 0 ;
203  }
204 
205 
206  // on sort
207  delete [] som ;
208  return ;
209 
210  } // fin du cas np=1
211 
212 
213 //----------------------------------------------------------------
214 // Cas 3-D
215 //----------------------------------------------------------------
216 
217 
218 // Boucle sur phi :
219 
220 
221  for (m=0; m < np + 1 ; m+=2) {
222 
223  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
224 
225  if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
226  // et sin( np phi) a zero
227  for (l=0; l<nt; l++) {
228  for (i=0; i<nr; i++) {
229  *resu = 0 ;
230  resu++ ;
231  }
232  }
233  }
234  else {
235 
236 // Boucle sur l'indice l du developpement en Legendre
237 
238  for (l=0; l<m/2; l++) {
239  for (i=0; i<nr; i++) {
240  *resu = 0 ;
241  resu++ ;
242  }
243  }
244 // ... produit matriciel (parallelise sur r)
245  for (l=m/2; l<nt; l++) {
246  for (i=0; i<nr; i++) {
247  som[i] = 0 ;
248  }
249 
250  jmin = ( m == 0 ) ? l : 0 ; // pour m=0, aa_lj = 0 pour j<l
251  for (j=jmin; j<nt; j++) {
252  double amlj = aa[nt*l + j] ;
253  for (i=0; i<nr; i++) {
254  som[i] += amlj * cc[nr*j + i] ;
255  }
256  }
257 
258  for (i=0; i<nr; i++) {
259  *resu = som[i] ;
260  resu++ ;
261  }
262 
263  } // fin de la boucle sur l
264 
265  } // fin du cas k != 1 et k!=np+1
266 
267 // On passe au phi suivant :
268  cc = cc + ntnr ;
269  k++ ;
270 
271  } // fin de la boucle sur k2
272 
273 // On passe a l'harmonique en phi suivante :
274 
275  aa += maa ; // pointeur sur la nouvelle matrice de passage
276 
277  } // fin de la boucle (m) sur phi
278 
279 //## verif :
280  assert(resu == cfo + (np+2)*ntnr) ;
281 
282  // Menage
283  delete [] som ;
284 
285 }
286 }
Lorene prototypes.
Definition: app_hor.h:67