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
23char chb_legpp_cosp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legpp_cosp.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)
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.7 2014/10/13 08:53:11 j_novak Exp $
88 * $Log: chb_legpp_cosp.C,v $
89 * Revision 1.7 2014/10/13 08:53:11 j_novak
90 * Lorene classes and functions now belong to the namespace Lorene.
91 *
92 * Revision 1.6 2014/10/06 15:16:01 j_novak
93 * Modified #include directives to use c++ syntax.
94 *
95 * Revision 1.5 2005/02/18 13:14:11 j_novak
96 * Changing of malloc/free to new/delete + suppression of some unused variables
97 * (trying to avoid compilation warnings).
98 *
99 * Revision 1.4 2003/12/19 16:21:46 j_novak
100 * Shadow hunt
101 *
102 * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
103 * Suppressed the directive #include <malloc.h> for malloc is defined
104 * in <stdlib.h>
105 *
106 * Revision 1.2 2002/10/16 14:36:53 j_novak
107 * Reorganization of #include instructions of standard C++, in order to
108 * use experimental version 3 of gcc.
109 *
110 * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
111 * LORENE
112 *
113 * Revision 2.1 2000/09/29 16:08:20 eric
114 * Mise a zero des coefficients k=1 et k=2 dans le cas np=1.
115 *
116 * Revision 2.0 1999/02/22 15:44:48 hyc
117 * *** empty log message ***
118 *
119 *
120 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legpp_cosp.C,v 1.7 2014/10/13 08:53:11 j_novak Exp $
121 *
122 */
123
124
125
126// headers du C
127#include <cstdlib>
128#include <cassert>
129
130// Prototypage
131#include "headcpp.h"
132#include "proto.h"
133
134namespace Lorene {
135//******************************************************************************
136
137void chb_legpp_cosp(const int* deg , const double* cfi, double* cfo) {
138
139int k2, l, 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 Legendre --> cos/sin
152 double* bb = mat_legpp_cosp(np, nt) ;
153
154// Increment en m pour la matrice bb :
155 int mbb = 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 j du developpement en cos(2 j theta)
176
177 for (j=0; j<nt; j++) {
178
179// ... produit matriciel (parallelise sur r)
180 for (i=0; i<nr; i++) {
181 som[i] = 0 ;
182 }
183
184 for (l=m/2; l<nt; l++) {
185
186 double bmjl = bb[nt*j + l] ;
187 for (i=0; i<nr; i++) {
188 som[i] += bmjl * cc[nr*l + i] ;
189 }
190 }
191
192 for (i=0; i<nr; i++) {
193 *resu = som[i] ;
194 resu++ ;
195 }
196
197 } // fin de la boucle sur j
198
199 // Mise a zero des coefficients k=1 et k=2 :
200 // ---------------------------------------
201
202 for (i=ntnr; i<3*ntnr; i++) {
203 cfo[i] = 0 ;
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 for (m=0; m < np + 1 ; m+=2) {
221
222 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
223
224 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
225 // et sin( np phi) a zero
226 for (j=0; j<nt; j++) {
227 for (i=0; i<nr; i++) {
228 *resu = 0 ;
229 resu++ ;
230 }
231 }
232 }
233 else {
234
235// Boucle sur l'indice j du developpement en cos(2 j theta)
236
237 for (j=0; j<nt; j++) {
238
239// ... produit matriciel (parallelise sur r)
240 for (i=0; i<nr; i++) {
241 som[i] = 0 ;
242 }
243
244 for (l=m/2; l<nt; l++) {
245
246 double bmjl = bb[nt*j + l] ;
247 for (i=0; i<nr; i++) {
248 som[i] += bmjl * cc[nr*l + i] ;
249 }
250 }
251
252 for (i=0; i<nr; i++) {
253 *resu = som[i] ;
254 resu++ ;
255 }
256
257 } // fin de la boucle sur j
258
259 } // fin du cas k != 1
260
261// On passe au phi suivant :
262 cc = cc + ntnr ;
263 k++ ;
264
265 } // fin de la boucle sur k2
266
267// On passe a l'harmonique en phi suivante :
268
269 bb += mbb ; // pointeur sur la nouvelle matrice de passage
270
271 } // fin de la boucle (m) sur phi
272
273//## verif :
274 assert(resu == cfo + (np+2)*ntnr) ;
275
276 // Menage
277 delete [] som ;
278
279}
280}
Lorene prototypes.
Definition app_hor.h:64