LORENE
chb_sini_legpi.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_sini_legpi_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_sini_legpi.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $" ;
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 sin((2j+1)*theta)
29 * representant une fonction 3-D symetrique par rapport au plan equatorial
30 * z = 0 et antisymetrique par le retournement (x, y, z) --> (-x, -y, z).
31 *
32 * Entree:
33 * -------
34 * const int* deg : tableau du nombre effectif de degres de liberte dans chacune
35 * des 3 dimensions:
36 * deg[0] = np : nombre de points de collocation en phi
37 * deg[1] = nt : nombre de points de collocation en theta
38 * deg[2] = nr : nombre de points de collocation en r
39 *
40 * const double* cfi : tableau des coefficients c_j du develop. en cos defini
41 * comme suit (a r et phi fixes)
42 *
43 * f(theta) = som_{j=0}^{nt-2} c_j sin( (2j+1) theta )
44 *
45 * L'espace memoire correspondant au pointeur cfi doit etre
46 * nr*nt*(np+2) et doit avoir ete alloue avant
47 * l'appel a la routine.
48 * Le coefficient c_j (0 <= j <= nt-2) doit etre stoke dans le
49 * tableau cfi comme suit
50 * c_j = cfi[ nr*nt* k + i + nr* j ]
51 * ou k et i sont les indices correspondant a
52 * phi et r respectivement. On a c_{nt-1} = 0.
53 *
54 * Sortie:
55 * -------
56 * double* cfo : tableau des coefficients a_j du develop. en fonctions de
57 * Legendre associees P_l^m (l impair, m impair)
58 *
59 * f(theta) =
60 * som_{l=(m-1)/2}^{nt-2} a_j P_{2j+1}^m( cos(theta) )
61 *
62 * avec m impair.
63 *
64 * P_l^m(x) represente la fonction de Legendre associee
65 * de degre l et d'ordre m normalisee de facon a ce que
66 *
67 * int_0^pi [ P_l^m(cos(theta)) ]^2 sin(theta) dtheta = 1
68 *
69 * L'espace memoire correspondant au pointeur cfo doit etre
70 * nr*nt*(np+2) et doit avoir ete alloue avant
71 * l'appel a la routine.
72 * Le coefficient a_j (0 <= j <= nt-1) est stoke dans le
73 * tableau cfo comme suit
74 * a_j = cfo[ nr*nt* k + i + nr* j ]
75 * ou k et i sont les indices correspondant a phi et r
76 * respectivement: m = 2( k/2 ).
77 * NB: pour j<(m-1)/2, a_j = 0
78 *
79 * NB:
80 * ---
81 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
82 */
83
84/*
85 * $Id: chb_sini_legpi.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $
86 * $Log: chb_sini_legpi.C,v $
87 * Revision 1.6 2014/10/13 08:53:11 j_novak
88 * Lorene classes and functions now belong to the namespace Lorene.
89 *
90 * Revision 1.5 2014/10/06 15:16:01 j_novak
91 * Modified #include directives to use c++ syntax.
92 *
93 * Revision 1.4 2005/02/18 13:14:12 j_novak
94 * Changing of malloc/free to new/delete + suppression of some unused variables
95 * (trying to avoid compilation warnings).
96 *
97 * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
98 * Suppressed the directive #include <malloc.h> for malloc is defined
99 * in <stdlib.h>
100 *
101 * Revision 1.2 2002/10/16 14:36:53 j_novak
102 * Reorganization of #include instructions of standard C++, in order to
103 * use experimental version 3 of gcc.
104 *
105 * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
106 * LORENE
107 *
108 * Revision 2.1 2000/11/14 15:12:18 eric
109 * Traitement du cas np=1
110 *
111 * Revision 2.0 2000/09/29 16:08:39 eric
112 * *** empty log message ***
113 *
114 *
115 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_sini_legpi.C,v 1.6 2014/10/13 08:53:11 j_novak Exp $
116 *
117 */
118
119// headers du C
120#include <cassert>
121#include <cstdlib>
122
123// Prototypage
124#include "headcpp.h"
125#include "proto.h"
126
127namespace Lorene {
128//******************************************************************************
129
130void chb_sini_legpi(const int* deg , const double* cfi, double* cfo) {
131
132int k2, l, jmin, j, i, m ;
133
134 // Nombres de degres de liberte en phi et theta :
135 int np = deg[0] ;
136 int nt = deg[1] ;
137 int nr = deg[2] ;
138
139 assert(np < 4*nt) ;
140 assert( cfi != cfo ) ;
141
142 // Tableau de travail
143 double* som = new double[nr] ;
144
145 // Recherche de la matrice de passage cos --> Legendre
146 double* aa = mat_sini_legpi(np, nt) ;
147
148 // Increment en m pour la matrice aa :
149 int maa = nt * nt ;
150
151 // Pointeurs de travail :
152 double* resu = cfo ;
153 const double* cc = cfi ;
154
155 // Increment en phi :
156 int ntnr = nt * nr ;
157
158 // Indice courant en phi :
159 int k = 0 ;
160
161 // Cas k=0 (m=1 : cos(phi))
162 // ------------------------
163
164 // ... produit matriciel (parallelise sur r)
165 for (l=0; l<nt-1; l++) {
166 for (i=0; i<nr; i++) {
167 som[i] = 0 ;
168 }
169
170 jmin = l ; // pour m=1, aa_lj = 0 pour j<l
171
172 for (j=jmin; j<nt-1; j++) {
173 double amlj = aa[nt*l + j] ;
174 for (i=0; i<nr; i++) {
175 som[i] += amlj * cc[nr*j + i] ;
176 }
177 }
178
179 for (i=0; i<nr; i++) {
180 *resu = som[i] ;
181 resu++ ;
182 }
183
184 } // fin de la boucle sur l
185
186 // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
187 for (i=0; i<nr; i++) {
188 *resu = 0 ;
189 resu++ ;
190 }
191
192 // Special case np=1 (axisymmetry)
193 // -------------------------------
194 if (np==1) {
195 for (i=0; i<2*ntnr; i++) {
196 *resu = 0 ;
197 resu++ ;
198 }
199 delete [] som ;
200 return ;
201 }
202
203
204 // On passe au phi suivant :
205 cc = cc + ntnr ;
206 k++ ;
207
208 // Cas k=1 : tout est mis a zero
209 // -----------------------------
210
211 for (l=0; l<nt; l++) {
212 for (i=0; i<nr; i++) {
213 *resu = 0 ;
214 resu++ ;
215 }
216 }
217
218 // On passe au phi suivant :
219 cc = cc + ntnr ;
220 k++ ;
221
222 // Cas k=2 (m=1 : sin(phi))
223 // ------------------------
224
225 // ... produit matriciel (parallelise sur r)
226 for (l=0; l<nt-1; l++) {
227 for (i=0; i<nr; i++) {
228 som[i] = 0 ;
229 }
230
231 jmin = l ; // pour m=1, aa_lj = 0 pour j<l
232
233 for (j=jmin; j<nt-1; j++) {
234 double amlj = aa[nt*l + j] ;
235 for (i=0; i<nr; i++) {
236 som[i] += amlj * cc[nr*j + i] ;
237 }
238 }
239
240 for (i=0; i<nr; i++) {
241 *resu = som[i] ;
242 resu++ ;
243 }
244
245 } // fin de la boucle sur l
246
247 // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
248 for (i=0; i<nr; i++) {
249 *resu = 0 ;
250 resu++ ;
251 }
252
253 // On passe au phi suivant :
254 cc = cc + ntnr ;
255 k++ ;
256
257 // On passe au m suivant
258 aa += maa ; // pointeur sur la nouvelle matrice de passage
259
260 // Cas k >= 3
261 // ----------
262
263 for (m=3; m < np ; m+=2) {
264
265 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
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 // ... 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 = 0 ;
281
282 for (j=jmin; j<nt-1; j++) {
283 double amlj = aa[nt*l + j] ;
284 for (i=0; i<nr; i++) {
285 som[i] += amlj * cc[nr*j + i] ;
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 // On passe au phi suivant :
303 cc = cc + ntnr ;
304 k++ ;
305
306 } // fin de la boucle sur k2
307
308 // On passe a l'harmonique en phi suivante :
309
310 aa += maa ; // pointeur sur la nouvelle matrice de passage
311
312 } // fin de la boucle (m) sur phi
313
314 // Cas k=np+1 : tout est mis a zero
315 // --------------------------------
316
317 for (l=0; l<nt; l++) {
318 for (i=0; i<nr; i++) {
319 *resu = 0 ;
320 resu++ ;
321 }
322 }
323
324
325//## verif :
326 assert(resu == cfo + (np+2)*ntnr) ;
327
328 // Menage
329 delete [] som ;
330
331}
332}
Lorene prototypes.
Definition app_hor.h:64