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.14 2024/01/26 17:44:25 g_servignat Exp $
39  * $Log: tbl.h,v $
40  * Revision 1.14 2024/01/26 17:44:25 g_servignat
41  * Updated the Pseudopolytrope_1D class to be consistent with the paper (i.e. with a GPP in the middle)
42  *
43  * Revision 1.13 2014/10/13 08:52:37 j_novak
44  * Lorene classes and functions now belong to the namespace Lorene.
45  *
46  * Revision 1.12 2014/10/06 15:09:40 j_novak
47  * Modified #include directives to use c++ syntax.
48  *
49  * Revision 1.11 2012/01/17 10:20:57 j_penner
50  * function added: Heaviside
51  *
52  * Revision 1.10 2006/09/25 10:01:45 p_grandclement
53  * Addition of N-dimensional Tbl
54  *
55  * Revision 1.9 2004/12/02 09:33:04 p_grandclement
56  * *** empty log message ***
57  *
58  * Revision 1.8 2004/03/22 13:12:43 j_novak
59  * Modification of comments to use doxygen instead of doc++
60  *
61  * Revision 1.7 2003/11/06 14:43:37 e_gourgoulhon
62  * Gave a name to const arguments in certain method prototypes (e.g.
63  * constructors) to correct a bug of DOC++.
64  *
65  * Revision 1.6 2002/10/16 14:36:29 j_novak
66  * Reorganization of #include instructions of standard C++, in order to
67  * use experimental version 3 of gcc.
68  *
69  * Revision 1.5 2002/09/24 10:49:42 e_gourgoulhon
70  *
71  * Modif commentaires.
72  *
73  * Revision 1.4 2002/09/24 08:33:35 e_gourgoulhon
74  *
75  * Added constructor from Matrice
76  *
77  * Revision 1.3 2002/06/17 14:05:17 j_novak
78  * friend functions are now also declared outside the class definition
79  *
80  * Revision 1.2 2002/01/03 13:18:40 j_novak
81  * Optimization: the members set(i,j) and operator(i,j) of class Matrice are
82  * now defined inline. Matrice is a friend class of Tbl.
83  *
84  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
85  * LORENE
86  *
87  * Revision 2.11 1999/12/02 17:52:59 phil
88  * *** empty log message ***
89  *
90  * Revision 2.10 1999/11/23 13:31:27 eric
91  * Le constructeur Tbl::Tbl(const Dim_tbl ) devient Tbl::Tbl(const Dim_tbl& ).
92  * Le constructeur Tbl::Tbl(const Grille3d* ) devient
93  * Tbl(const Grille3d& ).
94  *
95  * Revision 2.9 1999/11/15 16:36:08 eric
96  * Le membre dim est desormais un Dim_tbl et non plus un pointeur sur un
97  * Dim_tbl.
98  *
99  * Revision 2.8 1999/10/29 15:04:07 eric
100  * Suppression des fonctions membres min() et max():
101  * elles deviennent des fonctions externes.
102  * Ajout de fonctions mathematiques (abs, norme, etc...).
103  *
104  * Revision 2.7 1999/10/18 15:05:48 eric
105  * La fonction membre annule() est rebaptisee annule_hard().
106  *
107  * Revision 2.6 1999/10/01 10:18:18 eric
108  * Amelioration des commentaires.
109  *
110  * Revision 2.5 1999/09/30 12:50:59 eric
111  * Constructeur a 1 parametre rendu explicit.
112  * Amelioration des commentaires.
113  *
114  * Revision 2.4 1999/09/24 14:23:01 eric
115  * Depoussierage.
116  * Documentation.
117  *
118  * Revision 2.3 1999/03/02 18:54:36 eric
119  * Ajout de la fonction affiche_seuil.
120  *
121  * Revision 2.2 1999/02/23 10:40:55 hyc
122  * *** empty log message ***
123  *
124  *
125  * Revision 2.0 1998/12/02 11:11:16 hyc
126  * Version 2
127  *
128  * $Header: /cvsroot/Lorene/C++/Include/tbl.h,v 1.14 2024/01/26 17:44:25 g_servignat Exp $
129  *
130  */
131 
132 
133 // Fichiers includes
134 #include <cassert>
135 #include <cstdlib>
136 
137 #include "type_parite.h"
138 #include "dim_tbl.h"
139 #include "itbl.h"
140 
141 namespace Lorene {
142 class Grille3d ;
143 class Matrice ;
144 
145 
164 class Tbl {
165 
166  friend class Matrice ;
167 
168  // Data :
169  // -----
170  private:
172  int etat ;
173 
174  public:
176  double* t ;
177 
178  // Constructors - Destructor
179  // -------------------------
180 
181  public:
187  explicit Tbl(int size0) ;
188 
198  Tbl(int size1, int size0) ;
199 
212  Tbl(int size2, int size1, int size0) ;
213 
229  Tbl(int size3, int size2, int size1, int size0) ;
234  Tbl(Itbl sizes) ;
235 
236  explicit Tbl(const Grille3d& grid) ;
237  explicit Tbl(const Dim_tbl& dim) ;
238  explicit Tbl(FILE* ) ;
240  Tbl(const Tbl& a) ;
241 
246  explicit Tbl(const Matrice& mat) ;
247 
248 
249  ~Tbl() ;
250 
251  // Assignement
252  // -----------
253  void operator=(const Tbl& ) ;
254  void operator=(double ) ;
255  void operator=(int ) ;
256 
257  // Memory management
258  // -----------------
259  private:
263  void del_t() ;
264 
265  public:
266 
271  void set_etat_nondef() ;
272 
277  void set_etat_zero() ;
278 
285  void set_etat_qcq() ;
286 
295  void annule_hard() ;
296 
297  // Access to individual elements
298  // -----------------------------
299  public:
301  double& set(int i) {
302  assert (etat == ETATQCQ) ;
303  assert( dim.ndim == 1 ) ;
304  assert( i >= 0 ) ;
305  assert( i < dim.dim[0] ) ;
306  return t[i] ;
307  } ;
308 
310  void affecte(int i, double val) {
311  assert (etat == ETATQCQ) ;
312  assert( dim.ndim == 1 ) ;
313  assert( i >= 0 ) ;
314  assert( i < dim.dim[0] ) ;
315  t[i] = val ;
316  } ;
318  double operator()(int i) const {
319  assert(etat != ETATNONDEF) ;
320  assert( dim.ndim == 1 ) ;
321  assert( i >= 0 ) ;
322  assert( i < dim.dim[0] ) ;
323  if (etat == ETATZERO) {
324  double zero = 0. ;
325  return zero ;
326  }
327  else return t[i] ;
328  };
329 
331  double& set(int j, int i) {
332  assert (etat == ETATQCQ) ;
333  assert( dim.ndim == 2 ) ;
334  assert( (i>=0) && (i<dim.dim[0]) ) ;
335  assert( (j>=0) && (j<dim.dim[1]) ) ;
336  return t[dim.dim[0] * j + i] ;
337  };
338 
340  double operator()(int j, int i) const {
341  assert(etat != ETATNONDEF) ;
342  assert( dim.ndim == 2 ) ;
343  assert( (i>=0) && (i<dim.dim[0]) ) ;
344  assert( (j>=0) && (j<dim.dim[1]) ) ;
345  if (etat == ETATZERO) {
346  double zero = 0. ;
347  return zero ;
348  }
349  else return t[dim.dim[0] * j + i] ;
350  };
351 
353  double& set(int k, int j, int i) {
354  assert (etat == ETATQCQ) ;
355  assert( dim.ndim == 3 ) ;
356  assert( (i>=0) && (i<dim.dim[0]) ) ;
357  assert( (j>=0) && (j<dim.dim[1]) ) ;
358  assert( (k>=0) && (k<dim.dim[2]) ) ;
359  return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
360  };
361 
363  double operator()(int k, int j, int i) const {
364  assert(etat != ETATNONDEF) ;
365  assert( dim.ndim == 3 ) ;
366  assert( (i>=0) && (i<dim.dim[0]) ) ;
367  assert( (j>=0) && (j<dim.dim[1]) ) ;
368  assert( (k>=0) && (k<dim.dim[2]) ) ;
369  if (etat == ETATZERO) {
370  double zero = 0. ;
371  return zero ;
372  }
373  else return t[dim.dim[1]*dim.dim[0]*k + dim.dim[0]*j + i] ;
374  };
375 
377  double& set(const Itbl place) {
378  int n = place.get_dim(0) ;
379  assert (n == dim.ndim) ;
380  for (int i=0 ; i<n ; i++)
381  assert( (place(i)>=0) && (place(i)<dim.dim[0]) ) ;
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 
391  double operator()(const Itbl place) const {
392  assert(etat != ETATNONDEF) ;
393  int n = place.get_dim(0) ;
394  assert (n == dim.ndim) ;
395  for (int i=0 ; i<n ; i++)
396  assert( (place(i)>=0) && (place(i)<dim.dim[0]) ) ;
397  if (etat == ETATZERO) {
398  double zero = 0. ;
399  return zero ;
400  }
401  else {
402  int pos = 0 ;
403  for (int d=n-1 ; d>=0 ; d--) {
404  pos*=dim.dim[d] ;
405  pos += place(d) ;
406  }
407  return t[pos] ;
408  }
409  };
410 
411  // Extraction of information
412  // -------------------------
414  int get_etat() const { return etat ; };
415 
417  int get_taille() const { return dim.taille ; };
418 
420  int get_ndim() const { return dim.ndim ; };
421 
423  int get_dim(int i) const {
424  assert( (i>=0) && (i<dim.ndim) ) ;
425  return dim.dim[i] ;
426  };
427 
428  // Outputs
429  // -------
430  public:
431  void sauve(FILE* ) const ;
432 
439  void affiche_seuil(ostream& ostr, int precision = 4,
440  double threshold = 1.e-7) const ;
442  friend ostream& operator<<(ostream& , const Tbl& ) ;
443 
444  // Member arithmetics
445  // ------------------
446  public:
447 
448  void operator+=(const Tbl &) ;
449  void operator+=(double) ;
450  void operator-=(const Tbl &) ;
451  void operator-=(double) ;
452  void operator*=(const Tbl &) ;
453  void operator*=(double) ;
454  void operator/=(const Tbl &) ;
455  void operator/=(double) ;
456 
457 } ;
458 ostream& operator<<(ostream& , const Tbl& ) ;
459 
460 
466 Tbl operator+(const Tbl&) ;
467 Tbl operator-(const Tbl&) ;
468 Tbl operator+(const Tbl&, const Tbl&) ;
469 Tbl operator+(const Tbl&, double) ;
470 Tbl operator+(double, const Tbl&) ;
471 Tbl operator+(const Tbl&, int) ;
472 Tbl operator+(int, const Tbl&) ;
473 Tbl operator-(const Tbl&, const Tbl&) ;
474 Tbl operator-(const Tbl&, double) ;
475 Tbl operator-(double, const Tbl&) ;
476 Tbl operator-(const Tbl&, int) ;
477 Tbl operator-(int, const Tbl&) ;
478 Tbl operator*(const Tbl&, const Tbl&) ;
479 Tbl operator*(const Tbl&, double) ;
480 Tbl operator*(double, const Tbl&) ;
481 Tbl operator*(const Tbl&, int) ;
482 Tbl operator*(int, const Tbl&) ;
483 Tbl operator/(const Tbl&, const Tbl&) ;
484 Tbl operator/(const Tbl&, double) ;
485 Tbl operator/(double, const Tbl&) ;
486 Tbl operator/(const Tbl&, int) ;
487 Tbl operator/(int, const Tbl&) ;
488 
489 Tbl sin(const Tbl& ) ;
490 Tbl cos(const Tbl& ) ;
491 Tbl tan(const Tbl& ) ;
492 Tbl asin(const Tbl& ) ;
493 Tbl acos(const Tbl& ) ;
494 Tbl atan(const Tbl& ) ;
495 Tbl exp(const Tbl& ) ;
496 Tbl Heaviside(const Tbl& ) ;
497 Tbl log(const Tbl& ) ;
498 Tbl log10(const Tbl& ) ;
499 Tbl sqrt(const Tbl& ) ;
500 Tbl racine_cubique (const Tbl&) ;
501 Tbl pow(const Tbl& , int ) ;
502 Tbl pow(const Tbl& , double ) ;
503 Tbl abs(const Tbl& ) ;
504 double max(const Tbl& ) ;
505 double min(const Tbl& ) ;
506 
508 double norme(const Tbl& ) ;
509 
515 double diffrel(const Tbl& a, const Tbl& b) ;
516 
522 double diffrelmax(const Tbl& a, const Tbl& b) ;
523 
527 }
528 #endif
Cmp log(const Cmp &)
Neperian logarithm.
Definition: cmp_math.C:299
Cmp asin(const Cmp &)
Arcsine.
Definition: cmp_math.C:147
Cmp exp(const Cmp &)
Exponential.
Definition: cmp_math.C:273
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
void operator/=(const Tbl &)
Division of this by a Tbl.
Definition: tbl_arithm.C:681
Lorene prototypes.
Definition: app_hor.h:67
void operator-=(const Tbl &)
Subtraction of a Tbl to this.
Definition: tbl_arithm.C:559
Cmp racine_cubique(const Cmp &)
Cube root.
Definition: cmp_math.C:248
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
int taille
Total size of the array Tbl::t.
Definition: dim_tbl.h:112
Basic integer array class.
Definition: itbl.h:122
int get_etat() const
Gives the logical state.
Definition: tbl.h:414
Cmp operator/(const Cmp &, const Cmp &)
Cmp / Cmp.
Definition: cmp_arithm.C:460
Tbl min(const Cmp &)
Minimum values of a Cmp in each domain.
Definition: cmp_math.C:461
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:97
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition: cmp_math.C:507
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
Cmp tan(const Cmp &)
Tangent.
Definition: cmp_math.C:123
void operator+=(const Tbl &)
Addition of a Tbl to this.
Definition: tbl_arithm.C:487
friend ostream & operator<<(ostream &, const Tbl &)
Display.
Definition: tbl.C:394
int get_ndim() const
Gives the number of dimensions (ie dim.ndim)
Definition: tbl.h:420
Tbl norme(const Cmp &)
Sums of the absolute values of all the values of the Cmp in each domain.
Definition: cmp_math.C:484
Cmp atan(const Cmp &)
Arctangent.
Definition: cmp_math.C:198
Tbl(int size0)
1D constructor
Definition: tbl.C:147
double operator()(int j, int i) const
Read-only of a particular element (index (j,i)) (2D case)
Definition: tbl.h:340
Dim_tbl dim
Number of dimensions, size,...
Definition: tbl.h:175
double operator()(int i) const
Read-only of a particular element (index i) (1D case)
Definition: tbl.h:318
Cmp operator+(const Cmp &)
Definition: cmp_arithm.C:107
Matrix handling.
Definition: matrice.h:152
double * t
The array of double.
Definition: tbl.h:176
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition: tbl.C:357
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition: cmp_math.C:438
int get_dim(int i) const
Gives the i-th dimension (ie dim.dim[i])
Definition: tbl.h:423
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:351
int etat
logical state (ETATNONDEF, ETATQCQ or ETATZERO).
Definition: tbl.h:172
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition: tbl.C:350
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:471
int ndim
Number of dimensions of the Tbl: can be 1, 2 or 3.
Definition: dim_tbl.h:101
void operator*=(const Tbl &)
Multiplication of this by a Tbl.
Definition: tbl_arithm.C:631
Storage of array dimensions.
Definition: dim_tbl.h:99
void del_t()
Logical destructor: dellocates the memory occupied by the array t and sets the logical state to ETATN...
Definition: tbl.C:343
Cmp log10(const Cmp &)
Basis 10 logarithm.
Definition: cmp_math.C:325
~Tbl()
Destructor.
Definition: tbl.C:253
Cmp acos(const Cmp &)
Arccosine.
Definition: cmp_math.C:172
Cmp abs(const Cmp &)
Absolute value.
Definition: cmp_math.C:413
int get_taille() const
Gives the total size (ie dim.taille)
Definition: tbl.h:417
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] )
Definition: itbl.h:326
double operator()(int k, int j, int i) const
Read-only of a particular element (index (k,j,i)) (3D case)
Definition: tbl.h:363
void sauve(FILE *) const
Save in a file.
Definition: tbl.C:329
Cmp operator-(const Cmp &)
- Cmp
Definition: cmp_arithm.C:111
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:72
Mtbl Heaviside(const Mtbl &)
Heaviside function.
Definition: mtbl_math.C:320
Basic array class.
Definition: tbl.h:164
double operator()(const Itbl place) const
Read-only of a particular element (index (k,j,i)) (multi-dimensional case)
Definition: tbl.h:391
void annule_hard()
Sets the Tbl to zero in a hard way.
Definition: tbl.C:375
void operator=(const Tbl &)
Assignment to another Tbl.
Definition: tbl.C:262
3D grid class in one domain.
Definition: grilles.h:200
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition: cmp_math.C:542
int * dim
Array of dimensions (size: ndim).
Definition: dim_tbl.h:102
void affecte(int i, double val)
Affectation of a particular element (index i) (1D case)
Definition: tbl.h:310