cl_ptens_rr.C

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

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