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
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.6 2016/12/05 16:18:01 j_novak Exp $
93 * $Log: chb_legi_cossinci.C,v $
94 * Revision 1.6 2016/12/05 16:18:01 j_novak
95 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
96 *
97 * Revision 1.5 2014/10/13 08:53:10 j_novak
98 * Lorene classes and functions now belong to the namespace Lorene.
99 *
100 * Revision 1.4 2014/10/06 15:16:00 j_novak
101 * Modified #include directives to use c++ syntax.
102 *
103 * Revision 1.3 2005/02/18 13:14:10 j_novak
104 * Changing of malloc/free to new/delete + suppression of some unused variables
105 * (trying to avoid compilation warnings).
106 *
107 * Revision 1.2 2002/10/16 14:36:52 j_novak
108 * Reorganization of #include instructions of standard C++, in order to
109 * use experimental version 3 of gcc.
110 *
111 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
112 * LORENE
113 *
114 * Revision 2.0 1999/02/22 15:45:13 hyc
115 * *** empty log message ***
116 *
117 *
118 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legi_cossinci.C,v 1.6 2016/12/05 16:18:01 j_novak Exp $
119 *
120 */
121
122// headers du C
123#include <cassert>
124#include <cstdlib>
125
126// Prototypage
127#include "headcpp.h"
128#include "proto.h"
129
130namespace Lorene {
131//******************************************************************************
132
133void chb_legi_cossinci(const int* deg , const double* cfi, double* cfo) {
134
135int ip, k2, l, j, i, m ;
136
137// Nombres de degres de liberte en phi et theta :
138 int np = deg[0] ;
139 int nt = deg[1] ;
140 int nr = deg[2] ;
141
142 assert(np < 4*nt) ;
143
144 // Tableau de travail
145 double* som = new double[nr] ;
146
147// Recherche de la matrice de passage Legendre --> cos/sin
148 double* bb = mat_legi_cossinci(np, nt) ;
149
150// Increment en m pour la matrice bb :
151 int mbb = nt * nt ;
152
153// Pointeurs de travail :
154 double* resu = cfo ;
155 const double* cc = cfi ;
156
157// Increment en phi :
158 int ntnr = nt * nr ;
159
160// Indice courant en phi :
161 int k = 0 ;
162
163// Ordre des harmoniques du developpement de Fourier en phi :
164 m = 0 ;
165
166// --------------
167// Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3
168// -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1
169// k2 = 0 1 0 1
170
171 for (ip=0; ip < np/4 + 1 ; ip++) {
172
173//--------------------------------
174// Partie m pair
175//--------------------------------
176
177
178 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
179
180 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
181 // et sin( np/2 phi) a zero
182 for (j=0; j<nt; j++) {
183 for (i=0; i<nr; i++) {
184 *resu = 0 ;
185 resu++ ;
186 }
187 }
188 }
189 else {
190
191// Boucle sur l'indice j du developpement en cos((2 j+1) theta)
192
193 //... produit matriciel (parallelise sur r)
194 for (j=0; j<nt-1; j++) {
195
196 for (i=0; i<nr; i++) {
197 som[i] = 0 ;
198 }
199
200 for (l=m/2; l<nt-1; l++) {
201
202 double bmjl = bb[nt*j + l] ;
203 for (i=0; i<nr; i++) {
204 som[i] += bmjl * cc[nr*l + i] ;
205 }
206 }
207
208 for (i=0; i<nr; i++) {
209 *resu = som[i] ;
210 resu++ ;
211 }
212
213 } // fin de la boucle sur j
214
215 //... dernier coef en j=nt-1 mis a zero:
216 for (i=0; i<nr; i++) {
217 *resu = 0 ;
218 resu++ ;
219 }
220
221 } // fin du cas k != 1
222
223// On passe au phi suivant :
224 cc = cc + ntnr ;
225 k++ ;
226
227 } // fin de la boucle sur k2
228
229// On passe a l'harmonique en phi suivante :
230 m++ ;
231 bb += mbb ; // pointeur sur la nouvelle matrice de passage
232
233//--------------------------------
234// Partie m impair
235//--------------------------------
236
237 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
238
239 if ( k == np+1 ) { // On met les coef de
240 // 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
249 if (k < np+1) {
250
251// Boucle sur l'indice j du developpement en sin( 2j theta)
252
253 //... premier coef en j=0 mis a zero:
254 for (i=0; i<nr; i++) {
255 *resu = 0 ;
256 resu++ ;
257 }
258
259 //... produit matriciel (parallelise sur r)
260
261 for (j=1; j<nt-1; j++) {
262
263 for (i=0; i<nr; i++) {
264 som[i] = 0 ;
265 }
266
267 for (l=(m+1)/2; l<nt-1; l++) {
268 double bmjl = bb[nt*j + l] ;
269 for (i=0; i<nr; i++) {
270 som[i] += bmjl * cc[nr*l + i] ;
271 }
272 }
273
274 for (i=0; i<nr; i++) {
275 *resu = som[i] ;
276 resu++ ;
277 }
278
279 } // fin de la boucle sur j
280
281 //... dernier coef en j=nt-1 mis a zero :
282 for (i=0; i<nr; i++) {
283 *resu = 0 ;
284 resu++ ;
285 }
286
287// On passe au phi suivant :
288 cc = cc + ntnr ;
289 k++ ;
290
291 } // fin du cas k < np+1
292
293 } // fin de la boucle sur k2
294
295
296// On passe a l'harmonique en phi suivante :
297 m++ ;
298 bb += mbb ; // pointeur sur la nouvelle matrice de passage
299
300 } // fin de la boucle (ip) sur phi
301
302// Mise a zero des coefficients de sin( np/2 phi ) (k=np+1)
303
304//## verif :
305 assert(resu == cfo + (np+2)*ntnr) ;
306
307 // Menage
308 delete [] som ;
309
310}
311}
Lorene prototypes.
Definition app_hor.h:67