prepa_pvect_r.C

00001 /*
00002  *  Methods preparing the operators of Ope_pois_vect_r for inversion.
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 prepa_pvect_C[] = "$Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/prepa_pvect_r.C,v 1.2 2004/05/17 15:42:21 j_novak Exp $" ;
00029 
00030 /*
00031  * $Id: prepa_pvect_r.C,v 1.2 2004/05/17 15:42:21 j_novak Exp $
00032  * $Log: prepa_pvect_r.C,v $
00033  * Revision 1.2  2004/05/17 15:42:21  j_novak
00034  * The method 1 of vector Poisson eq. solves directly for F^r.
00035  * Some bugs were corrected in the operator poisson_vect.
00036  *
00037  * Revision 1.1  2004/05/10 15:28:22  j_novak
00038  * First version of functions for the solution of the r-component of the
00039  * vector Poisson equation.
00040  *
00041  *
00042  * $Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/prepa_pvect_r.C,v 1.2 2004/05/17 15:42:21 j_novak Exp $
00043  *
00044  */
00045 
00046 //fichiers includes
00047 #include <stdlib.h>
00048 
00049 #include "matrice.h"
00050 #include "type_parite.h"
00051 
00052 /*
00053  * Fonctions supprimant le nombre de colonnes (les premieres)
00054   et de lignes (les dernieres) a l'operateur renvoye par laplacien_mat, de facon
00055   a ce qu'il ne soit plus degenere. Ceci doit etre fait apres les combinaisons
00056   lineaires. La mise a bandes et la decomposition LU sont egalement effectuees ici
00057   
00058   
00059   Entree : lap :  resultat de laplacien_mat
00060         l : associe a lap
00061         puis : puissance dans la ZEC
00062         base_r : base de developpement
00063         
00064   Sortie : renvoie un operateur non degenere ....
00065  */
00066  
00067 Matrice _nondeg_pvect_r_pas_prevu(const Matrice &, int , double, int) ;
00068 Matrice _nondeg_pvect_r_cheb (const Matrice&, int, double, int) ;
00069 Matrice _nondeg_pvect_r_chebp (const Matrice&, int, double, int) ;
00070 Matrice _nondeg_pvect_r_chebi (const Matrice&, int, double, int) ;
00071 Matrice _nondeg_pvect_r_chebu (const Matrice&, int, double, int) ; 
00072 
00073 
00074         //------------------------------------
00075         // Routine pour les cas non prevus --
00076         //-----------------------------------
00077 
00078 Matrice _nondeg_pvect_r_pas_prevu(const Matrice &lap, int l, double echelle, int puis) {
00079     cout << "Construction non degeneree pas prevue..." << endl ;
00080     cout << "l : " << l << endl ;
00081     cout << "lap : " << lap << endl ;
00082     cout << "echelle : " << echelle << endl ;
00083     cout << " puis : " << puis << endl ;
00084     abort() ;
00085     exit(-1) ;
00086     Matrice res(1, 1) ;
00087     return res;
00088 }
00089 
00090 
00091 
00092             //-------------------
00093            //--  R_CHEB   -------
00094           //--------------------
00095 
00096 Matrice _nondeg_pvect_r_cheb (const Matrice &lap, int l, double echelle, int) {
00097     
00098     
00099     int n = lap.get_dim(0) ;
00100     
00101    const int nmax = 200 ; // Nombre de Matrices stockees
00102    static Matrice* tab[nmax] ;  // les matrices calculees
00103    static int nb_dejafait = 0 ; // nbre de matrices calculees
00104    static int l_dejafait[nmax] ;
00105    static int nr_dejafait[nmax] ;
00106    static double vieux_echelle = 0;
00107    
00108    // Si on a change l'echelle : on detruit tout :
00109    if (vieux_echelle != echelle) {
00110        for (int i=0 ; i<nb_dejafait ; i++) {
00111        l_dejafait[i] = -1 ;
00112        nr_dejafait[i] = -1 ;
00113        delete tab[i] ;   
00114        }
00115     vieux_echelle = echelle ;
00116      nb_dejafait = 0 ;
00117    }
00118       
00119    int indice = -1 ;
00120    
00121    // On determine si la matrice a deja ete calculee :
00122    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00123     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00124     indice = conte ;
00125     
00126    // Calcul a faire : 
00127    if (indice  == -1) {
00128        if (nb_dejafait >= nmax) {
00129        cout << "_nondeg_pvect_r_cheb : trop de matrices" << endl ;
00130        abort() ;
00131        exit (-1) ;
00132        }
00133        
00134         
00135     l_dejafait[nb_dejafait] = l ;
00136     nr_dejafait[nb_dejafait] = n ;
00137     
00138     
00139     //assert (l<n) ;
00140     
00141     Matrice res(n-2, n-2) ;
00142     res.set_etat_qcq() ;
00143     for (int i=0 ; i<n-2 ; i++)
00144     for (int j=0 ; j<n-2 ; j++)
00145         res.set(i, j) = lap(i, j+2) ;
00146     
00147     res.set_band(2, 2) ;
00148     res.set_lu() ;
00149     tab[nb_dejafait] = new Matrice(res) ;
00150     nb_dejafait ++ ;
00151     return res ;
00152     } 
00153     
00154     // Cas ou le calcul a deja ete effectue :
00155     else
00156     return *tab[indice] ;  
00157 }
00158 
00159 
00160 
00161 
00162             //------------------
00163            //--  R_CHEBP   ----
00164           //------------------
00165           
00166 Matrice _nondeg_pvect_r_chebp (const Matrice &lap, int l, double, int) {
00167     
00168     int n = lap.get_dim(0) ;
00169     
00170        
00171    const int nmax = 200 ; // Nombre de Matrices stockees
00172    static Matrice* tab[nmax] ;  // les matrices calculees
00173    static int nb_dejafait = 0 ; // nbre de matrices calculees
00174    static int l_dejafait[nmax] ;
00175    static int nr_dejafait[nmax] ;
00176     
00177    int indice = -1 ;
00178    
00179    // On determine si la matrice a deja ete calculee :
00180    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00181     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00182     indice = conte ;
00183     
00184    // Calcul a faire : 
00185    if (indice  == -1) {
00186        if (nb_dejafait >= nmax) {
00187        cout << "_nondeg_pvect_r_chebp : trop de matrices" << endl ;
00188        abort() ;
00189        exit (-1) ;
00190        }
00191        
00192         
00193     l_dejafait[nb_dejafait] = l ;
00194     nr_dejafait[nb_dejafait] = n ;
00195     
00196     assert (div(l, 2).rem == 1) ;
00197     
00198     if (l==1) {
00199     Matrice res(n-1, n-1) ;
00200     res.set_etat_qcq() ;
00201     for (int i=0 ; i<n-1 ; i++)
00202         for (int j=0 ; j<n-1 ; j++)
00203         res.set(i, j) = lap(i, j+1) ;
00204     res.set_band(3, 0) ;
00205     res.set_lu() ;
00206     tab[nb_dejafait] = new Matrice(res) ;
00207     nb_dejafait ++ ;
00208     return res ;
00209     }
00210     else {
00211     Matrice res(n-2, n-2) ;
00212     res.set_etat_qcq() ;
00213     for (int i=0 ;i<n-2 ; i++)
00214         for (int j=0 ; j<n-2 ; j++)
00215         res.set(i, j) = lap(i, j+2) ;
00216     
00217     res.set_band(2, 1) ;    
00218     res.set_lu() ;
00219     tab[nb_dejafait] = new Matrice(res) ;
00220     nb_dejafait ++ ;
00221     return res ;
00222      }
00223     }
00224     // Cas ou le calcul a deja ete effectue :
00225     else
00226     return *tab[indice] ;
00227 }
00228 
00229 
00230 
00231 
00232             //-------------------
00233            //--  R_CHEBI   -----
00234           //-------------------
00235           
00236 Matrice _nondeg_pvect_r_chebi (const Matrice &lap, int l, double, int) {
00237     
00238     int n = lap.get_dim(0) ;
00239        
00240    const int nmax = 200 ; // Nombre de Matrices stockees
00241    static Matrice* tab[nmax] ;  // les matrices calculees
00242    static int nb_dejafait = 0 ; // nbre de matrices calculees
00243    static int l_dejafait[nmax] ;
00244    static int nr_dejafait[nmax] ;
00245     
00246    int indice = -1 ;
00247    
00248    // On determine si la matrice a deja ete calculee :
00249    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00250     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00251     indice = conte ;
00252     
00253    // Calcul a faire : 
00254    if (indice  == -1) {
00255        if (nb_dejafait >= nmax) {
00256        cout << "_nondeg_pvect_r_chebi : trop de matrices" << endl ;
00257        abort() ;
00258        exit (-1) ;
00259        }
00260        
00261         
00262     l_dejafait[nb_dejafait] = l ;
00263     nr_dejafait[nb_dejafait] = n ;
00264     
00265     
00266     assert (div(l, 2).rem == 0) ;
00267   //  assert (l<=2*n-1) ;
00268     
00269     if (l<=2) { //### to be checked!!!
00270     Matrice res(n-1, n-1) ;
00271     res.set_etat_qcq() ;
00272     for (int i=0 ; i<n-1 ; i++)
00273         for (int j=0 ; j<n-1 ; j++)
00274         res.set(i, j) = lap(i, j+1) ;
00275     res.set_band(3, 0) ;
00276     res.set_lu() ;
00277     tab[nb_dejafait] = new Matrice(res) ;
00278     nb_dejafait ++ ;
00279     return res ;
00280     }
00281     else {
00282     Matrice res(n-2, n-2) ;
00283     res.set_etat_qcq() ;
00284     for (int i=0 ;i<n-2 ; i++)
00285         for (int j=0 ; j<n-2 ; j++)
00286         res.set(i, j) = lap(i, j+2) ;
00287     
00288     res.set_band(2, 1) ;
00289     res.set_lu() ;
00290     tab[nb_dejafait] = new Matrice(res) ;
00291     nb_dejafait ++ ;
00292     return res ;
00293     } 
00294     }
00295     // Cas ou le calcul a deja ete effectue :
00296     else
00297     return *tab[indice] ;
00298 }
00299 
00300 
00301 
00302 
00303             //-------------------
00304            //--  R_CHEBU   -----
00305           //-------------------
00306           
00307           
00308 Matrice _nondeg_pvect_r_chebu (const Matrice &lap, int l, double, int puis) {
00309 
00310   if (puis != 4) {
00311     cout << "_ope_pvect_r_mat_r_chebu : only the case dzpuis = 4 "
00312      << '\n' << "is implemented! \n"
00313      << "dzpuis = " << puis << endl ;
00314     abort() ;
00315   }
00316   int n = lap.get_dim(0) ;
00317     
00318   const int nmax = 200; // Nombre de Matrices stockees
00319   static Matrice* tab[nmax] ;  // les matrices calculees
00320   static int nb_dejafait = 0 ; // nbre de matrices calculees
00321   static int l_dejafait[nmax] ;
00322   static int nr_dejafait[nmax] ;
00323     
00324   int indice = -1 ;
00325    
00326   // On determine si la matrice a deja ete calculee :
00327   for (int conte=0 ; conte<nb_dejafait ; conte ++)
00328     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00329       indice = conte ;
00330     
00331   // Calcul a faire : 
00332   if (indice  == -1) {
00333     if (nb_dejafait >= nmax) {
00334       cout << "_nondeg_pvect_r_chebu : trop de matrices" << endl ;
00335       abort() ;
00336       exit (-1) ;
00337     }
00338        
00339     l_dejafait[nb_dejafait] = l ;
00340     nr_dejafait[nb_dejafait] = n ;
00341     
00342     Matrice res(n-3, n-3) ;
00343     res.set_etat_qcq() ;
00344     for (int i=0 ;i<n-3 ; i++)
00345       for (int j=0 ; j<n-3 ; j++)
00346     res.set(i, j) = lap(i, j+3) ;
00347     
00348     res.set_band(2, 1) ;
00349     res.set_lu() ;
00350     tab[nb_dejafait] = new Matrice(res) ;
00351     nb_dejafait ++ ;
00352     return res ;
00353     
00354   }
00355   // Cas ou le calcul a deja ete effectue :
00356   else
00357     return *tab[indice] ;
00358 }
00359 
00360 
00361             //-------------------
00362            //--  Fonction   ----
00363           //-------------------
00364           
00365 
00366 Matrice nondeg_pvect_r(const Matrice &lap, int l, double echelle, int puis, int base_r)
00367 {
00368 
00369         // Routines de derivation
00370     static Matrice (*nondeg_pvect_r[MAX_BASE])(const Matrice&, int, double, int) ;
00371     static int nap = 0 ;
00372 
00373         // Premier appel
00374     if (nap==0) {
00375     nap = 1 ;
00376     for (int i=0 ; i<MAX_BASE ; i++) {
00377         nondeg_pvect_r[i] = _nondeg_pvect_r_pas_prevu ;
00378     }
00379         // Les routines existantes
00380     nondeg_pvect_r[R_CHEB >> TRA_R] = _nondeg_pvect_r_cheb ;
00381     nondeg_pvect_r[R_CHEBU >> TRA_R] = _nondeg_pvect_r_chebu ;
00382     nondeg_pvect_r[R_CHEBP >> TRA_R] = _nondeg_pvect_r_chebp ;
00383     nondeg_pvect_r[R_CHEBI >> TRA_R] = _nondeg_pvect_r_chebi ;
00384     }
00385     
00386     Matrice res(nondeg_pvect_r[base_r](lap, l, echelle, puis)) ;
00387     return res ;
00388 }
00389 

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