LORENE
FFT991/cftsinp.C
1/*
2 * Copyright (c) 1999-2002 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/*
27 * Transformation en sin(2*l*theta) sur le deuxieme indice (theta)
28 * d'un tableau 3-D representant une fonction antisymetrique par rapport
29 * au plan z=0.
30 * Utilise la routine FFT Fortran FFT991
31 *
32 * Entree:
33 * -------
34 * int* deg : tableau du nombre effectif de degres de liberte dans chacune
35 * des 3 dimensions: le nombre de points de collocation
36 * en theta est nt = deg[1] et doit etre de la forme
37 * nt = 2^p 3^q 5^r + 1
38 * int* dimf : tableau du nombre d'elements de ff dans chacune des trois
39 * dimensions.
40 * On doit avoir dimf[1] >= deg[1] = nt.
41 * NB: pour dimf[0] = 1 (un seul point en phi), la transformation
42 * est bien effectuee.
43 * pour dimf[0] > 1 (plus d'un point en phi), la
44 * transformation n'est effectuee que pour les indices (en phi)
45 * j != 1 et j != dimf[0]-1 (cf. commentaires sur borne_phi).
46 *
47 * double* ff : tableau des valeurs de la fonction aux nt points de
48 * de collocation
49 *
50 * theta_l = pi/2 l/(nt-1) 0 <= l <= nt-1
51 *
52 * L'espace memoire correspondant a ce
53 * pointeur doit etre dimf[0]*dimf[1]*dimf[2] et doit
54 * etre alloue avant l'appel a la routine.
55 * Les valeurs de la fonction doivent etre stokees
56 * dans le tableau ff comme suit
57 * f( theta_l ) = ff[ dimf[1]*dimf[2] * j + k + dimf[2] * l ]
58 * ou j et k sont les indices correspondant a
59 * phi et r respectivement.
60 *
61 * int* dimc : tableau du nombre d'elements de cc dans chacune des trois
62 * dimensions.
63 * On doit avoir dimc[1] >= deg[1] = nt.
64 * Sortie:
65 * -------
66 * double* cf : tableau des coefficients c_l de la fonction definis
67 * comme suit (a r et phi fixes)
68 *
69 * f(theta) = som_{l=0}^{nt-1} c_l sin( 2 l theta ) .
70 *
71 * L'espace memoire correspondant a ce
72 * pointeur doit etre dimc[0]*dimc[1]*dimc[2] et doit
73 * etre alloue avant l'appel a la routine.
74 * Le coefficient c_l (0 <= l <= nt-1) est stoke dans
75 * le tableau cf comme suit
76 * c_l = cf[ dimc[1]*dimc[2] * j + k + dimc[2] * l ]
77 * ou j et k sont les indices correspondant a
78 * phi et r respectivement.
79 *
80 * NB: Si le pointeur ff est egal a cf, la routine ne travaille que sur un
81 * seul tableau, qui constitue une entree/sortie.
82 *
83 */
84
85/*
86 * $Id: cftsinp.C,v 1.5 2016/12/05 16:18:03 j_novak Exp $
87 * $Log: cftsinp.C,v $
88 * Revision 1.5 2016/12/05 16:18:03 j_novak
89 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
90 *
91 * Revision 1.4 2014/10/15 12:48:21 j_novak
92 * Corrected namespace declaration.
93 *
94 * Revision 1.3 2014/10/13 08:53:16 j_novak
95 * Lorene classes and functions now belong to the namespace Lorene.
96 *
97 * Revision 1.2 2014/10/06 15:18:45 j_novak
98 * Modified #include directives to use c++ syntax.
99 *
100 * Revision 1.1 2004/12/21 17:06:01 j_novak
101 * Added all files for using fftw3.
102 *
103 * Revision 1.4 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.3 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.2 2002/09/09 13:00:39 e_gourgoulhon
112 * Modification of declaration of Fortran 77 prototypes for
113 * a better portability (in particular on IBM AIX systems):
114 * All Fortran subroutine names are now written F77_* and are
115 * defined in the new file C++/Include/proto_f77.h.
116 *
117 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
118 * LORENE
119 *
120 * Revision 2.0 1999/02/22 15:46:20 hyc
121 * *** empty log message ***
122 *
123 *
124 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/FFT991/cftsinp.C,v 1.5 2016/12/05 16:18:03 j_novak Exp $
125 *
126 */
127// headers du C
128#include <cassert>
129#include <cstdlib>
130
131// Prototypes of F77 subroutines
132#include "headcpp.h"
133#include "proto_f77.h"
134
135// Prototypage des sous-routines utilisees:
136namespace Lorene {
137int* facto_ini(int ) ;
138double* trigo_ini(int ) ;
139double* cheb_ini(const int) ;
140//*****************************************************************************
141
142void cftsinp(const int* deg, const int* dimf, double* ff, const int* dimc,
143 double* cf)
144
145{
146
147int i, j, k ;
148
149// Dimensions des tableaux ff et cf :
150 int n1f = dimf[0] ;
151 int n2f = dimf[1] ;
152 int n3f = dimf[2] ;
153 int n1c = dimc[0] ;
154 int n2c = dimc[1] ;
155 int n3c = dimc[2] ;
156
157// Nombre de degres de liberte en theta :
158 int nt = deg[1] ;
159
160// Tests de dimension:
161 if (nt > n2f) {
162 cout << "cftsinp: nt > n2f : nt = " << nt << " , n2f = "
163 << n2f << endl ;
164 abort () ;
165 exit(-1) ;
166 }
167 if (nt > n2c) {
168 cout << "cftsinp: nt > n2c : nt = " << nt << " , n2c = "
169 << n2c << endl ;
170 abort () ;
171 exit(-1) ;
172 }
173 if (n1f > n1c) {
174 cout << "cftsinp: n1f > n1c : n1f = " << n1f << " , n1c = "
175 << n1c << endl ;
176 abort () ;
177 exit(-1) ;
178 }
179 if (n3f > n3c) {
180 cout << "cftsinp: n3f > n3c : n3f = " << n3f << " , n3c = "
181 << n3c << endl ;
182 abort () ;
183 exit(-1) ;
184 }
185
186// Nombre de points pour la FFT:
187 int nm1 = nt - 1;
188 int nm1s2 = nm1 / 2;
189
190// Recherche des tables pour la FFT:
191 int* facto = facto_ini(nm1) ;
192 double* trigo = trigo_ini(nm1) ;
193
194// Recherche de la table des sin(psi) :
195 double* sinp = cheb_ini(nt);
196
197 // tableau de travail t1 et G
198 // (la dimension nm1+2 = nt+1 est exigee par la routine fft991)
199 double* g = (double*)( malloc( (nm1+2)*sizeof(double) ) );
200 double* t1 = (double*)( malloc( (nm1+2)*sizeof(double) ) ) ;
201
202// Parametres pour la routine FFT991
203 int jump = 1 ;
204 int inc = 1 ;
205 int lot = 1 ;
206 int isign = - 1 ;
207
208// boucle sur phi et r (les boucles vont resp. de 0 a max(dimf[0]-2,0) et
209// 0 a dimf[2]-1)
210
211 int n2n3f = n2f * n3f ;
212 int n2n3c = n2c * n3c ;
213
214/*
215 * Borne de la boucle sur phi:
216 * si n1f = 1, on effectue la boucle une fois seulement.
217 * si n1f > 1, on va jusqu'a j = n1f-2 en sautant j = 1 (les coefficients
218 * j=n1f-1 et j=0 ne sont pas consideres car nuls).
219 */
220 int borne_phi = ( n1f > 1 ) ? n1f-1 : 1 ;
221
222 for (j=0; j< borne_phi; j++) {
223
224 if (j==1) continue ; // on ne traite pas le terme en sin(0 phi)
225
226 for (k=0; k<n3f; k++) {
227
228 int i0 = n2n3f * j + k ; // indice de depart
229 double* ff0 = ff + i0 ; // tableau des donnees a transformer
230
231 i0 = n2n3c * j + k ; // indice de depart
232 double* cf0 = cf + i0 ; // tableau resultat
233
234/*
235 * NB: dans les commentaires qui suivent, psi designe la variable de [0, pi]
236 * reliee a theta par psi = 2 theta et F(psi) = f(theta(psi)).
237 */
238
239// Fonction G(psi) = F+(psi) sin(psi) + F_(psi)
240//---------------------------------------------
241 for ( i = 1; i < nm1s2 ; i++ ) {
242// ... indice (dans le tableau g) du pt symetrique de psi par rapport a pi/2:
243 int isym = nm1 - i ;
244// ... indice (dans le tableau ff0) du point theta correspondant a psi
245 int ix = n3f * i ;
246// ... indice (dans le tableau ff0) du point theta correspondant a sym(psi)
247 int ixsym = n3f * isym ;
248// ... F+(psi) sin(psi)
249 double fps = 0.5 * ( ff0[ix] + ff0[ixsym] ) * sinp[i] ;
250// ... F_(psi)
251 double fm = 0.5 * ( ff0[ix] - ff0[ixsym] ) ;
252 g[i] = fps + fm ;
253 g[isym] = fps - fm ;
254 }
255//... cas particuliers:
256 g[0] = 0.5 * ( ff0[0] - ff0[ n3f*nm1 ] ) ;
257 g[nm1s2] = ff0[ n3f*nm1s2 ] ;
258
259// Developpement de G en series de Fourier par une FFT
260//----------------------------------------------------
261
262 F77_fft991( g, t1, trigo, facto, &inc, &jump, &nm1, &lot, &isign) ;
263
264// Coefficients pairs du developmt. sin(2l theta) de f
265//----------------------------------------------------
266// Ces coefficients sont egaux aux coefficients en sinus du developpement
267// de G en series de Fourier (le facteur -2. vient de la normalisation
268// de fft991: si fft991 donnait reellement les coefficients en sinus,
269// il faudrait le remplacer par un +1) :
270
271 cf0[0] = 0. ;
272 for (i=2; i<nm1; i += 2 ) cf0[n3c*i] = -2. * g[i+1] ;
273 cf0[n3c*nm1] = 0. ;
274
275// Coefficients impairs du developmt. en sin(2l theta) de f
276//---------------------------------------------------------
277// Ces coefficients sont obtenus par une recurrence a partir des
278// coefficients en cosinus du developpement de G en series de Fourier
279// (le facteur +4. vient de la normalisation
280// de fft991: si fft991 donnait reellement les coefficients en cosinus,
281// il faudrait le remplacer par un +2.)
282
283 cf0[n3c] = 2.* g[0] ;
284 for ( i = 3; i < nt; i += 2 ) {
285 cf0[ n3c*i ] = cf0[ n3c*(i-2) ] + 4. * g[i-1] ;
286 }
287
288 } // fin de la boucle sur r
289 } // fin de la boucle sur phi
290
291 // Menage
292 free (t1) ;
293 free (g) ;
294
295}
296}
Lorene prototypes.
Definition app_hor.h:67
Coord sinp
Definition map.h:735