LORENE
chb_legp_cossincp.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
23char chb_legp_cossincp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legp_cossincp.C,v 1.7 2014/10/13 08:53:11 j_novak Exp $" ;
24
25/*
26 * Calcule les coefficients du developpement (suivant theta)
27 * en cos(2*j*theta) [m pair] / sin( (2*j+1) * theta) [m impair]
28 * a partir des coefficients du developpement en fonctions
29 * associees de Legendre P_l^m(cos(theta))
30 * pour une une fonction 3-D symetrique 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:
43 *
44 * pour m pair: f(theta) =
45 * som_{l=m/2}^{nt-1} a_l P_{2l}^m( cos(theta) )
46 *
47 * pour m impair: f(theta) =
48 * som_{l=(m-1)/2}^{nt-2} a_l P_{2l+1}^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 et l < m/2, a_l = 0
64 * pour m impair et l < (m-1)/2, a_l = 0
65
66
67
68 *
69 * Sortie:
70 * -------
71 * double* cfo : tableau des coefficients c_j du develop. en cos/sin definis
72 * comme suit (a r et phi fixes) :
73 *
74 * pour m pair: f(theta) = som_{j=0}^{nt-1} c_j cos( 2 j theta )
75 *
76 * pour m impair: f(theta) = som_{j=0}^{nt-2} c_j sin( (2 j+1) theta )
77 *
78 * L'espace memoire correspondant au pointeur cfo doit etre
79 * nr*nt*(np+2) et doit avoir ete alloue avant
80 * l'appel a la routine.
81 * Le coefficient c_j (0 <= j <= nt-1) est stoke dans le
82 * tableau cfo comme suit
83 * c_j = cfo[ nr*nt* k + i + nr* j ]
84 * ou k et i sont les indices correspondant a
85 * phi et r respectivement: m = k/2.
86 * Pour m impair, c_0 = c_{nt-1} = 0.
87
88 *
89 * NB:
90 * ---
91 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
92 */
93
94/*
95 * $Id: chb_legp_cossincp.C,v 1.7 2014/10/13 08:53:11 j_novak Exp $
96 * $Log: chb_legp_cossincp.C,v $
97 * Revision 1.7 2014/10/13 08:53:11 j_novak
98 * Lorene classes and functions now belong to the namespace Lorene.
99 *
100 * Revision 1.6 2014/10/06 15:16:00 j_novak
101 * Modified #include directives to use c++ syntax.
102 *
103 * Revision 1.5 2013/04/25 15:46:05 j_novak
104 * Added special treatment in the case np = 1, for type_p = NONSYM.
105 *
106 * Revision 1.4 2005/02/18 13:14:10 j_novak
107 * Changing of malloc/free to new/delete + suppression of some unused variables
108 * (trying to avoid compilation warnings).
109 *
110 * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
111 * Suppressed the directive #include <malloc.h> for malloc is defined
112 * in <stdlib.h>
113 *
114 * Revision 1.2 2002/10/16 14:36:52 j_novak
115 * Reorganization of #include instructions of standard C++, in order to
116 * use experimental version 3 of gcc.
117 *
118 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
119 * LORENE
120 *
121 * Revision 2.0 1999/02/22 15:45:03 hyc
122 * *** empty log message ***
123 *
124 *
125 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legp_cossincp.C,v 1.7 2014/10/13 08:53:11 j_novak Exp $
126 *
127 */
128
129
130// headers du C
131#include <cassert>
132#include <cstdlib>
133
134// Prototypage
135#include "headcpp.h"
136#include "proto.h"
137
138namespace Lorene {
139//******************************************************************************
140
141void chb_legp_cossincp(const int* deg , const double* cfi, double* cfo) {
142
143int ip, k2, l, j, i, m ;
144
145// Nombres de degres de liberte en phi et theta :
146 int np = deg[0] ;
147 int nt = deg[1] ;
148 int nr = deg[2] ;
149
150 assert(np < 4*nt) ;
151
152 // Tableau de travail
153 double* som = new double[nr] ;
154
155// Recherche de la matrice de passage Legendre --> cos/sin
156 double* bb = mat_legp_cossincp(np, nt) ;
157
158// Increment en m pour la matrice bb :
159 int mbb = nt * nt ;
160
161// Pointeurs de travail :
162 double* resu = cfo ;
163 const double* cc = cfi ;
164
165// Increment en phi :
166 int ntnr = nt * nr ;
167
168// Indice courant en phi :
169 int k = 0 ;
170
171//----------------------------------------------------------------
172// Cas axisymetrique
173//----------------------------------------------------------------
174
175 if (np == 1) {
176
177 m = 0 ;
178
179// Boucle sur l'indice j du developpement en cos(2 j theta)
180
181 for (j=0; j<nt; j++) {
182
183// ... produit matriciel (parallelise sur r)
184 for (i=0; i<nr; i++) {
185 som[i] = 0 ;
186 }
187
188 for (l=m/2; l<nt; l++) {
189
190 double bmjl = bb[nt*j + l] ;
191 for (i=0; i<nr; i++) {
192 som[i] += bmjl * cc[nr*l + i] ;
193 }
194 }
195
196 for (i=0; i<nr; i++) {
197 *resu = som[i] ;
198 resu++ ;
199 }
200
201 } // fin de la boucle sur j
202
203 // Mise a zero des coefficients k=1 et k=2 :
204 // ---------------------------------------
205
206 for (i=0; i<2*ntnr; i++) {
207 *resu = 0 ;
208 resu++ ;
209 }
210
211 // On sort
212 delete [] som ;
213 return ;
214
215 } // fin du cas np=1
216
217
218//----------------------------------------------------------------
219// Cas 3-D
220//----------------------------------------------------------------
221
222// Ordre des harmoniques du developpement de Fourier en phi :
223 m = 0 ;
224
225// --------------
226// Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3
227// -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1
228// k2 = 0 1 0 1
229
230 for (ip=0; ip < np/4 + 1 ; ip++) {
231
232//--------------------------------
233// Partie m pair
234//--------------------------------
235
236
237 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
238
239 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
240 // et sin( np/2 phi) a zero
241 for (j=0; j<nt; j++) {
242 for (i=0; i<nr; i++) {
243 *resu = 0 ;
244 resu++ ;
245 }
246 }
247 }
248 else {
249
250// Boucle sur l'indice j du developpement en cos(2 j theta)
251
252 for (j=0; j<nt; j++) {
253
254// ... produit matriciel (parallelise sur r)
255 for (i=0; i<nr; i++) {
256 som[i] = 0 ;
257 }
258
259 for (l=m/2; l<nt; l++) {
260
261 double bmjl = bb[nt*j + l] ;
262 for (i=0; i<nr; i++) {
263 som[i] += bmjl * cc[nr*l + i] ;
264 }
265 }
266
267 for (i=0; i<nr; i++) {
268 *resu = som[i] ;
269 resu++ ;
270 }
271
272 } // fin de la boucle sur j
273
274 } // fin du cas k != 1
275
276// On passe au phi suivant :
277 cc = cc + ntnr ;
278 k++ ;
279
280 } // fin de la boucle sur k2
281
282// On passe a l'harmonique en phi suivante :
283 m++ ;
284 bb += mbb ; // pointeur sur la nouvelle matrice de passage
285
286//--------------------------------
287// Partie m impair
288//--------------------------------
289
290 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
291
292 if ( k == np+1 ) { // On met les coef de
293 // sin( np/2 phi) a zero
294 for (j=0; j<nt; j++) {
295 for (i=0; i<nr; i++) {
296 *resu = 0 ;
297 resu++ ;
298 }
299 }
300 }
301
302 if (k < np+1) {
303
304// Boucle sur l'indice j du developpement en sin( (2j+1) theta)
305
306 for (j=0; j<nt-1; j++) {
307
308// ... produit matriciel (parallelise sur r)
309 for (i=0; i<nr; i++) {
310 som[i] = 0 ;
311 }
312
313 for (l=(m-1)/2; l<nt-1; l++) {
314 double bmjl = bb[nt*j + l] ;
315 for (i=0; i<nr; i++) {
316 som[i] += bmjl * cc[nr*l + i] ;
317 }
318 }
319
320 for (i=0; i<nr; i++) {
321 *resu = som[i] ;
322 resu++ ;
323 }
324
325 } // fin de la boucle sur j
326
327// Dernier coef en j=nt-1 mis a zero pour le cas m impair :
328 for (i=0; i<nr; i++) {
329 *resu = 0 ;
330 resu++ ;
331 }
332
333// On passe au phi suivant :
334 cc = cc + ntnr ;
335 k++ ;
336
337 } // fin du cas k < np+1
338
339 } // fin de la boucle sur k2
340
341
342// On passe a l'harmonique en phi suivante :
343 m++ ;
344 bb += mbb ; // pointeur sur la nouvelle matrice de passage
345
346 } // fin de la boucle (ip) sur phi
347
348// Mise a zero des coefficients de sin( np/2 phi ) (k=np+1)
349
350//## verif :
351// assert(resu == cfo + (np+2)*ntnr) ;
352
353 // Menage
354 delete [] som ;
355
356}
357}
Lorene prototypes.
Definition app_hor.h:64