LORENE
chb_cossinc_leg.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)) a partir des coefficients du
28 * developpement en cos(j*theta) [m pair] / sin(j * theta) [m impair]
29 * representant une fonction 3-D.
30 *
31 * Entree:
32 * -------
33 * const int* deg : tableau du nombre effectif de degres de liberte dans chacune
34 * des 3 dimensions:
35 * deg[0] = np : nombre de points de collocation en phi
36 * deg[1] = nt : nombre de points de collocation en theta
37 * deg[2] = nr : nombre de points de collocation en r
38 *
39 * const double* cfi : tableau des coefficients c_j du develop. en cos/sin definis
40 * comme suit (a r et phi fixes)
41 *
42 * pour m pair: f(theta) = som_{j=0}^{nt-1} c_j cos( j theta )
43 *
44 * pour m impair: f(theta) = som_{j=0}^{nt-2} c_j sin( j theta )
45 *
46 * L'espace memoire correspondant au pointeur cfi doit etre
47 * nr*nt*(np+2) et doit avoir ete alloue avant
48 * l'appel a la routine.
49 * Le coefficient c_j (0 <= j <= nt-1) doit etre stoke dans le
50 * tableau cfi comme suit
51 * c_j = cfi[ nr*nt* k + i + nr* j ]
52 * ou k et i sont les indices correspondant a
53 * phi et r respectivement: m = k/2.
54 * Pour m impair, c_0 = c_{nt-1} = 0.
55 *
56 * Sortie:
57 * -------
58 * double* cfo : tableau des coefficients a_l du develop. en fonctions de
59 * Legendre associees P_n^m:
60 *
61 * pour m pair: f(theta) =
62 * som_{l=m}^{nt-1} a_l P_{l}^m( cos(theta) )
63 *
64 * pour m impair: f(theta) =
65 * som_{l=m}^{nt-2} a_l P_{l}^m( cos(theta) )
66 *
67 * ou P_n^m(x) represente la fonction de Legendre associee
68 * de degre n et d'ordre m normalisee de facon a ce que
69 *
70 * int_0^pi [ P_n^m(cos(theta)) ]^2 sin(theta) dtheta = 1
71 *
72 * L'espace memoire correspondant au pointeur cfo doit etre
73 * nr*nt*(np+2) et doit avoir ete alloue avant
74 * l'appel a la routine.
75 * Le coefficient a_l (0 <= l <= nt-1) est stoke dans le
76 * tableau cfo comme suit
77 * a_l = cfo[ nr*nt* k + i + nr* l ]
78 * ou k et i sont les indices correspondant a phi et r
79 * respectivement: m = k/2.
80 * NB: pour m pair et l < m, a_l = 0
81 * pour m impair et l < m, a_l = 0
82 *
83 * NB:
84 * ---
85 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
86 */
87
88/*
89 * $Id: chb_cossinc_leg.C,v 1.6 2016/12/05 16:18:00 j_novak Exp $
90 * $Log: chb_cossinc_leg.C,v $
91 * Revision 1.6 2016/12/05 16:18:00 j_novak
92 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
93 *
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 2005/02/16 15:23:23 m_forot
105 * Replace int1d_chebp by int1d_cheb
106 *
107 * Revision 1.1 2004/11/23 15:13:50 m_forot
108 * Added the bases for the cases without any equatorial symmetry
109 * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
110 *
111 *
112 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_cossinc_leg.C,v 1.6 2016/12/05 16:18:00 j_novak Exp $
113 *
114 */
115
116// headers du C
117#include <cassert>
118#include <cstdlib>
119
120// Prototypage
121#include "headcpp.h"
122#include "proto.h"
123
124namespace Lorene {
125//******************************************************************************
126
127void chb_cossinc_leg(const int* deg , const double* cfi, double* cfo) {
128
129// Espace de travail realloue eventuellement a chaque appel :
130
131int ip, k2, l, jmin, j, i, m ;
132
133// Nombres de degres de liberte en phi et theta :
134 int np = deg[0] ;
135 int nt = deg[1] ;
136 int nr = deg[2] ;
137
138 assert(np < 4*nt) ;
139
140 // Tableau de travail
141 double* som = new double[nr] ;
142
143// Recherche de la matrice de passage cos/sin --> Legendre
144 double* aa = mat_cossinc_leg(np, nt) ;
145
146// Increment en m pour la matrice aa :
147 int maa = nt * nt ;
148
149//## Test
150// double* aat = aa ;
151// for ( m=0; m < np/2+1 ; m++) {
152// cout << "---------------------------------------" << endl ;
153// cout << " m = " << m << endl ;
154// cout << " " << endl ;
155//
156// for (l=m/2; l<nt; l++) {
157// cout << " l = " << l << " : " ;
158// for (j=0; j<nt; j++) {
159// cout << aat[nt*l + j] << " " ;
160// }
161// cout << endl ;
162// }
163// arrete() ;
164// aat += maa ; // pointeur sur la nouvelle matrice de passage
165// }
166//##
167
168// Pointeurs de travail :
169 double* resu = cfo ;
170 const double* cc = cfi ;
171
172// Increment en phi :
173 int ntnr = nt * nr ;
174
175// Indice courant en phi :
176 int k = 0 ;
177
178// Ordre des harmoniques du developpement de Fourier en phi :
179 m = 0 ;
180
181// --------------
182// Boucle sur phi : k = 4*ip 4*ip+1 4*ip+2 4*ip+3
183// -------------- m = 2*ip 2*ip 2*ip+1 2*ip+1
184// k2 = 0 1 0 1
185
186 for (ip=0; ip < np/4 + 1 ; ip++) {
187
188//--------------------------------
189// Partie m pair
190//--------------------------------
191
192
193 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
194
195 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
196 // et sin( np/2 phi) a zero
197 for (l=0; l<nt; l++) {
198 for (i=0; i<nr; i++) {
199 *resu = 0 ;
200 resu++ ;
201 }
202 }
203 }
204 else {
205
206// Boucle sur l'indice l du developpement en Legendre
207
208 for (l=0; l<m; l++) {
209 for (i=0; i<nr; i++) {
210 *resu = 0 ;
211 resu++ ;
212 }
213 }
214// ... produit matriciel (parallelise sur r)
215 for (l=m; l<nt; l++) {
216 for (i=0; i<nr; i++) {
217 som[i] = 0 ;
218 }
219
220 jmin = ( m == 0 ) ? l : 0 ; // pour m=0, aa_lj = 0 pour j<l
221 for (j=jmin; j<nt; j++) {
222 double amlj = aa[nt*l + j] ;
223 for (i=0; i<nr; i++) {
224 som[i] += amlj * cc[nr*j + i] ;
225 }
226 }
227
228 for (i=0; i<nr; i++) {
229 *resu = som[i] ;
230 resu++ ;
231 }
232
233 } // fin de la boucle sur l
234
235 } // fin du cas k != 1
236
237// On passe au phi suivant :
238 cc = cc + ntnr ;
239 k++ ;
240
241 } // fin de la boucle sur k2
242
243// On passe a l'harmonique en phi suivante :
244 m++ ;
245 aa += maa ; // pointeur sur la nouvelle matrice de passage
246
247//--------------------------------
248// Partie m impair
249//--------------------------------
250
251 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
252
253 if ( k == np+1 ) { // On met les coef de
254 // sin( np/2 phi) a zero
255 for (l=0; l<nt; l++) {
256 for (i=0; i<nr; i++) {
257 *resu = 0 ;
258 resu++ ;
259 }
260 }
261 }
262
263 if (k < np+1) {
264
265// Boucle sur l'indice l du developpement en Legendre
266 for (l=0; l<m; l++) {
267 for (i=0; i<nr; i++) {
268 *resu = 0 ;
269 resu++ ;
270 }
271 }
272
273// ... produit matriciel (parallelise sur r)
274 for (l=m; l<nt-1; l++) {
275 for (i=0; i<nr; i++) {
276 som[i] = 0 ;
277 }
278
279 jmin = ( m == 1 ) ? l : 0 ; // pour m=1, aa_lj = 0 pour j<l
280
281 for (j=jmin; j<nt-1; j++) {
282 double amlj = aa[nt*l + j] ;
283 for (i=0; i<nr; i++) {
284 som[i] += amlj * cc[nr*j + i] ;
285
286 }
287 }
288
289 for (i=0; i<nr; i++) {
290 *resu = som[i] ;
291 resu++ ;
292 }
293
294 } // fin de la boucle sur l
295
296// Dernier coef en l=nt-1 mis a zero pour le cas m impair :
297 for (i=0; i<nr; i++) {
298 *resu = 0 ;
299 resu++ ;
300 }
301
302
303// On passe au phi suivant :
304 cc = cc + ntnr ;
305 k++ ;
306
307 } // fin du cas k < np+1
308
309 } // fin de la boucle sur k2
310
311
312// On passe a l'harmonique en phi suivante :
313 m++ ;
314 aa += maa ; // pointeur sur la nouvelle matrice de passage
315
316 } // fin de la boucle (ip) sur phi
317
318// Mise a zero des coefficients de sin( np/2 phi ) (k=np+1)
319
320//## verif :
321// assert(resu == cfo + (np+2)*ntnr) ;
322
323 // Menage
324 delete [] som ;
325
326}
327}
Lorene prototypes.
Definition app_hor.h:67