LORENE
chb_legpi_sini.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 sin((2j+1) theta)
28 * a partir des coefficients du developpement en fonctions
29 * associees de Legendre P_l^m(cos(theta)) (l impair et m impair)
30 * pour une une fonction 3-D symetrique par rapport au plan equatorial
31 * z = 0 et antisymetrique 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_j du develop. en fonctions de
42 * Legendre associees P_n^m:
43 *
44 * f(theta) =
45 * som_{l=(m-1)/2}^{nt-2} a_j P_{2j+1}^m( cos(theta) )
46 *
47 * (m impair)
48 *
49 * ou P_l^m(x) represente la fonction de Legendre associee
50 * de degre l et d'ordre m normalisee de facon a ce que
51 *
52 * int_0^pi [ P_l^m(cos(theta)) ]^2 sin(theta) dtheta = 1
53 *
54 * L'espace memoire correspondant au pointeur cfi doit etre
55 * nr*nt*(np+2) et doit avoir ete alloue avant
56 * l'appel a la routine.
57 * Le coefficient a_j (0 <= j <= nt-1) doit etre stoke dans le
58 * tableau cfi comme suit
59 * a_j = cfi[ nr*nt* k + i + nr* j ]
60 * ou k et i sont les indices correspondant a phi et r
61 * respectivement: m = 2 (k/2).
62 * NB: pour j<(m-1)/2, a_j = 0
63 *
64 * Sortie:
65 * -------
66 * double* cfo : tableau des coefficients c_j du develop. en sin definis
67 * comme suit (a r et phi fixes) :
68 *
69 * f(theta) = som_{j=0}^{nt-2} c_j sin( (2j+1) theta )
70 *
71 * L'espace memoire correspondant au pointeur cfo doit etre
72 * nr*nt*(np+2) et doit avoir ete alloue avant
73 * l'appel a la routine.
74 * Le coefficient c_j (0 <= j <= nt-1) est stoke dans le
75 * tableau cfo comme suit
76 * c_j = cfo[ nr*nt* k + i + nr* j ]
77 * ou k et i sont les indices correspondant a
78 * phi et r respectivement.
79 * NB: c_{nt-1} = 0.
80 *
81 *
82 * NB:
83 * ---
84 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
85 */
86
87/*
88 * $Id: chb_legpi_sini.C,v 1.7 2016/12/05 16:18:01 j_novak Exp $
89 * $Log: chb_legpi_sini.C,v $
90 * Revision 1.7 2016/12/05 16:18:01 j_novak
91 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
92 *
93 * Revision 1.6 2014/10/13 08:53:11 j_novak
94 * Lorene classes and functions now belong to the namespace Lorene.
95 *
96 * Revision 1.5 2014/10/06 15:16:00 j_novak
97 * Modified #include directives to use c++ syntax.
98 *
99 * Revision 1.4 2005/02/18 13:14:11 j_novak
100 * Changing of malloc/free to new/delete + suppression of some unused variables
101 * (trying to avoid compilation warnings).
102 *
103 * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
104 * Suppressed the directive #include <malloc.h> for malloc is defined
105 * in <stdlib.h>
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.1 2000/11/14 15:12:11 eric
115 * Traitement du cas np=1
116 *
117 * Revision 2.0 2000/09/29 16:07:35 eric
118 * *** empty log message ***
119 *
120 *
121 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legpi_sini.C,v 1.7 2016/12/05 16:18:01 j_novak Exp $
122 *
123 */
124
125// headers du C
126#include <cstdlib>
127#include <cassert>
128
129// Headers Lorene
130#include "headcpp.h"
131#include "proto.h"
132
133namespace Lorene {
134//******************************************************************************
135
136void chb_legpi_sini(const int* deg , const double* cfi, double* cfo) {
137
138int k2, l, 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 assert( cfi != cfo ) ;
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_legpi_sini(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 // Cas k=0 (m=1 : cos(phi))
168 // ------------------------
169
170 // Boucle sur l'indice j du developpement en sin( (2j+1) theta)
171
172 for (j=0; j<nt-1; j++) {
173
174 // ... produit matriciel (parallelise sur r)
175 for (i=0; i<nr; i++) {
176 som[i] = 0 ;
177 }
178
179 for (l=0; l<nt-1; l++) {
180 double bmjl = bb[nt*j + l] ;
181 for (i=0; i<nr; i++) {
182 som[i] += bmjl * cc[nr*l + i] ;
183 }
184 }
185
186 for (i=0; i<nr; i++) {
187 *resu = som[i] ;
188 resu++ ;
189 }
190
191 } // fin de la boucle sur j
192
193 // Dernier coef en j=nt-1 mis a zero pour le cas m impair :
194 for (i=0; i<nr; i++) {
195 *resu = 0 ;
196 resu++ ;
197 }
198
199 // Special case np=1 (axisymmetry)
200 // -------------------------------
201 if (np==1) {
202 for (i=0; i<2*ntnr; i++) {
203 *resu = 0 ;
204 resu++ ;
205 }
206 delete [] som ;
207 return ;
208 }
209
210 // On passe au phi suivant :
211 cc = cc + ntnr ;
212 k++ ;
213
214 // Cas k=1 : tout est mis a zero
215 // -----------------------------
216
217 for (l=0; l<nt; l++) {
218 for (i=0; i<nr; i++) {
219 *resu = 0 ;
220 resu++ ;
221 }
222 }
223
224 // On passe au phi suivant :
225 cc = cc + ntnr ;
226 k++ ;
227
228 // Cas k=2 (m=1 : sin(phi))
229 // ------------------------
230
231 // Boucle sur l'indice j du developpement en sin( (2j+1) theta)
232
233 for (j=0; j<nt-1; j++) {
234
235 // ... produit matriciel (parallelise sur r)
236 for (i=0; i<nr; i++) {
237 som[i] = 0 ;
238 }
239
240 for (l=0; l<nt-1; l++) {
241 double bmjl = bb[nt*j + l] ;
242 for (i=0; i<nr; i++) {
243 som[i] += bmjl * cc[nr*l + i] ;
244 }
245 }
246
247 for (i=0; i<nr; i++) {
248 *resu = som[i] ;
249 resu++ ;
250 }
251
252 } // fin de la boucle sur j
253
254 // Dernier coef en j=nt-1 mis a zero pour le cas m impair :
255 for (i=0; i<nr; i++) {
256 *resu = 0 ;
257 resu++ ;
258 }
259
260 // On passe au phi suivant :
261 cc = cc + ntnr ;
262 k++ ;
263
264 // On passe au m suivant :
265 bb += mbb ; // pointeur sur la nouvelle matrice de passage
266
267 // Cas k >= 3
268 // ----------
269
270 for (m=3; m < np ; m+=2) {
271
272 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
273
274 // Boucle sur l'indice j du developpement en sin( (2j+1) theta)
275
276 for (j=0; j<nt-1; j++) {
277
278 // ... produit matriciel (parallelise sur r)
279 for (i=0; i<nr; i++) {
280 som[i] = 0 ;
281 }
282
283 for (l=(m-1)/2; l<nt-1; l++) {
284 double bmjl = bb[nt*j + l] ;
285 for (i=0; i<nr; i++) {
286 som[i] += bmjl * cc[nr*l + 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 j
296
297 // Dernier coef en j=nt-1 mis a zero pour le cas m impair :
298 for (i=0; i<nr; i++) {
299 *resu = 0 ;
300 resu++ ;
301 }
302
303 // On passe au phi suivant :
304 cc = cc + ntnr ;
305 k++ ;
306
307 } // fin de la boucle sur k2
308
309 // On passe a l'harmonique en phi suivante :
310 bb += mbb ; // pointeur sur la nouvelle matrice de passage
311
312 } // fin de la boucle (m) sur phi
313
314
315 // Cas k=np+1 : tout est mis a zero
316 // --------------------------------
317
318 for (l=0; l<nt; l++) {
319 for (i=0; i<nr; i++) {
320 *resu = 0 ;
321 resu++ ;
322 }
323 }
324
325
326//## verif :
327 assert(resu == cfo + (np+2)*ntnr) ;
328
329 // Menage
330 delete [] som ;
331
332}
333}
Lorene prototypes.
Definition app_hor.h:67