00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __TBL_H_
00030 #define __TBL_H_
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
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
00159
00160 private:
00162 int etat ;
00163
00164 public:
00165 Dim_tbl dim ;
00166 double* t ;
00167
00168
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
00225
00226 void operator=(const Tbl& ) ;
00227 void operator=(double ) ;
00228 void operator=(int ) ;
00229
00230
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
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
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
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
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