LORENE
chb_legpp_cosp.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)
28  * a partir des coefficients du developpement en fonctions
29  * associees de Legendre P_l^m(cos(theta)) (l pair et m pair)
30  * pour une une fonction 3-D symetrique par rapport au plan equatorial
31  * z = 0 et symetrique par le retournement (x, y, z) --> (-x, -y, z).
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  * f(theta) = som_{l=m/2}^{nt-1} a_l P_{2l}^m( cos(theta) )
45  *
46  * (m pair)
47  *
48  * ou P_n^m(x) represente la fonction de Legendre associee
49  * de degre n et d'ordre m normalisee de facon a ce que
50  *
51  * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
52  *
53  * L'espace memoire correspondant au pointeur cfi doit etre
54  * nr*nt*(np+2) et doit avoir ete alloue avant
55  * l'appel a la routine.
56  * Le coefficient a_l (0 <= l <= nt-1) doit etre stoke dans le
57  * tableau cfi comme suit
58  * a_l = cfi[ nr*nt* k + i + nr* l ]
59  * ou k et i sont les indices correspondant a phi et r
60  * respectivement: m = 2 (k/2).
61  * NB: pour l < m/2, a_l = 0
62  *
63  * Sortie:
64  * -------
65  * double* cfo : tableau des coefficients c_j du develop. en cos/sin definis
66  * comme suit (a r et phi fixes) :
67  *
68  * f(theta) = som_{j=0}^{nt-1} c_j cos( 2 j theta )
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 c_j (0 <= j <= nt-1) est stoke dans le
74  * tableau cfo comme suit
75  * c_j = cfo[ nr*nt* k + i + nr* j ]
76  * ou k et i sont les indices correspondant a
77  * phi et r respectivement: m = 2 (k/2).
78  * Pour m impair, c_0 = c_{nt-1} = 0.
79  *
80  *
81  * NB:
82  * ---
83  * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
84  */
85 
86 /*
87  * $Id: chb_legpp_cosp.C,v 1.8 2016/12/05 16:18:01 j_novak Exp $
88  * $Log: chb_legpp_cosp.C,v $
89  * Revision 1.8 2016/12/05 16:18:01 j_novak
90  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
91  *
92  * Revision 1.7 2014/10/13 08:53:11 j_novak
93  * Lorene classes and functions now belong to the namespace Lorene.
94  *
95  * Revision 1.6 2014/10/06 15:16:01 j_novak
96  * Modified #include directives to use c++ syntax.
97  *
98  * Revision 1.5 2005/02/18 13:14:11 j_novak
99  * Changing of malloc/free to new/delete + suppression of some unused variables
100  * (trying to avoid compilation warnings).
101  *
102  * Revision 1.4 2003/12/19 16:21:46 j_novak
103  * Shadow hunt
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:53 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:28 e_gourgoulhon
114  * LORENE
115  *
116  * Revision 2.1 2000/09/29 16:08:20 eric
117  * Mise a zero des coefficients k=1 et k=2 dans le cas np=1.
118  *
119  * Revision 2.0 1999/02/22 15:44:48 hyc
120  * *** empty log message ***
121  *
122  *
123  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legpp_cosp.C,v 1.8 2016/12/05 16:18:01 j_novak Exp $
124  *
125  */
126 
127 
128 
129 // headers du C
130 #include <cstdlib>
131 #include <cassert>
132 
133 // Prototypage
134 #include "headcpp.h"
135 #include "proto.h"
136 
137 namespace Lorene {
138 //******************************************************************************
139 
140 void chb_legpp_cosp(const int* deg , const double* cfi, double* cfo) {
141 
142 int k2, l, j, i, m ;
143 
144 // Nombres de degres de liberte en phi et theta :
145  int np = deg[0] ;
146  int nt = deg[1] ;
147  int nr = deg[2] ;
148 
149  assert(np < 4*nt) ;
150 
151  // Tableau de travail
152  double* som = new double[nr] ;
153 
154 // Recherche de la matrice de passage Legendre --> cos/sin
155  double* bb = mat_legpp_cosp(np, nt) ;
156 
157 // Increment en m pour la matrice bb :
158  int mbb = nt * nt ;
159 
160 // Pointeurs de travail :
161  double* resu = cfo ;
162  const double* cc = cfi ;
163 
164 // Increment en phi :
165  int ntnr = nt * nr ;
166 
167 // Indice courant en phi :
168  int k = 0 ;
169 
170 //----------------------------------------------------------------
171 // Cas axisymetrique
172 //----------------------------------------------------------------
173 
174  if (np == 1) {
175 
176  m = 0 ;
177 
178 // Boucle sur l'indice j du developpement en cos(2 j theta)
179 
180  for (j=0; j<nt; j++) {
181 
182 // ... produit matriciel (parallelise sur r)
183  for (i=0; i<nr; i++) {
184  som[i] = 0 ;
185  }
186 
187  for (l=m/2; l<nt; l++) {
188 
189  double bmjl = bb[nt*j + l] ;
190  for (i=0; i<nr; i++) {
191  som[i] += bmjl * cc[nr*l + i] ;
192  }
193  }
194 
195  for (i=0; i<nr; i++) {
196  *resu = som[i] ;
197  resu++ ;
198  }
199 
200  } // fin de la boucle sur j
201 
202  // Mise a zero des coefficients k=1 et k=2 :
203  // ---------------------------------------
204 
205  for (i=ntnr; i<3*ntnr; i++) {
206  cfo[i] = 0 ;
207  }
208 
209  // On sort
210  delete [] som ;
211  return ;
212 
213  } // fin du cas np=1
214 
215 
216 //----------------------------------------------------------------
217 // Cas 3-D
218 //----------------------------------------------------------------
219 
220 
221 // Boucle sur phi :
222 
223  for (m=0; m < np + 1 ; m+=2) {
224 
225  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
226 
227  if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
228  // et sin( np phi) a zero
229  for (j=0; j<nt; j++) {
230  for (i=0; i<nr; i++) {
231  *resu = 0 ;
232  resu++ ;
233  }
234  }
235  }
236  else {
237 
238 // Boucle sur l'indice j du developpement en cos(2 j theta)
239 
240  for (j=0; j<nt; j++) {
241 
242 // ... produit matriciel (parallelise sur r)
243  for (i=0; i<nr; i++) {
244  som[i] = 0 ;
245  }
246 
247  for (l=m/2; l<nt; l++) {
248 
249  double bmjl = bb[nt*j + l] ;
250  for (i=0; i<nr; i++) {
251  som[i] += bmjl * cc[nr*l + i] ;
252  }
253  }
254 
255  for (i=0; i<nr; i++) {
256  *resu = som[i] ;
257  resu++ ;
258  }
259 
260  } // fin de la boucle sur j
261 
262  } // fin du cas k != 1
263 
264 // On passe au phi suivant :
265  cc = cc + ntnr ;
266  k++ ;
267 
268  } // fin de la boucle sur k2
269 
270 // On passe a l'harmonique en phi suivante :
271 
272  bb += mbb ; // pointeur sur la nouvelle matrice de passage
273 
274  } // fin de la boucle (m) sur phi
275 
276 //## verif :
277  assert(resu == cfo + (np+2)*ntnr) ;
278 
279  // Menage
280  delete [] som ;
281 
282 }
283 }
Lorene prototypes.
Definition: app_hor.h:67