LORENE
chb_cossinci_legi.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) en fonctions
27 * associees de Legendre P_l^m(cos(theta)) (l-m impair) a partir des
28 * coefficients du developpement en
29 * cos[(2*j+1)*theta] [m pair] / sin(2*j* theta) [m impair]
30 * representant 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 c_j du develop. en cos/sin definis
42 * comme suit (a r et phi fixes)
43 *
44 * pour m pair: f(theta) = som_{j=0}^{nt-2} c_j cos( (2 j+1) theta )
45 *
46 * pour m impair: f(theta) = som_{j=1}^{nt-2} c_j sin( 2j theta )
47 *
48 * L'espace memoire correspondant au pointeur cfi doit etre
49 * nr*nt*(np+2) et doit avoir ete alloue avant
50 * l'appel a la routine.
51 * Le coefficient c_j (0 <= j <= nt-1) doit etre stoke dans le
52 * tableau cfi comme suit
53 * c_j = cfi[ nr*nt* k + i + nr* j ]
54 * ou k et i sont les indices correspondant a
55 * phi et r respectivement: m = k/2.
56 * Pour m pair, c_{nt-1} = 0.
57 * Pour m impair, c_0 = c_{nt-1} = 0.
58 *
59 * Sortie:
60 * -------
61 * double* cfo : tableau des coefficients a_l du develop. en fonctions de
62 * Legendre associees P_n^m impaires:
63 *
64 * pour m pair: f(theta) =
65 * som_{l=m/2}^{nt-2} a_l P_{2l+1}^m( cos(theta) )
66 *
67 * pour m impair: f(theta) =
68 * som_{l=(m+1)/2}^{nt-2} a_l P_{2l}^m( cos(theta) )
69 *
70 * ou P_n^m(x) represente la fonction de Legendre associee
71 * de degre n et d'ordre m normalisee de facon a ce que
72 *
73 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
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 a_l (0 <= l <= nt-1) est stoke dans le
79 * tableau cfo comme suit
80 * a_l = cfo[ nr*nt* k + i + nr* l ]
81 * ou k et i sont les indices correspondant a phi et r
82 * respectivement: m = k/2.
83 * NB: pour m pair: si l < m/2 ou l = nt-1, a_l = 0
84 * pour m impair: si l < (m+1)/2 ou l = nt-1, a_l = 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_cossinci_legi.C,v 1.6 2016/12/05 16:18:00 j_novak Exp $
93 * $Log: chb_cossinci_legi.C,v $
94 * Revision 1.6 2016/12/05 16:18:00 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:41 hyc
115 * *** empty log message ***
116 *
117 *
118 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cossinci_legi.C,v 1.6 2016/12/05 16:18:00 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
131namespace Lorene {
132//******************************************************************************
133
134void chb_cossinci_legi(const int* deg , const double* cfi, double* cfo) {
135
136// Espace de travail realloue eventuellement a chaque appel :
137
138int ip, k2, l, jmin, j, i, m ;
139
140// Nombres de degres de liberte en phi et theta :
141 int np = deg[0] ;
142 int nt = deg[1] ;
143 int nr = deg[2] ;
144
145 assert(np < 4*nt) ;
146
147 // Tableau de travail
148 double* som = new double[nr] ;
149
150// Recherche de la matrice de passage cos/sin --> Legendre
151 double* aa = mat_cossinci_legi(np, nt) ;
152
153// Increment en m pour la matrice aa :
154 int maa = nt * nt ;
155
156// Pointeurs de travail :
157 double* resu = cfo ;
158 const double* cc = cfi ;
159
160// Increment en phi :
161 int ntnr = nt * nr ;
162
163// Indice courant en phi :
164 int k = 0 ;
165
166// Ordre des harmoniques du developpement de Fourier en phi :
167 m = 0 ;
168
169// --------------
170// Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3
171// -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1
172// k2 = 0 1 0 1
173
174 for (ip=0; ip < np/4 + 1 ; ip++) {
175
176//--------------------------------
177// Partie m pair
178//--------------------------------
179
180
181 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
182
183 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
184 // et sin( np/2 phi) a zero
185 for (l=0; l<nt; l++) {
186 for (i=0; i<nr; i++) {
187 *resu = 0 ;
188 resu++ ;
189 }
190 }
191 }
192 else {
193
194// Boucle sur l'indice l du developpement en Legendre
195
196 //... 0 <= l <= m/2 - 1 : a_l = 0
197 for (l=0; l<m/2; l++) {
198 for (i=0; i<nr; i++) {
199 *resu = 0 ;
200 resu++ ;
201 }
202 }
203
204 //... m/2 <= l <= nt-2 : produit matriciel (parallelise sur r)
205 for (l=m/2; l<nt-1; l++) {
206 for (i=0; i<nr; i++) {
207 som[i] = 0 ;
208 }
209
210 //## jmin = ( m == 0 ) ? l : 0 ; // pour m=0, aa_lj = 0 pour j<l
211 jmin = 0 ;
212 for (j=jmin; j<nt-1; j++) {
213 double amlj = aa[nt*l + j] ;
214 for (i=0; i<nr; i++) {
215 som[i] += amlj * cc[nr*j + i] ;
216 }
217 }
218
219 for (i=0; i<nr; i++) {
220 *resu = som[i] ;
221 resu++ ;
222 }
223
224 } // fin de la boucle sur l
225
226
227 //... l = nt-1 : a_l = 0
228 for (i=0; i<nr; i++) {
229 *resu = 0 ;
230 resu++ ;
231 }
232
233 } // fin du cas k != 1
234
235// On passe au phi suivant :
236 cc = cc + ntnr ;
237 k++ ;
238
239 } // fin de la boucle sur k2
240
241// On passe a l'harmonique en phi suivante :
242 m++ ;
243 aa += maa ; // pointeur sur la nouvelle matrice de passage
244
245//--------------------------------
246// Partie m impair
247//--------------------------------
248
249 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
250
251 if ( k == np+1 ) { // On met les coef de
252 // sin( np/2 phi) a zero
253 for (l=0; l<nt; l++) {
254 for (i=0; i<nr; i++) {
255 *resu = 0 ;
256 resu++ ;
257 }
258 }
259 }
260
261 if (k < np+1) {
262
263// Boucle sur l'indice l du developpement en Legendre
264
265 //... 0 <= l <= (m-1)/2 : a_l = 0
266
267 for (l=0; l<(m+1)/2; l++) {
268 for (i=0; i<nr; i++) {
269 *resu = 0 ;
270 resu++ ;
271 }
272 }
273
274 //... (m+1)/2 <= l <= nt-2 : produit matriciel (parallelise sur r)
275 for (l=(m+1)/2; l<nt-1; l++) {
276 for (i=0; i<nr; i++) {
277 som[i] = 0 ;
278 }
279
280 //## jmin = ( m == 1 ) ? l : 0 ; // pour m=1, aa_lj = 0 pour j<l
281 jmin = 1 ; // pour j=0, sin(2*j*theta)=0
282
283 for (j=jmin; j<nt-1; j++) {
284 double amlj = aa[nt*l + j] ;
285 for (i=0; i<nr; i++) {
286 som[i] += amlj * cc[nr*j + i] ;
287 }
288 }
289
290 for (i=0; i<nr; i++) {
291 *resu = som[i] ;
292 resu++ ;
293 }
294
295 } // fin de la boucle sur l
296
297 //... l = nt-1 : a_l = 0
298 for (i=0; i<nr; i++) {
299 *resu = 0 ;
300 resu++ ;
301 }
302
303
304// On passe au phi suivant :
305 cc = cc + ntnr ;
306 k++ ;
307
308 } // fin du cas k < np+1
309
310 } // fin de la boucle sur k2
311
312
313// On passe a l'harmonique en phi suivante :
314 m++ ;
315 aa += maa ; // pointeur sur la nouvelle matrice de passage
316
317 } // fin de la boucle (ip) sur phi
318
319// Mise a zero des coefficients de sin( np/2 phi ) (k=np+1)
320
321//## verif :
322 assert(resu == cfo + (np+2)*ntnr) ;
323
324 // Menage
325 delete [] som ;
326
327}
328}
Lorene prototypes.
Definition app_hor.h:67