sxpun_1d.C

00001 /*
00002  *   Copyright (c) 2000-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 sxpun_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sxpun_1d.C,v 1.6 2008/08/27 08:50:10 jl_cornou Exp $" ;
00024 
00025 /*
00026  * $Id: sxpun_1d.C,v 1.6 2008/08/27 08:50:10 jl_cornou Exp $
00027  * $Log: sxpun_1d.C,v $
00028  * Revision 1.6  2008/08/27 08:50:10  jl_cornou
00029  * Added Jacobi(0,2) polynomials
00030  *
00031  * Revision 1.5  2007/12/21 13:59:02  j_novak
00032  * Suppression of call to pow(-1, something).
00033  *
00034  * Revision 1.4  2007/12/12 09:56:57  jl_cornou
00035  * *** empty log message ***
00036  *
00037  * Revision 1.2  2002/10/16 14:37:07  j_novak
00038  * Reorganization of #include instructions of standard C++, in order to
00039  * use experimental version 3 of gcc.
00040  *
00041  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00042  * LORENE
00043  *
00044  * Revision 2.0  2000/04/03  17:01:59  phil
00045  * *** empty log message ***
00046  *
00047  *
00048  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sxpun_1d.C,v 1.6 2008/08/27 08:50:10 jl_cornou Exp $
00049  *
00050  */
00051 
00052 
00053 #include <stdlib.h>
00054 #include <math.h>
00055 
00056 #include "tbl.h"
00057 #include "type_parite.h"
00058 
00059 /*
00060  * Operateur :
00061  *  -R_CHEB : (f-f(-1))/(x+1)
00062  *  -R_JACO02 : (f-f(-1))/(x+1)
00063  * 
00064  *
00065  * Entree : coefficients de f dans tb
00066  *      nr : nombre de points en r
00067  * Sortie : coefficient du resultat dans tb
00068  * 
00069  * 
00070  */
00071 
00072 
00073         //-----------------------------------
00074         // Routine pour les cas non prevus --
00075         //-----------------------------------
00076 
00077 void _sxpun_1d_pas_prevu(int nr, double* tb, double *res) {
00078     cout << "sxpun pas prevu..." << endl ;
00079     cout << " valeurs: " << tb << "   " << res << endl ;
00080     cout << "nr : " << nr << endl ;
00081     abort () ;
00082     exit(-1) ;
00083 }
00084 
00085 
00086 
00087             //---------------
00088             // cas R_CHEB ---
00089             //---------------
00090 
00091 void _sxpun_1d_r_cheb (int nr, double* tb, double *xo)
00092 {
00093     
00094     assert (nr >= 3) ; 
00095     
00096     xo[nr-1] = 0 ;
00097     xo[nr-2] = 2*(tb[nr-1]-xo[nr-1]) ;
00098     
00099     for (int i=nr-3 ; i>0 ; i--)
00100     xo[i] = 2*tb[i+1]-2*xo[i+1]-xo[i+2] ;
00101     
00102     double somme = 0 ;
00103     for (int i=0 ; i<nr ; i++)
00104     if (i%2 == 0)
00105         somme += tb[i] ;
00106     else
00107         somme -= tb[i] ;
00108     
00109     xo[0] = tb[0]-xo[1]/2.-somme ;
00110 }
00111 
00112 
00113             //---------------
00114             // cas R_JACO02 -
00115             //---------------
00116 
00117 void _sxpun_1d_r_jaco02 (int nr, double* tb, double* xo)
00118 {
00119     
00120     xo[nr-1] = 0 ;
00121     double somme ;
00122     for (int i = 0 ; i < nr-1 ; i++) {
00123     somme = 0 ;
00124     for (int j = i+1 ; j < nr ; j++) {
00125       int signe = ((j-1-i)%2 == 0 ? 1 : -1) ;
00126     somme += signe*((j+1)*(j+2)/double((i+1)*(i+2))-(i+1)*(i+2)/double((j+1)*(j+2)))*tb[j] ;
00127     }
00128     xo[i] = (2*i+3)/double(4)*somme ;
00129     }
00130 }
00131 
00132             //----------------------------
00133             // La routine a appeler   ----
00134             //----------------------------
00135             
00136             
00137 void sxpun_1d(int nr, double **tb, int base_r)      // Version appliquee a this
00138 {
00139 
00140 // Routines de derivation
00141 static void (*sxpun_1d[MAX_BASE])(int, double *, double *) ;
00142 static int nap = 0 ;
00143 
00144     // Premier appel
00145     if (nap==0) {
00146     nap = 1 ;
00147     for (int i=0 ; i<MAX_BASE ; i++) {
00148         sxpun_1d[i] = _sxpun_1d_pas_prevu ;
00149     }
00150     // Les routines existantes
00151     sxpun_1d[R_CHEB >> TRA_R] = _sxpun_1d_r_cheb ;
00152     sxpun_1d[R_JACO02 >> TRA_R] = _sxpun_1d_r_jaco02 ;
00153     }
00154     
00155     double *result = new double[nr] ;
00156     sxpun_1d[base_r](nr, *tb, result) ;
00157     
00158     delete [] (*tb) ;
00159     (*tb) = result ;
00160 }

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