cipcossin.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 cipcossin_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/FFT991/cipcossin.C,v 1.1 2004/12/21 17:06:01 j_novak Exp $" ;
00024 
00025 
00026 /*
00027  * Transformation de Fourier inverse sur le premier indice d'un tableau 3-D
00028  *  par le biais de la routine FFT Fortran FFT991
00029  *
00030  * Entree:
00031  * -------
00032  *   int* deg   : tableau du nombre effectif de degres de liberte dans chacune 
00033  *        des 3 dimensions: le nombre de points de collocation
00034  *        en phi est  np = deg[0] et doit etre de la forme
00035  *          np = 2^p 3^q 5^r 
00036  *   int* dimc  : tableau du nombre d'elements dans chacune des trois 
00037  *            dimensions du tableau cf
00038  *        On doit avoir  dimc[0] >= deg[0] + 2  = np + 2. 
00039  *
00040  *   int* dimf  : tableau du nombre d'elements dans chacune des trois 
00041  *            dimensions du tableau ff
00042  *        On doit avoir  dimf[0] >= deg[0]  = np . 
00043  *
00044  *
00045  * Entree / sortie :
00046  * -----------------
00047  *   double* cf : entree: tableau des coefficients de la fonction f; 
00048  *            L'espace memoire correspondant a ce
00049  *                        pointeur doit etre dimc[0]*dimc[1]*dimc[2] et doit 
00050  *            avoir ete alloue avant l'appel a la routine.
00051  *            La convention de stokage est la suivante:
00052  *      cf[ dimc[2]*dimc[1]*k + dimc[2]*j + i ] = c_k      0<= k <= np,
00053  *            ou les indices j et i correspondent respectivement
00054  *            a theta et a r et ou les c_k sont les coefficients 
00055  *            du developpement de f en series de Fourier:
00056  *
00057  *          f(phi) = som_{l=0}^{np/2} c_{2l} cos( 2 pi/T l phi )
00058  *               + c_{2l+1} sin( 2 pi/T l phi ),
00059  *
00060  *                ou T est la periode de f.
00061  *            En particulier cf[1] = 0.
00062  *            De plus, cf[np+1] n'est pas egal a c_{np+1}
00063  *            mais a zero.
00064  *   !!!! CE TABLEAU EST DETRUIT EN SORTIE !!!!!
00065  *
00066  * Sortie:
00067  * -------
00068  *  double* ff : tableau des valeurs de la fonction aux points de
00069  *                        de collocation
00070  *
00071  *              phi_k = T k/np      0 <= k <= np-1
00072  *
00073  *            suivant la convention de stokage:
00074  *  ff[ dimf[2]*dimf[1]*k + dimf[2]*j + i ] = f(phi_k)    0 <= k <= np-1,
00075  *           les indices j et i correspondant respectivement
00076  *            a theta et a r. 
00077  *            L'espace memoire correspondant a ce
00078  *                        pointeur doit etre dimf[0]*dimf[1]*dimf[2] et doit 
00079  *            avoir ete alloue avant l'appel a la routine.
00080  */
00081 
00082 /*
00083  * $Id: cipcossin.C,v 1.1 2004/12/21 17:06:01 j_novak Exp $
00084  * $Log: cipcossin.C,v $
00085  * Revision 1.1  2004/12/21 17:06:01  j_novak
00086  * Added all files for using fftw3.
00087  *
00088  * Revision 1.4  2003/01/31 10:31:23  e_gourgoulhon
00089  * Suppressed the directive #include <malloc.h> for malloc is defined
00090  * in <stdlib.h>
00091  *
00092  * Revision 1.3  2002/10/16 14:36:53  j_novak
00093  * Reorganization of #include instructions of standard C++, in order to
00094  * use experimental version 3 of gcc.
00095  *
00096  * Revision 1.2  2002/09/09 13:00:40  e_gourgoulhon
00097  * Modification of declaration of Fortran 77 prototypes for
00098  * a better portability (in particular on IBM AIX systems):
00099  * All Fortran subroutine names are now written F77_* and are
00100  * defined in the new file C++/Include/proto_f77.h.
00101  *
00102  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00103  * LORENE
00104  *
00105  * Revision 2.0  1999/02/22  15:43:58  hyc
00106  * *** empty log message ***
00107  *
00108  *
00109  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Coef/FFT991/cipcossin.C,v 1.1 2004/12/21 17:06:01 j_novak Exp $
00110  *
00111  */
00112 
00113 
00114 // headers du C
00115 #include <assert.h>
00116 #include <stdlib.h>
00117 
00118 // Prototypes of F77 subroutines
00119 #include "headcpp.h"
00120 #include "proto_f77.h"
00121 
00122 // Prototypage des sous-routines utilisees:
00123 int*    facto_ini(int ) ;
00124 double* trigo_ini(int ) ;
00125 //*****************************************************************************
00126 
00127 void cipcossin(const int* deg, const int* dimc, const int* dimf, 
00128            double* cf, double* ff)
00129 {
00130 
00131 int i, j, k, index ;
00132 
00133 // Dimensions des tableaux ff et cf  :
00134     int n1f = dimf[0] ;
00135     int n2f = dimf[1] ;
00136     int n3f = dimf[2] ;
00137     int n1c = dimc[0] ;
00138     int n2c = dimc[1] ;
00139     int n3c = dimc[2] ;
00140 
00141 // Nombres de degres de liberte en phi:    
00142     int np = deg[0] ;
00143 
00144 // Tests de dimension:
00145     if (np+2 > n1c) {
00146     cout << "cipcossin: np+2 > n1c : np = " << np << " ,  n1c = " 
00147     << n1c << endl ;
00148     abort () ;
00149     exit(-1) ;
00150     }
00151     if (np > n1f) {
00152     cout << "cipcossin: np > n1f : np = " << np << " ,  n1f = " 
00153     << n1f << endl ;
00154     abort () ;
00155     exit(-1) ;
00156     }
00157     if (n3f > n3c) {
00158     cout << "cipcossin: n3f > n3c : n3f = " << n3f << " ,  n3c = " 
00159     << n3c << endl ;
00160     abort () ;
00161     exit(-1) ;
00162     }
00163     if (n2f > n2c) {
00164     cout << "cipcossin: n2f > n2c : n2f = " << n2f << " ,  n2c = " 
00165     << n2c << endl ;
00166     abort () ;
00167     exit(-1) ;
00168     }
00169 
00170     // Recherche des tables
00171     int* facto = facto_ini(np) ;
00172     double* trigo = trigo_ini(np) ;
00173     
00174     // Tableau de travail
00175     double* t1 = (double*)( malloc( (np+2)*sizeof(double) ) ) ;
00176 
00177 // Denormalisation des cosinus
00178     int n2n3c = n2c * n3c ;
00179     for (i=2; i<np; i += 2 )    {
00180         for (j=0; j<n2c; j++) {
00181         for (k=0; k<n3c; k++) {
00182         index = n2n3c * i + n3c * j + k ;
00183         cf[index] *=  .5 ;  
00184        }
00185     }
00186     }
00187 
00188 // Normalisation des sinus (les termes sin(0*phi) et sin(np/2 *phi) ne sont pas
00189 //              traites)
00190     for (i=3; i<np+1; i += 2 )  { 
00191         for (j=0; j<n2c; j++) {
00192         for (k=0; k<n3c; k++) {
00193         index = n2n3c * i + n3c * j + k ;
00194         cf[index] *=  -.5 ; 
00195        }
00196     }
00197     }
00198 
00199 // Parametres pour la routine FFT991
00200     int jump = 1 ;
00201     int inc = n2n3c ;
00202     int lot = 1 ;
00203     int isign = 1 ;
00204 
00205 // boucle sur r et theta
00206 
00207     for (j=0; j<n2c; j++) {
00208     for (k=0; k<n3c; k++) {
00209     
00210         index = n3c * j + k ;
00211 
00212 // FFT inverse
00213         double* debut = cf + index ;
00214 
00215             F77_fft991( debut, t1, trigo, facto, &inc, &jump, &np,
00216              &lot, &isign) ;
00217     }   // fin de la boucle sur r 
00218    }    // fin de la boucle sur theta
00219 
00220 // On recopie le resultat dans ff si besoin est (c'est-a-dire si le
00221 //  pointeur ff est different de cf) :
00222    
00223    if ( ff != cf ) {
00224     int n2n3f = n2f * n3f ;
00225     for (i=0; i<np; i++) {
00226             for (j=0; j<n2f; j++) {
00227             for (k=0; k<n3f; k++) {
00228             int indexc = n2n3c * i + n3c * j + k ;
00229             int indexf = n2n3f * i + n3f * j + k ;
00230             ff[indexf] = cf[indexc]  ;  
00231         }
00232         }
00233     }   
00234     
00235    }
00236 
00237     // Menage
00238     free (t1) ;
00239     
00240 }

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