LORENE
chb_sinp_legii.C
1/*
2 * Copyright (c) 2003 Jerome Novak
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_sinp_legii_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_sinp_legii.C,v 1.4 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*theta)
29 * representant une fonction 3-D antisymetrique 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 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_0 = 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 pair, m impair)
58 *
59 * f(theta) =
60 * som_{l=(m+1)/2}^{nt-2} a_j P_{2j}^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 ou l=nt-1, 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_sinp_legii.C,v 1.4 2014/10/13 08:53:11 j_novak Exp $
86 * $Log: chb_sinp_legii.C,v $
87 * Revision 1.4 2014/10/13 08:53:11 j_novak
88 * Lorene classes and functions now belong to the namespace Lorene.
89 *
90 * Revision 1.3 2014/10/06 15:16:01 j_novak
91 * Modified #include directives to use c++ syntax.
92 *
93 * Revision 1.2 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.1 2003/09/16 08:58:01 j_novak
98 * New functions for the T_LEG_II base
99 *
100 *
101 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_sinp_legii.C,v 1.4 2014/10/13 08:53:11 j_novak Exp $
102 *
103 */
104
105// headers du C
106#include <cassert>
107#include <cstdlib>
108
109// Prototypage
110#include "headcpp.h"
111#include "proto.h"
112
113namespace Lorene {
114//******************************************************************************
115
116void chb_sinp_legii(const int* deg , const double* cfi, double* cfo) {
117
118int k2, l, jmin, j, i, m ;
119
120 // Nombres de degres de liberte en phi et theta :
121 int np = deg[0] ;
122 int nt = deg[1] ;
123 int nr = deg[2] ;
124
125 assert(np < 4*nt) ;
126 assert( cfi != cfo ) ;
127
128 // Tableau de travail
129 double* som = new double[nr] ;
130
131 // Recherche de la matrice de passage cos --> Legendre
132 double* aa = mat_sinp_legii(np, nt) ;
133
134 // Increment en m pour la matrice aa :
135 int maa = nt * nt ;
136
137 // Pointeurs de travail :
138 double* resu = cfo ;
139 const double* cc = cfi ;
140
141 // Increment en phi :
142 int ntnr = nt * nr ;
143
144 // Indice courant en phi :
145 int k = 0 ;
146
147 // Cas k=0 (m=1 : cos(phi))
148 // ------------------------
149
150
151 // Cas l=0 : a_l = 0
152 for (i=0; i<nr; i++) {
153 *resu = 0. ;
154 resu++ ;
155 }
156
157 // ... produit matriciel (parallelise sur r)
158 for (l=1; l<nt-1; l++) {
159 for (i=0; i<nr; i++) {
160 som[i] = 0 ;
161 }
162
163 jmin = 1 ; // pour m=1, aa_lj = 0 pour j<l
164
165 for (j=jmin; j<nt-1; j++) {
166 double amlj = aa[nt*l + j] ;
167 for (i=0; i<nr; i++) {
168 som[i] += amlj * cc[nr*j + i] ;
169 }
170 }
171
172 for (i=0; i<nr; i++) {
173 *resu = som[i] ;
174 resu++ ;
175 }
176
177 } // fin de la boucle sur l
178
179 // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
180 for (i=0; i<nr; i++) {
181 *resu = 0 ;
182 resu++ ;
183 }
184
185 // Special case np=1 (axisymmetry)
186 // -------------------------------
187 if (np==1) {
188 for (i=0; i<2*ntnr; i++) {
189 *resu = 0 ;
190 resu++ ;
191 }
192 delete [] som ;
193 return ;
194 }
195
196
197 // On passe au phi suivant :
198 cc = cc + ntnr ;
199 k++ ;
200
201 // Cas k=1 : tout est mis a zero
202 // -----------------------------
203
204 for (l=0; l<nt; l++) {
205 for (i=0; i<nr; i++) {
206 *resu = 0 ;
207 resu++ ;
208 }
209 }
210
211 // On passe au phi suivant :
212 cc = cc + ntnr ;
213 k++ ;
214
215 // Cas k=2 (m=1 : sin(phi))
216 // ------------------------
217
218 // Cas l=0 : a_l = 0
219 for (i=0; i<nr; i++) {
220 *resu = 0. ;
221 resu++ ;
222 }
223
224 // ... produit matriciel (parallelise sur r)
225 for (l=1; l<nt-1; l++) {
226 for (i=0; i<nr; i++) {
227 som[i] = 0 ;
228 }
229
230 jmin = 1 ; // pour m=1, aa_lj = 0 pour j<l
231
232 for (j=jmin; j<nt-1; j++) {
233 double amlj = aa[nt*l + j] ;
234 for (i=0; i<nr; i++) {
235 som[i] += amlj * cc[nr*j + i] ;
236 }
237 }
238
239 for (i=0; i<nr; i++) {
240 *resu = som[i] ;
241 resu++ ;
242 }
243
244 } // fin de la boucle sur l
245
246 // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
247 for (i=0; i<nr; i++) {
248 *resu = 0 ;
249 resu++ ;
250 }
251
252 // On passe au phi suivant :
253 cc = cc + ntnr ;
254 k++ ;
255
256 // On passe au m suivant
257 aa += maa ; // pointeur sur la nouvelle matrice de passage
258
259 // Cas k >= 3
260 // ----------
261
262 for (m=3; m < np ; m+=2) {
263
264 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
265
266 for (l=0; l<(m+1)/2; 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+1)/2; l<nt-1; l++) {
275 for (i=0; i<nr; i++) {
276 som[i] = 0 ;
277 }
278
279 jmin = 1 ;
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 for (i=0; i<nr; i++) {
289 *resu = som[i] ;
290 resu++ ;
291 }
292
293 } // fin de la boucle sur l
294
295 // Dernier coef en l=nt-1 mis a zero pour le cas m impair :
296 for (i=0; i<nr; i++) {
297 *resu = 0 ;
298 resu++ ;
299 }
300
301 // On passe au phi suivant :
302 cc = cc + ntnr ;
303 k++ ;
304
305 } // fin de la boucle sur k2
306
307 // On passe a l'harmonique en phi suivante :
308
309 aa += maa ; // pointeur sur la nouvelle matrice de passage
310
311 } // fin de la boucle (m) sur phi
312
313 // Cas k=np+1 : tout est mis a zero
314 // --------------------------------
315
316 for (l=0; l<nt; l++) {
317 for (i=0; i<nr; i++) {
318 *resu = 0 ;
319 resu++ ;
320 }
321 }
322
323
324//## verif :
325 assert(resu == cfo + (np+2)*ntnr) ;
326
327 // Menage
328 delete [] som ;
329
330}
331}
Lorene prototypes.
Definition app_hor.h:64