LORENE
chb_legip_cosi.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
23char chb_legip_cosi_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legip_cosi.C,v 1.7 2014/10/13 08:53:10 j_novak Exp $" ;
24
25/*
26 * Calcule les coefficients du developpement (suivant theta)
27 * en cos((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 pair)
30 * pour une une fonction 3-D antisymetrique par rapport au plan equatorial
31 * z = 0 et symetrique 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_{j=m/2}^{nt-2} a_j P_{2j+1}^m( cos(theta) )
46 *
47 * (m pair)
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/2 ou j = nt-1, a_j = 0
63 *
64 * Sortie:
65 * -------
66 * double* cfo : tableau des coefficients c_j du develop. en cos/sin definis
67 * comme suit (a r et phi fixes) :
68 *
69 * f(theta) = som_{j=0}^{nt-2} c_j cos( (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: m = 2 (k/2).
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_legip_cosi.C,v 1.7 2014/10/13 08:53:10 j_novak Exp $
89 * $Log: chb_legip_cosi.C,v $
90 * Revision 1.7 2014/10/13 08:53:10 j_novak
91 * Lorene classes and functions now belong to the namespace Lorene.
92 *
93 * Revision 1.6 2014/10/06 15:16:00 j_novak
94 * Modified #include directives to use c++ syntax.
95 *
96 * Revision 1.5 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.4 2003/12/19 16:21:46 j_novak
101 * Shadow hunt
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:28 e_gourgoulhon
112 * LORENE
113 *
114 * Revision 2.1 2000/09/29 16:07:15 eric
115 * Mise a zero des coefficients k=1 et k=2 dans le cas np=1.
116 *
117 * Revision 2.0 2000/09/28 10:02:09 eric
118 * *** empty log message ***
119 *
120 *
121 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legip_cosi.C,v 1.7 2014/10/13 08:53:10 j_novak Exp $
122 *
123 */
124
125
126// headers du C
127#include <cstdlib>
128#include <cassert>
129
130// Headers Lorene
131#include "headcpp.h"
132#include "proto.h"
133
134namespace Lorene {
135//******************************************************************************
136
137void chb_legip_cosi(const int* deg , const double* cfi, double* cfo) {
138
139int k2, l, j, i, m ;
140
141// Nombres de degres de liberte en phi et theta :
142 int np = deg[0] ;
143 int nt = deg[1] ;
144 int nr = deg[2] ;
145
146 assert(np < 4*nt) ;
147 assert( cfi != cfo ) ;
148
149 // Tableau de travail
150 double* som = new double[nr] ;
151
152// Recherche de la matrice de passage Legendre --> cos/sin
153 double* bb = mat_legip_cosi(np, nt) ;
154
155// Increment en m pour la matrice bb :
156 int mbb = nt * nt ;
157
158// Pointeurs de travail :
159 double* resu = cfo ;
160 const double* cc = cfi ;
161
162// Increment en phi :
163 int ntnr = nt * nr ;
164
165// Indice courant en phi :
166 int k = 0 ;
167
168//----------------------------------------------------------------
169// Cas axisymetrique
170//----------------------------------------------------------------
171
172 if (np == 1) {
173
174 m = 0 ;
175
176// Boucle sur l'indice j du developpement en cos( (2j+1) theta )
177
178 for (j=0; j<nt-1; j++) {
179
180// ... produit matriciel (parallelise sur r)
181 for (i=0; i<nr; i++) {
182 som[i] = 0 ;
183 }
184
185 for (l=m/2; l<nt-1; l++) {
186
187 double bmjl = bb[nt*j + l] ;
188 for (i=0; i<nr; i++) {
189 som[i] += bmjl * cc[nr*l + i] ;
190 }
191 }
192
193 for (i=0; i<nr; i++) {
194 *resu = som[i] ;
195 resu++ ;
196 }
197
198 } // fin de la boucle sur j
199
200 //... dernier coef en j=nt-1 mis a zero:
201 for (i=0; i<nr; i++) {
202 *resu = 0 ;
203 resu++ ;
204 }
205
206 // Mise a zero des coefficients k=1 et k=2 :
207 // ---------------------------------------
208
209 for (i=ntnr; i<3*ntnr; i++) {
210 cfo[i] = 0 ;
211 }
212
213 // On sort
214 delete [] som ;
215 return ;
216
217 } // fin du cas np=1
218
219
220//----------------------------------------------------------------
221// Cas 3-D
222//----------------------------------------------------------------
223
224
225// Boucle sur phi :
226
227 for (m=0; m < np + 1 ; m+=2) {
228
229 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
230
231 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
232 // et sin( np phi) a zero
233 for (j=0; j<nt; j++) {
234 for (i=0; i<nr; i++) {
235 *resu = 0 ;
236 resu++ ;
237 }
238 }
239 }
240 else {
241
242// Boucle sur l'indice j du developpement en cos( (2j+1) theta )
243
244 for (j=0; j<nt-1; j++) {
245
246// ... produit matriciel (parallelise sur r)
247 for (i=0; i<nr; i++) {
248 som[i] = 0 ;
249 }
250
251 for (l=m/2; l<nt-1; l++) {
252
253 double bmjl = bb[nt*j + l] ;
254 for (i=0; i<nr; i++) {
255 som[i] += bmjl * cc[nr*l + i] ;
256 }
257 }
258
259 for (i=0; i<nr; i++) {
260 *resu = som[i] ;
261 resu++ ;
262 }
263
264 } // fin de la boucle sur j
265
266 //... dernier coef en j=nt-1 mis a zero:
267 for (i=0; i<nr; i++) {
268 *resu = 0 ;
269 resu++ ;
270 }
271
272 } // fin du cas k != 1
273
274// On passe au phi suivant :
275 cc = cc + ntnr ;
276 k++ ;
277
278 } // fin de la boucle sur k2
279
280// On passe a l'harmonique en phi suivante :
281
282 bb += mbb ; // pointeur sur la nouvelle matrice de passage
283
284 } // fin de la boucle (m) sur phi
285
286//## verif :
287 assert(resu == cfo + (np+2)*ntnr) ;
288
289 // Menage
290 delete [] som ;
291
292}
293}
Lorene prototypes.
Definition app_hor.h:64