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
23
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.8 2016/12/05 16:18:01 j_novak Exp $
89 * $Log: chb_legip_cosi.C,v $
90 * Revision 1.8 2016/12/05 16:18:01 j_novak
91 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
92 *
93 * Revision 1.7 2014/10/13 08:53:10 j_novak
94 * Lorene classes and functions now belong to the namespace Lorene.
95 *
96 * Revision 1.6 2014/10/06 15:16:00 j_novak
97 * Modified #include directives to use c++ syntax.
98 *
99 * Revision 1.5 2005/02/18 13:14:10 j_novak
100 * Changing of malloc/free to new/delete + suppression of some unused variables
101 * (trying to avoid compilation warnings).
102 *
103 * Revision 1.4 2003/12/19 16:21:46 j_novak
104 * Shadow hunt
105 *
106 * Revision 1.3 2003/01/31 10:31:23 e_gourgoulhon
107 * Suppressed the directive #include <malloc.h> for malloc is defined
108 * in <stdlib.h>
109 *
110 * Revision 1.2 2002/10/16 14:36:52 j_novak
111 * Reorganization of #include instructions of standard C++, in order to
112 * use experimental version 3 of gcc.
113 *
114 * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
115 * LORENE
116 *
117 * Revision 2.1 2000/09/29 16:07:15 eric
118 * Mise a zero des coefficients k=1 et k=2 dans le cas np=1.
119 *
120 * Revision 2.0 2000/09/28 10:02:09 eric
121 * *** empty log message ***
122 *
123 *
124 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/chb_legip_cosi.C,v 1.8 2016/12/05 16:18:01 j_novak Exp $
125 *
126 */
127
128
129// headers du C
130#include <cstdlib>
131#include <cassert>
132
133// Headers Lorene
134#include "headcpp.h"
135#include "proto.h"
136
137namespace Lorene {
138//******************************************************************************
139
140void chb_legip_cosi(const int* deg , const double* cfi, double* cfo) {
141
142int k2, l, j, i, m ;
143
144// Nombres de degres de liberte en phi et theta :
145 int np = deg[0] ;
146 int nt = deg[1] ;
147 int nr = deg[2] ;
148
149 assert(np < 4*nt) ;
150 assert( cfi != cfo ) ;
151
152 // Tableau de travail
153 double* som = new double[nr] ;
154
155// Recherche de la matrice de passage Legendre --> cos/sin
156 double* bb = mat_legip_cosi(np, nt) ;
157
158// Increment en m pour la matrice bb :
159 int mbb = nt * nt ;
160
161// Pointeurs de travail :
162 double* resu = cfo ;
163 const double* cc = cfi ;
164
165// Increment en phi :
166 int ntnr = nt * nr ;
167
168// Indice courant en phi :
169 int k = 0 ;
170
171//----------------------------------------------------------------
172// Cas axisymetrique
173//----------------------------------------------------------------
174
175 if (np == 1) {
176
177 m = 0 ;
178
179// Boucle sur l'indice j du developpement en cos( (2j+1) theta )
180
181 for (j=0; j<nt-1; j++) {
182
183// ... produit matriciel (parallelise sur r)
184 for (i=0; i<nr; i++) {
185 som[i] = 0 ;
186 }
187
188 for (l=m/2; l<nt-1; l++) {
189
190 double bmjl = bb[nt*j + l] ;
191 for (i=0; i<nr; i++) {
192 som[i] += bmjl * cc[nr*l + i] ;
193 }
194 }
195
196 for (i=0; i<nr; i++) {
197 *resu = som[i] ;
198 resu++ ;
199 }
200
201 } // fin de la boucle sur j
202
203 //... dernier coef en j=nt-1 mis a zero:
204 for (i=0; i<nr; i++) {
205 *resu = 0 ;
206 resu++ ;
207 }
208
209 // Mise a zero des coefficients k=1 et k=2 :
210 // ---------------------------------------
211
212 for (i=ntnr; i<3*ntnr; i++) {
213 cfo[i] = 0 ;
214 }
215
216 // On sort
217 delete [] som ;
218 return ;
219
220 } // fin du cas np=1
221
222
223//----------------------------------------------------------------
224// Cas 3-D
225//----------------------------------------------------------------
226
227
228// Boucle sur phi :
229
230 for (m=0; m < np + 1 ; m+=2) {
231
232 for (k2=0; k2 < 2; k2++) { // k2=0 : cos(m phi) ; k2=1 : sin(m phi)
233
234 if ( (k == 1) || (k == np+1) ) { // On met les coef de sin(0 phi)
235 // et sin( np phi) a zero
236 for (j=0; j<nt; j++) {
237 for (i=0; i<nr; i++) {
238 *resu = 0 ;
239 resu++ ;
240 }
241 }
242 }
243 else {
244
245// Boucle sur l'indice j du developpement en cos( (2j+1) theta )
246
247 for (j=0; j<nt-1; j++) {
248
249// ... produit matriciel (parallelise sur r)
250 for (i=0; i<nr; i++) {
251 som[i] = 0 ;
252 }
253
254 for (l=m/2; l<nt-1; l++) {
255
256 double bmjl = bb[nt*j + l] ;
257 for (i=0; i<nr; i++) {
258 som[i] += bmjl * cc[nr*l + i] ;
259 }
260 }
261
262 for (i=0; i<nr; i++) {
263 *resu = som[i] ;
264 resu++ ;
265 }
266
267 } // fin de la boucle sur j
268
269 //... dernier coef en j=nt-1 mis a zero:
270 for (i=0; i<nr; i++) {
271 *resu = 0 ;
272 resu++ ;
273 }
274
275 } // fin du cas k != 1
276
277// On passe au phi suivant :
278 cc = cc + ntnr ;
279 k++ ;
280
281 } // fin de la boucle sur k2
282
283// On passe a l'harmonique en phi suivante :
284
285 bb += mbb ; // pointeur sur la nouvelle matrice de passage
286
287 } // fin de la boucle (m) sur phi
288
289//## verif :
290 assert(resu == cfo + (np+2)*ntnr) ;
291
292 // Menage
293 delete [] som ;
294
295}
296}
Lorene prototypes.
Definition app_hor.h:67