sxdsdx_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 sxdsdx_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sxdsdx_1d.C,v 1.3 2003/10/31 09:58:55 p_grandclement Exp $" ;
00024 
00025 /*
00026  * $Id: sxdsdx_1d.C,v 1.3 2003/10/31 09:58:55 p_grandclement Exp $
00027  * $Log: sxdsdx_1d.C,v $
00028  * Revision 1.3  2003/10/31 09:58:55  p_grandclement
00029  * *** empty log message ***
00030  *
00031  * Revision 1.2  2002/10/16 14:37:00  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:37  phil
00039  * correction gestion memoire
00040  *
00041  * Revision 2.0  1999/07/07  10:15:14  phil
00042  * *** empty log message ***
00043  *
00044  *
00045  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sxdsdx_1d.C,v 1.3 2003/10/31 09:58:55 p_grandclement Exp $
00046  *
00047  */
00048 
00049 
00050 // Includes
00051 #include <stdlib.h>
00052 
00053 #include "tbl.h"
00054 #include "type_parite.h"
00055 
00056 /*
00057  * Operateur :
00058  *  -R_CHEB : ds/dx 
00059  *  -R_CHEBP ou R_CHEBI : (f'-f'(0))/x
00060  *  -R_CHEBU (f'-f'(1))/(x-1)
00061  * 
00062  * 
00063  * Entree : coefficients de f dans tb
00064  *      nr : nombre de points en r
00065  * Sortie : coeffieicient du resultat dans tb
00066  * 
00067  * 
00068  */
00069 
00070 
00071         //-----------------------------------
00072         // Routine pour les cas non prevus --
00073         //-----------------------------------
00074 
00075 void _sxdsdx_1d_pas_prevu(int nr, double* tb, double *res) {
00076     cout << "sxdsdx pas prevu..." << endl ;
00077     cout << " valeurs: " << tb << "   " << res << endl ;
00078     cout << "nr : " << nr << endl ;
00079     abort () ;
00080     exit(-1) ;
00081 }
00082 
00083 
00084 
00085             //---------------
00086             // cas R_CHEB ---
00087             //---------------
00088 
00089 void _dsdx_1d_r_cheb(int nr, double* tb, double *xo)
00090 {
00091 
00092     double som ;
00093         
00094     xo[nr-1] = 0 ;
00095     som = 2*(nr-1) * tb[nr-1] ;
00096     xo[nr-2] = som ;
00097     for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
00098     som += 2*(i+1) * tb[i+1] ;
00099     xo[i] = som ;
00100     }   // Fin de la premiere boucle sur r
00101     som = 2*(nr-2) * tb[nr-2] ;
00102     xo[nr-3] = som ;
00103     for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
00104     som += 2*(i+1) * tb[i+1] ;
00105     xo[i] = som ;
00106     }   // Fin de la deuxieme boucle sur r
00107     xo[0] *= .5 ;
00108 
00109 }
00110 
00111             //---------------
00112             // cas R_CHEBU ---
00113             //---------------
00114 
00115 void sxm1_1d_cheb (int, double*) ;
00116 
00117 void _sxmundsdx_1d_r_chebu(int nr, double* tb, double *xo)
00118 {
00119 
00120   double som ;
00121   
00122   xo[nr-1] = 0 ;
00123   som = 2*(nr-1) * tb[nr-1] ;
00124   xo[nr-2] = som ;
00125   for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
00126     som += 2*(i+1) * tb[i+1] ;
00127     xo[i] = som ;
00128   } // Fin de la premiere boucle sur r
00129   som = 2*(nr-2) * tb[nr-2] ;
00130   xo[nr-3] = som ;
00131   for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
00132     som += 2*(i+1) * tb[i+1] ;
00133     xo[i] = som ;
00134   } // Fin de la deuxieme boucle sur r
00135   xo[0] *= .5 ;
00136   
00137   sxm1_1d_cheb (nr, xo) ;
00138 }
00139 
00140             //----------------
00141             // cas R_CHEBP ---
00142             //----------------
00143 
00144 void _sxdsdx_1d_r_chebp(int nr, double* tb, double *xo)
00145 {
00146 
00147     double som ;
00148       
00149     xo[nr-1] = 0 ;
00150     som = 8 * (nr-1) * tb[nr-1] ;
00151     xo[nr-2] = som ;
00152     for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
00153     som += 8 * (i+1) * tb[i+1] ;
00154     xo[i] = som ;
00155     }   // Fin de la premiere boucle sur r
00156 
00157     som = 8 * (nr-2) * tb[nr-2] ;
00158     xo[nr-3] = som ;
00159     for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
00160     som += 8 * (i+1) * tb[i+1] ;
00161     xo[i] = som ;
00162     }   // Fin de la deuxieme boucle sur r
00163         
00164     xo[0] *= .5 ;
00165     
00166 }
00167 
00168             //----------------
00169             // cas R_CHEBI ---
00170             //----------------
00171             
00172 void _sxdsdx_1d_r_chebi(int nr, double* tb, double *xo)
00173 {
00174 
00175  
00176     double som ;
00177 
00178     xo[nr-1] = 0 ;
00179     som = 4 * (2*(nr-1)+1) * tb[nr-1] ;
00180     xo[nr-2] = som ;
00181     for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
00182     som += 4 * (2*(i+1)+1) * tb[i+1] ;
00183     xo[i] = som ;
00184     }   // Fin de la premiere boucle sur r
00185 
00186     som = 4 * (2*(nr-2)+1) * tb[nr-2] ;
00187     xo[nr-3] = som ;
00188     for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
00189     som += 4 * (2*(i+1)+1) * tb[i+1] ;
00190     xo[i] = som ;
00191     }   // Fin de la deuxieme boucle sur r
00192 
00193 }
00194 
00195 
00196             //----------------------------
00197             // La routine a appeler   ----
00198             //----------------------------
00199             
00200             
00201 void sxdsdx_1d(int nr, double **tb, int base_r)     // Version appliquee a this
00202 {
00203 
00204 // Routines de derivation
00205 static void (*sxdsdx_1d[MAX_BASE])(int, double *, double *) ;
00206 static int nap = 0 ;
00207 
00208     // Premier appel
00209     if (nap==0) {
00210     nap = 1 ;
00211     for (int i=0 ; i<MAX_BASE ; i++) {
00212         sxdsdx_1d[i] = _sxdsdx_1d_pas_prevu ;
00213     }
00214     // Les routines existantes
00215     sxdsdx_1d[R_CHEB >> TRA_R] = _dsdx_1d_r_cheb ;
00216     sxdsdx_1d[R_CHEBP >> TRA_R] = _sxdsdx_1d_r_chebp ;
00217     sxdsdx_1d[R_CHEBI >> TRA_R] = _sxdsdx_1d_r_chebi ;
00218     sxdsdx_1d[R_CHEBU >> TRA_R] = _sxmundsdx_1d_r_chebu ;
00219     }
00220     
00221     double *result = new double[nr] ;
00222     sxdsdx_1d[base_r](nr, *tb, result) ;
00223     
00224     delete [] (*tb) ;
00225     (*tb) = result ;
00226 }

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