cl_pvect_r.C

00001 /*
00002  *  Methods for linear combinations for Ope_pois_vect_r
00003  *
00004  *    (see file ope_elementary.h 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 cl_pvect_r_C[] = "$Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/cl_pvect_r.C,v 1.1 2004/05/10 15:28:22 j_novak Exp $" ;
00029 
00030 /*
00031  * $Id: cl_pvect_r.C,v 1.1 2004/05/10 15:28:22 j_novak Exp $
00032  * $Log: cl_pvect_r.C,v $
00033  * Revision 1.1  2004/05/10 15:28:22  j_novak
00034  * First version of functions for the solution of the r-component of the
00035  * vector Poisson equation.
00036  *
00037  *
00038  * $Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/cl_pvect_r.C,v 1.1 2004/05/10 15:28:22 j_novak Exp $
00039  *
00040  */
00041 
00042 //fichiers includes
00043 #include <stdlib.h>
00044 
00045 #include "matrice.h"
00046 #include "type_parite.h"
00047 
00048 /*   FONCTIONS FAISANT DES COMBINAISONS LINEAIRES DES LIGNES.
00049  * 
00050  * Entree :
00051  *  La Matrice de l'operateur
00052  *  l : nbre quantique
00053  *  puis = puissance dans la ZEC
00054  *  La base de developpement en R
00055  * 
00056  * Sortie :
00057  *  Renvoie la matrice apres Combinaison lineaire
00058  * 
00059  */
00060 
00061 Matrice _cl_pvect_r_pas_prevu (const Matrice&, int, double, int) ;
00062 Matrice _cl_pvect_r_cheb (const Matrice&, int, double, int) ;
00063 Matrice _cl_pvect_r_chebi (const Matrice&, int, double, int) ;
00064 Matrice _cl_pvect_r_chebu (const Matrice&, int, double, int) ;
00065 Matrice _cl_pvect_r_chebp (const Matrice&, int, double, int) ;
00066 
00067 // Version Matrice --> Matrice
00068 Matrice _cl_pvect_r_pas_prevu (const Matrice &source, int l, double echelle, int puis) {
00069     cout << "Combinaison lineaire pas prevu..." << endl ;
00070     cout << "Source : " << source << endl ;
00071     cout << "l : " << l << endl ;
00072     cout << "dzpuis : " << puis << endl ;
00073     cout << "Echelle : " << echelle << endl ;
00074     abort() ;
00075     exit(-1) ;
00076     return source;
00077 }
00078 
00079 
00080         //-------------------
00081            //--  R_CHEB   ------
00082           //-------------------
00083 
00084 Matrice _cl_pvect_r_cheb (const Matrice &source, int l, double echelle, int) {
00085     int n = source.get_dim(0) ;assert (n == source.get_dim(1)) ;
00086     
00087                 
00088    const int nmax = 100 ; // Nombre de Matrices stockees
00089    static Matrice* tab[nmax] ;  // les matrices calculees
00090    static int nb_dejafait = 0 ; // nbre de matrices calculees
00091    static int l_dejafait[nmax] ;
00092    static int nr_dejafait[nmax] ;
00093    static double vieux_echelle = 0 ;
00094    
00095    // Si on a change l'echelle : on detruit tout :
00096    if (vieux_echelle != echelle) {
00097        for (int i=0 ; i<nb_dejafait ; i++) {
00098        l_dejafait[i] = -1 ;
00099        nr_dejafait[i] = -1 ;
00100        delete tab[i] ;
00101        }
00102        nb_dejafait = 0 ;
00103        vieux_echelle = echelle ;
00104    }
00105       
00106    int indice = -1 ;
00107    
00108    // On determine si la matrice a deja ete calculee :
00109    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00110     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00111     indice = conte ;
00112     
00113    // Calcul a faire : 
00114    if (indice  == -1) {
00115        if (nb_dejafait >= nmax) {
00116        cout << "_cl_pvect_r_cheb : trop de matrices" << endl ;
00117        abort() ;
00118        exit (-1) ;
00119        }
00120        
00121     l_dejafait[nb_dejafait] = l ;
00122     nr_dejafait[nb_dejafait] = n ;
00123     
00124     Matrice barre(source) ;
00125     int dirac = 1 ;
00126     for (int i=0 ; i<n-2 ; i++) {
00127     for (int j=i ; j<(n>(i+7)? i+7 : n) ; j++)
00128         barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j))
00129                 /(i+1) ;
00130     if (i==0) dirac = 0 ;
00131     }
00132     
00133     Matrice res(barre) ;
00134     for (int i=0 ; i<n-4 ; i++)
00135     for (int j=i ; j<(n>(i+5)? i+5 : n) ; j++)
00136         res.set(i, j) = barre(i, j)-barre(i+2, j) ;
00137     tab[nb_dejafait] = new Matrice(res) ;
00138     nb_dejafait ++ ;    
00139     return res ;
00140     }
00141     
00142     // Cas ou le calcul a deja ete effectue :
00143     else
00144     return *tab[indice] ;  
00145 }
00146 
00147         //-------------------
00148            //--  R_CHEBP   -----
00149           //-------------------
00150 
00151 
00152 Matrice _cl_pvect_r_chebp (const Matrice &source, int l, double, int) {
00153     
00154     int n = source.get_dim(0) ;
00155     assert (n == source.get_dim(1)) ;
00156     
00157    const int nmax = 100 ; // Nombre de Matrices stockees
00158    static Matrice* tab[nmax] ;  // les matrices calculees
00159    static int nb_dejafait = 0 ; // nbre de matrices calculees
00160    static int l_dejafait[nmax] ;
00161    static int nr_dejafait[nmax] ;
00162     
00163    int indice = -1 ;
00164    
00165    // On determine si la matrice a deja ete calculee :
00166    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00167     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00168     indice = conte ;
00169     
00170    // Calcul a faire : 
00171    if (indice  == -1) {
00172        if (nb_dejafait >= nmax) {
00173        cout << "_cl_pvect_r_chebp : trop de matrices" << endl ;
00174        abort() ;
00175        exit (-1) ;
00176        }
00177        
00178     l_dejafait[nb_dejafait] = l ;
00179     nr_dejafait[nb_dejafait] = n ;
00180     
00181     Matrice barre(source) ;
00182   
00183     int dirac = 1 ;
00184     for (int i=0 ; i<n-2 ; i++) {
00185     for (int j=0 ; j<n ; j++)
00186         barre.set(i, j) = (1+dirac)*source(i, j)-source(i+2, j) ;
00187     if (i==0) dirac = 0 ;
00188     }
00189 
00190     Matrice tilde(barre) ;
00191     for (int i=0 ; i<n-4 ; i++)
00192     for (int j=0 ; j<n ; j++)
00193         tilde.set(i, j) = barre(i, j)-barre(i+2, j) ;
00194 
00195     Matrice res(tilde) ;
00196     for (int i=0 ; i<n-4 ; i++)
00197     for (int j=0 ; j<n ; j++)
00198         res.set(i, j) = tilde(i, j)-tilde(i+1, j) ;
00199     tab[nb_dejafait] = new Matrice(res) ;
00200     nb_dejafait ++ ;    
00201     return res ;
00202     }
00203     
00204     // Cas ou le calcul a deja ete effectue :
00205     else
00206     return *tab[indice] ;
00207 }
00208 
00209         //-------------------
00210            //--  R_CHEBI   -----
00211           //-------------------
00212 
00213 
00214 Matrice _cl_pvect_r_chebi (const Matrice &source, int l, double, int) {
00215     int n = source.get_dim(0) ;
00216     assert (n == source.get_dim(1)) ;
00217     
00218        
00219    const int nmax = 100 ; // Nombre de Matrices stockees
00220    static Matrice* tab[nmax] ;  // les matrices calculees
00221    static int nb_dejafait = 0 ; // nbre de matrices calculees
00222    static int l_dejafait[nmax] ;
00223    static int nr_dejafait[nmax] ;
00224     
00225    int indice = -1 ;
00226    
00227    // On determine si la matrice a deja ete calculee :
00228    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00229     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00230     indice = conte ;
00231     
00232    // Calcul a faire : 
00233    if (indice  == -1) {
00234        if (nb_dejafait >= nmax) {
00235        cout << "_cl_pvect_r_chebi : trop de matrices" << endl ;
00236        abort() ;
00237        exit (-1) ;
00238        }
00239         
00240     l_dejafait[nb_dejafait] = l ;
00241     nr_dejafait[nb_dejafait] = n ;
00242     
00243     Matrice barre(source) ;
00244    
00245     for (int i=0 ; i<n-2 ; i++)
00246     for (int j=0 ; j<n ; j++)
00247         barre.set(i, j) = source(i, j)-source(i+2, j) ;
00248 
00249     Matrice tilde(barre) ;
00250     for (int i=0 ; i<n-4 ; i++)
00251     for (int j=0 ; j<n ; j++)
00252         tilde.set(i, j) = barre(i, j)-barre(i+2, j) ;    
00253 
00254     Matrice res(tilde) ;
00255     for (int i=0 ; i<n-4 ; i++)
00256     for (int j=0 ; j<n ; j++)
00257         res.set(i, j) = tilde(i, j)-tilde(i+1, j) ;
00258     tab[nb_dejafait] = new Matrice(res) ;
00259     nb_dejafait ++ ;
00260     return res ;
00261     } 
00262     
00263     // Cas ou le calcul a deja ete effectue :
00264     else
00265     return *tab[indice] ;
00266 }
00267         //-------------------
00268            //--  R_CHEBU   -----
00269           //-------------------
00270 
00271 Matrice _cl_pvect_r_chebu (const Matrice &source, int l, double, int puis) {
00272   int n = source.get_dim(0) ;
00273   assert (n == source.get_dim(1)) ;
00274   if (puis != 4) {
00275     cout << "_ope_pvect_r_mat_r_chebu : only the case dzpuis = 4 "
00276      << '\n' << "is implemented! \n"
00277      << "dzpuis = " << puis << endl ;
00278     abort() ;
00279   }
00280 
00281   const int nmax = 200 ; // Nombre de Matrices stockees
00282   static Matrice* tab[nmax] ;  // les matrices calculees
00283   static int nb_dejafait = 0 ; // nbre de matrices calculees
00284   static int l_dejafait[nmax] ;
00285   static int nr_dejafait[nmax] ;
00286     
00287   int indice = -1 ;
00288    
00289   // On determine si la matrice a deja ete calculee :
00290   for (int conte=0 ; conte<nb_dejafait ; conte ++)
00291     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00292       indice = conte ;
00293     
00294   // Calcul a faire : 
00295   if (indice  == -1) {
00296     if (nb_dejafait >= nmax) {
00297       cout << "_cl_pvect_r_chebu_quatre : trop de matrices" << endl ;
00298       abort() ;
00299       exit (-1) ;
00300     }
00301        
00302     l_dejafait[nb_dejafait] = l ;
00303     nr_dejafait[nb_dejafait] = n ;
00304     
00305     Matrice barre(source) ;
00306   
00307     int dirac = 1 ;
00308     for (int i=0 ; i<n-2 ; i++) {
00309       for (int j=0 ; j<n ; j++)
00310     barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j)) ;
00311       if (i==0) dirac = 0 ;
00312     }
00313     
00314     Matrice tilde(barre) ;
00315     for (int i=0 ; i<n-4 ; i++)
00316       for (int j=0 ; j<n ; j++)
00317     tilde.set(i, j) = (barre(i, j)-barre(i+2, j)) ;
00318         
00319     Matrice prime(tilde) ;
00320     for (int i=0 ; i<n-4 ; i++)
00321       for (int j=0 ; j<n ; j++)
00322     prime.set(i, j) = (tilde(i, j)-tilde(i+1, j)) ;
00323     
00324     Matrice res(prime) ;
00325     for (int i=0 ; i<n-4 ; i++)
00326       for (int j=0 ; j<n ; j++)
00327     res.set(i, j) = (prime(i, j)-prime(i+2, j)) ;
00328     tab[nb_dejafait] = new Matrice(res) ;
00329     nb_dejafait ++ ;    
00330     return res ;
00331   } 
00332     
00333   // Cas ou le calcul a deja ete effectue :
00334   else
00335     return *tab[indice] ;
00336 }
00337 
00338 
00339         //-------------------------
00340            //- La routine a appeler ---
00341           //---------------------------
00342 
00343 Matrice cl_pvect_r(const Matrice &source, int l, double echelle, 
00344            int puis, int base_r) {
00345     
00346   // Routines de derivation
00347   static Matrice (*combinaison[MAX_BASE])(const Matrice &, int, double, int) ;
00348   static int nap = 0 ;
00349 
00350   // Premier appel
00351   if (nap==0) {
00352     nap = 1 ;
00353     for (int i=0 ; i<MAX_BASE ; i++) {
00354       combinaison[i] = _cl_pvect_r_pas_prevu ;
00355     }
00356     // Les routines existantes
00357     combinaison[R_CHEB >> TRA_R] = _cl_pvect_r_cheb ;
00358     combinaison[R_CHEBU >> TRA_R] = _cl_pvect_r_chebu ;
00359     combinaison[R_CHEBP >> TRA_R] = _cl_pvect_r_chebp ;
00360     combinaison[R_CHEBI >> TRA_R] = _cl_pvect_r_chebi ;
00361   }
00362   
00363   Matrice res(combinaison[base_r](source, l, echelle, puis)) ;
00364   return res ;
00365 }
00366 

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