ope_poisson_2d_cl.C

00001 /*
00002  *   Copyright (c) 2004 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 version 2
00008  *   as published by the Free Software Foundation.
00009  *
00010  *   LORENE is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with LORENE; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  */
00020 
00021 char ope_poisson_2d_cl_C[] = "$Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_poisson_2d/ope_poisson_2d_cl.C,v 1.1 2004/08/24 09:14:47 p_grandclement Exp $" ;
00022 
00023 /*
00024  * $Id: ope_poisson_2d_cl.C,v 1.1 2004/08/24 09:14:47 p_grandclement Exp $
00025  * $Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_poisson_2d/ope_poisson_2d_cl.C,v 1.1 2004/08/24 09:14:47 p_grandclement Exp $
00026  *
00027  */
00028 #include <math.h>
00029 #include <stdlib.h>
00030 
00031 #include "proto.h"
00032 #include "ope_elementary.h"
00033 
00034 // Version Matrice --> Matrice
00035 Matrice _cl_poisson_2d_pas_prevu (const Matrice & source, int, double,int) {
00036     cout << "Combinaison lineaire pas prevu..." << endl ;
00037     abort() ;
00038     exit(-1) ;
00039     return source;
00040 }
00041 
00042 
00043         //-------------------
00044            //--  R_CHEB   ------
00045           //-------------------
00046 
00047 Matrice _cl_poisson_2d_r_cheb (const Matrice &source, int l, double echelle, int) {
00048    int n = source.get_dim(0) ;assert (n == source.get_dim(1)) ;
00049                 
00050    const int nmax = 100 ; // Nombre de Matrices stockees
00051    static Matrice* tab[nmax] ;  // les matrices calculees
00052    static int nb_dejafait = 0 ; // nbre de matrices calculees
00053    static int l_dejafait[nmax] ;
00054    static int nr_dejafait[nmax] ;
00055    static double vieux_echelle = 0 ;
00056    
00057    // Si on a change l'echelle : on detruit tout :
00058    if (vieux_echelle != echelle) {
00059        for (int i=0 ; i<nb_dejafait ; i++) {
00060        l_dejafait[i] = -1 ;
00061        nr_dejafait[i] = -1 ;
00062        delete tab[i] ;
00063        }
00064        nb_dejafait = 0 ;
00065        vieux_echelle = echelle ;
00066    }
00067       
00068    int indice = -1 ;
00069    
00070    // On determine si la matrice a deja ete calculee :
00071    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00072     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00073     indice = conte ;
00074     
00075    // Calcul a faire : 
00076    if (indice  == -1) {
00077        if (nb_dejafait >= nmax) {
00078        cout << "_cl_poisson_r_cheb : trop de matrices" << endl ;
00079        abort() ;
00080        exit (-1) ;
00081        }
00082        
00083     l_dejafait[nb_dejafait] = l ;
00084     nr_dejafait[nb_dejafait] = n ;
00085     
00086     Matrice barre(source) ;
00087     int dirac = 1 ;
00088     for (int i=0 ; i<n-2 ; i++) {
00089     for (int j=0 ; j<n ; j++)
00090         barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j))
00091                 /(i+1) ;
00092     if (i==0) dirac = 0 ;
00093     }
00094     
00095     Matrice res(barre) ;
00096     for (int i=0 ; i<n-4 ; i++)
00097     for (int j=0 ; j<n ; j++)
00098         res.set(i, j) = barre(i, j)-barre(i+2, j) ;
00099     tab[nb_dejafait] = new Matrice(res) ;
00100     nb_dejafait ++ ;    
00101     return res ;
00102     }
00103     
00104     // Cas ou le calcul a deja ete effectue :
00105     else
00106     return *tab[indice] ;  
00107 }
00108 
00109         //-------------------
00110            //--  R_CHEBP   -----
00111           //-------------------
00112 
00113 
00114 Matrice _cl_poisson_2d_r_chebp (const Matrice &source, int l, double, int) {
00115     
00116     int n = source.get_dim(0) ;
00117     assert (n == source.get_dim(1)) ;
00118     
00119    const int nmax = 100 ; // Nombre de Matrices stockees
00120    static Matrice* tab[nmax] ;  // les matrices calculees
00121    static int nb_dejafait = 0 ; // nbre de matrices calculees
00122    static int l_dejafait[nmax] ;
00123    static int nr_dejafait[nmax] ;
00124     
00125    int indice = -1 ;
00126    
00127    // On determine si la matrice a deja ete calculee :
00128    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00129     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00130     indice = conte ;
00131     
00132    // Calcul a faire : 
00133    if (indice  == -1) {
00134        if (nb_dejafait >= nmax) {
00135        cout << "_cl_poisson_2d_r_chebp : trop de matrices" << endl ;
00136        abort() ;
00137        exit (-1) ;
00138        }
00139        
00140     l_dejafait[nb_dejafait] = l ;
00141     nr_dejafait[nb_dejafait] = n ;
00142     
00143     Matrice barre(source) ;
00144   
00145     int dirac = 1 ;
00146     for (int i=0 ; i<n-2 ; i++) {
00147     for (int j=0 ; j<n ; j++)
00148         barre.set(i, j) = (1+dirac)*source(i, j)-source(i+2, j) ;
00149     if (i==0) dirac = 0 ;
00150     }
00151 
00152     Matrice tilde(barre) ;
00153     for (int i=0 ; i<n-4 ; i++)
00154     for (int j=0 ; j<n ; j++)
00155         tilde.set(i, j) = barre(i, j)-barre(i+2, j) ;
00156 
00157     Matrice res(tilde) ;
00158     for (int i=0 ; i<n-4 ; i++)
00159     for (int j=0 ; j<n ; j++)
00160         res.set(i, j) = tilde(i, j)-tilde(i+1, j) ;
00161     tab[nb_dejafait] = new Matrice(res) ;
00162     nb_dejafait ++ ;    
00163     return res ;
00164     }
00165     
00166     // Cas ou le calcul a deja ete effectue :
00167     else
00168     return *tab[indice] ;
00169 }
00170 
00171         //-------------------
00172            //--  R_CHEBI   -----
00173           //-------------------
00174 
00175 
00176 Matrice _cl_poisson_2d_r_chebi (const Matrice &source, int l, double, int) {
00177     int n = source.get_dim(0) ;
00178     assert (n == source.get_dim(1)) ;
00179     
00180        
00181    const int nmax = 100 ; // Nombre de Matrices stockees
00182    static Matrice* tab[nmax] ;  // les matrices calculees
00183    static int nb_dejafait = 0 ; // nbre de matrices calculees
00184    static int l_dejafait[nmax] ;
00185    static int nr_dejafait[nmax] ;
00186     
00187    int indice = -1 ;
00188    
00189    // On determine si la matrice a deja ete calculee :
00190    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00191     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00192     indice = conte ;
00193     
00194    // Calcul a faire : 
00195    if (indice  == -1) {
00196        if (nb_dejafait >= nmax) {
00197        cout << "_cl_poisson_2d_r_chebi : trop de matrices" << endl ;
00198        abort() ;
00199        exit (-1) ;
00200        }
00201         
00202     l_dejafait[nb_dejafait] = l ;
00203     nr_dejafait[nb_dejafait] = n ;
00204     
00205     Matrice barre(source) ;
00206    
00207     for (int i=0 ; i<n-2 ; i++)
00208     for (int j=0 ; j<n ; j++)
00209         barre.set(i, j) = source(i, j)-source(i+2, j) ;
00210 
00211     Matrice tilde(barre) ;
00212     for (int i=0 ; i<n-4 ; i++)
00213     for (int j=0 ; j<n ; j++)
00214         tilde.set(i, j) = barre(i, j)-barre(i+2, j) ;    
00215 
00216     Matrice res(tilde) ;
00217     for (int i=0 ; i<n-4 ; i++)
00218     for (int j=0 ; j<n ; j++)
00219         res.set(i, j) = tilde(i, j)-tilde(i+1, j) ;
00220     tab[nb_dejafait] = new Matrice(res) ;
00221     nb_dejafait ++ ;
00222     return res ;
00223     } 
00224     
00225     // Cas ou le calcul a deja ete effectue :
00226     else
00227     return *tab[indice] ;
00228 }
00229         //-------------------
00230            //--  R_CHEBU   -----
00231           //-------------------
00232 
00233 Matrice _cl_poisson_2d_r_chebu_quatre (const Matrice&, int) ;
00234 Matrice _cl_poisson_2d_r_chebu_trois (const Matrice&, int) ;
00235 Matrice _cl_poisson_2d_r_chebu_deux (const Matrice&, int) ;
00236 
00237 
00238 Matrice _cl_poisson_2d_r_chebu (const Matrice &source, int l, double, int puis) {
00239     int n = source.get_dim(0) ;
00240     assert (n == source.get_dim(1)) ;
00241     
00242     Matrice res(n, n) ;
00243     res.set_etat_qcq() ;
00244     
00245     switch (puis) {
00246     case 4 :
00247         res = _cl_poisson_2d_r_chebu_quatre(source, l) ;
00248         break ;
00249     case 3 :
00250         res = _cl_poisson_2d_r_chebu_trois (source, l) ;
00251         break ;
00252     case 2 :
00253         res = _cl_poisson_2d_r_chebu_deux(source, l) ;
00254         break ;
00255     default :
00256         abort() ;
00257         exit(-1) ;
00258     }
00259     
00260     return res ;
00261 }
00262 
00263 
00264 // Cas dzpuis = 4
00265 Matrice _cl_poisson_2d_r_chebu_quatre (const Matrice &source, int l) {
00266     int n = source.get_dim(0) ;
00267     assert (n == source.get_dim(1)) ;
00268     
00269             
00270    const int nmax = 200 ; // Nombre de Matrices stockees
00271    static Matrice* tab[nmax] ;  // les matrices calculees
00272    static int nb_dejafait = 0 ; // nbre de matrices calculees
00273    static int l_dejafait[nmax] ;
00274    static int nr_dejafait[nmax] ;
00275     
00276    int indice = -1 ;
00277    
00278    // On determine si la matrice a deja ete calculee :
00279    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00280     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00281     indice = conte ;
00282     
00283    // Calcul a faire : 
00284    if (indice  == -1) {
00285        if (nb_dejafait >= nmax) {
00286        cout << "_cl_poisson_2d_r_chebu_quatre : trop de matrices" << endl ;
00287        abort() ;
00288        exit (-1) ;
00289        }
00290        
00291     l_dejafait[nb_dejafait] = l ;
00292     nr_dejafait[nb_dejafait] = n ;
00293     
00294     Matrice barre(source) ;
00295   
00296     int dirac = 1 ;
00297     for (int i=0 ; i<n-2 ; i++) {
00298     for (int j=0 ; j<n ; j++)
00299          barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j)) ;
00300     if (i==0) dirac = 0 ;
00301     }
00302     
00303     Matrice tilde(barre) ;
00304     for (int i=0 ; i<n-4 ; i++)
00305     for (int j=0 ; j<n ; j++)
00306         tilde.set(i, j) = (barre(i, j)-barre(i+2, j)) ;
00307         
00308     Matrice prime(tilde) ;
00309     for (int i=0 ; i<n-4 ; i++)
00310     for (int j=0 ; j<n ; j++)
00311         prime.set(i, j) = (tilde(i, j)-tilde(i+1, j)) ;
00312     
00313     Matrice res(prime) ;
00314     for (int i=0 ; i<n-4 ; i++)
00315     for (int j=0 ; j<n ; j++)
00316         res.set(i, j) = (prime(i, j)-prime(i+2, j)) ;
00317     tab[nb_dejafait] = new Matrice(res) ;
00318     nb_dejafait ++ ;    
00319     return res ;
00320     } 
00321     
00322     // Cas ou le calcul a deja ete effectue :
00323     else
00324     return *tab[indice] ;
00325 }
00326 
00327 // Cas dzpuis == 3
00328 Matrice _cl_poisson_2d_r_chebu_trois (const Matrice &source, int l) {
00329     int n = source.get_dim(0) ;
00330     assert (n == source.get_dim(1)) ;
00331     
00332             
00333    const int nmax = 200 ; // Nombre de Matrices stockees
00334    static Matrice* tab[nmax] ;  // les matrices calculees
00335    static int nb_dejafait = 0 ; // nbre de matrices calculees
00336    static int l_dejafait[nmax] ;
00337    static int nr_dejafait[nmax] ;
00338     
00339    int indice = -1 ;
00340    
00341    // On determine si la matrice a deja ete calculee :
00342    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00343     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00344     indice = conte ;
00345     
00346    // Calcul a faire : 
00347    if (indice  == -1) {
00348        if (nb_dejafait >= nmax) {
00349        cout << "_cl_poisson_2d_r_chebu_trois : trop de matrices" << endl ;
00350        abort() ;
00351        exit (-1) ;
00352        }
00353        
00354     l_dejafait[nb_dejafait] = l ;
00355     nr_dejafait[nb_dejafait] = n ;
00356 
00357     Matrice barre(source) ;
00358   
00359     int dirac = 1 ;
00360     for (int i=0 ; i<n-2 ; i++) {
00361     for (int j=0 ; j<n ; j++)
00362          barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j)) ;
00363     if (i==0) dirac = 0 ;
00364     }
00365     
00366     Matrice tilde(barre) ;
00367     for (int i=0 ; i<n-2 ; i++)
00368     for (int j=0 ; j<n ; j++)
00369         tilde.set(i, j) = (barre(i, j)-barre(i+2, j)) ;
00370 
00371     Matrice res(tilde) ;
00372     for (int i=0 ; i<n-2 ; i++)
00373     for (int j=0 ; j<n ; j++)
00374         res.set(i, j) = (tilde(i, j)+tilde(i+1, j)) ;
00375     
00376     tab[nb_dejafait] = new Matrice(res) ;
00377     nb_dejafait ++ ;    
00378     return res ;
00379     } 
00380     
00381     // Cas ou le calcul a deja ete effectue :
00382     else
00383     return *tab[indice] ;
00384 }
00385 
00386 
00387 //Cas dzpuis == 2
00388 Matrice _cl_poisson_2d_r_chebu_deux (const Matrice &source, int l) {
00389     int n = source.get_dim(0) ;
00390     assert (n == source.get_dim(1)) ;
00391     
00392             
00393    const int nmax = 200 ; // Nombre de Matrices stockees
00394    static Matrice* tab[nmax] ;  // les matrices calculees
00395    static int nb_dejafait = 0 ; // nbre de matrices calculees
00396    static int l_dejafait[nmax] ;
00397    static int nr_dejafait[nmax] ;
00398     
00399    int indice = -1 ;
00400    
00401    // On determine si la matrice a deja ete calculee :
00402    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00403     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00404     indice = conte ;
00405     
00406    // Calcul a faire : 
00407    if (indice  == -1) {
00408        if (nb_dejafait >= nmax) {
00409        cout << "_cl_poisson_2d_r_chebu_deux : trop de matrices" << endl ;
00410        abort() ;
00411        exit (-1) ;
00412        }
00413        
00414     l_dejafait[nb_dejafait] = l ;
00415     nr_dejafait[nb_dejafait] = n ;
00416     
00417     Matrice barre(source) ;
00418   
00419     int dirac = 1 ;
00420     for (int i=0 ; i<n-2 ; i++) {
00421     for (int j=0 ; j<n ; j++)
00422          barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j)) ;
00423     if (i==0) dirac = 0 ;
00424     }
00425    
00426     Matrice tilde(barre) ;
00427     for (int i=0 ; i<n-4 ; i++)
00428     for (int j=0 ; j<n ; j++)
00429         tilde.set(i, j) = (barre(i, j)-barre(i+2, j)) ;
00430         
00431     Matrice res(tilde) ;
00432     for (int i=0 ; i<n-4 ; i++)
00433     for (int j=0 ; j<n ; j++)
00434         res.set(i, j) = (tilde(i, j)+tilde(i+1, j)) ;
00435 
00436     return res ;
00437     } 
00438     
00439     // Cas ou le calcul a deja ete effectue :
00440     else
00441     return *tab[indice] ;
00442 }
00443 
00444 void Ope_poisson_2d::do_ope_cl() const {
00445   if (ope_mat == 0x0)
00446     do_ope_mat() ;
00447   
00448   if (ope_cl != 0x0)
00449     delete ope_cl ;
00450   
00451   // Routines de derivation
00452   static Matrice (*cl_poisson_2d[MAX_BASE])(const Matrice&, int, double, int);
00453   static int nap = 0 ;
00454   
00455   // Premier appel
00456   if (nap==0) {
00457     nap = 1 ;
00458     for (int i=0 ; i<MAX_BASE ; i++) {
00459       cl_poisson_2d[i] = _cl_poisson_2d_pas_prevu ;
00460     }
00461     // Les routines existantes
00462     cl_poisson_2d[R_CHEBP >> TRA_R] = _cl_poisson_2d_r_chebp ;
00463     cl_poisson_2d[R_CHEBI >> TRA_R] = _cl_poisson_2d_r_chebi ;
00464     cl_poisson_2d[R_CHEB >> TRA_R] = _cl_poisson_2d_r_cheb ;
00465     cl_poisson_2d[R_CHEBU >> TRA_R] = _cl_poisson_2d_r_chebu ;
00466   }
00467   ope_cl = new Matrice(cl_poisson_2d[base_r](*ope_mat, l_quant, beta/alpha, 
00468                          dzpuis)) ;
00469 }
00470 
00471 

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