LORENE
chb_legii_sinp.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_legii_sinp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legii_sinp.C,v 1.4 2014/10/13 08:53:10 j_novak Exp $" ;
24
25/*
26 * Calcule les coefficients du developpement (suivant theta)
27 * en sin(2j theta)
28 * a partir des coefficients du developpement en fonctions
29 * associees de Legendre P_l^m(cos(theta)) (l pair et m impair)
30 * pour une une fonction 3-D antisymetrique 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}^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=1}^{nt-2} c_j sin( 2j 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_0 = 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_legii_sinp.C,v 1.4 2014/10/13 08:53:10 j_novak Exp $
89 * $Log: chb_legii_sinp.C,v $
90 * Revision 1.4 2014/10/13 08:53:10 j_novak
91 * Lorene classes and functions now belong to the namespace Lorene.
92 *
93 * Revision 1.3 2014/10/06 15:16:00 j_novak
94 * Modified #include directives to use c++ syntax.
95 *
96 * Revision 1.2 2005/02/18 13:14:10 j_novak
97 * Changing of malloc/free to new/delete + suppression of some unused variables
98 * (trying to avoid compilation warnings).
99 *
100 * Revision 1.1 2003/09/16 08:58:01 j_novak
101 * New functions for the T_LEG_II base
102 *
103 *
104 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legii_sinp.C,v 1.4 2014/10/13 08:53:10 j_novak Exp $
105 *
106 */
107
108// headers du C
109#include <cstdlib>
110#include <cassert>
111
112// Headers Lorene
113#include "headcpp.h"
114#include "proto.h"
115
116namespace Lorene {
117//******************************************************************************
118
119void chb_legii_sinp(const int* deg , const double* cfi, double* cfo) {
120
121int k2, l, j, i, m ;
122
123// Nombres de degres de liberte en phi et theta :
124 int np = deg[0] ;
125 int nt = deg[1] ;
126 int nr = deg[2] ;
127
128 assert(np < 4*nt) ;
129 assert( cfi != cfo ) ;
130
131 // Tableau de travail
132 double* som = new double[nr] ;
133// Recherche de la matrice de passage Legendre --> cos/sin
134 double* bb = mat_legii_sinp(np, nt) ;
135
136// Increment en m pour la matrice bb :
137 int mbb = nt * nt ;
138
139// Pointeurs de travail :
140 double* resu = cfo ;
141 const double* cc = cfi ;
142
143// Increment en phi :
144 int ntnr = nt * nr ;
145
146// Indice courant en phi :
147 int k = 0 ;
148
149 // Cas k=0 (m=1 : cos(phi))
150 // ------------------------
151
152 //... premier coef en j=0 mis a zero:
153 for (i=0; i<nr; i++) {
154 *resu = 0 ;
155 resu++ ;
156 }
157
158 // Boucle sur l'indice j du developpement en sin( 2j theta)
159
160 for (j=1; j<nt-1; j++) {
161
162 // ... produit matriciel (parallelise sur r)
163 for (i=0; i<nr; i++) {
164 som[i] = 0 ;
165 }
166
167 for (l=1; l<nt-1; l++) {
168 double bmjl = bb[nt*j + l] ;
169 for (i=0; i<nr; i++) {
170 som[i] += bmjl * cc[nr*l + i] ;
171 }
172 }
173
174 for (i=0; i<nr; i++) {
175 *resu = som[i] ;
176 resu++ ;
177 }
178
179 } // fin de la boucle sur j
180
181 // Dernier coef en j=nt-1 mis a zero pour le cas m impair :
182 for (i=0; i<nr; i++) {
183 *resu = 0 ;
184 resu++ ;
185 }
186
187 // Special case np=1 (axisymmetry)
188 // -------------------------------
189 if (np==1) {
190 for (i=0; i<2*ntnr; i++) {
191 *resu = 0 ;
192 resu++ ;
193 }
194 delete [] som ;
195 return ;
196 }
197
198 // On passe au phi suivant :
199 cc = cc + ntnr ;
200 k++ ;
201
202 // Cas k=1 : tout est mis a zero
203 // -----------------------------
204
205 for (l=0; l<nt; l++) {
206 for (i=0; i<nr; i++) {
207 *resu = 0 ;
208 resu++ ;
209 }
210 }
211
212 // On passe au phi suivant :
213 cc = cc + ntnr ;
214 k++ ;
215
216 // Cas k=2 (m=1 : sin(phi))
217 // ------------------------
218
219 //... premier coef en j=0 mis a zero:
220 for (i=0; i<nr; i++) {
221 *resu = 0 ;
222 resu++ ;
223 }
224
225 // Boucle sur l'indice j du developpement en sin( 2j theta)
226
227 for (j=1; j<nt-1; j++) {
228
229 // ... produit matriciel (parallelise sur r)
230 for (i=0; i<nr; i++) {
231 som[i] = 0 ;
232 }
233
234 for (l=1; l<nt-1; l++) {
235 double bmjl = bb[nt*j + l] ;
236 for (i=0; i<nr; i++) {
237 som[i] += bmjl * cc[nr*l + i] ;
238 }
239 }
240
241 for (i=0; i<nr; i++) {
242 *resu = som[i] ;
243 resu++ ;
244 }
245
246 } // fin de la boucle sur j
247
248 // Dernier coef en j=nt-1 mis a zero pour le cas m impair :
249 for (i=0; i<nr; i++) {
250 *resu = 0 ;
251 resu++ ;
252 }
253
254 // On passe au phi suivant :
255 cc = cc + ntnr ;
256 k++ ;
257
258 // On passe au m suivant :
259 bb += mbb ; // pointeur sur la nouvelle matrice de passage
260
261 // Cas k >= 3
262 // ----------
263
264 for (m=3; m < np ; m+=2) {
265
266 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
267
268 // Boucle sur l'indice j du developpement en sin( 2j theta)
269
270 //... premier coef en j=0 mis a zero:
271 for (i=0; i<nr; i++) {
272 *resu = 0 ;
273 resu++ ;
274 }
275
276 for (j=1; j<nt-1; j++) {
277
278 for (i=0; i<nr; i++) {
279 som[i] = 0 ;
280 }
281
282 for (l=(m+1)/2; l<nt-1; l++) {
283 double bmjl = bb[nt*j + l] ;
284 for (i=0; i<nr; i++) {
285 som[i] += bmjl * cc[nr*l + 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 j
295
296 // Dernier coef en j=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 bb += mbb ; // pointeur sur la nouvelle matrice de passage
310
311 } // fin de la boucle (m) sur phi
312
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