tbl.h
/*
* Definition of Lorene class Tbl
*
*/
/*
* Copyright (c) 1999-2000 Jean-Alain Marck
* Copyright (c) 1999-2001 Eric Gourgoulhon
*
* This file is part of LORENE.
*
* LORENE is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LORENE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LORENE; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __TBL_H_
#define __TBL_H_
/*
* Classe de tableaux de dimension determinee (actuellement 1, 2 et 3)
*
*/
/*
* $Id: tbl.h,v 1.13 2014/10/13 08:52:37 j_novak Exp $
* $Log: tbl.h,v $
* Revision 1.13 2014/10/13 08:52:37 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.12 2014/10/06 15:09:40 j_novak
* Modified #include directives to use c++ syntax.
*
* Revision 1.11 2012/01/17 10:20:57 j_penner
* function added: Heaviside
*
* Revision 1.10 2006/09/25 10:01:45 p_grandclement
* Addition of N-dimensional Tbl
*
* Revision 1.9 2004/12/02 09:33:04 p_grandclement
* *** empty log message ***
*
* Revision 1.8 2004/03/22 13:12:43 j_novak
* Modification of comments to use doxygen instead of doc++
*
* Revision 1.7 2003/11/06 14:43:37 e_gourgoulhon
* Gave a name to const arguments in certain method prototypes (e.g.
* constructors) to correct a bug of DOC++.
*
* Revision 1.6 2002/10/16 14:36:29 j_novak
* Reorganization of #include instructions of standard C++, in order to
* use experimental version 3 of gcc.
*
* Revision 1.5 2002/09/24 10:49:42 e_gourgoulhon
*
* Modif commentaires.
*
* Revision 1.4 2002/09/24 08:33:35 e_gourgoulhon
*
* Added constructor from Matrice
*
* Revision 1.3 2002/06/17 14:05:17 j_novak
* friend functions are now also declared outside the class definition
*
* Revision 1.2 2002/01/03 13:18:40 j_novak
* Optimization: the members set(i,j) and operator(i,j) of class Matrice are
* now defined inline. Matrice is a friend class of Tbl.
*
* Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
* LORENE
*
* Revision 2.11 1999/12/02 17:52:59 phil
* *** empty log message ***
*
* Revision 2.10 1999/11/23 13:31:27 eric
* Le constructeur Tbl::Tbl(const Dim_tbl ) devient Tbl::Tbl(const Dim_tbl& ).
* Le constructeur Tbl::Tbl(const Grille3d* ) devient
* Tbl(const Grille3d& ).
*
* Revision 2.9 1999/11/15 16:36:08 eric
* Le membre dim est desormais un Dim_tbl et non plus un pointeur sur un
* Dim_tbl.
*
* Revision 2.8 1999/10/29 15:04:07 eric
* Suppression des fonctions membres min() et max():
* elles deviennent des fonctions externes.
* Ajout de fonctions mathematiques (abs, norme, etc...).
*
* Revision 2.7 1999/10/18 15:05:48 eric
* La fonction membre annule() est rebaptisee annule_hard().
*
* Revision 2.6 1999/10/01 10:18:18 eric
* Amelioration des commentaires.
*
* Revision 2.5 1999/09/30 12:50:59 eric
* Constructeur a 1 parametre rendu explicit.
* Amelioration des commentaires.
*
* Revision 2.4 1999/09/24 14:23:01 eric
* Depoussierage.
* Documentation.
*
* Revision 2.3 1999/03/02 18:54:36 eric
* Ajout de la fonction affiche_seuil.
*
* Revision 2.2 1999/02/23 10:40:55 hyc
* *** empty log message ***
*
*
* Revision 2.0 1998/12/02 11:11:16 hyc
* Version 2
*
* $Header: /cvsroot/Lorene/C++/Include/tbl.h,v 1.13 2014/10/13 08:52:37 j_novak Exp $
*
*/
// Fichiers includes
#include <cassert>
#include <cstdlib>
#include "type_parite.h"
#include "dim_tbl.h"
#include "itbl.h"
namespace Lorene {
class Grille3d ;
class Matrice ;
class Tbl {
friend class Matrice ;
// Data :
// -----
private:
int etat ;
public:
Dim_tbl dim ;
double* t ;
// Constructors - Destructor
// -------------------------
public:
explicit Tbl(int size0) ;
Tbl(int size1, int size0) ;
Tbl(int size2, int size1, int size0) ;
Tbl(Itbl sizes) ;
explicit Tbl(const Grille3d& grid) ;
explicit Tbl(const Dim_tbl& dim) ;
explicit Tbl(FILE* ) ;
Tbl(const Tbl& a) ;
explicit Tbl(const Matrice& mat) ;
~Tbl() ;
// Assignement
// -----------
void operator=(const Tbl& ) ;
void operator=(double ) ;
void operator=(int ) ;
// Memory management
// -----------------
private:
void del_t() ;
public:
void set_etat_nondef() ;
void set_etat_zero() ;
void set_etat_qcq() ;
void annule_hard() ;
// Access to individual elements
// -----------------------------
public:
double& set(int i) {
assert (etat == ETATQCQ) ;
assert( dim.ndim == 1 ) ;
assert( i >= 0 ) ;
assert( i < dim.dim[0] ) ;
return t[i] ;
} ;
void affecte(int i, double val) {
assert (etat == ETATQCQ) ;
assert( dim.ndim == 1 ) ;
assert( i >= 0 ) ;
assert( i < dim.dim[0] ) ;
t[i] = val ;
} ;
double operator()(int i) const {
assert(etat != ETATNONDEF) ;
assert( dim.ndim == 1 ) ;
assert( i >= 0 ) ;
assert( i < dim.dim[0] ) ;
if (etat == ETATZERO) {
double zero = 0. ;
return zero ;
}
else return t[i] ;
};
double& set(int j, int i) {
assert (etat == ETATQCQ) ;
assert( dim.ndim == 2 ) ;
assert( (i>=0) && (i<dim.dim[0]) ) ;
assert( (j>=0) && (j<dim.dim[1]) ) ;
return t[dim.dim[0] * j + i] ;
};
double operator()(int j, int i) const {
assert(etat != ETATNONDEF) ;
assert( dim.ndim == 2 ) ;
assert( (i>=0) && (i<dim.dim[0]) ) ;
assert( (j>=0) && (j<dim.dim[1]) ) ;
if (etat == ETATZERO) {
double zero = 0. ;
return zero ;
}
else return t[dim.dim[0] * j + i] ;
};
double& set(int k, int j, int i) {
assert (etat == ETATQCQ) ;
assert( dim.ndim == 3 ) ;
assert( (i>=0) && (i<dim.dim[0]) ) ;
assert( (j>=0) && (j<dim.dim[1]) ) ;
assert( (k>=0) && (k<dim.dim[2]) ) ;
return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
};
double operator()(int k, int j, int i) const {
assert(etat != ETATNONDEF) ;
assert( dim.ndim == 3 ) ;
assert( (i>=0) && (i<dim.dim[0]) ) ;
assert( (j>=0) && (j<dim.dim[1]) ) ;
assert( (k>=0) && (k<dim.dim[2]) ) ;
if (etat == ETATZERO) {
double zero = 0. ;
return zero ;
}
else return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
};
double& set(const Itbl place) {
int n = place.get_dim(0) ;
assert (n == dim.ndim) ;
for (int i=0 ; i<n ; i++)
assert( (place(i)>=0) && (place(i)<dim.dim[0]) ) ;
int pos = 0 ;
for (int d=n-1 ; d>=0 ; d--) {
pos*=dim.dim[d] ;
pos += place(d) ;
}
return t[pos] ;
};
double operator()(const Itbl place) const {
assert(etat != ETATNONDEF) ;
int n = place.get_dim(0) ;
assert (n == dim.ndim) ;
for (int i=0 ; i<n ; i++)
assert( (place(i)>=0) && (place(i)<dim.dim[0]) ) ;
if (etat == ETATZERO) {
double zero = 0. ;
return zero ;
}
else {
int pos = 0 ;
for (int d=n-1 ; d>=0 ; d--) {
pos*=dim.dim[d] ;
pos += place(d) ;
}
return t[pos] ;
}
};
// Extraction of information
// -------------------------
int get_etat() const { return etat ; };
int get_taille() const { return dim.taille ; };
int get_ndim() const { return dim.ndim ; };
int get_dim(int i) const {
assert( (i>=0) && (i<dim.ndim) ) ;
return dim.dim[i] ;
};
// Outputs
// -------
public:
void sauve(FILE* ) const ;
void affiche_seuil(ostream& ostr, int precision = 4,
double threshold = 1.e-7) const ;
friend ostream& operator<<(ostream& , const Tbl& ) ;
// Member arithmetics
// ------------------
public:
void operator+=(const Tbl &) ;
void operator+=(double) ;
void operator-=(const Tbl &) ;
void operator-=(double) ;
void operator*=(const Tbl &) ;
void operator*=(double) ;
void operator/=(const Tbl &) ;
void operator/=(double) ;
} ;
ostream& operator<<(ostream& , const Tbl& ) ;
Tbl operator+(const Tbl&) ;
Tbl operator-(const Tbl&) ;
Tbl operator+(const Tbl&, const Tbl&) ;
Tbl operator+(const Tbl&, double) ;
Tbl operator+(double, const Tbl&) ;
Tbl operator+(const Tbl&, int) ;
Tbl operator+(int, const Tbl&) ;
Tbl operator-(const Tbl&, const Tbl&) ;
Tbl operator-(const Tbl&, double) ;
Tbl operator-(double, const Tbl&) ;
Tbl operator-(const Tbl&, int) ;
Tbl operator-(int, const Tbl&) ;
Tbl operator*(const Tbl&, const Tbl&) ;
Tbl operator*(const Tbl&, double) ;
Tbl operator*(double, const Tbl&) ;
Tbl operator*(const Tbl&, int) ;
Tbl operator*(int, const Tbl&) ;
Tbl operator/(const Tbl&, const Tbl&) ;
Tbl operator/(const Tbl&, double) ;
Tbl operator/(double, const Tbl&) ;
Tbl operator/(const Tbl&, int) ;
Tbl operator/(int, const Tbl&) ;
Tbl sin(const Tbl& ) ;
Tbl cos(const Tbl& ) ;
Tbl tan(const Tbl& ) ;
Tbl asin(const Tbl& ) ;
Tbl acos(const Tbl& ) ;
Tbl atan(const Tbl& ) ;
Tbl exp(const Tbl& ) ;
Tbl Heaviside(const Tbl& ) ;
Tbl log(const Tbl& ) ;
Tbl log10(const Tbl& ) ;
Tbl sqrt(const Tbl& ) ;
Tbl racine_cubique (const Tbl&) ;
Tbl pow(const Tbl& , int ) ;
Tbl pow(const Tbl& , double ) ;
Tbl abs(const Tbl& ) ;
double max(const Tbl& ) ;
double min(const Tbl& ) ;
double norme(const Tbl& ) ;
double diffrel(const Tbl& a, const Tbl& b) ;
double diffrelmax(const Tbl& a, const Tbl& b) ;
}
#endif
Lorene::Dim_tbl
Storage of array dimensions.
Definition dim_tbl.h:99
Lorene::Grille3d
3D grid class in one domain.
Definition grilles.h:194
Lorene::Itbl
Basic integer array class.
Definition itbl.h:122
Lorene::Itbl::get_dim
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] ).
Definition itbl.h:326
Lorene::Matrice
Matrix handling.
Definition matrice.h:152
Lorene::Tbl
Basic array class.
Definition tbl.h:161
Lorene::Tbl::dim
Dim_tbl dim
Number of dimensions, size,...
Definition tbl.h:172
Lorene::Tbl::operator=
void operator=(const Tbl &)
Assignment to another Tbl.
Definition tbl.C:259
Lorene::Tbl::get_ndim
int get_ndim() const
Gives the number of dimensions (ie dim.ndim).
Definition tbl.h:400
Lorene::Tbl::operator*=
void operator*=(const Tbl &)
Multiplication of this by a Tbl.
Definition tbl_arithm.C:628
Lorene::Tbl::Tbl
Tbl(int size0)
1D constructor
Definition tbl.C:144
Lorene::Tbl::operator()
double operator()(int j, int i) const
Read-only of a particular element (index (j,i)) (2D case).
Definition tbl.h:320
Lorene::Tbl::get_etat
int get_etat() const
Gives the logical state.
Definition tbl.h:394
Lorene::Tbl::etat
int etat
logical state (ETATNONDEF, ETATQCQ or ETATZERO).
Definition tbl.h:169
Lorene::Tbl::operator/=
void operator/=(const Tbl &)
Division of this by a Tbl.
Definition tbl_arithm.C:678
Lorene::Tbl::affiche_seuil
void affiche_seuil(ostream &ostr, int precision=4, double threshold=1.e-7) const
Prints only the values greater than a given threshold.
Definition tbl.C:468
Lorene::Tbl::sauve
void sauve(FILE *) const
Save in a file.
Definition tbl.C:326
Lorene::Tbl::annule_hard
void annule_hard()
Sets the Tbl to zero in a hard way.
Definition tbl.C:372
Lorene::Tbl::set_etat_zero
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition tbl.C:347
Lorene::Tbl::del_t
void del_t()
Logical destructor: dellocates the memory occupied by the array t and sets the logical state to ETATN...
Definition tbl.C:340
Lorene::Tbl::operator()
double operator()(int k, int j, int i) const
Read-only of a particular element (index (k,j,i)) (3D case).
Definition tbl.h:343
Lorene::Tbl::operator()
double operator()(int i) const
Read-only of a particular element (index i) (1D case).
Definition tbl.h:298
Lorene::Tbl::~Tbl
~Tbl()
Destructor.
Definition tbl.C:250
Lorene::Tbl::set
double & set(const Itbl place)
Read/write of a particular element (multi-dimensional case).
Definition tbl.h:357
Lorene::Tbl::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition tbl.C:361
Lorene::Tbl::operator-=
void operator-=(const Tbl &)
Subtraction of a Tbl to this.
Definition tbl_arithm.C:556
Lorene::Tbl::set
double & set(int i)
Read/write of a particular element (index i) (1D case).
Definition tbl.h:281
Lorene::Tbl::set_etat_nondef
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition tbl.C:354
Lorene::Tbl::affecte
void affecte(int i, double val)
Affectation of a particular element (index i) (1D case).
Definition tbl.h:290
Lorene::Tbl::get_taille
int get_taille() const
Gives the total size (ie dim.taille).
Definition tbl.h:397
Lorene::Tbl::operator<<
friend ostream & operator<<(ostream &, const Tbl &)
Display.
Definition tbl.C:391
Lorene::Tbl::t
double * t
The array of double.
Definition tbl.h:173
Lorene::Tbl::operator()
double operator()(const Itbl place) const
Read-only of a particular element (index (k,j,i)) (multi-dimensional case).
Definition tbl.h:371
Lorene::Tbl::set
double & set(int k, int j, int i)
Read/write of a particular element (index (k,j,i)) (3D case).
Definition tbl.h:333
Lorene::Tbl::set
double & set(int j, int i)
Read/write of a particular element (index (j,i)) (2D case).
Definition tbl.h:311
Lorene::Tbl::operator+=
void operator+=(const Tbl &)
Addition of a Tbl to this.
Definition tbl_arithm.C:484
Lorene::Tbl::get_dim
int get_dim(int i) const
Gives the i-th dimension (ie dim.dim[i]).
Definition tbl.h:403
Lorene::operator*
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
Definition base_val_mult.C:102
Lorene::operator-
Cmp operator-(const Cmp &)
- Cmp
Definition cmp_arithm.C:108
Lorene::atan
Cmp atan(const Cmp &)
Arctangent.
Definition cmp_math.C:195
Lorene::sqrt
Cmp sqrt(const Cmp &)
Square root.
Definition cmp_math.C:220
Lorene::log10
Cmp log10(const Cmp &)
Basis 10 logarithm.
Definition cmp_math.C:322
Lorene::operator/
Cmp operator/(const Cmp &, const Cmp &)
Cmp / Cmp.
Definition cmp_arithm.C:457
Lorene::exp
Cmp exp(const Cmp &)
Exponential.
Definition cmp_math.C:270
Lorene::sin
Cmp sin(const Cmp &)
Sine.
Definition cmp_math.C:69
Lorene::diffrel
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition cmp_math.C:504
Lorene::norme
Tbl norme(const Cmp &)
Sums of the absolute values of all the values of the Cmp in each domain.
Definition cmp_math.C:481
Lorene::acos
Cmp acos(const Cmp &)
Arccosine.
Definition cmp_math.C:169
Lorene::asin
Cmp asin(const Cmp &)
Arcsine.
Definition cmp_math.C:144
Lorene::racine_cubique
Cmp racine_cubique(const Cmp &)
Cube root.
Definition cmp_math.C:245
Lorene::min
Tbl min(const Cmp &)
Minimum values of a Cmp in each domain.
Definition cmp_math.C:458
Lorene::max
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition cmp_math.C:435
Lorene::pow
Cmp pow(const Cmp &, int)
Power .
Definition cmp_math.C:348
Lorene::cos
Cmp cos(const Cmp &)
Cosine.
Definition cmp_math.C:94
Lorene::abs
Cmp abs(const Cmp &)
Absolute value.
Definition cmp_math.C:410
Lorene::diffrelmax
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition cmp_math.C:539
Lorene::operator+
Cmp operator+(const Cmp &)
Definition cmp_arithm.C:104
Lorene::tan
Cmp tan(const Cmp &)
Tangent.
Definition cmp_math.C:120
Lorene::log
Cmp log(const Cmp &)
Neperian logarithm.
Definition cmp_math.C:296
Lorene::Heaviside
Mtbl Heaviside(const Mtbl &)
Heaviside function.
Definition mtbl_math.C:317
Lorene
Lorene prototypes.
Definition app_hor.h:64