dsdx_1d.C

00001     /*
00002  *   Copyright (c) 2004 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 dsdx_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/dsdx_1d.C,v 1.5 2007/12/12 12:30:48 jl_cornou Exp $" ;
00024 
00025 /*
00026  * $Id: dsdx_1d.C,v 1.5 2007/12/12 12:30:48 jl_cornou Exp $
00027  * $Log: dsdx_1d.C,v $
00028  * Revision 1.5  2007/12/12 12:30:48  jl_cornou
00029  * *** empty log message ***
00030  *
00031  * Revision 1.4  2007/12/11 15:28:18  jl_cornou
00032  * Jacobi(0,2) polynomials partially implemented
00033  *
00034  * Revision 1.3  2006/04/10 15:19:20  j_novak
00035  * New definition of 1D operators dsdx and sx in the nucleus (bases R_CHEBP and
00036  * R_CHEBI).
00037  *
00038  * Revision 1.2  2005/01/10 16:34:53  j_novak
00039  * New class for 1D mono-domain differential operators.
00040  *
00041  * Revision 1.1  2004/02/06 10:53:53  j_novak
00042  * New dzpuis = 5 -> dzpuis = 3 case (not ready yet).
00043  *
00044  *
00045  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/dsdx_1d.C,v 1.5 2007/12/12 12:30:48 jl_cornou Exp $
00046  *
00047  */
00048 
00049 #include <math.h>
00050 #include <stdlib.h>
00051 #include "type_parite.h"
00052 #include "headcpp.h"
00053 #include "proto.h"
00054 
00055 /*
00056  * Routine appliquant l'operateur dsdx.
00057  * 
00058  * Entree : tb contient les coefficients du developpement 
00059  *      int nr : nombre de points en r. 
00060  *
00061  * Sortie : tb contient dsdx
00062  * 
00063  */
00064 
00065         //----------------------------------
00066         // Routine pour les cas non prevus --
00067         //----------------------------------
00068 
00069 void _dsdx_1d_pas_prevu(int nr, double* tb, double *xo) {
00070     cout << "dsdx pas prevu..." << endl ;
00071     cout << "Nombre de points : " << nr << endl ;
00072     cout << "Valeurs : " << tb << "  " << xo <<endl ;
00073     abort() ;
00074     exit(-1) ;
00075 }
00076 
00077             //----------------
00078             // cas R_CHEBU ---
00079             //----------------
00080 
00081 void _dsdx_1d_r_chebu(int nr,  double* tb, double *xo)
00082 {
00083 
00084     double som ;
00085         
00086     xo[nr-1] = 0 ;
00087     som = 2*(nr-1) * tb[nr-1] ;
00088     xo[nr-2] = som ;
00089     for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
00090       som += 2*(i+1) * tb[i+1] ;
00091       xo[i] = som ;
00092     }   // Fin de la premiere boucle sur r
00093     som = 2*(nr-2) * tb[nr-2] ;
00094     xo[nr-3] = som ;
00095     for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
00096       som += 2*(i+1) * tb[i+1] ;
00097       xo[i] = som ;
00098     }   // Fin de la deuxieme boucle sur r
00099     xo[0] *= .5 ;
00100 
00101 }
00102 
00103 
00104             //----------------
00105             // cas R_JACO02 --
00106             //----------------
00107 
00108 void _dsdx_1d_r_jaco02(int nr,  double* tb, double *xo)
00109 {
00110 
00111     double som ;
00112         
00113     xo[nr-1] = 0 ;
00114     for (int i = 0 ; i < nr-1 ; i++ ) {
00115       som = 0 ;
00116     for ( int j = i+1 ; j < nr ; j++ ) {
00117     som += (1 - pow(double(-1),(j-i))*(i+1)*(i+2)/double((j+1)*(j+2)))*tb[j] ;
00118     }  // Fin de la boucle auxiliaire
00119       xo[i] = (i+1.5)*som ;
00120     }   // Fin de la boucle sur R
00121 
00122 }
00123 
00124             //----------------
00125             // cas R_CHEBI ---
00126             //----------------
00127 
00128 void _dsdx_1d_r_chebi(int nr,  double* tb, double *xo)
00129 {
00130 
00131     double som ;
00132         
00133     xo[nr-1] = 0 ;
00134     som = 2*(2*nr-3) * tb[nr-2] ;
00135     xo[nr-2] = som ;
00136     for (int i = nr-3 ; i >= 0 ; i -- ) {
00137       som += 2*(2*i+1) * tb[i] ;
00138       xo[i] = som ;
00139     }   
00140     xo[0] *= .5 ;
00141 }
00142 
00143             //----------------
00144             // cas R_CHEBP ---
00145             //----------------
00146 
00147 void _dsdx_1d_r_chebp(int nr,  double* tb, double *xo)
00148 {
00149 
00150     double som ;
00151         
00152     xo[nr-1] = 0 ;
00153     som = 4*(nr-1) * tb[nr-1] ;
00154     xo[nr-2] = som ;
00155     for (int i = nr-3 ; i >= 0 ; i --) {
00156       som += 4*(i+1) * tb[i+1] ;
00157       xo[i] = som ;
00158     }   
00159 }
00160 
00161         // ---------------------
00162         // La routine a appeler
00163         //----------------------
00164         
00165         
00166 void dsdx_1d(int nr, double** tb, int base_r)
00167 {
00168 
00169         // Routines de derivation
00170     static void (*dsdx_1d[MAX_BASE])(int, double*, double *) ;
00171     static int nap = 0 ;
00172 
00173         // Premier appel
00174     if (nap==0) {
00175     nap = 1 ;
00176     for (int i=0 ; i<MAX_BASE ; i++) {
00177         dsdx_1d[i] = _dsdx_1d_pas_prevu ;
00178     }
00179         // Les routines existantes
00180     dsdx_1d[R_CHEBU >> TRA_R] = _dsdx_1d_r_chebu ;
00181     dsdx_1d[R_CHEBP >> TRA_R] = _dsdx_1d_r_chebp ;
00182     dsdx_1d[R_CHEBI >> TRA_R] = _dsdx_1d_r_chebi ;
00183     dsdx_1d[R_CHEB >> TRA_R] = _dsdx_1d_r_cheb ;
00184     dsdx_1d[R_JACO02 >> TRA_R] = _dsdx_1d_r_jaco02 ;
00185 
00186     }
00187     
00188     double *result = new double[nr] ;
00189     
00190     dsdx_1d[base_r](nr, *tb, result) ;
00191     
00192     delete [] (*tb) ;
00193     (*tb) = result ;
00194 }

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