sx2_1d.C

00001 /*
00002  *   Copyright (c) 1999-2001 Philippe Grandclement
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 sx2_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sx2_1d.C,v 1.3 2007/12/11 15:28:18 jl_cornou Exp $" ;
00024 
00025 /*
00026  * $Id: sx2_1d.C,v 1.3 2007/12/11 15:28:18 jl_cornou Exp $
00027  * $Log: sx2_1d.C,v $
00028  * Revision 1.3  2007/12/11 15:28:18  jl_cornou
00029  * Jacobi(0,2) polynomials partially implemented
00030  *
00031  * Revision 1.2  2002/10/16 14:36:59  j_novak
00032  * Reorganization of #include instructions of standard C++, in order to
00033  * use experimental version 3 of gcc.
00034  *
00035  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00036  * LORENE
00037  *
00038  * Revision 2.1  1999/07/08  09:55:21  phil
00039  * correction gestion memoire
00040  *
00041  * Revision 2.0  1999/07/07  10:15:03  phil
00042  * *** empty log message ***
00043  *
00044  *
00045  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sx2_1d.C,v 1.3 2007/12/11 15:28:18 jl_cornou Exp $
00046  *
00047  */
00048 
00049 // Includes
00050 #include <stdlib.h>
00051 
00052 
00053 #include "headcpp.h"
00054 #include "type_parite.h"
00055 #include "proto.h"
00056 
00057 /*
00058  * Operateurs non singuliers :
00059  *  R_CHEB : Identite
00060  *  R_CHEBP, R_CHEBI : (f-f(0)-f'(0)x)/x^2
00061  *  R_CHEBU : (f-f(1)-(x-1)*f'(1))/(x-1)^2
00062  * 
00063  *Entree : tb contient coefficients de developpement en r
00064  *         nr : nombre de points en r.  
00065  *Sortie : tb contient les coefficients du resultat
00066  * 
00067  */
00068 
00069         //-----------------------------------
00070         // Routine pour les cas non prevus --
00071         //-----------------------------------
00072 
00073 void _sx2_1d_pas_prevu(int nr, double* tb, double *res) {
00074     cout << "sx2 pas prevu..." << tb << "    " << res << endl ;
00075     cout << "nr : " << nr << endl ;
00076     abort() ;
00077     exit(-1) ;
00078 }
00079 
00080 
00081             //-------------
00082             // Identite --
00083             //------------
00084 
00085 void _sx2_1d_identite(int nr, double*tb ,double *res) {
00086     for (int i=0 ; i<nr ; i++)
00087     res[i] = tb[i] ;
00088 }
00089 
00090 
00091             //---------------
00092             // cas R_CHEBP --
00093             //---------------
00094 
00095 void _sx2_1d_r_chebp(int nr, double* tb, double *xo)
00096 {
00097    
00098    
00099    
00100     double somp, somn ;
00101     int sgn = 1 ;
00102         
00103     xo[nr-1] = 0 ;
00104     somp = 4 * sgn * (nr-1) * tb[nr-1] ;
00105     somn = 2 * sgn * tb[nr-1] ;
00106     xo[nr-2] = somp - 2*(nr-2)*somn ;
00107     for (int i = nr-3 ; i >= 0 ; i-- ) {
00108     sgn = - sgn ;
00109     somp += 4 * (i+1) * sgn * tb[i+1] ;
00110     somn += 2 * sgn * tb[i+1] ;
00111     xo[i] = somp - 2*i * somn ;
00112     }   // Fin de la premiere boucle sur r
00113     for (int i=0 ; i<nr ; i+=2) {
00114     xo[i] = -xo[i] ;
00115     }   // Fin de la deuxieme boucle sur r
00116     xo[0] *= .5 ;
00117 
00118 }
00119 
00120 
00121             //---------------
00122             // cas R_CHEBI --
00123             //---------------
00124 
00125 void _sx2_1d_r_chebi(int nr, double* tb, double *xo)
00126 {
00127     double somp, somn ;
00128     int sgn = 1 ;
00129         
00130     xo[nr-1] = 0 ;
00131     somp = 2 * sgn * (2*(nr-1)+1) * tb[nr-1] ;
00132     somn = 2 * sgn * tb[nr-1] ;
00133     xo[nr-2] = somp - (2*(nr-2)+1)*somn ;
00134     for (int i = nr-3 ; i >= 0 ; i-- ) {
00135     sgn = - sgn ;
00136     somp += 2 * (2*(i+1)+1) * sgn * tb[i+1] ;
00137     somn += 2 * sgn * tb[i+1] ;
00138     xo[i] = somp - (2*i+1) * somn ;
00139     }   // Fin de la premiere boucle sur r
00140     for (int i=0 ; i<nr ; i+=2) {
00141     xo[i] = -xo[i] ;
00142     }   // Fin de la deuxieme boucle sur r
00143 
00144 }
00145             //----------------
00146             // cas R_CHEBU --
00147             //---------------
00148 
00149 void _sxm12_1d_r_chebu(int nr, double* tb, double *xo) {
00150 
00151     // On appelle juste deux fois la routine existante :
00152     sxm1_1d_cheb(nr, tb) ;
00153     sxm1_1d_cheb(nr, tb) ;
00154     for (int i=0 ; i<nr ; i++)
00155     xo[i] = tb[i] ;
00156 }  
00157 
00158             //----------------------
00159             // La routine a appeler
00160             //----------------------
00161             
00162 void sx2_1d(int nr, double **tb, int base_r)        // Version appliquee a this
00163 {
00164 
00165 // Routines de derivation
00166 static void (*sx2_1d[MAX_BASE])(int, double *, double*) ;
00167 static int nap = 0 ;
00168 
00169     // Premier appel
00170     if (nap==0) {
00171     nap = 1 ;
00172     for (int i=0 ; i<MAX_BASE ; i++) {
00173         sx2_1d[i] = _sx2_1d_pas_prevu ;
00174     }
00175     // Les routines existantes
00176     sx2_1d[R_CHEB >> TRA_R] = _sx2_1d_identite ;
00177     sx2_1d[R_CHEBP >> TRA_R] = _sx2_1d_r_chebp ;
00178     sx2_1d[R_CHEBI >> TRA_R] = _sx2_1d_r_chebi ;
00179     sx2_1d[R_CHEBU >> TRA_R] = _sxm12_1d_r_chebu ;
00180     }
00181     
00182     double *result = new double[nr] ;
00183     sx2_1d[base_r](nr, *tb, result) ;
00184     
00185     delete [] (*tb) ;
00186     (*tb) = result ;
00187 }       

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