citsinp.C

00001 /*
00002  *   Copyright (c) 1999-2002 Eric Gourgoulhon
00003  *
00004  *   This file is part of LORENE.
00005  *
00006  *   LORENE is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   LORENE is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with LORENE; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 char citsinp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/FFT991/citsinp.C,v 1.1 2004/12/21 17:06:01 j_novak Exp $" ;
00024 
00025 
00026 /*
00027  * Transformation en sin(2*l*theta) inverse sur le deuxieme indice (theta)
00028  *  d'un tableau 3-D representant une fonction antisymetrique par rapport
00029  *  au plan z=0.
00030  *  Utilise la routine FFT Fortran FFT991
00031  *
00032  * Entree:
00033  * -------
00034  *   int* deg   : tableau du nombre effectif de degres de liberte dans chacune 
00035  *        des 3 dimensions: le nombre de points de collocation
00036  *        en theta est  nt = deg[1] et doit etre de la forme
00037  *          nt = 2^p 3^q 5^r + 1 
00038  *   int* dimc  : tableau du nombre d'elements de cc dans chacune des trois 
00039  *            dimensions.
00040  *        On doit avoir  dimc[1] >= deg[1] = nt. 
00041  *        NB: pour dimc[0] = 1 (un seul point en phi), la transformation
00042  *            est bien effectuee.
00043  *            pour dimc[0] > 1 (plus d'un point en phi), la
00044  *            transformation n'est effectuee que pour les indices (en phi)
00045  *            j != 1 et j != dimc[0]-1 (cf. commentaires sur borne_phi).
00046  *
00047  *   double* cf :   tableau des coefficients c_l de la fonction definis
00048  *            comme suit (a r et phi fixes)
00049  *
00050  *             f(theta) = som_{l=0}^{nt-1} c_l sin( 2 l theta ) . 
00051  *
00052  *            L'espace memoire correspondant a ce
00053  *                        pointeur doit etre dimc[0]*dimc[1]*dimc[2] et doit 
00054  *            avoir ete alloue avant l'appel a la routine.   
00055  *           Le coefficient c_l (0 <= l <= nt-1) doit etre stoke dans
00056  *           le tableau cf comme suit
00057  *                c_l = cf[ dimc[1]*dimc[2] * j + k + dimc[2] * l ]
00058  *           ou j et k sont les indices correspondant a
00059  *           phi et r respectivement.
00060  *
00061  *   int* dimf  : tableau du nombre d'elements de ff dans chacune des trois 
00062  *            dimensions.
00063  *        On doit avoir  dimf[1] >= deg[1] = nt. 
00064  *
00065  * Sortie:
00066  * -------
00067  *   double* ff : tableau des valeurs de la fonction aux nt points de
00068  *                        de collocation
00069  *
00070  *            theta_l =  pi/2 l/(nt-1)       0 <= l <= nt-1 
00071  *
00072  *            L'espace memoire correspondant a ce
00073  *                        pointeur doit etre dimf[0]*dimf[1]*dimf[2] et doit 
00074  *            avoir ete alloue avant l'appel a la routine.   
00075  *            Les valeurs de la fonction sont stokees
00076  *            dans le tableau ff comme suit
00077  *          f( theta_l ) = ff[ dimf[1]*dimf[2] * j + k + dimf[2] * l ]
00078  *           ou j et k sont les indices correspondant a
00079  *           phi et r respectivement.
00080  *
00081  * NB: Si le pointeur cf est egal a ff, la routine ne travaille que sur un 
00082  *     seul tableau, qui constitue une entree/sortie.
00083  *
00084  */
00085 
00086 /*
00087  * $Id: citsinp.C,v 1.1 2004/12/21 17:06:01 j_novak Exp $
00088  * $Log: citsinp.C,v $
00089  * Revision 1.1  2004/12/21 17:06:01  j_novak
00090  * Added all files for using fftw3.
00091  *
00092  * Revision 1.4  2003/01/31 10:31:24  e_gourgoulhon
00093  * Suppressed the directive #include <malloc.h> for malloc is defined
00094  * in <stdlib.h>
00095  *
00096  * Revision 1.3  2002/10/16 14:36:54  j_novak
00097  * Reorganization of #include instructions of standard C++, in order to
00098  * use experimental version 3 of gcc.
00099  *
00100  * Revision 1.2  2002/09/09 13:00:40  e_gourgoulhon
00101  * Modification of declaration of Fortran 77 prototypes for
00102  * a better portability (in particular on IBM AIX systems):
00103  * All Fortran subroutine names are now written F77_* and are
00104  * defined in the new file C++/Include/proto_f77.h.
00105  *
00106  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00107  * LORENE
00108  *
00109  * Revision 2.0  1999/02/22  15:41:05  hyc
00110  * *** empty log message ***
00111  *
00112  *
00113  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/FFT991/citsinp.C,v 1.1 2004/12/21 17:06:01 j_novak Exp $
00114  *
00115  */
00116 
00117 // headers du C
00118 #include <assert.h>
00119 #include <stdlib.h>
00120 
00121 // Prototypes of F77 subroutines
00122 #include "headcpp.h"
00123 #include "proto_f77.h"
00124 
00125 // Prototypage des sous-routines utilisees:
00126 int*    facto_ini(int ) ;
00127 double* trigo_ini(int ) ;
00128 double* cheb_ini(const int) ;
00129 //*****************************************************************************
00130 
00131 void citsinp(const int* deg, const int* dimc, double* cf, const int* dimf,
00132            double* ff)
00133 {
00134 
00135 int i, j, k ;
00136 
00137 // Dimensions des tableaux ff et cf  :
00138     int n1f = dimf[0] ;
00139     int n2f = dimf[1] ;
00140     int n3f = dimf[2] ;
00141     int n1c = dimc[0] ;
00142     int n2c = dimc[1] ;
00143     int n3c = dimc[2] ;
00144 
00145 // Nombres de degres de liberte en theta :    
00146     int nt = deg[1] ;
00147     
00148 // Tests de dimension:
00149     if (nt > n2f) {
00150     cout << "citsinp: nt > n2f : nt = " << nt << " ,  n2f = " 
00151     << n2f << endl ;
00152     abort () ;
00153     exit(-1) ;
00154     }
00155     if (nt > n2c) {
00156     cout << "citsinp: nt > n2c : nt = " << nt << " ,  n2c = " 
00157     << n2c << endl ;
00158     abort () ;
00159     exit(-1) ;
00160     }
00161     if ( (n1f > 1) && (n1c > n1f) ) {
00162     cout << "citsinp: n1c > n1f : n1c = " << n1c << " ,  n1f = " 
00163     << n1f << endl ;
00164     abort () ;
00165     exit(-1) ;
00166     }
00167     if (n3c > n3f) {
00168     cout << "citsinp: n3c > n3f : n3c = " << n3c << " ,  n3f = " 
00169     << n3f << endl ;
00170     abort () ;
00171     exit(-1) ;
00172     }
00173 
00174 // Nombre de points pour la FFT:
00175     int nm1 = nt - 1;
00176     int nm1s2 = nm1 / 2;
00177 
00178 // Recherche des tables pour la FFT:
00179     int* facto = facto_ini(nm1) ;
00180     double* trigo = trigo_ini(nm1) ;
00181 
00182 // Recherche de la table des sin(psi) :
00183     double* sinp = cheb_ini(nt);    
00184     
00185     // tableau de travail t1 et g
00186     //   (la dimension nm1+2 = nt+1 est exigee par la routine fft991)
00187     double* g =  (double*)( malloc( (nm1+2)*sizeof(double) ) ) ;    
00188     double* t1 = (double*)( malloc( (nm1+2)*sizeof(double) ) ) ;
00189 
00190 // Parametres pour la routine FFT991
00191     int jump = 1 ;
00192     int inc = 1 ;
00193     int lot = 1 ;
00194     int isign = 1 ;
00195 
00196 // boucle sur phi et r (les boucles vont resp. de 0 a max(dimc[0]-2,0) 
00197 //          et 0 a dimc[2]-1)
00198 
00199     int n2n3f = n2f * n3f ;
00200     int n2n3c = n2c * n3c ;
00201     
00202 /*   
00203  * Borne de la boucle sur phi: 
00204  *    si n1f = 1, on effectue la boucle une fois seulement.
00205  *    si n1c > 1, on va jusqu'a j = n1c-2 en sautant j = 1 (les coefficients
00206  *  j=n1c-1 et j=0 ne sont pas consideres car nuls). 
00207  */
00208     int borne_phi =  n1c-1  ;
00209     if (n1f == 1) borne_phi = 1 ; 
00210 
00211     for (j=0; j< borne_phi; j++) {
00212     
00213     if (j==1) continue ;    // on ne traite pas le terme en sin(0 phi)
00214 
00215     for (k=0; k<n3c; k++) {
00216 
00217         int i0 = n2n3c * j + k ; // indice de depart 
00218         double* cf0 = cf + i0 ;    // tableau des donnees a transformer
00219 
00220         i0 = n2n3f * j + k ; // indice de depart 
00221         double* ff0 = ff + i0 ;    // tableau resultat
00222          
00223 
00224 /*
00225  * NB: dans les commentaires qui suivent, psi designe la variable de [0, pi]
00226  *     reliee a theta par psi = 2 theta  et F(psi) = f(theta(psi)).  
00227  */
00228  
00229 
00230 // Calcul des coefficients de Fourier de la fonction 
00231 //   G(psi) = F+(psi) + F_(psi) sin(psi)
00232 // en fonction des coefficients en sin(2l theta) de f:
00233 
00234 //@@
00235 // Coefficients 
00236 //@@
00237 // Coefficients en sinus de G
00238 //---------------------------
00239 //  Ces coefficients sont egaux aux coefficients pairs du developmt. en
00240 //  sin(2l theta) de f (le facteur -.5 vient de la normalisation
00241 //  de fft991: si fft991 donnait reellement les coefficients en sinus,
00242 //  il faudrait le remplacer par un +1) :
00243 
00244         g[1] = 0. ;
00245             for (i=2; i<nm1; i += 2 ) g[i+1] = - .5 * cf0[n3c*i] ;  
00246         g[nt] = 0. ;    
00247 
00248 
00249 // Coefficients en cosinus de G
00250 //-----------------------------
00251 // Ces coefficients se deduisent des coefficients impairs du developmt. 
00252 // en sin(2l theta) de f (le facteur +.25 vient de la normalisation
00253 //  de fft991: si fft991 donnait reellement les coefficients en cosinus,
00254 //  il faudrait le remplacer par un +.5)
00255 
00256         g[0] = .5 * cf0[n3c] ;
00257             for ( i = 3; i < nt; i += 2 ) {
00258         g[i-1] = .25 * ( cf0[ n3c*i ] - cf0[ n3c*(i-2) ] ) ;
00259             }
00260         g[nm1] = - .5 * cf0[ n3c*(nt-2) ] ;
00261 
00262 
00263 // Transformation de Fourier inverse de G 
00264 //---------------------------------------
00265 
00266 // FFT inverse
00267             F77_fft991( g, t1, trigo, facto, &inc, &jump, &nm1, &lot, &isign) ;
00268 
00269 // Valeurs de f deduites de celles de G
00270 //-------------------------------------
00271 
00272             for ( i = 1; i < nm1s2 ; i++ ) {
00273 // ... indice du pt symetrique de psi par rapport a pi/2:
00274         int isym = nm1 - i ; 
00275     
00276         double fp = 0.5 * ( g[i] + g[isym] ) / sinp[i] ;
00277         double fm = 0.5 * ( g[i] - g[isym] ) ;
00278         ff0[ n3f*i ] = fp + fm ;
00279         ff0[ n3f*isym ] = fp - fm ;
00280             }
00281     
00282 //... cas particuliers:
00283         ff0[0] = 0. ;
00284         ff0[ n3f*nm1 ] = -2. * g[0] ;
00285         ff0[ n3f*nm1s2 ] = g[nm1s2] ;
00286 
00287 
00288     }   // fin de la boucle sur r 
00289    }    // fin de la boucle sur phi
00290 
00291     // Menage
00292     free (t1) ;
00293     free (g) ;
00294 
00295 }

Generated on Tue Feb 7 01:35:15 2012 for LORENE by  doxygen 1.4.6