LORENE
chb_legmi_sin.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
24char chb_legmi_sin_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legmi_sin.C,v 1.3 2014/10/13 08:53:11 j_novak Exp $" ;
25
26/*
27 * Calcule les coefficients du developpement (suivant theta)
28 * en sin(j theta)
29 * a partir des coefficients du developpement en fonctions
30 * associees de Legendre P_l^m(cos(theta)) (m impair)
31 * pour une une fonction 3-D antisymetrique par le retournement
32 * (x, y, z) --> (-x, -y, z).
33 *
34 * Entree:
35 * -------
36 * const int* deg : tableau du nombre effectif de degres de liberte dans chacune
37 * des 3 dimensions:
38 * deg[0] = np : nombre de points de collocation en phi
39 * deg[1] = nt : nombre de points de collocation en theta
40 * deg[2] = nr : nombre de points de collocation en r
41 *
42 * const double* cfi : tableau des coefficients a_j du develop. en fonctions de
43 * Legendre associees P_n^m:
44 *
45 * f(theta) =
46 * som_{l=m}^{nt-2} a_j P_j^m( cos(theta) )
47 *
48 * (m impair)
49 *
50 * ou P_l^m(x) represente la fonction de Legendre associee
51 * de degre l et d'ordre m normalisee de facon a ce que
52 *
53 * int_0^pi [ P_l^m(cos(theta)) ]^2 sin(theta) dtheta = 1
54 *
55 * L'espace memoire correspondant au pointeur cfi doit etre
56 * nr*nt*(np+2) et doit avoir ete alloue avant
57 * l'appel a la routine.
58 * Le coefficient a_j (0 <= j <= nt-1) doit etre stoke dans le
59 * tableau cfi comme suit
60 * a_j = cfi[ nr*nt* k + i + nr* j ]
61 * ou k et i sont les indices correspondant a phi et r
62 * respectivement: m = 2 (k/2).
63 * NB: pour j<m, a_j = 0
64 *
65 * Sortie:
66 * -------
67 * double* cfo : tableau des coefficients c_j du develop. en sin definis
68 * comme suit (a r et phi fixes) :
69 *
70 * f(theta) = som_{j=0}^{nt-2} c_j sin( j theta )
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 c_j (0 <= j <= nt-1) est stoke dans le
76 * tableau cfo comme suit
77 * c_j = cfo[ nr*nt* k + i + nr* j ]
78 * ou k et i sont les indices correspondant a
79 * phi et r respectivement.
80 * NB: c_{nt-1} = 0.
81 *
82 *
83 * NB:
84 * ---
85 * Il n'est pas possible d'avoir le pointeur cfo egal a cfi.
86 */
87
88/*
89 * $Id: chb_legmi_sin.C,v 1.3 2014/10/13 08:53:11 j_novak Exp $
90 * $Log: chb_legmi_sin.C,v $
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:00 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 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legmi_sin.C,v 1.3 2014/10/13 08:53:11 j_novak Exp $
102 *
103 */
104
105// headers du C
106#include <cstdlib>
107#include <cassert>
108
109// Headers Lorene
110#include "headcpp.h"
111#include "proto.h"
112
113namespace Lorene {
114//******************************************************************************
115
116void chb_legmi_sin(const int* deg , const double* cfi, double* cfo) {
117
118int k2, l, 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 Legendre --> cos/sin
132 double* bb = mat_legmi_sin(np, nt) ;
133
134// Increment en m pour la matrice bb :
135 int mbb = 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 //... premier coef en j=0 mis a zero:
151 for (i=0; i<nr; i++) {
152 *resu = 0 ;
153 resu++ ;
154 }
155
156 // Boucle sur l'indice j du developpement en sin( j theta)
157
158 for (j=1; j<nt-1; j++) {
159
160 // ... produit matriciel
161 for (i=0; i<nr; i++) {
162 som[i] = 0 ;
163 }
164
165 for (l=1; l<nt-1; l++) {
166 double bmjl = bb[nt*j + l] ;
167 for (i=0; i<nr; i++) {
168 som[i] += bmjl * cc[nr*l + 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 j
178
179 // Dernier coef en j=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 // On passe au phi suivant :
197 cc = cc + ntnr ;
198 k++ ;
199
200 // Cas k=1 : tout est mis a zero
201 // -----------------------------
202
203 for (l=0; l<nt; l++) {
204 for (i=0; i<nr; i++) {
205 *resu = 0 ;
206 resu++ ;
207 }
208 }
209
210 // On passe au phi suivant :
211 cc = cc + ntnr ;
212 k++ ;
213
214 // Cas k=2 (m=1 : sin(phi))
215 // ------------------------
216
217 //... premier coef en j=0 mis a zero:
218 for (i=0; i<nr; i++) {
219 *resu = 0 ;
220 resu++ ;
221 }
222
223 // Boucle sur l'indice j du developpement en sin( j theta)
224
225 for (j=1; j<nt-1; j++) {
226
227 // ... produit matriciel
228 for (i=0; i<nr; i++) {
229 som[i] = 0 ;
230 }
231
232 for (l=1; l<nt-1; l++) {
233 double bmjl = bb[nt*j + l] ;
234 for (i=0; i<nr; i++) {
235 som[i] += bmjl * cc[nr*l + 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 j
245
246 // Dernier coef en j=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 bb += mbb ; // 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 // Boucle sur l'indice j du developpement en sin( (2j+1) theta)
267
268 //... premier coef en j=0 mis a zero:
269 for (i=0; i<nr; i++) {
270 *resu = 0 ;
271 resu++ ;
272 }
273
274 for (j=1; j<nt-1; j++) {
275
276 // ... produit matriciel
277 for (i=0; i<nr; i++) {
278 som[i] = 0 ;
279 }
280
281 for (l=m; l<nt-1; l++) {
282 double bmjl = bb[nt*j + l] ;
283 for (i=0; i<nr; i++) {
284 som[i] += bmjl * cc[nr*l + 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 j
294
295 // Dernier coef en j=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 bb += mbb ; // pointeur sur la nouvelle matrice de passage
309
310 } // fin de la boucle (m) sur phi
311
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