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
00030
00031 char mtbl_cf_C[] = "$Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf.C,v 1.7 2008/08/19 06:42:00 j_novak Exp $" ;
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 #include <assert.h>
00107 #include <stdlib.h>
00108 #include <math.h>
00109
00110
00111 #include "mtbl_cf.h"
00112 #include "utilitaires.h"
00113
00114
00115
00116
00117 Mtbl_cf::Mtbl_cf(const Mg3d& g, const Base_val& ba) : mg(&g),
00118 etat(ETATNONDEF),
00119 base(ba),
00120 t(0x0) {
00121 nzone = g.get_nzone() ;
00122 assert(base.get_nzone() == nzone) ;
00123 }
00124
00125 Mtbl_cf::Mtbl_cf(const Mg3d* g, const Base_val& ba) : mg(g),
00126 etat(ETATNONDEF),
00127 base(ba),
00128 t(0x0) {
00129 nzone = g->get_nzone() ;
00130 assert(base.get_nzone() == nzone) ;
00131 }
00132
00133
00134
00135
00136 Mtbl_cf::~Mtbl_cf() {
00137
00138 del_t() ;
00139 }
00140
00141
00142
00143 Mtbl_cf::Mtbl_cf(const Mtbl_cf& mtc) : mg(mtc.mg),
00144 nzone(mtc.nzone),
00145 base(mtc.base) {
00146
00147
00148 assert(mtc.get_etat() != ETATNONDEF) ;
00149
00150 t = 0x0 ;
00151 etat = ETATNONDEF ;
00152 if (mtc.etat == ETATQCQ) {
00153 set_etat_qcq() ;
00154 for (int i=0 ; i<nzone ; i++) {
00155 *t[i] = *mtc.t[i] ;
00156 }
00157 }
00158 else {
00159 assert(mtc.etat == ETATZERO) ;
00160 }
00161 etat = mtc.etat ;
00162 }
00163
00164
00165
00166 Mtbl_cf::Mtbl_cf(const Mg3d& g, FILE* fd) : mg(&g),
00167 base(fd) {
00168
00169
00170 Mg3d* mg_tmp = new Mg3d(fd) ;
00171 if (*mg != *mg_tmp) {
00172 cout << "Mtbl_cf::Mtbl_cf(const Mg3d& , FILE*): grid not consistent !"
00173 << endl ;
00174 abort() ;
00175 }
00176 delete mg_tmp ;
00177
00178
00179 nzone = mg->get_nzone() ;
00180 assert(base.get_nzone() == nzone) ;
00181 fread_be(&etat, sizeof(int), 1, fd) ;
00182
00183
00184 t = 0x0 ;
00185 if (etat == ETATQCQ) {
00186 t = new Tbl*[nzone] ;
00187 for (int i=0 ; i<nzone ; i++) {
00188 t[i] = new Tbl(fd) ;
00189 }
00190 }
00191 int dzpuis_vieux ;
00192 fread_be(&dzpuis_vieux, sizeof(int), 1, fd) ;
00193 }
00194
00195
00196
00197 void Mtbl_cf::sauve(FILE* fd) const {
00198
00199 base.sauve(fd) ;
00200 mg->sauve(fd) ;
00201 fwrite_be(&etat, sizeof(int), 1, fd) ;
00202 if (etat == ETATQCQ) {
00203 for (int i=0 ; i<nzone ; i++) {
00204 t[i]->sauve(fd) ;
00205 }
00206 }
00207 int dzpuis_vieux = 0 ;
00208 fwrite_be(&dzpuis_vieux, sizeof(int), 1, fd) ;
00209 }
00210
00211
00212
00213 void Mtbl_cf::operator=(const Mtbl_cf& mtc)
00214 {
00215
00216 assert (mg == mtc.mg) ;
00217 assert(mtc.get_etat() != ETATNONDEF) ;
00218
00219
00220 base = mtc.base ;
00221
00222
00223 if (mtc.get_etat() == ETATZERO) {
00224 set_etat_zero() ;
00225 }
00226 else {
00227 assert(mtc.get_etat() == ETATQCQ) ;
00228 set_etat_qcq() ;
00229 for (int i=0 ; i<nzone ; i++) {
00230 *t[i] = *mtc.t[i] ;
00231 }
00232 }
00233 }
00234
00235 void Mtbl_cf::operator=(double x)
00236 {
00237 if ( x == double(0) ) {
00238 set_etat_zero() ;
00239 }
00240 else {
00241 set_etat_qcq() ;
00242 for (int i=0 ; i<nzone ; i++) {
00243 *t[i] = x ;
00244 }
00245 }
00246
00247 }
00248
00249 void Mtbl_cf::operator=(int m)
00250 {
00251 if (m == 0) {
00252 set_etat_zero() ;
00253 }
00254 else {
00255 set_etat_qcq() ;
00256 for (int i=0 ; i<nzone ; i++) {
00257 *t[i] = m ;
00258 }
00259 }
00260
00261 }
00262
00263
00264
00265
00266
00267
00268
00269 void Mtbl_cf::del_t() {
00270
00271 if (t != 0x0) {
00272 for (int l=0 ; l<nzone ; l++) {
00273 delete t[l] ;
00274 }
00275 delete [] t ;
00276 t = 0x0 ;
00277 }
00278 etat = ETATNONDEF ;
00279 }
00280
00281 void Mtbl_cf::set_etat_zero() {
00282 if (etat == ETATZERO) return ;
00283 del_t() ;
00284 etat = ETATZERO ;
00285 }
00286
00287 void Mtbl_cf::set_etat_nondef() {
00288 if (etat == ETATNONDEF) return ;
00289 del_t() ;
00290 etat = ETATNONDEF ;
00291 }
00292
00293 void Mtbl_cf::set_etat_qcq() {
00294 if (etat == ETATQCQ) return ;
00295 t = new Tbl*[nzone] ;
00296 for (int i=0 ; i<nzone ; i++) {
00297 int nbr = mg->get_nr(i) ;
00298 int nbt = mg->get_nt(i) ;
00299 int nbp = mg->get_np(i) ;
00300 t[i] = new Tbl(nbp+2, nbt, nbr) ;
00301 }
00302 etat = ETATQCQ ;
00303 }
00304
00305 void Mtbl_cf::annule_hard() {
00306 if (t == 0x0) {
00307 t = new Tbl*[nzone] ;
00308 for (int i=0 ; i<nzone ; i++) {
00309 int nbr = mg->get_nr(i) ;
00310 int nbt = mg->get_nt(i) ;
00311 int nbp = mg->get_np(i) ;
00312 t[i] = new Tbl(nbp+2, nbt, nbr) ;
00313 }
00314 }
00315
00316 for (int i=0 ; i<nzone ; i++) {
00317 t[i]->annule_hard() ;
00318 }
00319 etat = ETATQCQ ;
00320 }
00321
00322
00323
00324
00325 void Mtbl_cf::annule(int l_min, int l_max) {
00326
00327 assert( (l_min >= 0) && (l_min < nzone) ) ;
00328 assert( (l_max >= 0) && (l_max < nzone) ) ;
00329
00330
00331 if ( (l_min == 0) && (l_max == nzone-1) ) {
00332 set_etat_zero() ;
00333 return ;
00334 }
00335
00336 assert( etat != ETATNONDEF ) ;
00337
00338 if ( etat == ETATZERO ) {
00339 return ;
00340 }
00341 else {
00342 assert( etat == ETATQCQ ) ;
00343 for (int l=l_min; l<=l_max; l++) {
00344 t[l]->set_etat_zero() ;
00345 }
00346
00347 }
00348
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 ostream& operator<<(ostream& o, const Mtbl_cf& mt) {
00360
00361 assert(mt.get_etat() != ETATNONDEF) ;
00362
00363 int nzone = mt.get_nzone() ;
00364 o.precision(4);
00365 o.setf(ios::showpoint);
00366 o << "*** MTBL_CF " << nzone << " domains" << endl ;
00367
00368 o << mt.base << endl ;
00369
00370 o << "Values of the coefficients : " << endl ;
00371 if (mt.get_etat() == ETATZERO) {
00372 o << "Logically NUL" << endl ;
00373 }
00374 else {
00375 for (int l=0 ; l<nzone ; l++) {
00376 o << " Domain #" << l << endl ;
00377 o << *(mt.t[l]) ;
00378 o << endl ;
00379 }
00380 }
00381
00382 o << endl ;
00383 return o ;
00384 }
00385
00386
00387
00388
00389
00390 void Mtbl_cf::affiche_seuil(ostream& ost, int precis, double seuil) const {
00391 ost << "*** Mtbl_cf " << nzone << " domains" << endl ;
00392 ost << base << endl ;
00393 ost << "Values of the coefficients : " << endl ;
00394
00395
00396
00397
00398 if (etat == ETATNONDEF) {
00399 ost << " state: UNDEFINED" << endl ;
00400 return ;
00401 }
00402
00403 if (etat == ETATZERO) {
00404 ost << " state: ZERO" << endl ;
00405 return ;
00406 }
00407
00408
00409
00410 assert( t != 0x0 ) ;
00411
00412 for (int l=0; l < nzone; l++) {
00413 t[l]->affiche_seuil( ost , precis, seuil ) ;
00414 }
00415
00416 }
00417
00418
00419
00420
00421
00422 void Mtbl_cf::operator*=(double ) {
00423 const char* f = __FILE__ ;
00424 c_est_pas_fait(f) ;
00425 }
00426
00427 void Mtbl_cf::operator/=(double ) {
00428 const char* f = __FILE__ ;
00429 c_est_pas_fait(f) ;
00430 }
00431
00432