d2sdx2_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 d2sdx2_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/d2sdx2_1d.C,v 1.4 2007/12/11 15:28:18 jl_cornou Exp $" ;
00024 
00025 /*
00026  * $Id: d2sdx2_1d.C,v 1.4 2007/12/11 15:28:18 jl_cornou Exp $
00027  * $Log: d2sdx2_1d.C,v $
00028  * Revision 1.4  2007/12/11 15:28:18  jl_cornou
00029  * Jacobi(0,2) polynomials partially implemented
00030  *
00031  * Revision 1.3  2002/10/16 15:05:54  j_novak
00032  * *** empty log message ***
00033  *
00034  * Revision 1.2  2002/10/16 14:36:58  j_novak
00035  * Reorganization of #include instructions of standard C++, in order to
00036  * use experimental version 3 of gcc.
00037  *
00038  * Revision 1.1.1.1  2001/11/20 15:19:29  e_gourgoulhon
00039  * LORENE
00040  *
00041  * Revision 2.4  1999/10/11  15:18:14  phil
00042  * *** empty log message ***
00043  *
00044  * Revision 2.3  1999/10/11  14:27:06  phil
00045  * initialisation des variables statiques
00046  *
00047  * Revision 2.2  1999/09/03  14:15:56  phil
00048  * Correction termes 0 (/2)
00049  *
00050  * Revision 2.1  1999/07/08  09:53:13  phil
00051  * correction gestion memoire
00052  *
00053  * Revision 2.0  1999/07/07  10:15:26  phil
00054  * *** empty log message ***
00055  *
00056  *
00057  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/d2sdx2_1d.C,v 1.4 2007/12/11 15:28:18 jl_cornou Exp $
00058  *
00059  */
00060 
00061 #include <stdlib.h>
00062 #include "type_parite.h"
00063 #include "headcpp.h"
00064 #include "proto.h"
00065 
00066 /*
00067  * Routine appliquant l'operateur d2sdx2.
00068  * 
00069  * Entree : tb contient les coefficients du developpement 
00070  *      int nr : nombre de points en r. 
00071  *
00072  * Sortie : tb contient d2sdx2
00073  * 
00074  */
00075 
00076         //----------------------------------
00077         // Routine pour les cas non prevus --
00078         //----------------------------------
00079 
00080 void _d2sdx2_1d_pas_prevu(int nr, double* tb, double *xo) {
00081     cout << "d2sdx2 pas prevu..." << endl ;
00082     cout << "Nombre de points : " << nr << endl ;
00083     cout << "Valeurs : " << tb << "  " << xo <<endl ;
00084     abort() ;
00085     exit(-1) ;
00086 }
00087 
00088             //----------------
00089             // cas R_CHEBU ---
00090             //----------------
00091 
00092 void _d2sdx2_1d_r_chebu(int nr,  double* tb, double *xo)
00093 {
00094     // Variables statiques
00095     static double* cx1 = 0x0 ;
00096     static double* cx2 = 0x0 ;
00097     static double* cx3 = 0x0 ;
00098     static int nr_pre = 0 ;
00099 
00100     // Test sur np pour initialisation eventuelle
00101     if (nr > nr_pre) {
00102     nr_pre = nr ;
00103     if (cx1 != 0x0) delete [] cx1 ;
00104     if (cx2 != 0x0) delete [] cx2 ;
00105     if (cx3 != 0x0) delete [] cx3 ;
00106     cx1 = new double [nr] ;
00107     cx2 = new double [nr] ;
00108     cx3 = new double [nr] ;
00109     for (int i=0 ; i<nr ; i++) {
00110         cx1[i] =  (i+2)*(i+2)*(i+2) ;
00111         cx2[i] =  (i+2) ;
00112         cx3[i] =  i*i ;
00113         }
00114     }
00115 
00116     double som1, som2 ;
00117         
00118     xo[nr-1] = 0 ;
00119     som1 = (nr-1)*(nr-1)*(nr-1) * tb[nr-1] ;
00120     som2 = (nr-1) * tb[nr-1] ;
00121     xo[nr-3] = som1 - (nr-3)*(nr-3)*som2 ;
00122     for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
00123     som1 += cx1[i] * tb[i+2] ;
00124     som2 += cx2[i] * tb[i+2] ;
00125     xo[i] = som1 - cx3[i] * som2 ;
00126     }   // Fin de la premiere boucle sur r
00127         
00128     xo[nr-2] = 0 ;
00129     som1 = (nr-2)*(nr-2)*(nr-2) * tb[nr-2] ;
00130     som2 = (nr-2) * tb[nr-2] ;
00131     xo[nr-4] = som1 - (nr-4)*(nr-4)*som2 ;
00132     for (int i = nr-6 ; i >= 0 ; i -= 2 ) {
00133     som1 += cx1[i] * tb[i+2] ;
00134     som2 += cx2[i] * tb[i+2] ;
00135     xo[i] = som1 - cx3[i] * som2 ;
00136     }       // Fin de la deuxieme boucle sur r
00137         xo[0] *= 0.5 ;
00138     
00139 }
00140 
00141             //---------------
00142             // cas R_CHEB ---
00143             //---------------
00144 
00145 void _d2sdx2_1d_r_cheb(int nr, double* tb, double *xo)
00146 {
00147   
00148     // Variables statiques
00149     static double* cx1 = 0x0 ;
00150     static double* cx2 = 0x0 ;
00151     static double* cx3 = 0x0 ;
00152     static int nr_pre = 0 ;
00153 
00154     // Test sur np pour initialisation eventuelle
00155     if (nr > nr_pre) {
00156     nr_pre = nr ;
00157     if (cx1 != 0x0) delete [] cx1 ;
00158     if (cx2 != 0x0) delete [] cx2 ;
00159     if (cx3 != 0x0) delete [] cx3 ;
00160     cx1 = new double [nr] ;
00161     cx2 = new double [nr] ;
00162     cx3 = new double [nr] ;
00163     for (int i=0 ; i<nr ; i++) {
00164         cx1[i] =  (i+2)*(i+2)*(i+2) ;
00165         cx2[i] =  (i+2) ;
00166         cx3[i] =  i*i ;
00167         }
00168     }
00169 
00170     double som1, som2 ;
00171         
00172     xo[nr-1] = 0 ;
00173     som1 = (nr-1)*(nr-1)*(nr-1) * tb[nr-1] ;
00174     som2 = (nr-1) * tb[nr-1] ;
00175     xo[nr-3] = som1 - (nr-3)*(nr-3)*som2 ;
00176     for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
00177     som1 += cx1[i] * tb[i+2] ;
00178     som2 += cx2[i] * tb[i+2] ;
00179     xo[i] = som1 - cx3[i] * som2 ;
00180     }   // Fin de la premiere boucle sur r
00181     xo[nr-2] = 0 ;
00182     som1 = (nr-2)*(nr-2)*(nr-2) * tb[nr-2] ;
00183     som2 = (nr-2) * tb[nr-2] ;
00184     xo[nr-4] = som1 - (nr-4)*(nr-4)*som2 ;
00185     for (int i = nr-6 ; i >= 0 ; i -= 2 ) {
00186     som1 += cx1[i] * tb[i+2] ;
00187     som2 += cx2[i] * tb[i+2] ;
00188     xo[i] = som1 - cx3[i] * som2 ;
00189     }   // Fin de la deuxieme boucle sur r
00190     xo[0] *= .5 ;
00191        
00192 }
00193 
00194               //----------------
00195              // cas R_JACO02 --
00196             //----------------
00197 
00198 void _d2sdx2_1d_r_jaco02(int nr, double* tb, double *xo)
00199 {
00200     dsdx_1d(nr, &tb, R_JACO02 >> TRA_R) ;
00201     dsdx_1d(nr, &tb, R_JACO02 >> TRA_R) ;
00202     for (int i = 0 ;  i<nr ; i++) {
00203         xo[i] = tb[i] ;
00204     }
00205 }
00206 
00207 
00208             //-----------------
00209             // cas R_CHEBP ---
00210             //----------------
00211 
00212 void _d2sdx2_1d_r_chebp(int nr, double* tb, double *xo)
00213 {
00214     // Variables statiques
00215     static double* cx1 = 0x0 ;
00216     static double* cx2 = 0x0 ;
00217     static double* cx3 = 0x0 ;
00218     static int nr_pre = 0 ;
00219 
00220     // Test sur np pour initialisation eventuelle
00221     if (nr > nr_pre) {
00222     nr_pre = nr ;
00223     if (cx1 != 0x0) delete [] cx1 ;
00224     if (cx2 != 0x0) delete [] cx2 ;
00225     if (cx3 != 0x0) delete [] cx3 ;
00226     cx1 = new double [nr] ;
00227     cx2 = new double [nr] ;
00228     cx3 = new double [nr] ;
00229     for (int i=0 ; i<nr ; i++) {
00230         cx1[i] =  8*(i+1)*(i+1)*(i+1) ;
00231         cx2[i] =  2*(i+1) ;
00232         cx3[i] =  4*i*i ;
00233         }
00234     }
00235     
00236     double som1, som2 ;
00237 
00238     xo[nr-1] = 0 ; 
00239     som1 = 8*(nr-1)*(nr-1)*(nr-1) * tb[nr-1] ;
00240     som2 = 2*(nr-1) * tb[nr-1] ;
00241     xo[nr-2] = som1 - 4*(nr-2)*(nr-2)*som2 ;
00242   
00243     for (int i = nr-3 ; i >= 0 ; i-- ) {
00244     som1 += cx1[i] * tb[i+1] ;
00245     som2 += cx2[i] * tb[i+1] ;
00246     xo[i] = som1 - cx3[i] * som2 ;
00247     }   // Fin de la boucle sur r
00248     xo[0] *= .5 ;
00249 }
00250 
00251             //---------------
00252             // cas R_CHEBI --
00253             //---------------
00254 
00255 void _d2sdx2_1d_r_chebi(int nr, double* tb, double *xo)
00256 {
00257     // Variables statiques
00258     static double* cx1 = 0x0 ;
00259     static double* cx2 = 0x0 ;
00260     static double* cx3 = 0x0 ;
00261     static int nr_pre = 0 ;
00262 
00263     // Test sur np pour initialisation eventuelle
00264     
00265     if (nr > nr_pre) {
00266     nr_pre = nr ;
00267     if (cx1 != 0x0) delete [] cx1 ;
00268     if (cx2 != 0x0) delete [] cx2 ;
00269     if (cx3 != 0x0) delete [] cx3 ;
00270     cx1 = new double [nr] ;
00271     cx2 = new double [nr] ;
00272     cx3 = new double [nr] ;
00273     for (int i=0 ; i<nr ; i++) {
00274         cx1[i] =  (2*i+3)*(2*i+3)*(2*i+3) ;
00275         cx2[i] =  (2*i+3) ;
00276         cx3[i] =  (2*i+1)*(2*i+1) ;
00277         }
00278     }
00279   
00280     // pt. sur le tableau de double resultat
00281     double som1, som2 ;
00282         
00283     xo[nr-1] = 0 ;
00284     som1 = (2*nr-1)*(2*nr-1)*(2*nr-1) * tb[nr-1] ;
00285     som2 = (2*nr-1) * tb[nr-1] ;
00286     xo[nr-2] = som1 - (2*nr-3)*(2*nr-3)*som2 ;
00287     for (int i = nr-3 ; i >= 0 ; i-- ) {
00288     som1 += cx1[i] * tb[i+1] ;
00289     som2 += cx2[i] * tb[i+1] ;
00290     xo[i] = som1 - cx3[i] * som2 ;
00291     }   // Fin de la boucle su r
00292 
00293 }
00294 
00295 
00296         // ---------------------
00297         // La routine a appeler
00298         //----------------------
00299         
00300         
00301 void d2sdx2_1d(int nr, double** tb, int base_r)
00302 {
00303 
00304         // Routines de derivation
00305     static void (*d2sdx2_1d[MAX_BASE])(int, double*, double *) ;
00306     static int nap = 0 ;
00307 
00308         // Premier appel
00309     if (nap==0) {
00310     nap = 1 ;
00311     for (int i=0 ; i<MAX_BASE ; i++) {
00312         d2sdx2_1d[i] = _d2sdx2_1d_pas_prevu ;
00313     }
00314         // Les routines existantes
00315     d2sdx2_1d[R_CHEB >> TRA_R] = _d2sdx2_1d_r_cheb ;
00316     d2sdx2_1d[R_CHEBU >> TRA_R] = _d2sdx2_1d_r_chebu ;
00317     d2sdx2_1d[R_CHEBP >> TRA_R] = _d2sdx2_1d_r_chebp ;
00318     d2sdx2_1d[R_CHEBI >> TRA_R] = _d2sdx2_1d_r_chebi ;
00319     d2sdx2_1d[R_JACO02 >> TRA_R] = _d2sdx2_1d_r_jaco02 ;
00320     }
00321     
00322     double *result = new double[nr] ;
00323     
00324     d2sdx2_1d[base_r](nr, *tb, result) ;
00325     
00326     delete [] (*tb) ;
00327     (*tb) = result ;
00328 }

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