sh_pvect_r.C

00001 /*
00002  *  Methods for computing the homogeneous solutions for Ope_pois_vect_r.
00003  *
00004  *    (see file Ope_elementary for documentation).
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2004 Jerome Novak
00010  *
00011  *   This file is part of LORENE.
00012  *
00013  *   LORENE is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License version 2
00015  *   as published by the Free Software Foundation.
00016  *
00017  *   LORENE is distributed in the hope that it will be useful,
00018  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *   GNU General Public License for more details.
00021  *
00022  *   You should have received a copy of the GNU General Public License
00023  *   along with LORENE; if not, write to the Free Software
00024  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 char sh_pvect_r_C[] = "$Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/sh_pvect_r.C,v 1.3 2004/12/23 16:00:10 j_novak Exp $" ;
00029 
00030 /*
00031  * $Id: sh_pvect_r.C,v 1.3 2004/12/23 16:00:10 j_novak Exp $
00032  * $Log: sh_pvect_r.C,v $
00033  * Revision 1.3  2004/12/23 16:00:10  j_novak
00034  * Modif. comments.
00035  *
00036  * Revision 1.2  2004/05/10 15:36:42  j_novak
00037  * Corrected a missing #include
00038  *
00039  * Revision 1.1  2004/05/10 15:28:22  j_novak
00040  * First version of functions for the solution of the r-component of the
00041  * vector Poisson equation.
00042  *
00043  *
00044  * $Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/sh_pvect_r.C,v 1.3 2004/12/23 16:00:10 j_novak Exp $
00045  *
00046  */
00047 
00048 //fichiers includes
00049 #include <stdlib.h>
00050 #include <math.h>
00051 
00052 #include "matrice.h"
00053 #include "type_parite.h"
00054 #include "proto.h"
00055 
00056 /*
00057  * 
00058  * Renvoie une ou 2 solution homogene
00059  * Si l <> 0 :
00060  *  Si base_r = R_CHEB deux solutions (x+echelle)^(l-1) dans (0, *) et
00061  *              1/(x+echelle)^(l+2) dans (1, *)
00062  *  Si base_r = R_CHEBU 1 solution (x-1)^(l+2) dans (*) 
00063  *  Si base_r = R_CHEBP ou R_CHEBI x^(l-1) dans (*)
00064  * 
00065  * Si l = 0:
00066  *  Si base_r = R_CHEB deux solutions (x+echelle) dans (0, *) et
00067  *              1/(x+echelle)^(l+2) dans (1, *)
00068  *  Si base_r = R_CHEBU 1 solution (x-1)^(l+2) dans (*) 
00069  *  Si base_r = R_CHEBP ou R_CHEBI x dans (*)
00070  *
00071  * Entree : 
00072  *  n : nbre de points en r
00073  *  l : nbre quantique associe
00074  *  echelle : cf ci-dessus, utile que dans le cas R_CHEB
00075  *  base_r : base de decomposition
00076  * 
00077  * Sortie :
00078  *  Tbl contenant les coefficient de la ou des solution homogenes
00079  * 
00080  */
00081 
00082 Tbl _sh_pvect_r_pas_prevu (int, int, double) ;
00083 Tbl _sh_pvect_r_cheb (int, int, double) ;
00084 Tbl _sh_pvect_r_chebp (int, int, double) ;
00085 Tbl _sh_pvect_r_chebi (int, int, double) ;
00086 Tbl _sh_pvect_r_chebu (int, int, double) ;
00087 
00088         //------------------------------------
00089         // Routine pour les cas non prevus --
00090         //------------------------------------
00091 Tbl _sh_pvect_r_pas_prevu (int n, int l, double echelle) {
00092 
00093     cout << " Solution homogene pas prevue ..... : "<< endl ;
00094     cout << " N : " << n << endl ;
00095     cout << " l : " << l << endl ;
00096     cout << " echelle : " << echelle << endl ;
00097     abort() ;
00098     exit(-1) ;
00099     Tbl res(1) ;
00100     return res;
00101 }
00102     
00103     
00104         //-------------------
00105            //--  R_CHEB   ------
00106           //-------------------
00107 
00108 Tbl _sh_pvect_r_cheb (int n, int l, double echelle) {
00109                 
00110    const int nmax = 200 ; // Nombre de Tbl stockes
00111    static Tbl* tab[nmax] ;  // les Tbl calcules
00112    static int nb_dejafait = 0 ; // nbre de Tbl calcules
00113    static int l_dejafait[nmax] ;
00114    static int nr_dejafait[nmax] ;
00115    static double vieux_echelle = 0;
00116    
00117    // Si on a change l'echelle : on detruit tout :
00118    if (vieux_echelle != echelle) {
00119        for (int i=0 ; i<nb_dejafait ; i++) {
00120        l_dejafait[i] = -1 ;
00121        nr_dejafait[i] = -1 ;
00122        delete tab[i] ;
00123        }
00124     nb_dejafait = 0 ;
00125     vieux_echelle = echelle ;
00126    }
00127       
00128    int indice = -1 ;
00129    
00130    // On determine si la matrice a deja ete calculee :
00131    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00132     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00133     indice = conte ;
00134     
00135    // Calcul a faire : 
00136    if (indice  == -1) {
00137        if (nb_dejafait >= nmax) {
00138        cout << "_sh_pvect_r_cheb : trop de Tbl" << endl ;
00139        abort() ;
00140        exit (-1) ;
00141        }
00142        
00143         
00144     l_dejafait[nb_dejafait] = l ;
00145     nr_dejafait[nb_dejafait] = n ;
00146         
00147   //  assert (l < n) ;
00148     
00149     Tbl res(2, n) ;
00150     res.set_etat_qcq() ;
00151     double* coloc = new double[n] ;
00152     
00153     int * deg = new int[3] ;
00154     deg[0] = 1 ; 
00155     deg[1] = 1 ;
00156     deg[2] = n ;
00157     
00158     //Construction de la premiere solution homogene :
00159     // cad celle polynomiale.
00160     
00161     if (l==0) {
00162     for (int i=0 ; i<n ; i++)
00163         coloc[i] = echelle - cos(M_PI*i/(n-1)) ;
00164     
00165     cfrcheb(deg, deg, coloc, deg, coloc) ;
00166     for (int i=0 ; i<n ;i++)
00167         res.set(0, i) = coloc[i] ;
00168     }
00169     else if (l==1) {
00170       res.set(0, 0) = 1 ;
00171       for (int i=1 ; i<n ; i++)
00172     res.set(0, i) = 0 ;
00173     }
00174     else {
00175 
00176     for (int i=0 ; i<n ; i++)
00177         coloc[i] = pow(echelle-cos(M_PI*i/(n-1)), double(l-1)) ;
00178     
00179     cfrcheb(deg, deg, coloc, deg, coloc) ;
00180     for (int i=0 ; i<n ;i++)
00181       res.set(0, i) = coloc[i] ;
00182     }
00183     
00184     
00185     // construction de la seconde solution homogene :
00186     // cad celle fractionnelle.
00187     for (int i=0 ; i<n ; i++)
00188       coloc[i] = 1/pow(echelle-cos(M_PI*i/(n-1)), double(l+2)) ;
00189     
00190       cfrcheb(deg, deg, coloc, deg, coloc) ;
00191       for (int i=0 ; i<n ;i++)
00192     res.set(1, i) = coloc[i] ;  
00193     
00194     delete [] coloc ;
00195     delete [] deg ;
00196     tab[nb_dejafait] = new Tbl(res) ;
00197     nb_dejafait ++ ;
00198     return res ;
00199     }
00200     
00201     else return *tab[indice] ;
00202 }   
00203     
00204         //-------------------
00205            //--  R_CHEBP  ------
00206           //-------------------
00207 
00208 Tbl _sh_pvect_r_chebp (int n, int l, double) {
00209    
00210    const int nmax = 200 ; // Nombre de Tbl stockes
00211    static Tbl* tab[nmax] ;  // les Tbl calcules
00212    static int nb_dejafait = 0 ; // nbre de Tbl calcules
00213    static int l_dejafait[nmax] ;
00214    static int nr_dejafait[nmax] ;
00215     
00216    int indice = -1 ;
00217    
00218    // On determine si la matrice a deja ete calculee :
00219    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00220     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00221     indice = conte ;
00222     
00223    // Calcul a faire : 
00224    if (indice  == -1) {
00225        if (nb_dejafait >= nmax) {
00226        cout << "_sh_pvect_r_chebp : trop de Tbl" << endl ;
00227        abort() ;
00228        exit (-1) ;
00229        }
00230        
00231     
00232     l_dejafait[nb_dejafait] = l ;
00233     nr_dejafait[nb_dejafait] = n ;
00234     
00235     Tbl res(n) ;
00236     res.set_etat_qcq() ;
00237     double* coloc = new double[n] ;
00238     
00239     int * deg = new int[3] ;
00240     deg[0] = 1 ; 
00241     deg[1] = 1 ;
00242     deg[2] = n ;
00243     
00244     assert (div(l, 2).rem == 1)  ;
00245    if (l==1) {
00246       res.set(0) = 1 ;
00247       for (int i=1 ; i<n ; i++)
00248     res.set(i) = 0 ;
00249     }
00250     else {
00251       for (int i=0 ; i<n ; i++)
00252     coloc[i] = pow(sin(M_PI*i/2/(n-1)), double(l-1)) ;
00253     
00254     cfrchebp(deg, deg, coloc, deg, coloc) ;
00255     for (int i=0 ; i<n ;i++)
00256         res.set(i) = coloc[i] ;
00257     }
00258 
00259     delete [] coloc ;
00260     delete [] deg ;
00261     tab[nb_dejafait] = new Tbl(res) ;
00262     nb_dejafait ++ ;
00263     return res ;
00264     }
00265     
00266     else return *tab[indice] ;
00267 }
00268     
00269     
00270             //-------------------
00271            //--  R_CHEBI   -----
00272           //-------------------
00273     
00274 Tbl _sh_pvect_r_chebi (int n, int l, double) {
00275        
00276    const int nmax = 200 ; // Nombre de Tbl stockes
00277    static Tbl* tab[nmax] ;  // les Tbl calcules
00278    static int nb_dejafait = 0 ; // nbre de Tbl calcules
00279    static int l_dejafait[nmax] ;
00280    static int nr_dejafait[nmax] ;
00281     
00282    int indice = -1 ;
00283    
00284    // On determine si la matrice a deja ete calculee :
00285    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00286     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00287     indice = conte ;
00288     
00289    // Calcul a faire : 
00290    if (indice  == -1) {
00291        if (nb_dejafait >= nmax) {
00292        cout << "_sh_pvect_r_chebi : trop de Tbl" << endl ;
00293        abort() ;
00294        exit (-1) ;
00295        }
00296        
00297         
00298     l_dejafait[nb_dejafait] = l ;
00299     nr_dejafait[nb_dejafait] = n ;
00300     
00301     
00302     assert (div(l, 2).rem == 0)  ;
00303    // assert (l < 2*n) ;
00304     
00305     Tbl res(n) ;
00306     res.set_etat_qcq() ;
00307     double* coloc = new double[n] ;
00308     
00309     int * deg = new int[3] ;
00310     deg[0] = 1 ; 
00311     deg[1] = 1 ;
00312     deg[2] = n ;
00313     
00314     if (l==0) {
00315     res.set(0) = 1 ;
00316     for (int i=1 ; i<n ; i++)
00317         res.set(i) = 0 ;
00318         }
00319     else {
00320     for (int i=0 ; i<n ; i++)
00321         coloc[i] = pow(sin(M_PI*i/2/(n-1)), double(l-1)) ;
00322     
00323     cfrchebi(deg, deg, coloc, deg, coloc) ;
00324     for (int i=0 ; i<n ;i++)
00325         res.set(i) = coloc[i] ;
00326     }
00327     
00328     delete [] coloc ;
00329     delete [] deg ;
00330     tab[nb_dejafait] = new Tbl(res) ;
00331     nb_dejafait ++ ;
00332     return res ;
00333     }
00334     
00335     else return *tab[indice] ;
00336 }
00337     
00338     
00339     
00340             //-------------------
00341            //--  R_CHEBU   -----
00342           //-------------------
00343     
00344 Tbl _sh_pvect_r_chebu (int n, int l, double) {
00345            
00346    const int nmax = 200 ; // Nombre de Tbl stockes
00347    static Tbl* tab[nmax] ;  // les Tbl calcules
00348    static int nb_dejafait = 0 ; // nbre de Tbl calcules
00349    static int l_dejafait[nmax] ;
00350    static int nr_dejafait[nmax] ;
00351     
00352    int indice = -1 ;
00353    
00354    // On determine si la matrice a deja ete calculee :
00355    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00356     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00357     indice = conte ;
00358     
00359    // Calcul a faire : 
00360    if (indice  == -1) {
00361        if (nb_dejafait >= nmax) {
00362        cout << "_sh_pvect_r_chebu : trop de Tbl" << endl ;
00363        abort() ;
00364        exit (-1) ;
00365       }
00366        
00367         
00368     l_dejafait[nb_dejafait] = l ;
00369     nr_dejafait[nb_dejafait] = n ;
00370     
00371     
00372   //  assert (l < n-1) ;
00373     Tbl res(n) ;
00374     res.set_etat_qcq() ;
00375     double* coloc = new double[n] ;
00376     
00377     int * deg = new int[3] ;
00378     deg[0] = 1 ; 
00379     deg[1] = 1 ;
00380     deg[2] = n ;
00381     
00382     for (int i=0 ; i<n ; i++)
00383     coloc[i] = pow(-1-cos(M_PI*i/(n-1)), double(l+2)) ;
00384     
00385     cfrcheb(deg, deg, coloc, deg, coloc) ;
00386     for (int i=0 ; i<n ;i++)
00387     res.set(i) = coloc[i] ;
00388     
00389     delete [] coloc ;
00390     delete [] deg ;
00391     tab[nb_dejafait] = new Tbl(res) ;
00392     nb_dejafait ++ ;
00393     return res ;
00394     }
00395     
00396     else return *tab[indice] ;
00397 }
00398     
00399     
00400     
00401     
00402             //-------------------
00403            //--  Fonction   ----
00404           //-------------------
00405           
00406           
00407 Tbl sh_pvect_r(int n, int l, double echelle, int base_r) {
00408 
00409         // Routines de derivation
00410     static Tbl (*sh_pvect_r[MAX_BASE])(int, int, double) ;
00411     static int nap = 0 ;
00412 
00413         // Premier appel
00414     if (nap==0) {
00415     nap = 1 ;
00416     for (int i=0 ; i<MAX_BASE ; i++) {
00417         sh_pvect_r[i] = _sh_pvect_r_pas_prevu ;
00418     }
00419         // Les routines existantes
00420     sh_pvect_r[R_CHEB >> TRA_R] = _sh_pvect_r_cheb ;
00421     sh_pvect_r[R_CHEBU >> TRA_R] = _sh_pvect_r_chebu ;
00422     sh_pvect_r[R_CHEBP >> TRA_R] = _sh_pvect_r_chebp ;
00423     sh_pvect_r[R_CHEBI >> TRA_R] = _sh_pvect_r_chebi ;
00424     }
00425     
00426     Tbl res(sh_pvect_r[base_r](n, l, echelle)) ;
00427     return res ;
00428 }

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