LORENE
FFTW3/cftsin.C
1/*
2 * Copyright (c) 1999-2002 Eric Gourgoulhon
3 * Copyright (c) 2002 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/*
24 * Transformation en sin(l*theta) sur le deuxieme indice (theta)
25 * d'un tableau 3-D representant une fonction quelconque (theta
26 * varie entre 0 et pi).Utilise la bibliotheque fftw
27 *
28 * Entree:
29 * -------
30 * int* deg : tableau du nombre effectif de degres de liberte dans chacune
31 * des 3 dimensions: le nombre de points de collocation
32 * en theta est nt = deg[1] et doit etre de la forme
33 * nt = 2*p + 1
34 * int* dimf : tableau du nombre d'elements de ff dans chacune des trois
35 * dimensions.
36 * On doit avoir dimf[1] >= deg[1] = nt.
37 * NB: pour dimf[0] = 1 (un seul point en phi), la transformation
38 * est bien effectuee.
39 * pour dimf[0] > 1 (plus d'un point en phi), la
40 * transformation n'est effectuee que pour les indices (en phi)
41 * j != 1 et j != dimf[0]-1 (cf. commentaires sur borne_phi).
42 *
43 * double* ff : tableau des valeurs de la fonction aux nt points de
44 * de collocation
45 *
46 * theta_l = pi l/(nt-1) 0 <= l <= nt-1
47 *
48 * L'espace memoire correspondant a ce
49 * pointeur doit etre dimf[0]*dimf[1]*dimf[2] et doit
50 * etre alloue avant l'appel a la routine.
51 * Les valeurs de la fonction doivent etre stokees
52 * dans le tableau ff comme suit
53 * f( theta_l ) = ff[ dimf[1]*dimf[2] * j + k + dimf[2] * l ]
54 * ou j et k sont les indices correspondant a
55 * phi et r respectivement.
56 *
57 * int* dimc : tableau du nombre d'elements de cc dans chacune des trois
58 * dimensions.
59 * On doit avoir dimc[1] >= deg[1] = nt.
60 * Sortie:
61 * -------
62 * double* cf : tableau des coefficients c_l de la fonction definis
63 * comme suit (a r et phi fixes)
64 *
65 * f(theta) = som_{l=0}^{nt-1} c_l sin( l theta ) .
66 *
67 * L'espace memoire correspondant a ce
68 * pointeur doit etre dimc[0]*dimc[1]*dimc[2] et doit
69 * etre alloue avant l'appel a la routine.
70 * Le coefficient c_l (0 <= l <= nt-1) est stoke dans
71 * le tableau cf comme suit
72 * c_l = cf[ dimc[1]*dimc[2] * j + k + dimc[2] * l ]
73 * ou j et k sont les indices correspondant a
74 * phi et r respectivement.
75 *
76 * NB: Si le pointeur ff est egal a cf, la routine ne travaille que sur un
77 * seul tableau, qui constitue une entree/sortie.
78 *
79 */
80
81
82
83/*
84 * $Id: cftsin.C,v 1.4 2016/12/05 16:18:05 j_novak Exp $
85 * $Log: cftsin.C,v $
86 * Revision 1.4 2016/12/05 16:18:05 j_novak
87 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
88 *
89 * Revision 1.3 2014/10/13 08:53:19 j_novak
90 * Lorene classes and functions now belong to the namespace Lorene.
91 *
92 * Revision 1.2 2014/10/06 15:18:48 j_novak
93 * Modified #include directives to use c++ syntax.
94 *
95 * Revision 1.1 2004/12/21 17:06:02 j_novak
96 * Added all files for using fftw3.
97 *
98 * Revision 1.1 2004/11/23 15:13:50 m_forot
99 * Added the bases for the cases without any equatorial symmetry
100 * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
101 *
102 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/FFTW3/cftsin.C,v 1.4 2016/12/05 16:18:05 j_novak Exp $
103 *
104 */
105
106// headers du C
107#include <cstdlib>
108#include <fftw3.h>
109
111#include "tbl.h"
112
113// Prototypage des sous-routines utilisees:
114namespace Lorene {
115fftw_plan prepare_fft(int, Tbl*&) ;
116double* cheb_ini(const int) ;
117//*****************************************************************************
118
119void cftsin(const int* deg, const int* dimf, double* ff, const int* dimc,
120 double* cf)
121{
122
123int i, j, k ;
124
125// Dimensions des tableaux ff et cf :
126 int n1f = dimf[0] ;
127 int n2f = dimf[1] ;
128 int n3f = dimf[2] ;
129 int n1c = dimc[0] ;
130 int n2c = dimc[1] ;
131 int n3c = dimc[2] ;
132
133// Nombre de degres de liberte en theta :
134 int nt = deg[1] ;
135
136// Tests de dimension:
137 if (nt > n2f) {
138 cout << "cftsin: nt > n2f : nt = " << nt << " , n2f = "
139 << n2f << endl ;
140 abort () ;
141 exit(-1) ;
142 }
143 if (nt > n2c) {
144 cout << "cftsin: nt > n2c : nt = " << nt << " , n2c = "
145 << n2c << endl ;
146 abort () ;
147 exit(-1) ;
148 }
149 if (n1f > n1c) {
150 cout << "cftsin: n1f > n1c : n1f = " << n1f << " , n1c = "
151 << n1c << endl ;
152 abort () ;
153 exit(-1) ;
154 }
155 if (n3f > n3c) {
156 cout << "cftsin: n3f > n3c : n3f = " << n3f << " , n3c = "
157 << n3c << endl ;
158 abort () ;
159 exit(-1) ;
160 }
161
162// Nombre de points pour la FFT:
163 int nm1 = nt - 1;
164 int nm1s2 = nm1 / 2;
165
166// Recherche des tables pour la FFT:
167 Tbl* pg = 0x0 ;
168 fftw_plan p = prepare_fft(nm1, pg) ;
169 Tbl& g = *pg ;
170
171// Recherche de la table des sin(psi) :
172 double* sinp = cheb_ini(nt);
173
174// boucle sur phi et r (les boucles vont resp. de 0 a max(dimf[0]-2,0) et
175// 0 a dimf[2]-1 )
176
177 int n2n3f = n2f * n3f ;
178 int n2n3c = n2c * n3c ;
179
180/*
181 * Borne de la boucle sur phi:
182 * si n1f = 1, on effectue la boucle une fois seulement.
183 * si n1f > 1, on va jusqu'a j = n1f-2 en sautant j = 1 (les coefficients
184 * j=n1f-1 et j=0 ne sont pas consideres car nuls).
185 */
186 int borne_phi = ( n1f > 1 ) ? n1f-1 : 1 ;
187
188 for (j=0; j< borne_phi; j++) {
189
190 if (j==1) continue ; // on ne traite pas le terme en sin(0 phi)
191
192 for (k=0; k<n3f; k++) {
193
194 int i0 = n2n3f * j + k ; // indice de depart
195 double* ff0 = ff + i0 ; // tableau des donnees a transformer
196
197 i0 = n2n3c * j + k ; // indice de depart
198 double* cf0 = cf + i0 ; // tableau resultat
199
200// Fonction G(psi) = F+(psi)sin(psi) + F_(psi)
201//---------------------------------------------
202 for ( i = 1; i < nm1s2 ; i++ ) {
203// ... indice (dans le tableau g) du pt symetrique de psi par rapport a pi/2:
204 int isym = nm1 - i ;
205// ... indice (dans le tableau ff0) du point theta correspondant a psi
206 int ix = n3f * i ;
207// ... indice (dans le tableau ff0) du point theta correspondant a sym(psi)
208 int ixsym = n3f * isym ;
209// ... F+(psi)
210 double fp = 0.5 * ( ff0[ix] + ff0[ixsym] ) * sinp[i] ;
211// ... F_(psi) sin(psi)
212 double fms = 0.5 * ( ff0[ix] - ff0[ixsym] ) ;
213 g.set(i) = fp + fms ;
214 g.set(isym) = fp - fms ;
215 }
216//... cas particuliers:
217 g.set(0) = 0.5 * ( ff0[0] + ff0[ n3f*nm1 ] );
218 g.set(nm1s2) = ff0[ n3f*nm1s2 ];
219
220// Developpement de G en series de Fourier par une FFT
221//----------------------------------------------------
222
223 fftw_execute(p) ;
224
225// Coefficients pairs du developmt. sin(l theta) de f
226//----------------------------------------------------
227// Ces coefficients sont egaux aux coefficients en sinus du developpement
228// de G en series de Fourier (le facteur -2/nm1 vient de la normalisation
229// de fftw) :
230
231 double fac = -2. / double(nm1) ;
232 cf0[0] = 0. ;
233 for (i=2; i<nm1; i += 2 ) cf0[n3c*i] = fac * g(nm1 - i/2) ;
234 cf0[n3c*nm1] = 0. ;
235
236// Coefficients impairs du developmt. en sin(l theta) de f
237//---------------------------------------------------------
238// 1. Coef. c'_k (recurrence amorcee a partir de zero):
239// Le 4/nm1 en facteur de g[i] est du a la normalisation de fftw
240// (si fftw donnait reellement les coef. en sinus, il faudrait le
241// remplacer par un -2.)
242
243 cf0[n3c] = -fac * g(0);
244 fac *= -2. ;
245 for ( i = 3; i < nt; i += 2 ) {
246 cf0[n3c*i] = cf0[n3c*(i-2)] + fac * g(i/2) ;
247 }
248
249 } // fin de la boucle sur r
250 } // fin de la boucle sur phi
251
252}
253}
Basic array class.
Definition tbl.h:161
Lorene prototypes.
Definition app_hor.h:67
Coord sinp
Definition map.h:735