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 char chb_cosp_legpp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cosp_legpp.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*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.7 2014/10/13 08:53:10 j_novak Exp $
86  * $Log: chb_cosp_legpp.C,v $
87  * Revision 1.7 2014/10/13 08:53:10 j_novak
88  * Lorene classes and functions now belong to the namespace Lorene.
89  *
90  * Revision 1.6 2014/10/06 15:16:00 j_novak
91  * Modified #include directives to use c++ syntax.
92  *
93  * Revision 1.5 2005/02/18 13:14:10 j_novak
94  * Changing of malloc/free to new/delete + suppression of some unused variables
95  * (trying to avoid compilation warnings).
96  *
97  * Revision 1.4 2003/12/19 16:21:46 j_novak
98  * Shadow hunt
99  *
100  * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
101  * Suppressed the directive #include <malloc.h> for malloc is defined
102  * in <stdlib.h>
103  *
104  * Revision 1.2 2002/10/16 14:36:52 j_novak
105  * Reorganization of #include instructions of standard C++, in order to
106  * use experimental version 3 of gcc.
107  *
108  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
109  * LORENE
110  *
111  * Revision 2.1 2000/09/29 16:06:31 eric
112  * Mise a zero des coefficients k=1 et k=2.
113  *
114  * Revision 2.0 1999/02/22 15:45:54 hyc
115  * *** empty log message ***
116  *
117  *
118  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cosp_legpp.C,v 1.7 2014/10/13 08:53:10 j_novak Exp $
119  *
120  */
121 
122 
123 // headers du C
124 #include <cassert>
125 #include <cstdlib>
126 
127 // Prototypage
128 #include "headcpp.h"
129 #include "proto.h"
130 
131 namespace Lorene {
132 //******************************************************************************
133 
134 void chb_cosp_legpp(const int* deg , const double* cfi, double* cfo) {
135 
136 int k2, l, jmin, j, i, m ;
137 
138 // Nombres de degres de liberte en phi et theta :
139  int np = deg[0] ;
140  int nt = deg[1] ;
141  int nr = deg[2] ;
142 
143  assert(np < 4*nt) ;
144 
145  // Tableau de travail
146  double* som = new double[nr] ;
147 
148 // Recherche de la matrice de passage cos --> Legendre
149  double* aa = mat_cosp_legpp(np, nt) ;
150 
151 // Increment en m pour la matrice aa :
152  int maa = nt * nt ;
153 
154 // Pointeurs de travail :
155  double* resu = cfo ;
156  const double* cc = cfi ;
157 
158 // Increment en phi :
159  int ntnr = nt * nr ;
160 
161 // Indice courant en phi :
162  int k = 0 ;
163 
164 //----------------------------------------------------------------
165 // Cas axisymetrique
166 //----------------------------------------------------------------
167 
168  if (np == 1) {
169 
170  m = 0 ;
171 
172 // Boucle sur l'indice l du developpement en Legendre
173 
174 // ... produit matriciel (parallelise sur r)
175  for (l=m/2; l<nt; l++) {
176  for (i=0; i<nr; i++) {
177  som[i] = 0 ;
178  }
179 
180  jmin = l ; // pour m=0, aa_lj = 0 pour j<l
181  for (j=jmin; j<nt; j++) {
182  double amlj = aa[nt*l + j] ;
183  for (i=0; i<nr; i++) {
184  som[i] += amlj * cc[nr*j + i] ;
185  }
186  }
187 
188  for (i=0; i<nr; i++) {
189  *resu = som[i] ;
190  resu++ ;
191  }
192 
193  } // fin de la boucle sur l
194 
195  // Mise a zero des coefficients k=1 et k=2 :
196  // ---------------------------------------
197 
198  for (i=ntnr; i<3*ntnr; i++) {
199  cfo[i] = 0 ;
200  }
201 
202 
203  // on sort
204  delete [] som ;
205  return ;
206 
207  } // fin du cas np=1
208 
209 
210 //----------------------------------------------------------------
211 // Cas 3-D
212 //----------------------------------------------------------------
213 
214 
215 // Boucle sur phi :
216 
217 
218  for (m=0; m < np + 1 ; m+=2) {
219 
220  for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
221 
222  if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
223  // et sin( np phi) a zero
224  for (l=0; l<nt; l++) {
225  for (i=0; i<nr; i++) {
226  *resu = 0 ;
227  resu++ ;
228  }
229  }
230  }
231  else {
232 
233 // Boucle sur l'indice l du developpement en Legendre
234 
235  for (l=0; l<m/2; l++) {
236  for (i=0; i<nr; i++) {
237  *resu = 0 ;
238  resu++ ;
239  }
240  }
241 // ... produit matriciel (parallelise sur r)
242  for (l=m/2; l<nt; l++) {
243  for (i=0; i<nr; i++) {
244  som[i] = 0 ;
245  }
246 
247  jmin = ( m == 0 ) ? l : 0 ; // pour m=0, aa_lj = 0 pour j<l
248  for (j=jmin; j<nt; j++) {
249  double amlj = aa[nt*l + j] ;
250  for (i=0; i<nr; i++) {
251  som[i] += amlj * cc[nr*j + 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 l
261 
262  } // fin du cas k != 1 et k!=np+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  aa += maa ; // 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
Lorene prototypes.
Definition: app_hor.h:64