sx_1d.C

00001 /*
00002  *   Copyright (c) 2006 Jerome Novak
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 sx_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sx_1d.C,v 1.1 2006/04/10 15:19:20 j_novak Exp $" ;
00024 
00025 /*
00026  * $Id: sx_1d.C,v 1.1 2006/04/10 15:19:20 j_novak Exp $
00027  * $Log: sx_1d.C,v $
00028  * Revision 1.1  2006/04/10 15:19:20  j_novak
00029  * New definition of 1D operators dsdx and sx in the nucleus (bases R_CHEBP and
00030  * R_CHEBI).
00031  *
00032  *
00033  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sx_1d.C,v 1.1 2006/04/10 15:19:20 j_novak Exp $
00034  *
00035  */
00036  
00037  
00038  // Includes
00039 #include <stdlib.h>
00040 
00041 #include "headcpp.h"
00042 #include "type_parite.h"
00043 #include "proto.h"
00044 
00045 
00046 /*
00047  * 1/x operator (division by x)
00048  * 
00049  * Only for the bases R_CHEBP and R_CHEBI
00050  * 
00051  * Input :
00052  * 
00053  *  int nr : number of coefficients
00054  *  tb     : the array of coefficients of the input function
00055  *  
00056  * Output :
00057  *  tb     : the array of coefficients of the result
00058  */
00059  
00060  
00061         //----------------------------
00062         // Bases not implemented -----
00063         //----------------------------
00064 
00065 void _sx_1d_pas_prevu(int , double* , double *) {
00066     cout << "sx_1d : base not implemented..." << endl ;
00067     abort() ;
00068     exit(-1) ;
00069 }
00070 
00071 
00072         //-------------------
00073         // case R_CHEBP  ---
00074         //-------------------
00075 
00076 void _sx_1d_r_chebp (int nr, double* tb, double* res) {
00077    
00078     double som ;
00079     int sign = 1 ; 
00080     res[nr-1] = 0 ;
00081     som = 2 * sign * tb[nr-1] ;
00082     res[nr-2] = som ;
00083     for (int i=nr-3 ; i>=0 ; i--) {
00084     sign = - sign ;
00085     som += 2 * sign * tb[i+1] ;
00086     res[i] = (i%2 == 0 ? -1 : 1) * som ;
00087     }
00088  
00089 }
00090 
00091 
00092         //-------------------
00093         // case R_CHEBI  ---
00094         //-------------------
00095 
00096 void _sx_1d_r_chebi (int nr, double* tb, double* res) {
00097    
00098     double som ;
00099     int sign = 1 ; 
00100     res[nr-1] = 0 ;
00101     som = 2 * sign * tb[nr-2] ;
00102     res[nr-2] = som ;
00103     for (int i=nr-3 ; i>=0 ; i--) {
00104     sign = - sign ;
00105     som += 2 * sign * tb[i] ;
00106     res[i] = (i%2 == 0 ? -1 : 1) * som ;
00107     }
00108     res[0] *= 0.5 ;
00109 }
00110 
00111         //-------------------
00112         // case R_CHEBU  ---
00113         //-------------------
00114 
00115 void _sx_1d_r_chebu (int nr, double* tb, double* res) {
00116    
00117     for (int i=0; i<nr; i++)
00118     res[i] = tb[i] ;
00119 
00120     sxm1_1d_cheb(nr, res) ;
00121 
00122 }
00123 
00124 
00125 
00126         // ----------------------
00127         // The calling function 
00128         //-----------------------
00129         
00130 void sx_1d(int nr,  double **tb, int base_r)
00131 {
00132 
00133     static void (*sx_1d[MAX_BASE])(int, double *, double *) ;
00134     static int nap = 0 ;
00135 
00136         // Premier appel
00137     if (nap==0) {
00138     nap = 1 ;
00139     for (int i=0 ; i<MAX_BASE ; i++) {
00140         sx_1d[i] = _sx_1d_pas_prevu ;
00141     }
00142         // Les routines existantes
00143     sx_1d[R_CHEBP >> TRA_R] = _sx_1d_r_chebp ;
00144     sx_1d[R_CHEBI >> TRA_R] = _sx_1d_r_chebi ;
00145     sx_1d[R_CHEBU >> TRA_R] = _sx_1d_r_chebu ;
00146     }
00147     
00148     
00149     double *result = new double[nr] ;
00150     sx_1d[base_r](nr, *tb, result) ;
00151     delete [] (*tb) ;
00152     (*tb) = result ;
00153 }
00154 

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