mtbl_cf.C

00001 /*
00002  *  Methods of class Mtbl_cf
00003  *
00004  *   (see file mtbl_cf.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 1999-2000 Jean-Alain Marck
00010  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00011  *
00012  *   This file is part of LORENE.
00013  *
00014  *   LORENE is free software; you can redistribute it and/or modify
00015  *   it under the terms of the GNU General Public License as published by
00016  *   the Free Software Foundation; either version 2 of the License, or
00017  *   (at your option) any later version.
00018  *
00019  *   LORENE is distributed in the hope that it will be useful,
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *   GNU General Public License for more details.
00023  *
00024  *   You should have received a copy of the GNU General Public License
00025  *   along with LORENE; if not, write to the Free Software
00026  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  * $Id: mtbl_cf.C,v 1.7 2008/08/19 06:42:00 j_novak Exp $
00035  * $Log: mtbl_cf.C,v $
00036  * Revision 1.7  2008/08/19 06:42:00  j_novak
00037  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00038  * cast-type operations, and constant strings that must be defined as const char*
00039  *
00040  * Revision 1.6  2008/02/18 13:53:41  j_novak
00041  * Removal of special indentation instructions.
00042  *
00043  * Revision 1.5  2003/10/19 19:51:23  e_gourgoulhon
00044  * Access to Base_val::nzone now via the method Base_val::get_nzone().
00045  *
00046  * Revision 1.4  2002/10/16 14:36:43  j_novak
00047  * Reorganization of #include instructions of standard C++, in order to
00048  * use experimental version 3 of gcc.
00049  *
00050  * Revision 1.3  2002/05/07 07:36:03  e_gourgoulhon
00051  * Compatibilty with xlC compiler on IBM SP2:
00052  *    suppressed the parentheses around argument of instruction new:
00053  *  e.g.   t = new (Tbl *[nzone])  -->   t = new Tbl*[nzone]
00054  *
00055  * Revision 1.2  2001/12/04 21:27:54  e_gourgoulhon
00056  *
00057  * All writing/reading to a binary file are now performed according to
00058  * the big endian convention, whatever the system is big endian or
00059  * small endian, thanks to the functions fwrite_be and fread_be
00060  *
00061  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00062  * LORENE
00063  *
00064  * Revision 2.13  2000/08/16  10:43:09  eric
00065  * Suppression du membre dzpuis.
00066  *
00067  * Revision 2.12  2000/02/25  10:27:44  eric
00068  * Suppression des appels a nettoie() dans l'affichage.
00069  *
00070  * Revision 2.11  1999/10/29  15:07:27  eric
00071  * Suppression des fonctions membres min() et max():
00072  * elles deviennent des fonctions externes.
00073  *
00074  * Revision 2.10  1999/10/21  13:42:05  eric
00075  * *** empty log message ***
00076  *
00077  * Revision 2.9  1999/10/18  15:16:12  eric
00078  * *** empty log message ***
00079  *
00080  * Revision 2.8  1999/10/18  15:08:44  eric
00081  * La fonction membre annule() est rebaptisee annule_hard().
00082  * Introduction de la fonction membre annule(int, int).
00083  *
00084  * Revision 2.7  1999/10/13  15:52:03  eric
00085  * Depoussierage.
00086  * Ajout du membre base.
00087  *
00088  * Revision 2.6  1999/10/01  14:49:38  eric
00089  * Depoussierage.
00090  * Documentation.
00091  *
00092  * Revision 2.5  1999/03/03  10:35:37  hyc
00093  * *** empty log message ***
00094  *
00095  * Revision 2.4  1999/03/02  16:26:39  eric
00096  * Modif des indentations dans <<
00097  *
00098  * Revision 2.3  1999/03/02  15:34:30  eric
00099  * Anglicisation des messages...
00100  *
00101  *
00102  * $Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf.C,v 1.7 2008/08/19 06:42:00 j_novak Exp $
00103  *
00104  */
00105 // headers C
00106 #include <assert.h>
00107 #include <stdlib.h>
00108 #include <math.h>
00109 
00110 // headers Lorene
00111 #include "mtbl_cf.h"
00112 #include "utilitaires.h"
00113 
00114 // Constructeur
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 // Destructeur
00135 // -----------
00136 Mtbl_cf::~Mtbl_cf() {
00137 
00138     del_t() ;
00139 }
00140 
00141 // Copie
00142 // -----
00143 Mtbl_cf::Mtbl_cf(const Mtbl_cf& mtc) : mg(mtc.mg), 
00144                        nzone(mtc.nzone),
00145                        base(mtc.base) {
00146 
00147     // Protection
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) ;  // sinon...
00160     }
00161     etat = mtc.etat ;
00162 }
00163 
00164 // Constructeur a partir d'une grille et d'un fichier
00165 // --------------------------------------------------
00166 Mtbl_cf::Mtbl_cf(const Mg3d& g, FILE* fd) : mg(&g), 
00167                         base(fd) {
00168     
00169     // La multi-grille
00170     Mg3d* mg_tmp = new Mg3d(fd) ;   // la multi-grille d'origine
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     // Lecture
00179     nzone = mg->get_nzone() ;
00180     assert(base.get_nzone() == nzone) ; 
00181     fread_be(&etat, sizeof(int), 1, fd) ;       // etat
00182     
00183     // Le tableau
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) ;       // le vieux dzpuis !
00193 }
00194 
00195 // Sauvegarde sur un fichier
00196 // -------------------------
00197 void Mtbl_cf::sauve(FILE* fd) const {
00198 
00199     base.sauve(fd) ;                // la base
00200     mg->sauve(fd) ;             // la multi-grille
00201     fwrite_be(&etat, sizeof(int), 1, fd) ;          // etat
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) ;      // le vieux dzpuis !
00209 }
00210 
00211 // Affectations
00212 // ------------
00213 void Mtbl_cf::operator=(const Mtbl_cf& mtc)
00214 {
00215     // Protection
00216     assert (mg == mtc.mg) ;
00217     assert(mtc.get_etat() != ETATNONDEF) ;
00218 
00219     // Les choses fixes
00220     base = mtc.base ; 
00221     
00222     // Gestion des donnees
00223     if (mtc.get_etat() == ETATZERO) {
00224     set_etat_zero() ;
00225     }
00226     else {
00227         assert(mtc.get_etat() == ETATQCQ) ; // sinon...
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                     // Gestion memoire //
00266             //-----------------//
00267 
00268 // Destructeur logique
00269 void Mtbl_cf::del_t() {
00270     // Detruit le mtbl_cf
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 // ETATZERO
00281 void Mtbl_cf::set_etat_zero() {
00282     if (etat == ETATZERO) return ;
00283     del_t() ;
00284     etat = ETATZERO ;
00285 }
00286 // ETATNONDEF
00287 void Mtbl_cf::set_etat_nondef() {
00288     if (etat == ETATNONDEF) return ;
00289     del_t() ;
00290     etat = ETATNONDEF ;
00291 }
00292 // ETATQCQ
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 // ZERO hard
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 // Sets the {\tt Mtbl_cf} to zero in some domains
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     // Cas particulier: annulation globale : 
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 ;        // rien n'a faire si c'est deja zero
00340     }
00341     else {
00342     assert( etat == ETATQCQ ) ; // sinon...
00343     for (int l=l_min; l<=l_max; l++) {
00344         t[l]->set_etat_zero() ; 
00345     }
00346      
00347     }
00348     
00349 }
00350 
00351             //------------------------//
00352             //  Display       //
00353             //------------------------//
00354             
00355 //-----------           
00356 // Operator<<
00357 //-----------           
00358             
00359 ostream& operator<<(ostream& o, const Mtbl_cf& mt) { 
00360     // Protection
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 // Affiche_seuil
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     // Cas particuliers
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     // Affichage des Tbl
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 // To be done
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 

Generated on Tue Feb 7 01:35:18 2012 for LORENE by  doxygen 1.4.6