LORENE
chb_sin_legmi.C
1/*
2 * Copyright (c) 1999-2001 Eric Gourgoulhon
3 * Copyright (c) 2009 Jerome Novak
4 *
5 * This file is part of LORENE.
6 *
7 * LORENE is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * LORENE is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with LORENE; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23
24
25
26/*
27 * Calcule les coefficients du developpement (suivant theta) en fonctions
28 * associees de Legendre P_l^m(cos(theta)) a partir des coefficients du
29 * developpement en sin(j*theta)
30 * representant une fonction 3-D antisymetrique par le retournement
31 * (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 c_j du develop. en cos defini
42 * comme suit (a r et phi fixes)
43 *
44 * f(theta) = som_{j=0}^{nt-1} 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-2) 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.
54 *
55 * Sortie:
56 * -------
57 * double* cfo : tableau des coefficients a_j du develop. en fonctions de
58 * Legendre associees P_l^m (m impair)
59 *
60 * f(theta) =
61 * som_{l=m}^{nt-1} a_j P_j^m( cos(theta) )
62 *
63 * avec m impair.
64 *
65 * P_l^m(x) represente la fonction de Legendre associee
66 * de degre l et d'ordre m normalisee de facon a ce que
67 *
68 * int_0^pi [ P_l^m(cos(theta)) ]^2 sin(theta) dtheta = 1
69 *
70 * L'espace memoire correspondant au pointeur cfo doit etre
71 * nr*nt*(np+2) et doit avoir ete alloue avant
72 * l'appel a la routine.
73 * Le coefficient a_j (0 <= j <= nt-1) est stoke dans le
74 * tableau cfo comme suit
75 * a_j = cfo[ nr*nt* k + i + nr* j ]
76 * ou k et i sont les indices correspondant a phi et r
77 * respectivement: m = 2( k/2 ).
78 * NB: pour j< m, a_j = 0
79 *
80 * NB:
81 * ---
82 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
83 */
84
85/*
86 * $Id: chb_sin_legmi.C,v 1.4 2016/12/05 16:18:01 j_novak Exp $
87 * $Log: chb_sin_legmi.C,v $
88 * Revision 1.4 2016/12/05 16:18:01 j_novak
89 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
90 *
91 * Revision 1.3 2014/10/13 08:53:11 j_novak
92 * Lorene classes and functions now belong to the namespace Lorene.
93 *
94 * Revision 1.2 2014/10/06 15:16:01 j_novak
95 * Modified #include directives to use c++ syntax.
96 *
97 * Revision 1.1 2009/10/23 12:54:47 j_novak
98 * New base T_LEG_MI
99 *
100 *
101 *
102 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_sin_legmi.C,v 1.4 2016/12/05 16:18:01 j_novak Exp $
103 *
104 */
105
106// headers du C
107#include <cassert>
108#include <cstdlib>
109
110// Prototypage
111#include "headcpp.h"
112#include "proto.h"
113
114namespace Lorene {
115//******************************************************************************
116
117void chb_sin_legmi(const int* deg , const double* cfi, double* cfo) {
118
119int k2, l, jmin, j, i, m ;
120
121 // Nombres de degres de liberte en phi et theta :
122 int np = deg[0] ;
123 int nt = deg[1] ;
124 int nr = deg[2] ;
125
126 assert(np < 4*nt) ;
127 assert( cfi != cfo ) ;
128
129 // Tableau de travail
130 double* som = new double[nr] ;
131
132 // Recherche de la matrice de passage sin --> Legendre
133 double* aa = mat_sin_legmi(np, nt) ;
134
135 // Increment en m pour la matrice aa :
136 int maa = nt * nt ;
137
138 // Pointeurs de travail :
139 double* resu = cfo ;
140 const double* cc = cfi ;
141
142 // Increment en phi :
143 int ntnr = nt * nr ;
144
145 // Indice courant en phi :
146 int k = 0 ;
147
148 // Cas k=0 (m=1 : cos(phi))
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
158 for (l=1; l<nt-1; l++) {
159 for (i=0; i<nr; i++) {
160 som[i] = 0 ;
161 }
162
163 jmin = l ; // 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
225 for (l=1; l<nt-1; l++) {
226 for (i=0; i<nr; i++) {
227 som[i] = 0 ;
228 }
229
230 jmin = l ; // 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 int lmax = (m<nt-1 ? m : nt -1) ;
266 for (l=0; l<lmax; l++) {
267 for (i=0; i<nr; i++) {
268 *resu = 0 ;
269 resu++ ;
270 }
271 }
272
273 // ... produit matriciel
274 for (l=m; 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:67