LORENE
tbl.h
1 /*
2  * Definition of Lorene class Tbl
3  *
4  */
5 
6 /*
7  * Copyright (c) 1999-2000 Jean-Alain Marck
8  * Copyright (c) 1999-2001 Eric Gourgoulhon
9  *
10  * This file is part of LORENE.
11  *
12  * LORENE is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * LORENE is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with LORENE; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  */
27 
28 
29 #ifndef __TBL_H_
30 #define __TBL_H_
31 
32 /*
33  * Classe de tableaux de dimension determinee (actuellement 1, 2 et 3)
34  *
35  */
36 
37 /*
38  * $Id: tbl.h,v 1.13 2014/10/13 08:52:37 j_novak Exp $
39  * $Log: tbl.h,v $
40  * Revision 1.13 2014/10/13 08:52:37 j_novak
41  * Lorene classes and functions now belong to the namespace Lorene.
42  *
43  * Revision 1.12 2014/10/06 15:09:40 j_novak
44  * Modified #include directives to use c++ syntax.
45  *
46  * Revision 1.11 2012/01/17 10:20:57 j_penner
47  * function added: Heaviside
48  *
49  * Revision 1.10 2006/09/25 10:01:45 p_grandclement
50  * Addition of N-dimensional Tbl
51  *
52  * Revision 1.9 2004/12/02 09:33:04 p_grandclement
53  * *** empty log message ***
54  *
55  * Revision 1.8 2004/03/22 13:12:43 j_novak
56  * Modification of comments to use doxygen instead of doc++
57  *
58  * Revision 1.7 2003/11/06 14:43:37 e_gourgoulhon
59  * Gave a name to const arguments in certain method prototypes (e.g.
60  * constructors) to correct a bug of DOC++.
61  *
62  * Revision 1.6 2002/10/16 14:36:29 j_novak
63  * Reorganization of #include instructions of standard C++, in order to
64  * use experimental version 3 of gcc.
65  *
66  * Revision 1.5 2002/09/24 10:49:42 e_gourgoulhon
67  *
68  * Modif commentaires.
69  *
70  * Revision 1.4 2002/09/24 08:33:35 e_gourgoulhon
71  *
72  * Added constructor from Matrice
73  *
74  * Revision 1.3 2002/06/17 14:05:17 j_novak
75  * friend functions are now also declared outside the class definition
76  *
77  * Revision 1.2 2002/01/03 13:18:40 j_novak
78  * Optimization: the members set(i,j) and operator(i,j) of class Matrice are
79  * now defined inline. Matrice is a friend class of Tbl.
80  *
81  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
82  * LORENE
83  *
84  * Revision 2.11 1999/12/02 17:52:59 phil
85  * *** empty log message ***
86  *
87  * Revision 2.10 1999/11/23 13:31:27 eric
88  * Le constructeur Tbl::Tbl(const Dim_tbl ) devient Tbl::Tbl(const Dim_tbl& ).
89  * Le constructeur Tbl::Tbl(const Grille3d* ) devient
90  * Tbl(const Grille3d& ).
91  *
92  * Revision 2.9 1999/11/15 16:36:08 eric
93  * Le membre dim est desormais un Dim_tbl et non plus un pointeur sur un
94  * Dim_tbl.
95  *
96  * Revision 2.8 1999/10/29 15:04:07 eric
97  * Suppression des fonctions membres min() et max():
98  * elles deviennent des fonctions externes.
99  * Ajout de fonctions mathematiques (abs, norme, etc...).
100  *
101  * Revision 2.7 1999/10/18 15:05:48 eric
102  * La fonction membre annule() est rebaptisee annule_hard().
103  *
104  * Revision 2.6 1999/10/01 10:18:18 eric
105  * Amelioration des commentaires.
106  *
107  * Revision 2.5 1999/09/30 12:50:59 eric
108  * Constructeur a 1 parametre rendu explicit.
109  * Amelioration des commentaires.
110  *
111  * Revision 2.4 1999/09/24 14:23:01 eric
112  * Depoussierage.
113  * Documentation.
114  *
115  * Revision 2.3 1999/03/02 18:54:36 eric
116  * Ajout de la fonction affiche_seuil.
117  *
118  * Revision 2.2 1999/02/23 10:40:55 hyc
119  * *** empty log message ***
120  *
121  *
122  * Revision 2.0 1998/12/02 11:11:16 hyc
123  * Version 2
124  *
125  * $Header: /cvsroot/Lorene/C++/Include/tbl.h,v 1.13 2014/10/13 08:52:37 j_novak Exp $
126  *
127  */
128 
129 
130 // Fichiers includes
131 #include <cassert>
132 #include <cstdlib>
133 
134 #include "type_parite.h"
135 #include "dim_tbl.h"
136 #include "itbl.h"
137 
138 namespace Lorene {
139 class Grille3d ;
140 class Matrice ;
141 
142 
161 class Tbl {
162 
163  friend class Matrice ;
164 
165  // Data :
166  // -----
167  private:
169  int etat ;
170 
171  public:
173  double* t ;
174 
175  // Constructors - Destructor
176  // -------------------------
177 
178  public:
184  explicit Tbl(int size0) ;
185 
195  Tbl(int size1, int size0) ;
196 
209  Tbl(int size2, int size1, int size0) ;
214  Tbl(Itbl sizes) ;
215 
216  explicit Tbl(const Grille3d& grid) ;
217  explicit Tbl(const Dim_tbl& dim) ;
218  explicit Tbl(FILE* ) ;
220  Tbl(const Tbl& a) ;
221 
226  explicit Tbl(const Matrice& mat) ;
227 
228 
229  ~Tbl() ;
230 
231  // Assignement
232  // -----------
233  void operator=(const Tbl& ) ;
234  void operator=(double ) ;
235  void operator=(int ) ;
236 
237  // Memory management
238  // -----------------
239  private:
243  void del_t() ;
244 
245  public:
246 
251  void set_etat_nondef() ;
252 
257  void set_etat_zero() ;
258 
265  void set_etat_qcq() ;
266 
275  void annule_hard() ;
276 
277  // Access to individual elements
278  // -----------------------------
279  public:
281  double& set(int i) {
282  assert (etat == ETATQCQ) ;
283  assert( dim.ndim == 1 ) ;
284  assert( i >= 0 ) ;
285  assert( i < dim.dim[0] ) ;
286  return t[i] ;
287  } ;
288 
290  void affecte(int i, double val) {
291  assert (etat == ETATQCQ) ;
292  assert( dim.ndim == 1 ) ;
293  assert( i >= 0 ) ;
294  assert( i < dim.dim[0] ) ;
295  t[i] = val ;
296  } ;
298  double operator()(int i) const {
299  assert(etat != ETATNONDEF) ;
300  assert( dim.ndim == 1 ) ;
301  assert( i >= 0 ) ;
302  assert( i < dim.dim[0] ) ;
303  if (etat == ETATZERO) {
304  double zero = 0. ;
305  return zero ;
306  }
307  else return t[i] ;
308  };
309 
311  double& set(int j, int i) {
312  assert (etat == ETATQCQ) ;
313  assert( dim.ndim == 2 ) ;
314  assert( (i>=0) && (i<dim.dim[0]) ) ;
315  assert( (j>=0) && (j<dim.dim[1]) ) ;
316  return t[dim.dim[0] * j + i] ;
317  };
318 
320  double operator()(int j, int i) const {
321  assert(etat != ETATNONDEF) ;
322  assert( dim.ndim == 2 ) ;
323  assert( (i>=0) && (i<dim.dim[0]) ) ;
324  assert( (j>=0) && (j<dim.dim[1]) ) ;
325  if (etat == ETATZERO) {
326  double zero = 0. ;
327  return zero ;
328  }
329  else return t[dim.dim[0] * j + i] ;
330  };
331 
333  double& set(int k, int j, int i) {
334  assert (etat == ETATQCQ) ;
335  assert( dim.ndim == 3 ) ;
336  assert( (i>=0) && (i<dim.dim[0]) ) ;
337  assert( (j>=0) && (j<dim.dim[1]) ) ;
338  assert( (k>=0) && (k<dim.dim[2]) ) ;
339  return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
340  };
341 
343  double operator()(int k, int j, int i) const {
344  assert(etat != ETATNONDEF) ;
345  assert( dim.ndim == 3 ) ;
346  assert( (i>=0) && (i<dim.dim[0]) ) ;
347  assert( (j>=0) && (j<dim.dim[1]) ) ;
348  assert( (k>=0) && (k<dim.dim[2]) ) ;
349  if (etat == ETATZERO) {
350  double zero = 0. ;
351  return zero ;
352  }
353  else return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
354  };
355 
357  double& set(const Itbl place) {
358  int n = place.get_dim(0) ;
359  assert (n == dim.ndim) ;
360  for (int i=0 ; i<n ; i++)
361  assert( (place(i)>=0) && (place(i)<dim.dim[0]) ) ;
362  int pos = 0 ;
363  for (int d=n-1 ; d>=0 ; d--) {
364  pos*=dim.dim[d] ;
365  pos += place(d) ;
366  }
367  return t[pos] ;
368  };
369 
371  double operator()(const Itbl place) const {
372  assert(etat != ETATNONDEF) ;
373  int n = place.get_dim(0) ;
374  assert (n == dim.ndim) ;
375  for (int i=0 ; i<n ; i++)
376  assert( (place(i)>=0) && (place(i)<dim.dim[0]) ) ;
377  if (etat == ETATZERO) {
378  double zero = 0. ;
379  return zero ;
380  }
381  else {
382  int pos = 0 ;
383  for (int d=n-1 ; d>=0 ; d--) {
384  pos*=dim.dim[d] ;
385  pos += place(d) ;
386  }
387  return t[pos] ;
388  }
389  };
390 
391  // Extraction of information
392  // -------------------------
394  int get_etat() const { return etat ; };
395 
397  int get_taille() const { return dim.taille ; };
398 
400  int get_ndim() const { return dim.ndim ; };
401 
403  int get_dim(int i) const {
404  assert( (i>=0) && (i<dim.ndim) ) ;
405  return dim.dim[i] ;
406  };
407 
408  // Outputs
409  // -------
410  public:
411  void sauve(FILE* ) const ;
412 
419  void affiche_seuil(ostream& ostr, int precision = 4,
420  double threshold = 1.e-7) const ;
422  friend ostream& operator<<(ostream& , const Tbl& ) ;
423 
424  // Member arithmetics
425  // ------------------
426  public:
427 
428  void operator+=(const Tbl &) ;
429  void operator+=(double) ;
430  void operator-=(const Tbl &) ;
431  void operator-=(double) ;
432  void operator*=(const Tbl &) ;
433  void operator*=(double) ;
434  void operator/=(const Tbl &) ;
435  void operator/=(double) ;
436 
437 } ;
438 ostream& operator<<(ostream& , const Tbl& ) ;
439 
440 
446 Tbl operator+(const Tbl&) ;
447 Tbl operator-(const Tbl&) ;
448 Tbl operator+(const Tbl&, const Tbl&) ;
449 Tbl operator+(const Tbl&, double) ;
450 Tbl operator+(double, const Tbl&) ;
451 Tbl operator+(const Tbl&, int) ;
452 Tbl operator+(int, const Tbl&) ;
453 Tbl operator-(const Tbl&, const Tbl&) ;
454 Tbl operator-(const Tbl&, double) ;
455 Tbl operator-(double, const Tbl&) ;
456 Tbl operator-(const Tbl&, int) ;
457 Tbl operator-(int, const Tbl&) ;
458 Tbl operator*(const Tbl&, const Tbl&) ;
459 Tbl operator*(const Tbl&, double) ;
460 Tbl operator*(double, const Tbl&) ;
461 Tbl operator*(const Tbl&, int) ;
462 Tbl operator*(int, const Tbl&) ;
463 Tbl operator/(const Tbl&, const Tbl&) ;
464 Tbl operator/(const Tbl&, double) ;
465 Tbl operator/(double, const Tbl&) ;
466 Tbl operator/(const Tbl&, int) ;
467 Tbl operator/(int, const Tbl&) ;
468 
469 Tbl sin(const Tbl& ) ;
470 Tbl cos(const Tbl& ) ;
471 Tbl tan(const Tbl& ) ;
472 Tbl asin(const Tbl& ) ;
473 Tbl acos(const Tbl& ) ;
474 Tbl atan(const Tbl& ) ;
475 Tbl exp(const Tbl& ) ;
476 Tbl Heaviside(const Tbl& ) ;
477 Tbl log(const Tbl& ) ;
478 Tbl log10(const Tbl& ) ;
479 Tbl sqrt(const Tbl& ) ;
480 Tbl racine_cubique (const Tbl&) ;
481 Tbl pow(const Tbl& , int ) ;
482 Tbl pow(const Tbl& , double ) ;
483 Tbl abs(const Tbl& ) ;
484 double max(const Tbl& ) ;
485 double min(const Tbl& ) ;
486 
488 double norme(const Tbl& ) ;
489 
495 double diffrel(const Tbl& a, const Tbl& b) ;
496 
502 double diffrelmax(const Tbl& a, const Tbl& b) ;
503 
507 }
508 #endif
Lorene::Grille3d
3D grid class in one domain.
Definition: grilles.h:194
Lorene::Dim_tbl
Storage of array dimensions.
Definition: dim_tbl.h:99
Lorene::racine_cubique
Cmp racine_cubique(const Cmp &)
Cube root.
Definition: cmp_math.C:245
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
double & set(int j, int i)
Read/write of a particular element (index (j,i)) (2D case)
Definition: tbl.h:311
Lorene::Tbl::affecte
void affecte(int i, double val)
Affectation of a particular element (index i) (1D case)
Definition: tbl.h:290
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::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::exp
Cmp exp(const Cmp &)
Exponential.
Definition: cmp_math.C:270
Lorene::diffrel
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition: cmp_math.C:504
Lorene
Lorene prototypes.
Definition: app_hor.h:64
Lorene::Tbl::annule_hard
void annule_hard()
Sets the Tbl to zero in a hard way.
Definition: tbl.C:372
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::Itbl::get_dim
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] )
Definition: itbl.h:326
Lorene::Tbl::operator/=
void operator/=(const Tbl &)
Division of this by a Tbl.
Definition: tbl_arithm.C:678
Lorene::diffrelmax
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition: cmp_math.C:539
Lorene::Dim_tbl::dim
int * dim
Array of dimensions (size: ndim).
Definition: dim_tbl.h:102
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::max
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition: cmp_math.C:435
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::abs
Cmp abs(const Cmp &)
Absolute value.
Definition: cmp_math.C:410
Lorene::atan
Cmp atan(const Cmp &)
Arctangent.
Definition: cmp_math.C:195
Lorene::Tbl::get_ndim
int get_ndim() const
Gives the number of dimensions (ie dim.ndim)
Definition: tbl.h:400
Lorene::Itbl
Basic integer array class.
Definition: itbl.h:122
Lorene::Tbl::Tbl
Tbl(int size0)
1D constructor
Definition: tbl.C:144
Lorene::Tbl::dim
Dim_tbl dim
Number of dimensions, size,...
Definition: tbl.h:172
Lorene::pow
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:348
Lorene::Tbl::t
double * t
The array of double.
Definition: tbl.h:173
Lorene::Tbl::set_etat_nondef
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition: tbl.C:354
Lorene::Tbl::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:361
Lorene::Dim_tbl::taille
int taille
Total size of the array Tbl::t.
Definition: dim_tbl.h:112
Lorene::Tbl::operator<<
friend ostream & operator<<(ostream &, const Tbl &)
Display
Definition: tbl.C:391
Lorene::Tbl::get_dim
int get_dim(int i) const
Gives the i-th dimension (ie dim.dim[i])
Definition: tbl.h:403
Lorene::asin
Cmp asin(const Cmp &)
Arcsine.
Definition: cmp_math.C:144
Lorene::operator/
Cmp operator/(const Cmp &, const Cmp &)
Cmp / Cmp.
Definition: cmp_arithm.C:457
Lorene::Tbl::set_etat_zero
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition: tbl.C:347
Lorene::operator-
Cmp operator-(const Cmp &)
- Cmp
Definition: cmp_arithm.C:108
Lorene::min
Tbl min(const Cmp &)
Minimum values of a Cmp in each domain.
Definition: cmp_math.C:458
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
Basic array class.
Definition: tbl.h:161
Lorene::log10
Cmp log10(const Cmp &)
Basis 10 logarithm.
Definition: cmp_math.C:322
Lorene::Tbl::operator=
void operator=(const Tbl &)
Assignment to another Tbl.
Definition: tbl.C:259
Lorene::acos
Cmp acos(const Cmp &)
Arccosine.
Definition: cmp_math.C:169
Lorene::sqrt
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:220
Lorene::Tbl::operator+=
void operator+=(const Tbl &)
Addition of a Tbl to this.
Definition: tbl_arithm.C:484
Lorene::Tbl::etat
int etat
logical state (ETATNONDEF, ETATQCQ or ETATZERO).
Definition: tbl.h:169
Lorene::cos
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:94
Lorene::Tbl::sauve
void sauve(FILE *) const
Save in a file.
Definition: tbl.C:326
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::Matrice
Matrix handling.
Definition: matrice.h:152
Lorene::Tbl::operator()
double operator()(int i) const
Read-only of a particular element (index i) (1D case)
Definition: tbl.h:298
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::operator+
Cmp operator+(const Cmp &)
Definition: cmp_arithm.C:104
Lorene::Tbl::operator*=
void operator*=(const Tbl &)
Multiplication of this by a Tbl.
Definition: tbl_arithm.C:628
Lorene::Dim_tbl::ndim
int ndim
Number of dimensions of the Tbl: can be 1, 2 or 3.
Definition: dim_tbl.h:101
Lorene::Tbl::~Tbl
~Tbl()
Destructor.
Definition: tbl.C:250
Lorene::Tbl::get_taille
int get_taille() const
Gives the total size (ie dim.taille)
Definition: tbl.h:397
Lorene::Tbl::set
double & set(const Itbl place)
Read/write of a particular element (multi-dimensional case)
Definition: tbl.h:357
Lorene::tan
Cmp tan(const Cmp &)
Tangent.
Definition: cmp_math.C:120
Lorene::Tbl::get_etat
int get_etat() const
Gives the logical state.
Definition: tbl.h:394
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::sin
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:69