laplacien_mat.C

00001 /*
00002  *   Copyright (c) 1999-2001 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 as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   LORENE is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with LORENE; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 char laplacien_mat_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/laplacien_mat.C,v 1.9 2007/12/11 15:28:22 jl_cornou Exp $" ;
00024 
00025 /*
00026  * $Id: laplacien_mat.C,v 1.9 2007/12/11 15:28:22 jl_cornou Exp $
00027  * $Log: laplacien_mat.C,v $
00028  * Revision 1.9  2007/12/11 15:28:22  jl_cornou
00029  * Jacobi(0,2) polynomials partially implemented
00030  *
00031  * Revision 1.8  2007/06/06 07:43:28  p_grandclement
00032  * nmax increased to 200
00033  *
00034  * Revision 1.7  2005/01/27 10:19:43  j_novak
00035  * Now using Diff operators to build the matrices.
00036  *
00037  * Revision 1.6  2004/10/05 15:44:21  j_novak
00038  * Minor speed enhancements.
00039  *
00040  * Revision 1.5  2004/02/06 10:53:54  j_novak
00041  * New dzpuis = 5 -> dzpuis = 3 case (not ready yet).
00042  *
00043  * Revision 1.4  2003/01/31 08:49:58  e_gourgoulhon
00044  * Increased the number nmax of stored matrices from 100 to 200.
00045  *
00046  * Revision 1.3  2002/10/16 14:37:11  j_novak
00047  * Reorganization of #include instructions of standard C++, in order to
00048  * use experimental version 3 of gcc.
00049  *
00050  * Revision 1.2  2002/10/09 12:47:32  j_novak
00051  * Execution speed improved
00052  *
00053  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00054  * LORENE
00055  *
00056  * Revision 2.15  2000/05/22  13:36:33  phil
00057  * ajout du cas dzpuis == 3
00058  *
00059  * Revision 2.14  2000/01/04  19:00:09  phil
00060  * Double nmax
00061  *
00062  * Revision 2.13  1999/10/11  14:27:26  phil
00063  * & -> &&
00064  *
00065  * Revision 2.12  1999/09/30  09:17:11  phil
00066  * remplacement && en & et initialisation des variables statiques.
00067  *
00068  * Revision 2.11  1999/09/17  15:19:30  phil
00069  * correction de definition de nmax
00070  *
00071  * Revision 2.10  1999/09/03  14:07:15  phil
00072  * pas de modif
00073  *
00074  * Revision 2.9  1999/07/08  09:54:20  phil
00075  * *** empty log message ***
00076  *
00077  * Revision 2.8  1999/07/07  10:02:39  phil
00078  * Passage aux operateurs 1d
00079  *
00080  * Revision 2.7  1999/06/23  12:34:07  phil
00081  * ajout de dzpuis = 2
00082  *
00083  * Revision 2.6  1999/04/28  10:45:54  phil
00084  * augmentation de NMAX a 50
00085  *
00086  * Revision 2.5  1999/04/19  14:03:42  phil
00087  * *** empty log message ***
00088  *
00089  * Revision 2.4  1999/04/16  13:15:52  phil
00090  * *** empty log message ***
00091  *
00092  * Revision 2.3  1999/04/14  13:57:26  phil
00093  * Sauvegarde des Matrices deja calculees
00094  *
00095  * Revision 2.2  1999/04/13  13:58:30  phil
00096  * ajout proto.h
00097  *
00098  * Revision 2.1  1999/04/07  14:22:17  phil
00099  * *** empty log message ***
00100  *
00101  * Revision 2.0  1999/04/07  14:09:41  phil
00102  * *** empty log message ***
00103  *
00104  *
00105  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/laplacien_mat.C,v 1.9 2007/12/11 15:28:22 jl_cornou Exp $
00106  *
00107  */
00108 
00109 //fichiers includes
00110 #include <stdio.h>
00111 #include <stdlib.h>
00112 
00113 #include "diff.h"
00114 #include "proto.h"
00115 
00116 /*
00117  * Routine calculant l'operateur suivant :
00118  * 
00119  * -R_CHEB : r^2d2sdx2+2*rdsdx-l*(l+1)Id
00120  * 
00121  * -R_CHEBP et R_CHEBI : d2sdx2+2/r dsdx-l(l+1)/r^2
00122  *  
00123  * -R_CHEBU : d2sdx2-l(l+1)/x^2
00124  * 
00125  * -R_JACO02 : d2sdx2 + 2/r dsdx - l(l+1)/r^2
00126  * 
00127  * Entree :
00128  *  -n nbre de points en r
00129     -l voire operateur.
00130     -echelle utile uniquement pour R_CHEB : represente beta/alpha 
00131                         (cf mapping)
00132     
00133     - puis : exposant de multiplication dans la ZEC
00134     - base_r : base de developpement
00135     
00136     Sortie :
00137     La fonction renvoie la matrice.
00138     
00139  */
00140         //-----------------------------------
00141         // Routine pour les cas non prevus --
00142         //-----------------------------------
00143 
00144 Matrice _laplacien_mat_pas_prevu(int n, int l, double echelle, int puis) {
00145     cout << "laplacien pas prevu..." << endl ;
00146     cout << "n : " << n << endl ;
00147     cout << "l : " << l << endl ;
00148     cout << "puissance : " << puis << endl ;
00149     cout << "echelle : " << echelle << endl ;
00150     abort() ;
00151     exit(-1) ;
00152     Matrice res(1, 1) ;
00153     return res;
00154 }
00155 
00156 
00157            //-------------------------
00158            //--   CAS R_JACO02   -----
00159            //-------------------------
00160             
00161 
00162 Matrice _laplacien_mat_r_jaco02 (int n, int l, double, int) {
00163    
00164    const int nmax = 200 ;// Nombre de Matrices stockees
00165    static Matrice* tab[nmax] ;  // les matrices calculees
00166    static int nb_dejafait = 0 ; // nbre de matrices calculees
00167    static int l_dejafait[nmax] ;
00168    static int nr_dejafait[nmax] ;
00169     
00170    int indice = -1 ;
00171    
00172    // On determine si la matrice a deja ete calculee :
00173    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00174     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00175     indice = conte ;
00176     
00177    // Calcul a faire : 
00178    if (indice  == -1) {
00179        if (nb_dejafait >= nmax) {
00180        cout << "_laplacien_mat_r_jaco02 : trop de matrices" << endl ;
00181        abort() ;
00182        exit (-1) ;
00183        }
00184        
00185 
00186     l_dejafait[nb_dejafait] = l ;
00187     nr_dejafait[nb_dejafait] = n ;
00188     
00189     Diff_dsdx2 d2(R_JACO02, n) ;
00190     Diff_sxdsdx sxd(R_JACO02, n) ;
00191     Diff_sx2 sx2(R_JACO02, n) ;
00192     
00193     tab[nb_dejafait] = new Matrice(d2 + 2.*sxd -(l*(l+1))*sx2) ;
00194 
00195     indice = nb_dejafait ;
00196     nb_dejafait ++ ;    
00197    }
00198     
00199    return *tab[indice] ;
00200 }
00201 
00202 
00203            //-------------------------
00204            //--   CAS R_CHEBP    -----
00205            //--------------------------
00206             
00207 
00208 Matrice _laplacien_mat_r_chebp (int n, int l, double, int) {
00209    
00210    const int nmax = 200 ;// Nombre de Matrices stockees
00211    static Matrice* tab[nmax] ;  // les matrices calculees
00212    static int nb_dejafait = 0 ; // nbre de matrices calculees
00213    static int l_dejafait[nmax] ;
00214    static int nr_dejafait[nmax] ;
00215     
00216    int indice = -1 ;
00217    
00218    // On determine si la matrice a deja ete calculee :
00219    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00220     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00221     indice = conte ;
00222     
00223    // Calcul a faire : 
00224    if (indice  == -1) {
00225        if (nb_dejafait >= nmax) {
00226        cout << "_laplacien_mat_r_chebp : trop de matrices" << endl ;
00227        abort() ;
00228        exit (-1) ;
00229        }
00230        
00231 
00232     l_dejafait[nb_dejafait] = l ;
00233     nr_dejafait[nb_dejafait] = n ;
00234     
00235     Diff_dsdx2 d2(R_CHEBP, n) ;
00236     Diff_sxdsdx sxd(R_CHEBP, n) ;
00237     Diff_sx2 sx2(R_CHEBP, n) ;
00238     
00239     tab[nb_dejafait] = new Matrice(d2 + 2.*sxd -(l*(l+1))*sx2) ;
00240 
00241     indice = nb_dejafait ;
00242     nb_dejafait ++ ;    
00243    }
00244     
00245    return *tab[indice] ;
00246 }
00247 
00248 
00249 
00250            //------------------------
00251            //--   CAS R_CHEBI    ----
00252            //------------------------
00253             
00254 
00255 Matrice _laplacien_mat_r_chebi (int n, int l, double, int) {
00256    
00257    const int nmax = 200 ;// Nombre de Matrices stockees
00258    static Matrice* tab[nmax] ;  // les matrices calculees
00259    static int nb_dejafait = 0 ; // nbre de matrices calculees
00260    static int l_dejafait[nmax] ;
00261    static int nr_dejafait[nmax] ;
00262     
00263    int indice = -1 ;
00264    
00265    // On determine si la matrice a deja ete calculee :
00266    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00267     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00268     indice = conte ;
00269     
00270    // Calcul a faire : 
00271    if (indice  == -1) {
00272        if (nb_dejafait >= nmax) {
00273        cout << "_laplacien_mat_r_chebi : trop de matrices" << endl ;
00274        abort() ;
00275        exit (-1) ;
00276        }
00277        
00278     
00279     l_dejafait[nb_dejafait] = l ;
00280     nr_dejafait[nb_dejafait] = n ;
00281     
00282     Diff_dsdx2 d2(R_CHEBI, n) ;
00283     Diff_sxdsdx sxd(R_CHEBI, n) ;
00284     Diff_sx2 sx2(R_CHEBI, n) ;
00285     
00286     tab[nb_dejafait] = new Matrice(d2 + 2.*sxd - (l*(l+1))*sx2) ;
00287     indice = nb_dejafait ;
00288     nb_dejafait ++ ;
00289    } 
00290     
00291    return *tab[indice] ;
00292 }
00293 
00294 
00295 
00296 
00297            //-------------------------
00298            //--   CAS R_CHEBU    -----
00299            //-------------------------
00300 
00301 Matrice _laplacien_mat_r_chebu( int n, int l, double, int puis) {
00302     Matrice res(n, n) ;
00303     res.set_etat_qcq() ;
00304     switch (puis) {
00305     case 4 :
00306         res = _laplacien_mat_r_chebu_quatre (n, l) ;
00307         break ;
00308     case 3 :
00309         res = _laplacien_mat_r_chebu_trois (n, l) ;
00310         break ;
00311     case 2 :
00312         res = _laplacien_mat_r_chebu_deux (n, l) ;
00313         break ;
00314     case 5 :
00315         res = _laplacien_mat_r_chebu_cinq (n, l) ;
00316         break ;
00317     default :
00318         abort() ;
00319         exit(-1) ;
00320     }
00321     return res ;
00322 }
00323     
00324     // Cas ou dzpuis = 4
00325 Matrice _laplacien_mat_r_chebu_quatre (int n, int l) {
00326         
00327    const int nmax = 200 ;// Nombre de Matrices stockees
00328    static Matrice* tab[nmax] ;  // les matrices calculees
00329    static int nb_dejafait = 0 ; // nbre de matrices calculees
00330    static int l_dejafait[nmax] ;
00331    static int nr_dejafait[nmax] ;
00332     
00333    int indice = -1 ;
00334    
00335    // On determine si la matrice a deja ete calculee :
00336    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00337     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00338     indice = conte ;
00339     
00340    // Calcul a faire : 
00341    if (indice  == -1) {
00342        if (nb_dejafait >= nmax) {
00343        cout << "_laplacien_mat_r_chebu_quatre : trop de matrices" << endl ;
00344        abort() ;
00345        exit (-1) ;
00346        }
00347        
00348         
00349     l_dejafait[nb_dejafait] = l ;
00350     nr_dejafait[nb_dejafait] = n ;
00351     
00352     Diff_dsdx2 dd(R_CHEBU, n) ;
00353     Diff_sx2 xx(R_CHEBU, n) ;
00354     
00355     tab[nb_dejafait] = new Matrice(dd-(l*(l+1))*xx) ;
00356     indice = nb_dejafait ;
00357     nb_dejafait ++ ;
00358    } 
00359     
00360    return *tab[indice] ;
00361 }
00362 
00363 // Cas ou dzpuis =3 
00364 Matrice _laplacien_mat_r_chebu_trois (int n, int l) {
00365         
00366    const int nmax = 200 ;// Nombre de Matrices stockees
00367    static Matrice* tab[nmax] ;  // les matrices calculees
00368    static int nb_dejafait = 0 ; // nbre de matrices calculees
00369    static int l_dejafait[nmax] ;
00370    static int nr_dejafait[nmax] ;
00371     
00372    int indice = -1 ;
00373    
00374    // On determine si la matrice a deja ete calculee :
00375    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00376     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00377     indice = conte ;
00378     
00379    // Calcul a faire : 
00380    if (indice  == -1) {
00381        if (nb_dejafait >= nmax) {
00382        cout << "_laplacien_mat_r_chebu_trois : trop de matrices" << endl ;
00383        abort() ;
00384        exit (-1) ;
00385        }
00386        
00387         
00388     l_dejafait[nb_dejafait] = l ;
00389     nr_dejafait[nb_dejafait] = n ;
00390     
00391     Diff_xdsdx2 xd2(R_CHEBU, n) ;
00392     Diff_sx sx(R_CHEBU, n) ;
00393 
00394     tab[nb_dejafait] = new Matrice(xd2 -(l*(l+1))*sx) ;
00395     
00396     indice = nb_dejafait ;
00397     nb_dejafait ++ ;
00398    } 
00399     
00400    return *tab[indice] ;
00401 }
00402 
00403 
00404     //Cas ou dzpuis = 2
00405 Matrice _laplacien_mat_r_chebu_deux (int n, int l) {
00406         
00407    const int nmax = 200 ;// Nombre de Matrices stockees
00408    static Matrice* tab[nmax] ;  // les matrices calculees
00409    static int nb_dejafait = 0 ; // nbre de matrices calculees
00410    static int l_dejafait[nmax] ;
00411    static int nr_dejafait[nmax] ;
00412     
00413    int indice = -1 ;
00414    
00415    // On determine si la matrice a deja ete calculee :
00416    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00417     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00418     indice = conte ;
00419     
00420    // Calcul a faire : 
00421    if (indice  == -1) {
00422        if (nb_dejafait >= nmax) {
00423        cout << "_laplacien_mat_r_chebu_deux : trop de matrices" << endl ;
00424        abort() ;
00425        exit (-1) ;
00426        }
00427        
00428         
00429     l_dejafait[nb_dejafait] = l ;
00430     nr_dejafait[nb_dejafait] = n ;
00431 
00432     Diff_x2dsdx2 x2dd(R_CHEBU, n) ;
00433     Diff_id id(R_CHEBU, n) ;
00434     
00435     tab[nb_dejafait] = new Matrice(x2dd - (l*(l+1))*id) ;
00436     
00437     indice = nb_dejafait ;
00438     nb_dejafait ++ ;
00439    } 
00440 
00441    return *tab[indice] ;
00442 }
00443 
00444     //Cas ou dzpuis = 5
00445 Matrice _laplacien_mat_r_chebu_cinq (int n, int l) {
00446         
00447    const int nmax = 200 ;// Nombre de Matrices stockees
00448    static Matrice* tab[nmax] ;  // les matrices calculees
00449    static int nb_dejafait = 0 ; // nbre de matrices calculees
00450    static int l_dejafait[nmax] ;
00451    static int nr_dejafait[nmax] ;
00452     
00453    int indice = -1 ;
00454    
00455    // On determine si la matrice a deja ete calculee :
00456    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00457     if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00458     indice = conte ;
00459     
00460    // Calcul a faire : 
00461    if (indice  == -1) {
00462        if (nb_dejafait >= nmax) {
00463        cout << "_laplacien_mat_r_chebu_cinq : trop de matrices" << endl ;
00464        abort() ;
00465        exit (-1) ;
00466        }
00467        
00468         
00469     l_dejafait[nb_dejafait] = l ;
00470     nr_dejafait[nb_dejafait] = n ;
00471     
00472     Diff_x2dsdx2 x2dd(R_CHEBU, n) ;
00473     Diff_xdsdx xd1(R_CHEBU, n) ;
00474     Diff_id id(R_CHEBU, n) ;
00475 
00476     tab[nb_dejafait] = new Matrice( x2dd + 6.*xd1 + (6-l*(l+1))*id ) ;
00477 
00478     indice = nb_dejafait ;
00479     nb_dejafait ++ ;
00480    } 
00481     
00482    return *tab[indice] ;
00483 }
00484 
00485            //-------------------------
00486            //--   CAS R_CHEB    -----
00487            //-----------------------
00488             
00489 
00490 Matrice _laplacien_mat_r_cheb (int n, int l, double echelle, int) {
00491             
00492    const int nmax = 200 ;// Nombre de Matrices stockees
00493    static Matrice* tab[nmax] ;  // les matrices calculees
00494    static int nb_dejafait = 0 ; // nbre de matrices calculees
00495    static int l_dejafait[nmax] ;
00496    static int nr_dejafait[nmax] ;
00497    static double vieux_echelle = 0;
00498    
00499    // Si on a change l'echelle : on detruit tout :
00500    if (vieux_echelle != echelle) {
00501        for (int i=0 ; i<nb_dejafait ; i++) {
00502        l_dejafait[i] = -1 ;
00503        nr_dejafait[i] = -1 ;
00504        delete tab[i] ;
00505        }
00506        
00507        nb_dejafait = 0 ;
00508        vieux_echelle = echelle ;
00509    }
00510    
00511    int indice = -1 ;
00512    
00513    // On determine si la matrice a deja ete calculee :
00514    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00515        if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00516        indice = conte ;
00517    
00518    // Calcul a faire : 
00519    if (indice  == -1) {
00520        if (nb_dejafait >= nmax) {
00521        cout << "_laplacien_mat_r_cheb : trop de matrices" << endl ;
00522        abort() ;
00523        exit (-1) ;
00524        }
00525        
00526        
00527        l_dejafait[nb_dejafait] = l ;
00528        nr_dejafait[nb_dejafait] = n ;
00529        
00530        Diff_dsdx2 d2(R_CHEB, n) ;
00531        Diff_xdsdx2 xd2(R_CHEB, n) ;
00532        Diff_x2dsdx2 x2d2(R_CHEB, n) ;
00533        Diff_dsdx d1(R_CHEB, n) ;
00534        Diff_xdsdx xd1(R_CHEB, n) ;
00535        Diff_id id(R_CHEB, n) ;
00536 
00537        tab[nb_dejafait] = 
00538        new Matrice(x2d2 + (2*echelle)*xd2 + (echelle*echelle)*d2
00539                + 2*xd1 + (2*echelle)*d1 - (l*(l+1))*id) ;
00540     indice = nb_dejafait ;
00541     nb_dejafait ++ ;
00542    } 
00543    
00544    return *tab[indice] ;  
00545 }
00546 
00547 
00548          //--------------------------
00549         //- La routine a appeler  ---
00550            //----------------------------
00551 Matrice laplacien_mat(int n, int l, double echelle, int puis, int base_r)
00552 {
00553 
00554         // Routines de derivation
00555     static Matrice (*laplacien_mat[MAX_BASE])(int, int, double, int) ;
00556     static int nap = 0 ;
00557 
00558         // Premier appel
00559     if (nap==0) {
00560     nap = 1 ;
00561     for (int i=0 ; i<MAX_BASE ; i++) {
00562         laplacien_mat[i] = _laplacien_mat_pas_prevu ;
00563     }
00564         // Les routines existantes
00565     laplacien_mat[R_CHEB >> TRA_R] = _laplacien_mat_r_cheb ;
00566     laplacien_mat[R_CHEBU >> TRA_R] = _laplacien_mat_r_chebu ;
00567     laplacien_mat[R_CHEBP >> TRA_R] = _laplacien_mat_r_chebp ;
00568     laplacien_mat[R_CHEBI >> TRA_R] = _laplacien_mat_r_chebi ;
00569     laplacien_mat[R_JACO02 >> TRA_R] = _laplacien_mat_r_jaco02 ;
00570     }
00571     
00572     return laplacien_mat[base_r](n, l, echelle, puis) ;
00573 }
00574 

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