tbl_val.h

00001 /*
00002  *  Definition of Lorene class Tbl_val
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 2001 Jerome Novak
00008  *
00009  *   This file is part of LORENE.
00010  *
00011  *   LORENE is free software; you can redistribute it and/or modify
00012  *   it under the terms of the GNU General Public License as published by
00013  *   the Free Software Foundation; either version 2 of the License, or
00014  *   (at your option) any later version.
00015  *
00016  *   LORENE is distributed in the hope that it will be useful,
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *   GNU General Public License for more details.
00020  *
00021  *   You should have received a copy of the GNU General Public License
00022  *   along with LORENE; if not, write to the Free Software
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 
00028 #ifndef __TBL_VAL_H_
00029 #define __TBL_VAL_H_
00030 
00031 /*
00032  * $Id: tbl_val.h,v 1.10 2012/01/17 10:21:31 j_penner Exp $
00033  * $Log: tbl_val.h,v $
00034  * Revision 1.10  2012/01/17 10:21:31  j_penner
00035  * function added: Heaviside
00036  *
00037  * Revision 1.9  2010/04/14 11:45:24  j_novak
00038  * Changed comments
00039  *
00040  * Revision 1.8  2007/11/02 15:45:56  j_novak
00041  * Added an ugly method "append_array", which substitutes the argument to the
00042  * main array t.
00043  *
00044  * Revision 1.7  2005/06/22 09:09:38  lm_lin
00045  *
00046  * Grid wedding: convert from the old C++ object "Cmp" to "Scalar".
00047  *
00048  * Revision 1.6  2004/11/26 17:02:18  j_novak
00049  * Added a function giving a smooth transition to the atmosphere.
00050  *
00051  * Revision 1.5  2004/03/22 13:12:43  j_novak
00052  * Modification of comments to use doxygen instead of doc++
00053  *
00054  * Revision 1.4  2002/11/13 11:22:57  j_novak
00055  * Version "provisoire" de l'interpolation (sommation depuis la grille
00056  * spectrale) aux interfaces de la grille de Valence.
00057  *
00058  * Revision 1.3  2002/11/12 10:03:53  j_novak
00059  * The method "Tbl_val::get_gval" has been changed to "get_grid".
00060  *
00061  * Revision 1.2  2002/10/16 14:36:29  j_novak
00062  * Reorganization of #include instructions of standard C++, in order to
00063  * use experimental version 3 of gcc.
00064  *
00065  * Revision 1.1  2001/11/22 13:38:09  j_novak
00066  * added Include files for Valencia objects: tbl_val.h and grille_val.h
00067  *
00068  *
00069  * $Header: /cvsroot/Lorene/C++/Include/tbl_val.h,v 1.10 2012/01/17 10:21:31 j_penner Exp $
00070  *
00071  */
00072 
00073 // Fichiers includes
00074 #include <assert.h>
00075 #include <stdlib.h>
00076 
00077 #include "grille_val.h"
00078 #include "tensor.h"
00079 
00080 class Grille_val ; 
00081 
00090 class Tbl_val {
00091 
00092   // Data : 
00093   // -----
00094  private:
00096   int etat ;
00101   const Dim_tbl* dim ;
00103   const Grille_val* gval ;  
00104   
00105  public:
00107   double* t ;       
00109   double* tzri ;    
00111   double* txti ;    
00113   double* typi ;    
00114   
00115   // Constructors - Destructor
00116   // -------------------------
00117   
00118  public:
00120   explicit Tbl_val(const Grille_val* ) ; 
00122   explicit Tbl_val(const Grille_val*, FILE* ) ; 
00124   Tbl_val(const Tbl_val& ) ;        
00125   
00127   ~Tbl_val() ;          
00128   
00129   // Assignement
00130   // -----------
00132   void operator=(const Tbl_val& ) ; 
00134   void operator=(double ) ; 
00136   void operator=(int ) ;     
00137 
00138   // Memory management
00139   // -----------------
00140  private:
00144   void del_t() ;        
00145   
00146  public:
00147   
00152   void set_etat_nondef() ;  
00153   
00158   void set_etat_zero() ;            
00159   
00166   void set_etat_qcq() ;         
00167     
00172   void append_array(double* t_in) ;
00173 
00182   void annule_hard() ;          
00183   
00184   // Access to individual elements
00185   // -----------------------------
00186  public:
00188   double& set(int i) {
00189     assert (etat == ETATQCQ) ;
00190     assert( dim->ndim == 1 ) ;
00191     int fant = gval->get_fantome() ; 
00192     assert( i >= - fant) ; 
00193     assert( i < dim->dim[0] + fant) ;
00194     return t[i + fant] ;
00195   } ;
00196   
00198   double& set_zri(int i) {
00199     assert (etat == ETATQCQ) ;
00200     assert( dim->ndim == 1 ) ; 
00201     int fant = gval->get_fantome() ; 
00202     assert( i >= -fant ) ; 
00203     assert( i < dim->dim[0] + fant + 1) ;
00204     return tzri[i+fant] ;
00205   } ;
00206   
00208   double operator()(int i) const {
00209     assert(etat != ETATNONDEF) ;
00210     assert( dim->ndim == 1 ) ; 
00211     int fant = gval->get_fantome() ; 
00212     assert( i >= -fant ) ; 
00213     assert( i < dim->dim[0] + fant ) ;
00214     if (etat == ETATZERO) {
00215       double zero = 0. ;
00216       return zero ; 
00217     }
00218     else return t[i+fant] ;
00219   };
00220   
00222   double get_zri(int i) const {
00223     assert(etat != ETATNONDEF) ;
00224     assert( dim->ndim == 1 ) ; 
00225     int fant = gval->get_fantome() ; 
00226     assert( i >= -fant ) ; 
00227     assert( i < dim->dim[0] + fant +1) ;
00228     if (etat == ETATZERO) {
00229       double zero = 0. ;
00230       return zero ; 
00231     }
00232     else return tzri[i+fant] ;
00233   };
00234   
00236   double& set(int j, int i) {
00237     assert (etat == ETATQCQ) ;
00238     assert( dim->ndim == 2 ) ;
00239     int fant = gval->get_fantome() ; 
00240     assert( (i>=-fant) && (i<dim->dim[0]+fant) ) ;
00241     assert( (j>=-fant) && (j<dim->dim[1]+fant) ) ;
00242     return t[(dim->dim[0] +2*fant)* (j+fant) + i + fant] ;
00243   };
00244 
00249   double& set_xti(int j, int i) {
00250     assert (etat == ETATQCQ) ;
00251     assert( dim->ndim == 2 ) ;
00252     int fant = gval->get_fantome() ; 
00253     assert( (i>=-fant) && (i<dim->dim[0]+fant) ) ;
00254     assert( (j>=-fant) && (j<dim->dim[1]+fant+1) ) ;
00255     return txti[(dim->dim[0] +2*fant)*(j+fant) + i + fant] ;
00256   };
00257   
00262   double& set_zri(int j, int i) {
00263     assert (etat == ETATQCQ) ;
00264     assert( dim->ndim == 2 ) ;
00265     int fant = gval->get_fantome() ; 
00266     assert( (i>=-fant) && (i<dim->dim[0] + fant+1) ) ;
00267     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00268     return tzri[(dim->dim[0] +2*fant+1)*(j+fant) + i + fant] ;
00269   };
00270   
00272   double operator()(int j, int i) const {
00273     assert(etat != ETATNONDEF) ;
00274     assert( dim->ndim == 2 ) ;
00275     int fant = gval->get_fantome() ; 
00276     assert( (i>=-fant) && (i<dim->dim[0] + fant) ) ;
00277     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00278     if (etat == ETATZERO) {
00279       double zero = 0. ;
00280       return zero ; 
00281     }
00282     else return t[(dim->dim[0] + 2*fant) *(j+fant) + i + fant] ;
00283   };
00284   
00289   double get_xti(int j, int i) const {
00290     assert(etat != ETATNONDEF) ;
00291     assert( dim->ndim == 2 ) ;
00292     int fant = gval->get_fantome() ; 
00293     assert( (i>=-fant) && (i<dim->dim[0] + fant) ) ;
00294     assert( (j>=-fant) && (j<dim->dim[1] + fant + 1) ) ;
00295     if (etat == ETATZERO) {
00296       double zero = 0. ;
00297       return zero ; 
00298     }
00299     else return txti[(dim->dim[0] + 2*fant) *(j+fant) + i + fant] ;
00300   };
00301   
00306   double get_zri(int j, int i) const {
00307     assert(etat != ETATNONDEF) ;
00308     assert( dim->ndim == 2 ) ;
00309     int fant = gval->get_fantome() ; 
00310     assert( (i>=-fant) && (i<dim->dim[0] + fant + 1) ) ;
00311     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00312     if (etat == ETATZERO) {
00313       double zero = 0. ;
00314       return zero ; 
00315     }
00316     else return tzri[(dim->dim[0] + 2*fant + 1) *(j+fant) + i + fant] ;
00317   };
00318   
00320   double& set(int k, int j, int i) {    
00321     assert (etat == ETATQCQ) ;
00322     assert( dim->ndim == 3 ) ;
00323     int fant = gval->get_fantome() ; 
00324     assert( (i>=-fant) && (i<dim->dim[0] + fant) ) ;
00325     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00326     assert( (k>=-fant) && (k<dim->dim[2] + fant) ) ;
00327     return t[(dim->dim[1]+2*fant)*(dim->dim[0]+2*fant)*(k+fant) + 
00328         (dim->dim[0]+2*fant)*(j+fant) + i +fant] ;
00329   };
00330   
00335   double& set_ypi(int k, int j, int i) {    
00336     assert (etat == ETATQCQ) ;
00337     assert( dim->ndim == 3 ) ;
00338     int fant = gval->get_fantome() ; 
00339     assert( (i>=-fant) && (i<dim->dim[0] + fant) ) ;
00340     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00341     assert( (k>=-fant) && (k<dim->dim[2] + fant + 1) ) ;
00342     return typi[(dim->dim[1]+2*fant)*(dim->dim[0]+2*fant)*(k+fant) + 
00343           (dim->dim[0]+2*fant)*(j+fant) + i +fant] ;
00344   };
00345 
00350   double& set_xti(int k, int j, int i) {    
00351     assert (etat == ETATQCQ) ;
00352     assert( dim->ndim == 3 ) ;
00353     int fant = gval->get_fantome() ; 
00354     assert( (i>=-fant) && (i<dim->dim[0] + fant) ) ;
00355     assert( (j>=-fant) && (j<dim->dim[1] + fant + 1) ) ;
00356     assert( (k>=-fant) && (k<dim->dim[2] + fant) ) ;
00357     return txti[(dim->dim[1]+2*fant+1)*(dim->dim[0]+2*fant)*(k+fant) + 
00358           (dim->dim[0]+2*fant)*(j+fant) + i +fant] ;
00359   };
00360 
00365   double& set_zri(int k, int j, int i) {    
00366     assert (etat == ETATQCQ) ;
00367     assert( dim->ndim == 3 ) ;
00368     int fant = gval->get_fantome() ; 
00369     assert( (i>=-fant) && (i<dim->dim[0] + fant + 1) ) ;
00370     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00371     assert( (k>=-fant) && (k<dim->dim[2] + fant) ) ;
00372     return tzri[(dim->dim[1]+2*fant)*(dim->dim[0]+2*fant+1)*(k+fant) + 
00373           (dim->dim[0]+2*fant+1)*(j+fant) + i +fant] ;
00374   };
00375   
00377   double operator()(int k, int j, int i) const {
00378     assert(etat != ETATNONDEF) ;
00379     assert( dim->ndim == 3 ) ;
00380     int fant = gval->get_fantome() ; 
00381     assert( (i>=-fant) && (i<dim->dim[0] + fant) ) ;
00382     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00383     assert( (k>=-fant) && (k<dim->dim[2] + fant) ) ;
00384     if (etat == ETATZERO) {
00385       double zero = 0. ;
00386       return zero ; 
00387     }
00388     else return t[(dim->dim[1]+2*fant)*(dim->dim[0]+2*fant)*(k+fant) 
00389          + (dim->dim[0]+2*fant)*(j+fant) + i +fant] ;
00390   };
00391 
00396   double get_ypi(int k, int j, int i) const {
00397     assert(etat != ETATNONDEF) ;
00398     assert( dim->ndim == 3 ) ;
00399     int fant = gval->get_fantome() ; 
00400     assert( (i>=-fant) && (i<dim->dim[0] + fant) ) ;
00401     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00402     assert( (k>=-fant) && (k<dim->dim[2] + fant + 1) ) ;
00403     if (etat == ETATZERO) {
00404       double zero = 0. ;
00405       return zero ; 
00406     }
00407     else return typi[(dim->dim[1]+2*fant)*(dim->dim[0]+2*fant)*(k+fant) 
00408            + (dim->dim[0]+2*fant)*(j+fant) + i +fant] ;
00409   };
00410   
00415   double get_xti(int k, int j, int i) const {
00416     assert(etat != ETATNONDEF) ;
00417     assert( dim->ndim == 3 ) ;
00418     int fant = gval->get_fantome() ; 
00419     assert( (i>=-fant) && (i<dim->dim[0] + fant) ) ;
00420     assert( (j>=-fant) && (j<dim->dim[1] + fant + 1) ) ;
00421     assert( (k>=-fant) && (k<dim->dim[2] + fant) ) ;
00422     if (etat == ETATZERO) {
00423       double zero = 0. ;
00424       return zero ; 
00425     }
00426     else return txti[(dim->dim[1]+2*fant+1)*(dim->dim[0]+2*fant)*(k+fant) 
00427            + (dim->dim[0]+2*fant)*(j+fant) + i +fant] ;
00428   };
00429   
00434   double get_zri(int k, int j, int i) const {
00435     assert(etat != ETATNONDEF) ;
00436     assert( dim->ndim == 3 ) ;
00437     int fant = gval->get_fantome() ; 
00438     assert( (i>=-fant) && (i<dim->dim[0] + fant + 1) ) ;
00439     assert( (j>=-fant) && (j<dim->dim[1] + fant) ) ;
00440     assert( (k>=-fant) && (k<dim->dim[2] + fant) ) ;
00441     if (etat == ETATZERO) {
00442       double zero = 0. ;
00443       return zero ; 
00444     }
00445     else return tzri[(dim->dim[1]+2*fant)*(dim->dim[0]+2*fant+1)*(k+fant) 
00446            + (dim->dim[0]+2*fant+1)*(j+fant) + i +fant] ;
00447   };
00448 
00449   // Extraction of information
00450   // -------------------------
00452   int get_etat() const { return etat ; };       
00453   
00455   int get_taille() const { 
00456     int resu = 1 ;
00457     for (int i=0; i<dim->ndim; i++) 
00458       resu *= dim->dim[i] + 2*(gval->get_fantome()) ;
00459     return resu ; }; 
00460   
00462   int get_taille_i(int i) const {
00463     assert (i<dim->ndim) ; 
00464     int resu = 1 ;
00465     for (int j=0; j<dim->ndim; j++) 
00466       if (j!=i) {
00467     resu *= dim->dim[j] + 2*gval->get_fantome() ;
00468       }
00469       else {
00470     resu *= dim->dim[j] + 2*gval->get_fantome() + 1 ;
00471       }
00472     return resu ; }; 
00473   
00475   int get_ndim() const { return dim->ndim ; };  
00476   
00478   int get_dim(int i) const {    
00479     assert( (i>=0) && (i<dim->ndim) ) ;
00480     return dim->dim[i] ;
00481   };
00482 
00484   const Grille_val* get_grille() const { return gval ; } ;
00485   
00486   // Outputs
00487   // -------
00488  public:
00490   void sauve(FILE* ) const ;    
00491   
00498   void affiche_seuil(ostream& ostr, int precision = 4, 
00499              double threshold = 1.e-7) const ;
00501   friend ostream& operator<<(ostream& , const Tbl_val& ) ;  
00502   
00503   // Member arithmetics
00504   // ------------------
00505  public:
00506   
00508   void operator+=(const Tbl_val &) ;    
00510   void operator+=(double) ; 
00512   void operator-=(const Tbl_val &) ;    
00514   void operator-=(double) ; 
00516   void operator*=(const Tbl_val &) ;    
00518   void operator*=(double) ; 
00520   void operator/=(const Tbl_val &) ;    
00522   void operator/=(double) ; 
00523 
00546   Scalar to_spectral(const Map& map, const int lmax, const int lmin=0, 
00547               int type_inter = 2) const ;
00548   
00556   void from_spectral(const Scalar& meudon, int lmax, int lmin=0,
00557              bool interfr = false, bool interft = false) ;
00558 
00559 
00560   void smooth_atmosphere(double atmosphere_thr) ;
00561 } ;
00562 
00563 
00570 
00571 Tbl_val operator+(const Tbl_val&) ;         
00573 Tbl_val operator-(const Tbl_val&) ;         
00575 Tbl_val operator+(const Tbl_val&, const Tbl_val&) ; 
00577 Tbl_val operator+(const Tbl_val&, double) ;     
00579 Tbl_val operator+(double, const Tbl_val&) ;     
00581 Tbl_val operator+(const Tbl_val&, int) ;        
00583 Tbl_val operator+(int, const Tbl_val&) ;        
00585 Tbl_val operator-(const Tbl_val&, const Tbl_val&) ; 
00587 Tbl_val operator-(const Tbl_val&, double) ;     
00589 Tbl_val operator-(double, const Tbl_val&) ;     
00591 Tbl_val operator-(const Tbl_val&, int) ;        
00593 Tbl_val operator-(int, const Tbl_val&) ;        
00595 Tbl_val operator*(const Tbl_val&, const Tbl_val&) ; 
00597 Tbl_val operator*(const Tbl_val&, double) ;     
00599 Tbl_val operator*(double, const Tbl_val&) ;     
00601 Tbl_val operator*(const Tbl_val&, int) ;        
00603 Tbl_val operator*(int, const Tbl_val&) ;        
00605 Tbl_val operator/(const Tbl_val&, const Tbl_val&) ; 
00607 Tbl_val operator/(const Tbl_val&, double) ;     
00609 Tbl_val operator/(double, const Tbl_val&) ;     
00611 Tbl_val operator/(const Tbl_val&, int) ;        
00613 Tbl_val operator/(int, const Tbl_val&) ;        
00614 
00616 Tbl_val sin(const Tbl_val& ) ;      
00618 Tbl_val cos(const Tbl_val& ) ;      
00620 Tbl_val tan(const Tbl_val& ) ;      
00622 Tbl_val asin(const Tbl_val& ) ;     
00624 Tbl_val acos(const Tbl_val& ) ;     
00626 Tbl_val atan(const Tbl_val& ) ;     
00628 Tbl_val exp(const Tbl_val& ) ;      
00630 Tbl_val Heaviside(const Tbl_val& ) ;        
00632 Tbl_val log(const Tbl_val& ) ;      
00634 Tbl_val log10(const Tbl_val& ) ;    
00636 Tbl_val sqrt(const Tbl_val& ) ;     
00638 Tbl_val racine_cubique (const Tbl_val&) ; 
00640 Tbl_val pow(const Tbl_val& , int ) ;  
00642 Tbl_val pow(const Tbl_val& , double ) ; 
00644 Tbl_val abs(const Tbl_val& ) ;      
00646 double max(const Tbl_val& ) ;   
00648 double min(const Tbl_val& ) ;   
00649 
00651 double norme(const Tbl_val& ) ;   
00652 
00658 double diffrel(const Tbl_val& a, const Tbl_val& b) ; 
00659 
00665 double diffrelmax(const Tbl_val& a, const Tbl_val& b) ; 
00666 
00669 #endif
00670 

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