tbl.h

00001 /*
00002  *  Definition of Lorene class Tbl
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 1999-2000 Jean-Alain Marck
00008  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00009  *
00010  *   This file is part of LORENE.
00011  *
00012  *   LORENE is free software; you can redistribute it and/or modify
00013  *   it under the terms of the GNU General Public License as published by
00014  *   the Free Software Foundation; either version 2 of the License, or
00015  *   (at your option) any later version.
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 
00029 #ifndef __TBL_H_
00030 #define __TBL_H_
00031 
00032 /*
00033  * Classe de tableaux de dimension determinee (actuellement 1, 2 et 3)
00034  *
00035  */
00036 
00037 /*
00038  * $Id: tbl.h,v 1.11 2012/01/17 10:20:57 j_penner Exp $
00039  * $Log: tbl.h,v $
00040  * Revision 1.11  2012/01/17 10:20:57  j_penner
00041  * function added: Heaviside
00042  *
00043  * Revision 1.10  2006/09/25 10:01:45  p_grandclement
00044  * Addition of N-dimensional Tbl
00045  *
00046  * Revision 1.9  2004/12/02 09:33:04  p_grandclement
00047  * *** empty log message ***
00048  *
00049  * Revision 1.8  2004/03/22 13:12:43  j_novak
00050  * Modification of comments to use doxygen instead of doc++
00051  *
00052  * Revision 1.7  2003/11/06 14:43:37  e_gourgoulhon
00053  * Gave a name to const arguments in certain method prototypes (e.g.
00054  * constructors) to correct a bug of DOC++.
00055  *
00056  * Revision 1.6  2002/10/16 14:36:29  j_novak
00057  * Reorganization of #include instructions of standard C++, in order to
00058  * use experimental version 3 of gcc.
00059  *
00060  * Revision 1.5  2002/09/24 10:49:42  e_gourgoulhon
00061  *
00062  * Modif commentaires.
00063  *
00064  * Revision 1.4  2002/09/24 08:33:35  e_gourgoulhon
00065  *
00066  * Added constructor from Matrice
00067  *
00068  * Revision 1.3  2002/06/17 14:05:17  j_novak
00069  * friend functions are now also declared outside the class definition
00070  *
00071  * Revision 1.2  2002/01/03 13:18:40  j_novak
00072  * Optimization: the members set(i,j) and operator(i,j) of class Matrice are
00073  * now defined inline. Matrice is a friend class of Tbl.
00074  *
00075  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00076  * LORENE
00077  *
00078  * Revision 2.11  1999/12/02  17:52:59  phil
00079  * *** empty log message ***
00080  *
00081  * Revision 2.10  1999/11/23  13:31:27  eric
00082  * Le constructeur Tbl::Tbl(const Dim_tbl ) devient Tbl::Tbl(const Dim_tbl& ).
00083  * Le constructeur Tbl::Tbl(const Grille3d* ) devient
00084  *   Tbl(const Grille3d& ).
00085  *
00086  * Revision 2.9  1999/11/15  16:36:08  eric
00087  * Le membre dim est desormais un Dim_tbl et non plus un pointeur sur un
00088  * Dim_tbl.
00089  *
00090  * Revision 2.8  1999/10/29  15:04:07  eric
00091  * Suppression des fonctions membres min() et max():
00092  * elles deviennent des fonctions externes.
00093  * Ajout de fonctions mathematiques (abs, norme, etc...).
00094  *
00095  * Revision 2.7  1999/10/18  15:05:48  eric
00096  * La fonction membre annule() est rebaptisee annule_hard().
00097  *
00098  * Revision 2.6  1999/10/01  10:18:18  eric
00099  * Amelioration des commentaires.
00100  *
00101  * Revision 2.5  1999/09/30  12:50:59  eric
00102  *  Constructeur a 1 parametre rendu explicit.
00103  * Amelioration des commentaires.
00104  *
00105  * Revision 2.4  1999/09/24  14:23:01  eric
00106  * Depoussierage.
00107  * Documentation.
00108  *
00109  * Revision 2.3  1999/03/02  18:54:36  eric
00110  * Ajout de la fonction affiche_seuil.
00111  *
00112  * Revision 2.2  1999/02/23  10:40:55  hyc
00113  * *** empty log message ***
00114  *
00115  *
00116  * Revision 2.0  1998/12/02  11:11:16  hyc
00117  * Version 2
00118  *
00119  * $Header: /cvsroot/Lorene/C++/Include/tbl.h,v 1.11 2012/01/17 10:20:57 j_penner Exp $
00120  *
00121  */
00122 
00123 
00124 // Fichiers includes
00125 #include <assert.h>
00126 #include <stdlib.h>
00127 
00128 #include "type_parite.h"
00129 #include "dim_tbl.h"
00130 #include "itbl.h"
00131 
00132 class Grille3d ;
00133 class Matrice ;
00134 
00135 
00154 class Tbl {
00155 
00156   friend class Matrice ;
00157 
00158     // Data : 
00159     // -----
00160     private:
00162     int etat ;  
00163 
00164     public:
00165         Dim_tbl dim ;       
00166     double* t ;     
00167 
00168     // Constructors - Destructor
00169     // -------------------------
00170     
00171     public:
00177     explicit Tbl(int size0) ;           
00178 
00188     Tbl(int size1, int size0) ;     
00189     
00202     Tbl(int size2, int size1, int size0) ;      
00207     Tbl(Itbl sizes) ;   
00208     
00209     explicit Tbl(const Grille3d& grid) ; 
00210     explicit Tbl(const Dim_tbl& dim) ;   
00211 
00212     explicit Tbl(FILE* ) ;  
00213     Tbl(const Tbl& a) ;     
00214     
00219     explicit Tbl(const Matrice& mat) ;
00220     
00221 
00222     ~Tbl() ;            
00223 
00224     // Assignement
00225     // -----------
00226     void operator=(const Tbl& ) ;   
00227     void operator=(double ) ; 
00228     void operator=(int ) ;   
00229 
00230     // Memory management
00231     // -----------------
00232     private:
00236     void del_t() ;      
00237 
00238     public:
00239 
00244     void set_etat_nondef() ;    
00245     
00250     void set_etat_zero() ;          
00251 
00258     void set_etat_qcq() ;           
00259     
00268     void annule_hard() ;            
00269     
00270     // Access to individual elements
00271     // -----------------------------
00272     public:
00274     double& set(int i) {
00275         assert (etat == ETATQCQ) ;
00276         assert( dim.ndim == 1 ) ; 
00277         assert( i >= 0 ) ; 
00278         assert( i < dim.dim[0] ) ;
00279         return t[i] ;
00280     } ;
00281     
00283     void affecte(int i, double val) {
00284         assert (etat == ETATQCQ) ;
00285         assert( dim.ndim == 1 ) ; 
00286         assert( i >= 0 ) ; 
00287         assert( i < dim.dim[0] ) ;
00288         t[i] = val ;
00289     } ;
00291     double operator()(int i) const {
00292         assert(etat != ETATNONDEF) ;
00293         assert( dim.ndim == 1 ) ; 
00294         assert( i >= 0 ) ; 
00295         assert( i < dim.dim[0] ) ;
00296         if (etat == ETATZERO) {
00297         double zero = 0. ;
00298         return zero ; 
00299         }
00300         else return t[i] ;
00301     };
00302 
00304     double& set(int j, int i) {
00305         assert (etat == ETATQCQ) ;
00306         assert( dim.ndim == 2 ) ;
00307         assert( (i>=0) && (i<dim.dim[0]) ) ;
00308         assert( (j>=0) && (j<dim.dim[1]) ) ;
00309         return t[dim.dim[0] * j + i] ;
00310     };
00311 
00313     double operator()(int j, int i) const {
00314         assert(etat != ETATNONDEF) ;
00315         assert( dim.ndim == 2 ) ;
00316         assert( (i>=0) && (i<dim.dim[0]) ) ;
00317         assert( (j>=0) && (j<dim.dim[1]) ) ;
00318         if (etat == ETATZERO) {
00319         double zero = 0. ;
00320         return zero ; 
00321         }
00322         else return t[dim.dim[0] * j + i] ;
00323     };
00324 
00326     double& set(int k, int j, int i) {  
00327         assert (etat == ETATQCQ) ;
00328         assert( dim.ndim == 3 ) ;
00329         assert( (i>=0) && (i<dim.dim[0]) ) ;
00330         assert( (j>=0) && (j<dim.dim[1]) ) ;
00331         assert( (k>=0) && (k<dim.dim[2]) ) ;
00332         return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
00333     };
00334 
00336     double operator()(int k, int j, int i) const {
00337         assert(etat != ETATNONDEF) ;
00338         assert( dim.ndim == 3 ) ;
00339         assert( (i>=0) && (i<dim.dim[0]) ) ;
00340         assert( (j>=0) && (j<dim.dim[1]) ) ;
00341         assert( (k>=0) && (k<dim.dim[2]) ) ;
00342         if (etat == ETATZERO) {
00343         double zero = 0. ;
00344         return zero ; 
00345         }
00346         else return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
00347     };
00348 
00350     double& set(const Itbl place) {
00351         int n = place.get_dim(0) ;
00352         assert (n == dim.ndim) ;
00353         for (int i=0 ; i<n ; i++)
00354             assert( (place(i)>=0) && (place(i)<dim.dim[0]) ) ;
00355         int pos = 0 ;
00356         for (int d=n-1 ; d>=0 ; d--) {
00357              pos*=dim.dim[d] ;
00358          pos += place(d) ;
00359         }
00360         return t[pos] ;
00361     };
00362 
00364     double operator()(const Itbl place) const {
00365         assert(etat != ETATNONDEF) ;
00366         int n = place.get_dim(0) ;
00367         assert (n == dim.ndim) ;
00368         for (int i=0 ; i<n ; i++)
00369             assert( (place(i)>=0) && (place(i)<dim.dim[0]) ) ;
00370         if (etat == ETATZERO) {
00371         double zero = 0. ;
00372         return zero ; 
00373         }
00374         else {
00375             int pos = 0 ;
00376             for (int d=n-1 ; d>=0 ; d--) {
00377                 pos*=dim.dim[d] ;
00378             pos += place(d) ;
00379             }
00380             return t[pos] ;
00381         }
00382     };
00383 
00384     // Extraction of information
00385     // -------------------------
00387     int get_etat() const { return etat ; }; 
00388 
00390     int get_taille() const { return dim.taille ; };
00391 
00393     int get_ndim() const { return dim.ndim ; };
00394     
00396     int get_dim(int i) const {  
00397         assert( (i>=0) && (i<dim.ndim) ) ;
00398         return dim.dim[i] ;
00399     };
00400     
00401     // Outputs
00402     // -------
00403     public:
00404     void sauve(FILE* ) const ;  
00405 
00412     void affiche_seuil(ostream& ostr, int precision = 4, 
00413                double threshold = 1.e-7) const ;
00415     friend ostream& operator<<(ostream& , const Tbl& ) ;    
00416 
00417     // Member arithmetics
00418     // ------------------
00419     public:
00420     
00421     void operator+=(const Tbl &) ;  
00422     void operator+=(double) ;   
00423     void operator-=(const Tbl &) ;  
00424     void operator-=(double) ;   
00425     void operator*=(const Tbl &) ;  
00426     void operator*=(double) ;   
00427     void operator/=(const Tbl &) ;  
00428     void operator/=(double) ;   
00429 
00430 } ;
00431 ostream& operator<<(ostream& , const Tbl& ) ;   
00432 
00433 
00439 Tbl operator+(const Tbl&) ;         
00440 Tbl operator-(const Tbl&) ;         
00441 Tbl operator+(const Tbl&, const Tbl&) ;     
00442 Tbl operator+(const Tbl&, double) ;     
00443 Tbl operator+(double, const Tbl&) ;     
00444 Tbl operator+(const Tbl&, int) ;        
00445 Tbl operator+(int, const Tbl&) ;        
00446 Tbl operator-(const Tbl&, const Tbl&) ;     
00447 Tbl operator-(const Tbl&, double) ;     
00448 Tbl operator-(double, const Tbl&) ;     
00449 Tbl operator-(const Tbl&, int) ;        
00450 Tbl operator-(int, const Tbl&) ;        
00451 Tbl operator*(const Tbl&, const Tbl&) ;     
00452 Tbl operator*(const Tbl&, double) ;     
00453 Tbl operator*(double, const Tbl&) ;     
00454 Tbl operator*(const Tbl&, int) ;        
00455 Tbl operator*(int, const Tbl&) ;        
00456 Tbl operator/(const Tbl&, const Tbl&) ;     
00457 Tbl operator/(const Tbl&, double) ;     
00458 Tbl operator/(double, const Tbl&) ;     
00459 Tbl operator/(const Tbl&, int) ;        
00460 Tbl operator/(int, const Tbl&) ;        
00461 
00462 Tbl sin(const Tbl& ) ;      
00463 Tbl cos(const Tbl& ) ;      
00464 Tbl tan(const Tbl& ) ;      
00465 Tbl asin(const Tbl& ) ;     
00466 Tbl acos(const Tbl& ) ;     
00467 Tbl atan(const Tbl& ) ;     
00468 Tbl exp(const Tbl& ) ;      
00469 Tbl Heaviside(const Tbl& ) ;        
00470 Tbl log(const Tbl& ) ;      
00471 Tbl log10(const Tbl& ) ;    
00472 Tbl sqrt(const Tbl& ) ;     
00473 Tbl racine_cubique (const Tbl&) ; 
00474 Tbl pow(const Tbl& , int ) ;  
00475 Tbl pow(const Tbl& , double ) ; 
00476 Tbl abs(const Tbl& ) ;      
00477 double max(const Tbl& ) ;   
00478 double min(const Tbl& ) ;   
00479 
00481 double norme(const Tbl& ) ;   
00482 
00488 double diffrel(const Tbl& a, const Tbl& b) ; 
00489 
00495 double diffrelmax(const Tbl& a, const Tbl& b) ; 
00496 
00500 #endif

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