ope_ptens_rr_mat.C

00001 /*
00002  *  Builds the operator 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 ope_ptens_rr_mat_C[] = "$Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/ope_ptens_rr_mat.C,v 1.1 2004/12/23 16:30:15 j_novak Exp $" ;
00029 
00030 /*
00031  * $Id: ope_ptens_rr_mat.C,v 1.1 2004/12/23 16:30:15 j_novak Exp $
00032  * $Log: ope_ptens_rr_mat.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/ope_ptens_rr_mat.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 #include "proto.h"
00049 
00050 /*
00051  * Routine caluclant l'operateur suivant :
00052  * 
00053  * -R_CHEB : r^2d2sdx2+6*rdsdx+6-l*(l+1)Id
00054  * 
00055  * -R_CHEBP et R_CHEBI : d2sdx2+6/r dsdx +(6-l(l+1))/r^2
00056  * 
00057  * -R_CHEBU : d2sdx2+(6-l(l+1))/x^2
00058  * 
00059  * Entree :
00060  *  -n nbre de points en r
00061  *      -l voire operateur. (doit etre >=2)
00062  *      -echelle utile uniquement pour R_CHEB : represente beta/alpha 
00063  *        (cf mapping)  
00064  *      - puis : exposant de multiplication dans la ZEC
00065  *      - base_r : base de developpement
00066  *  Sortie :
00067  *  La fonction renvoie la matrice. 
00068  */
00069  
00070 Matrice _ope_ptens_rr_mat_pas_prevu(int, int, double, int) ;
00071 Matrice _ope_ptens_rr_mat_r_chebp(int, int, double, int) ;
00072 Matrice _ope_ptens_rr_mat_r_chebi(int, int, double, int) ;
00073 Matrice _ope_ptens_rr_mat_r_chebu(int, int, double, int) ;
00074 Matrice _ope_ptens_rr_mat_r_cheb(int, int, double, int) ;
00075 
00076                        //-----------------------------------
00077                        // Routine pour les cas non prevus --
00078                        //-----------------------------------
00079 
00080 Matrice _ope_ptens_rr_mat_pas_prevu(int n, int l, double echelle, int puis) {
00081   cout << "laplacien tens_rr pas prevu..." << endl ;
00082   cout << "n : " << n << endl ;
00083   cout << "l : " << l << endl ;
00084   cout << "puissance : " << puis << endl ;
00085   cout << "echelle : " << echelle << endl ;
00086   abort() ;
00087   exit(-1) ;
00088   Matrice res(1, 1) ;
00089   return res;
00090 }
00091 
00092 
00093                              //-------------------------
00094                              //----  CAS R_CHEBP    ----
00095                              //-------------------------
00096             
00097 
00098 Matrice _ope_ptens_rr_mat_r_chebp (int n, int l, double, int) {
00099    
00100   const int nmax = 100 ;// Nombre de Matrices stockees
00101   static Matrice* tab[nmax] ;  // les matrices calculees
00102   static int nb_dejafait = 0 ; // nbre de matrices calculees
00103   static int l_dejafait[nmax] ;
00104   static int nr_dejafait[nmax] ;
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 << "_ope_ptens_rr_mat_r_chebp : trop de matrices" << endl ;
00117       abort() ;
00118       exit (-1) ;
00119     }
00120        
00121 
00122     l_dejafait[nb_dejafait] = l ;
00123     nr_dejafait[nb_dejafait] = n ;
00124     
00125     Matrice dd(n, n) ;
00126     dd.set_etat_qcq() ;
00127     Matrice xd(n, n) ;
00128     xd.set_etat_qcq() ;
00129     Matrice xx(n, n) ;
00130     xx.set_etat_qcq() ;
00131 
00132     double* vect  = new double[n] ;
00133     
00134     for (int i=0 ; i<n ; i++) {
00135       for (int j=0 ; j<n ; j++)
00136     vect[j] = 0 ;
00137       vect[i] = 1 ;
00138       d2sdx2_1d (n, &vect, R_CHEBP) ;
00139     
00140       for (int j=0 ; j<n ; j++)
00141     dd.set(j, i) = vect[j] ; 
00142     }
00143     
00144     for (int i=0 ; i<n ; i++) {
00145       for (int j=0 ; j<n ; j++)
00146     vect[j] = 0 ;
00147       vect[i] = 1 ;
00148       sxdsdx_1d (n, &vect, R_CHEBP) ;
00149       for (int j=0 ; j<n ; j++)
00150     xd.set(j, i) = vect[j] ;
00151     
00152     }
00153     
00154     for (int i=0 ; i<n ; i++) {
00155       for (int j=0 ; j<n ; j++)
00156     vect[j] = 0 ;
00157       vect[i] = 1 ;
00158       sx2_1d (n, &vect, R_CHEBP) ;
00159       for (int j=0 ; j<n ; j++)
00160     xx.set(j, i) = vect[j] ;
00161     }
00162    
00163     delete [] vect ;
00164     
00165     Matrice res(n, n) ;
00166     res = dd+6*xd+(6-l*(l+1))*xx ;
00167     tab[nb_dejafait] = new Matrice(res) ;
00168     nb_dejafait ++ ;    
00169     return res ;
00170   }
00171     
00172   // Cas ou le calcul a deja ete effectue :
00173   else
00174     return *tab[indice] ;
00175 }
00176 
00177 
00178 
00179                              //------------------------
00180                              //--   CAS R_CHEBI    ----
00181                              //------------------------
00182             
00183 
00184 Matrice _ope_ptens_rr_mat_r_chebi (int n, int l, double, int) {
00185    
00186   const int nmax = 100 ;// Nombre de Matrices stockees
00187   static Matrice* tab[nmax] ;  // les matrices calculees
00188   static int nb_dejafait = 0 ; // nbre de matrices calculees
00189   static int l_dejafait[nmax] ;
00190   static int nr_dejafait[nmax] ;
00191     
00192   int indice = -1 ;
00193    
00194   // On determine si la matrice a deja ete calculee :
00195   for (int conte=0 ; conte<nb_dejafait ; conte ++)
00196     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00197       indice = conte ;
00198     
00199   // Calcul a faire : 
00200   if (indice  == -1) {
00201     if (nb_dejafait >= nmax) {
00202       cout << "_ope_ptens_rr_mat_r_chebi : trop de matrices" << endl ;
00203       abort() ;
00204       exit (-1) ;
00205     }
00206        
00207     
00208     l_dejafait[nb_dejafait] = l ;
00209     nr_dejafait[nb_dejafait] = n ;
00210     
00211     Matrice dd(n, n) ;
00212     dd.set_etat_qcq() ;
00213     Matrice xd(n, n) ;
00214     xd.set_etat_qcq() ;
00215     Matrice xx(n, n) ;
00216     xx.set_etat_qcq() ;
00217 
00218     double* vect = new double[n] ;
00219     
00220     for (int i=0 ; i<n ; i++) {
00221       for (int j=0 ; j<n ; j++)
00222     vect[j] = 0 ;
00223       vect[i] = 1 ;
00224       d2sdx2_1d (n, &vect, R_CHEBI) ;  // appel dans le cas impair
00225       for (int j=0 ; j<n ; j++)
00226     dd.set(j, i) = vect[j] ;
00227     }
00228     
00229     for (int i=0 ; i<n ; i++) {
00230       for (int j=0 ; j<n ; j++)
00231     vect[j] = 0 ;
00232       vect[i] = 1 ;
00233       sxdsdx_1d (n, &vect, R_CHEBI) ;
00234       for (int j=0 ; j<n ; j++)
00235     xd.set(j, i) = vect[j] ;
00236     }
00237     
00238     for (int i=0 ; i<n ; i++) {
00239       for (int j=0 ; j<n ; j++)
00240     vect[j] = 0 ;
00241       vect[i] = 1 ;
00242       sx2_1d (n, &vect, R_CHEBI) ;
00243       for (int j=0 ; j<n ; j++)
00244     xx.set(j, i) = vect[j] ;
00245     }
00246     
00247     delete [] vect ;
00248     
00249     Matrice res(n, n) ;
00250     res = dd+6*xd+(6-l*(l+1))*xx ;
00251     tab[nb_dejafait] = new Matrice(res) ;
00252     nb_dejafait ++ ;
00253     return res ;
00254   } 
00255     
00256   // Cas ou le calcul a deja ete effectue :
00257   else
00258     return *tab[indice] ;
00259 }
00260 
00261 
00262 
00263 
00264                             //------------------------
00265                             //----  CAS R_CHEBU   ----
00266                             //------------------------
00267 
00268 Matrice _ope_ptens_rr_mat_r_chebu( int n, int l, double, int puis) {
00269 
00270   if (puis != 4) {
00271     cout << "_ope_ptens_rr_mat_r_chebu : only the case dzpuis = 4 "
00272      << '\n' << "is implemented! \n"
00273      << "dzpuis = " << puis << endl ;
00274     abort() ;
00275   }
00276         
00277   const int nmax = 200 ;// Nombre de Matrices stockees
00278   static Matrice* tab[nmax] ;  // les matrices calculees
00279   static int nb_dejafait = 0 ; // nbre de matrices calculees
00280   static int l_dejafait[nmax] ;
00281   static int nr_dejafait[nmax] ;
00282     
00283   int indice = -1 ;
00284    
00285   // On determine si la matrice a deja ete calculee :
00286   for (int conte=0 ; conte<nb_dejafait ; conte ++)
00287     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00288       indice = conte ;
00289     
00290   // Calcul a faire : 
00291   if (indice  == -1) {
00292     if (nb_dejafait >= nmax) {
00293       cout << "_ope_ptens_rr_mat_r_chebu : trop de matrices" << endl ;
00294       abort() ;
00295       exit (-1) ;
00296     }
00297        
00298     l_dejafait[nb_dejafait] = l ;
00299     nr_dejafait[nb_dejafait] = n ;
00300       
00301     Matrice dd(n, n) ;
00302     dd.set_etat_qcq() ;
00303     Matrice xd(n, n) ;
00304     xd.set_etat_qcq() ;
00305     Matrice xx(n, n) ;
00306     xx.set_etat_qcq() ;
00307       
00308     double* vect = new double[n] ;
00309       
00310     for (int i=0 ; i<n ; i++) {
00311       for (int j=0 ; j<n ; j++)
00312     vect[j] = 0 ;
00313       vect[i] = 1 ;
00314       d2sdx2_1d (n, &vect, R_CHEBU) ;  // appel dans le cas unsurr
00315       for (int j=0 ; j<n ; j++)
00316     dd.set(j, i) = vect[j] ;
00317     }
00318       
00319     for (int i=0 ; i<n ; i++) {
00320       for (int j=0 ; j<n ; j++)
00321     vect[j] = 0 ;
00322       vect[i] = 1 ;
00323       dsdx_1d (n, &vect, R_CHEBU) ;  // appel dans le cas unsurr
00324       sxm1_1d_cheb (n, vect) ;
00325       for (int j=0 ; j<n ; j++)
00326     xd.set(j, i) = vect[j] ;
00327     }
00328       
00329     for (int i=0 ; i<n ; i++) {
00330       for (int j=0 ; j<n ; j++)
00331     vect[j] = 0 ;
00332       vect[i] = 1 ;
00333       sx2_1d (n, &vect, R_CHEBU) ;
00334       for (int j=0 ; j<n ; j++)
00335     xx.set(j, i) = vect[j] ;
00336     }
00337     
00338     delete [] vect ;
00339     
00340     Matrice res(n, n) ;
00341     res = dd - 4*xd + (6 -l*(l+1))*xx ;
00342     tab[nb_dejafait] = new Matrice(res) ;
00343     nb_dejafait ++ ;
00344     return res ;
00345   } 
00346     
00347   // Cas ou le calcul a deja ete effectue :
00348   else
00349     return *tab[indice] ;
00350 }
00351 
00352 
00353                    //-----------------------
00354                    //----  CAS R_CHEB   ----
00355                    //-----------------------
00356             
00357 
00358 Matrice _ope_ptens_rr_mat_r_cheb (int n, int l, double echelle, int) {
00359             
00360   const int nmax = 200 ;// Nombre de Matrices stockees
00361   static Matrice* tab[nmax] ;  // les matrices calculees
00362   static int nb_dejafait = 0 ; // nbre de matrices calculees
00363   static int l_dejafait[nmax] ;
00364   static int nr_dejafait[nmax] ;
00365   static double vieux_echelle = 0;
00366    
00367   // Si on a change l'echelle : on detruit tout :
00368   if (vieux_echelle != echelle) {
00369     for (int i=0 ; i<nb_dejafait ; i++) {
00370       l_dejafait[i] = -1 ;
00371       nr_dejafait[i] = -1 ;
00372       delete tab[i] ;
00373     }
00374        
00375     nb_dejafait = 0 ;
00376     vieux_echelle = echelle ;
00377   }
00378       
00379   int indice = -1 ;
00380    
00381   // On determine si la matrice a deja ete calculee :
00382   for (int conte=0 ; conte<nb_dejafait ; conte ++)
00383     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00384       indice = conte ;
00385     
00386   // Calcul a faire : 
00387   if (indice  == -1) {
00388     if (nb_dejafait >= nmax) {
00389       cout << "_ope_ptens_rr_mat_r_cheb : trop de matrices" << endl ;
00390       abort() ;
00391       exit (-1) ;
00392     }
00393        
00394         
00395     l_dejafait[nb_dejafait] = l ;
00396     nr_dejafait[nb_dejafait] = n ;
00397     
00398     Matrice dd(n, n) ;
00399     dd.set_etat_qcq() ;
00400     Matrice xd(n, n) ;
00401     xd.set_etat_qcq() ;
00402     Matrice xx(n, n) ;
00403     xx.set_etat_qcq() ;
00404 
00405     double* vect = new double[n] ;
00406     
00407     for (int i=0 ; i<n ; i++) {
00408       for (int j=0 ; j<n ; j++)
00409     vect[j] = 0 ;
00410       vect[i] = 1 ;
00411       d2sdx2_1d (n, &vect, R_CHEB) ;  // appel dans le cas fin
00412       for (int j=0 ; j<n ; j++)
00413     dd.set(j, i) = vect[j]*echelle*echelle ;
00414     }
00415     
00416     for (int i=0 ; i<n ; i++) {
00417       for (int j=0 ; j<n ; j++)
00418     vect[j] = 0 ;
00419       vect[i] = 1 ;
00420       d2sdx2_1d (n, &vect, R_CHEB) ;  // appel dans le cas fin
00421       multx_1d (n, &vect, R_CHEB) ;
00422       for (int j=0 ; j<(n>i+1 ? i+1 : n) ; j++)
00423     dd.set(j, i) += 2*echelle*vect[j] ;
00424     }
00425     
00426     for (int i=0 ; i<n ; i++) {
00427       for (int j=0 ; j<n ; j++)
00428     vect[j] = 0 ;
00429       vect[i] = 1 ;
00430       d2sdx2_1d (n, &vect, R_CHEB) ;  // appel dans le cas fin
00431       multx_1d (n, &vect, R_CHEB) ;
00432       multx_1d (n, &vect, R_CHEB) ;
00433       for (int j=0 ; j<(n>i+1 ? i+1 : n) ; j++)
00434     dd.set(j, i) += vect[j] ;
00435     }
00436     
00437     for (int i=0 ; i<n ; i++) {
00438       for (int j=0 ; j<n ; j++)
00439     vect[j] = 0 ;
00440       vect[i] = 1 ;
00441       sxdsdx_1d (n, &vect, R_CHEB) ;
00442       for (int j=0 ; j<n ; j++)
00443     xd.set(j, i) = vect[j]*echelle ;
00444     }
00445     
00446     for (int i=0 ; i<n ; i++) {
00447       for (int j=0 ; j<n ; j++)
00448     vect[j] = 0 ;
00449       vect[i] = 1 ;
00450       sxdsdx_1d (n, &vect, R_CHEB) ;
00451       multx_1d (n, &vect, R_CHEB) ;
00452       for (int j=0 ; j<(n>i+1 ? i+1 : n) ; j++)
00453     xd.set(j, i) += vect[j] ;
00454     }
00455        
00456     for (int i=0 ; i<n ; i++) {
00457       for (int j=0 ; j<n ; j++)
00458     vect[j] = 0 ;
00459       vect[i] = 1 ;
00460       sx2_1d (n, &vect, R_CHEB) ;
00461       for (int j=0 ; j<n ; j++)
00462     xx.set(j, i) = vect[j] ;
00463     }
00464     
00465     delete [] vect ;
00466     
00467     Matrice res(n, n) ;
00468     res = dd + 6*xd + (6 - l*(l+1))*xx ;
00469     tab[nb_dejafait] = new Matrice(res) ;
00470     nb_dejafait ++ ;
00471     return res ;
00472   } 
00473     
00474   // Cas ou le calcul a deja ete effectue :
00475   else
00476     return *tab[indice] ;  
00477 }
00478 
00479 
00480                         //----------------------------
00481                         //--- La routine a appeler ---
00482                         //----------------------------
00483 
00484 Matrice ope_ptens_rr_mat(int n, int l, double echelle, int puis, int base_r)
00485 {
00486 
00487   // Routines de derivation
00488   static Matrice (*ope_ptens_rr_mat[MAX_BASE])(int, int, double, int) ;
00489   static int nap = 0 ;
00490 
00491   // Premier appel
00492   if (nap==0) {
00493     nap = 1 ;
00494     for (int i=0 ; i<MAX_BASE ; i++) {
00495       ope_ptens_rr_mat[i] = _ope_ptens_rr_mat_pas_prevu ;
00496     }
00497     // Les routines existantes
00498     ope_ptens_rr_mat[R_CHEB >> TRA_R] = _ope_ptens_rr_mat_r_cheb ;
00499     ope_ptens_rr_mat[R_CHEBU >> TRA_R] = _ope_ptens_rr_mat_r_chebu ;
00500     ope_ptens_rr_mat[R_CHEBP >> TRA_R] = _ope_ptens_rr_mat_r_chebp ;
00501     ope_ptens_rr_mat[R_CHEBI >> TRA_R] = _ope_ptens_rr_mat_r_chebi ;
00502   }
00503   assert (l>1) ;
00504   Matrice res(ope_ptens_rr_mat[base_r](n, l, echelle, puis)) ;
00505   return res ;
00506 }
00507 

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