xdsdx_mat.C

00001 /*
00002  *   Copyright (c) 2000-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 xdsdx_mat_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/xdsdx_mat.C,v 1.3 2007/06/21 20:07:16 k_taniguchi Exp $" ;
00024 
00025 /*
00026  * $Id: xdsdx_mat.C,v 1.3 2007/06/21 20:07:16 k_taniguchi Exp $
00027  * $Log: xdsdx_mat.C,v $
00028  * Revision 1.3  2007/06/21 20:07:16  k_taniguchi
00029  * nmax increased to 200
00030  *
00031  * Revision 1.2  2002/10/16 14:37:12  j_novak
00032  * Reorganization of #include instructions of standard C++, in order to
00033  * use experimental version 3 of gcc.
00034  *
00035  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00036  * LORENE
00037  *
00038  * Revision 2.0  2000/03/16  16:23:17  phil
00039  * *** empty log message ***
00040  *
00041  *
00042  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/xdsdx_mat.C,v 1.3 2007/06/21 20:07:16 k_taniguchi Exp $
00043  *
00044  */
00045 
00046 /*
00047  * Routine renvoyan la matrice de l'operateur x f' = s
00048  * Pour  l != 1 le resultat est donne en s est donne en Chebyshev et
00049  * f en Gelerkin (T_i + T_{i+1} pour l pair et (2*i+3)T_i + (2*i+1)T_{i+1} pour 
00050  * l impair.
00051  * Pour l=1 pas de probleme de singularite on reste donc en Chebyshev.
00052  */
00053 
00054 //fichiers includes
00055 #include <stdio.h>
00056 #include <stdlib.h>
00057 
00058 #include "matrice.h"
00059 #include "type_parite.h"
00060 #include "proto.h"
00061 
00062         //-----------------------------------
00063         // Routine pour les cas non prevus --
00064         //-----------------------------------
00065 
00066 Matrice _xdsdx_mat_pas_prevu(int n, int) {
00067     cout << "xdsdx_mat pas prevu..." << endl ;
00068     cout << "n : " << n << endl ;
00069     abort() ;
00070     exit(-1) ;
00071     Matrice res(1, 1) ; // On ne passe jamais ici de toute facon !
00072     return res;
00073 }
00074 
00075 
00076            //-------------------------
00077            //--   CAS R_CHEBP    -----
00078            //--------------------------
00079             
00080 
00081 Matrice _xdsdx_mat_r_chebp (int n, int) {
00082    const int nmax = 200 ;// Nombre de Matrices stockees
00083    static Matrice* tab[nmax] ;  // les matrices calculees
00084    static int nb_dejafait = 0 ; // nbre de matrices calculees
00085    static int nr_dejafait[nmax] ;
00086     
00087    int indice = -1 ;
00088    
00089    // On determine si la matrice a deja ete calculee :
00090    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00091     if (nr_dejafait[conte] == n)
00092     indice = conte ;
00093     
00094    // Calcul a faire : 
00095    if (indice  == -1) {
00096        if (nb_dejafait >= nmax) {
00097        cout << "_laplacien_nul_mat_r_chebp : trop de matrices" << endl ;
00098        abort() ;
00099        exit (-1) ;
00100        }
00101        
00102     nr_dejafait[nb_dejafait] = n ;
00103     
00104     Matrice res(n-1, n-1) ;
00105     res.set_etat_qcq() ;
00106     
00107     double* xdsdx  = new double[n] ;
00108     
00109     for (int i=0 ; i<n-1 ; i++) {
00110     for (int j=0 ; j<n ; j++)
00111         xdsdx[j] = 0 ;
00112     xdsdx[i] = 1 ;
00113     xdsdx[i+1] = 1 ;
00114     xdsdx_1d (n, &xdsdx, R_CHEBP) ;
00115     
00116     for (int j=0 ; j<n-1 ; j++)
00117         res.set(j, i) = xdsdx[j] ; 
00118     }
00119     delete [] xdsdx ;
00120     tab[nb_dejafait] = new Matrice(res) ;
00121     nb_dejafait ++ ;    
00122     return res ;
00123     }
00124     
00125     else
00126     return *tab[indice] ;
00127 }
00128 
00129 
00130 
00131            //------------------------
00132            //--   CAS R_CHEBI    ----
00133            //------------------------
00134             
00135 
00136 Matrice _xdsdx_mat_r_chebi (int n, int l) {
00137    const int nmax = 200 ;// Nombre de Matrices stockees
00138    static Matrice* tab[nmax] ;  // les matrices calculees
00139    static int nb_dejafait = 0 ; // nbre de matrices calculees
00140    static int nr_dejafait[nmax] ;
00141    static int nl_dejafait[nmax] ;
00142     
00143    int indice = -1 ;
00144    // On separe les cas l=1 et l != 1
00145    int indic_l = (l == 1) ? 1 : 2 ;
00146    
00147    // On determine si la matrice a deja ete calculee :
00148    for (int conte=0 ; conte<nb_dejafait ; conte ++)
00149     if ((nr_dejafait[conte] == n) && (nl_dejafait[conte] == indic_l))
00150     indice = conte ;
00151     
00152    // Calcul a faire : 
00153    if (indice  == -1) {
00154        if (nb_dejafait >= nmax) {
00155        cout << "_laplacien_nul_mat_r_chebp : trop de matrices" << endl ;
00156        abort() ;
00157        exit (-1) ;
00158        }
00159        
00160     nr_dejafait[nb_dejafait] = n ;
00161     nl_dejafait[nb_dejafait] = indic_l ;
00162     
00163     // non degenere pour l=1
00164     int taille = (l==1) ? n : n-1 ;
00165     Matrice res(taille, taille) ;
00166     res.set_etat_qcq() ;
00167   
00168     double* xdsdx = new double[n] ;
00169     
00170     for (int i=0 ; i<taille ; i++) {
00171     for (int j=0 ; j<n ; j++)
00172         xdsdx[j] = 0 ;
00173     
00174     // Gelerkin ou Chebyshev ?
00175     if (taille == n) {
00176         xdsdx[i] = 1 ;
00177     }
00178     else {
00179         xdsdx[i] = 2*i+3 ;
00180         xdsdx[i+1] = 2*i+1 ;
00181         }
00182     xdsdx_1d (n, &xdsdx, R_CHEBI) ;  // appel dans le cas impair
00183     
00184     for (int j=0 ; j<taille ; j++)
00185         res.set(j, i) = xdsdx[j] ;
00186     }
00187   
00188     delete [] xdsdx ;
00189     tab[nb_dejafait] = new Matrice(res) ;
00190     nb_dejafait ++ ;    
00191     return res ;
00192     }
00193     
00194     else
00195     return *tab[indice] ;
00196 }
00197 
00198 
00199          //--------------------------
00200         //- La routine a appeler  ---
00201            //----------------------------
00202 Matrice xdsdx_mat(int n, int l, int base_r)
00203 {
00204 
00205         // Routines de derivation
00206     static Matrice (*xdsdx_mat[MAX_BASE])(int, int) ;
00207     static int nap = 0 ;
00208 
00209         // Premier appel
00210     if (nap==0) {
00211     nap = 1 ;
00212     for (int i=0 ; i<MAX_BASE ; i++) {
00213         xdsdx_mat[i] = _xdsdx_mat_pas_prevu ;
00214     }
00215         // Les routines existantes
00216     xdsdx_mat[R_CHEBP >> TRA_R] = _xdsdx_mat_r_chebp ;
00217     xdsdx_mat[R_CHEBI >> TRA_R] = _xdsdx_mat_r_chebi ;
00218     }
00219     
00220     Matrice res(xdsdx_mat[base_r](n, l)) ;
00221     return res ;
00222 }
00223 

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