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