mtbl_cf_arithm.C

00001 /*
00002  * Arithmetical operations for class Mtbl_cf
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 1999-2000 Jean-Alain Marck
00008  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00009  *   Copyright (c) 1999-2001 Philippe Grandclement
00010  *
00011  *   This file is part of LORENE.
00012  *
00013  *   LORENE is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License as published by
00015  *   the Free Software Foundation; either version 2 of the License, or
00016  *   (at your option) any later version.
00017  *
00018  *   LORENE is distributed in the hope that it will be useful,
00019  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *   GNU General Public License for more details.
00022  *
00023  *   You should have received a copy of the GNU General Public License
00024  *   along with LORENE; if not, write to the Free Software
00025  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  */
00028 
00029 
00030 char mtbl_cf_arithm_C[] = "$Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf_arithm.C,v 1.2 2002/10/16 14:36:43 j_novak Exp $" ;
00031 
00032 /*
00033  * $Id: mtbl_cf_arithm.C,v 1.2 2002/10/16 14:36:43 j_novak Exp $
00034  * $Log: mtbl_cf_arithm.C,v $
00035  * Revision 1.2  2002/10/16 14:36:43  j_novak
00036  * Reorganization of #include instructions of standard C++, in order to
00037  * use experimental version 3 of gcc.
00038  *
00039  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00040  * LORENE
00041  *
00042  * Revision 2.6  2000/09/27  14:25:15  eric
00043  * Multiplication par un double : on met le resultat a ETATZERO si x == 0.
00044  *
00045  * Revision 2.5  2000/08/16  10:43:18  eric
00046  * Suppression du membre dzpuis.
00047  *
00048  * Revision 2.4  1999/10/26  08:09:03  eric
00049  * Ajout de protection dzpuis dans +=, -=
00050  *
00051  * Revision 2.3  1999/10/18  15:07:34  eric
00052  * La fonction membre annule() est rebaptisee annule_hard().
00053  *
00054  * Revision 2.2  1999/10/13  15:50:49  eric
00055  * *** empty log message ***
00056  *
00057  * Revision 2.1  1999/10/01  14:50:14  eric
00058  * Ajout des operations manquantes.
00059  *
00060  * Revision 2.0  1999/06/23  12:36:43  phil
00061  * *** empty log message ***
00062  *
00063  *
00064  * $Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf_arithm.C,v 1.2 2002/10/16 14:36:43 j_novak Exp $
00065  *
00066  */
00067 
00068 
00069 // Fichiers include
00070 // ----------------
00071 #include <math.h>
00072 #include <assert.h>
00073 #include <stdlib.h>
00074 
00075 #include "mtbl_cf.h"
00076 
00077             //********************//
00078             // OPERATEURS UNAIRES //
00079             //********************//
00080 
00081 // + Mtbl_cf
00082 // ---------
00083 Mtbl_cf operator+(const Mtbl_cf& t1)        
00084 {
00085     // Protection
00086     assert(t1.get_etat() != ETATNONDEF) ;
00087     
00088     return t1 ;
00089 }
00090 
00091 
00092 // - Mtbl_cf
00093 // ---------
00094 Mtbl_cf operator-(const Mtbl_cf& t1)        
00095 {
00096 
00097     // Protection
00098     assert(t1.get_etat() != ETATNONDEF) ;
00099     
00100     // Cas particulier
00101     if (t1.get_etat() == ETATZERO) {
00102     return t1 ;
00103     }
00104     
00105     // Cas general
00106     assert(t1.get_etat() == ETATQCQ) ;  // sinon...
00107     Mtbl_cf r(t1) ; // Mtbl_cf resultat
00108 
00109     for (int i=0 ; i<r.get_nzone() ; i++) {
00110     *(r.t)[i] = -(*(t1.t)[i]) ;
00111     }
00112     return r ;
00113 }
00114 
00115             //**********//
00116             // ADDITION //
00117             //**********//
00118 
00119 // Mtbl_cf + Mtbl_cf
00120 // -----------------
00121 Mtbl_cf operator+(const Mtbl_cf& t1, const Mtbl_cf& t2)     
00122 {
00123     // Protection
00124     assert(t1.get_etat() != ETATNONDEF) ;
00125     assert(t2.get_etat() != ETATNONDEF) ;
00126     assert(t1.get_mg() == t2.get_mg()) ;
00127     assert(t1.base == t2.base) ;
00128     
00129     // Cas particulier
00130     if (t1.get_etat() == ETATZERO) {
00131         return t2 ;
00132     }
00133     if (t2.get_etat() == ETATZERO) {
00134         return t1 ;
00135     }
00136     assert(t1.get_etat() == ETATQCQ) ;  // sinon...
00137     assert(t2.get_etat() == ETATQCQ) ;  // sinon...
00138 
00139     // Cas general
00140     int nz = t1.get_nzone() ;
00141 
00142     Mtbl_cf r(t1) ; // Mtbl resultat
00143 
00144     for (int i=0 ; i<nz ; i++) {
00145     *(r.t)[i] += *(t2.t)[i] ;
00146     }
00147 
00148     return r ;
00149 }
00150 
00151 
00152 
00153             //**************//
00154             // SOUSTRACTION //
00155             //**************//
00156 
00157 // Mtbl_cf - Mtbl_cf
00158 // -----------------
00159 Mtbl_cf operator-(const Mtbl_cf& t1, const Mtbl_cf& t2)  
00160 {
00161     // Protection
00162     assert(t1.get_etat() != ETATNONDEF) ;
00163     assert(t2.get_etat() != ETATNONDEF) ;
00164     assert(t1.get_mg() == t2.get_mg()) ;
00165     assert(t1.base == t2.base) ;
00166     
00167     // Cas particulier
00168     if (t1.get_etat() == ETATZERO) {
00169         return - t2 ;
00170     }
00171     if (t2.get_etat() == ETATZERO) {
00172         return t1 ;
00173     }
00174     assert(t1.get_etat() == ETATQCQ) ;  // sinon...
00175     assert(t2.get_etat() == ETATQCQ) ;  // sinon...
00176 
00177     // Cas general
00178     int nz = t1.get_nzone() ;
00179 
00180     Mtbl_cf r(t1) ; // Mtbl_cf resultat
00181 
00182     for (int i=0 ; i<nz ; i++) {
00183     *(r.t)[i] -= *(t2.t)[i] ;
00184     }
00185 
00186     return r ;
00187 }
00188 
00189 
00190             //****************//
00191             // MULTIPLICATION //
00192             //****************//
00193 
00194 
00195 // Mtbl_cf * double
00196 // ----------------
00197 Mtbl_cf operator*(const Mtbl_cf& t1, double x)      // Mtbl_cf * double
00198 {
00199 
00200     // Protection
00201     assert(t1.get_etat() != ETATNONDEF) ;
00202 
00203     // Cas particulier
00204     if ((t1.get_etat() == ETATZERO) || ( x == double(1) )) {
00205     return t1 ;
00206     }
00207 
00208     // Cas general
00209     assert(t1.get_etat() == ETATQCQ) ;  // sinon...
00210 
00211     Mtbl_cf r(t1) ; // Mtbl_cf resultat
00212 
00213     if ( x == double(0) ) {
00214     r.set_etat_zero() ;
00215     }
00216     else{
00217     int nz = t1.get_nzone() ;
00218     for (int i=0 ; i<nz ; i++) {
00219     *(r.t)[i] *= x ;
00220     }
00221     }
00222     
00223     return r ;
00224 }
00225 
00226 // double * Mtbl_cf
00227 // ----------------
00228 Mtbl_cf operator*(double x, const Mtbl_cf& t1)      
00229 {
00230     return t1 * x ;
00231 }
00232 
00233 // Mtbl_cf * int
00234 // -------------
00235 Mtbl_cf operator*(const Mtbl_cf& t1, int m)
00236 {
00237     return t1 * double(m) ;
00238 }
00239 
00240 // int * Mtbl_cf
00241 // -------------
00242 Mtbl_cf operator*(int m, const Mtbl_cf& t1)     
00243 {
00244     return t1 * double(m) ;
00245 }
00246 
00247 
00248             //**********//
00249             // DIVISION //
00250             //**********//
00251 
00252 
00253 // Mtbl_cf / double
00254 // ----------------
00255 Mtbl_cf operator/(const Mtbl_cf& t1, double x)      
00256 {
00257 
00258     // Protection
00259     assert(t1.get_etat() != ETATNONDEF) ;
00260     if ( x == double(0) ) {
00261     cout << "Mtbl_cf division by 0 !" << endl ;
00262     abort() ;
00263     }
00264     
00265     // Cas particulier
00266     if ((t1.get_etat() == ETATZERO) || ( x == double(1) )) {
00267     return t1 ;
00268     }
00269     
00270     // Cas general
00271     assert(t1.get_etat() == ETATQCQ) ;  // sinon...
00272 
00273     Mtbl_cf r(t1) ; // Mtbl_cf resultat
00274     int nz = t1.get_nzone() ;
00275     for (int i=0 ; i<nz ; i++) {
00276     *(r.t)[i] /= x ;
00277     }
00278 
00279     return r ;
00280 }
00281 
00282 // Mtbl_cf / int
00283 // -------------
00284 Mtbl_cf operator/(const Mtbl_cf& t1, int n)     
00285 {
00286     return t1/double(n) ;
00287 }
00288 
00289 
00290 
00291             //*******************//
00292             // operateurs +=,... //
00293             //*******************//
00294 
00295 void Mtbl_cf::operator+=(const Mtbl_cf & mi) {
00296     
00297     // Protection
00298     assert(mg == mi.get_mg()) ;         // meme grille
00299     assert(base == mi.base) ;           // meme base
00300     assert(etat != ETATNONDEF) ;        // etat defini
00301     assert(mi.get_etat() != ETATNONDEF) ;   // etat defini
00302     
00303     // Cas particulier
00304     if (mi.get_etat() == ETATZERO) {
00305     return ;
00306     }
00307     
00308     // Cas general
00309 
00310     if (etat == ETATZERO) {
00311     annule_hard() ;
00312     }
00313     for (int i=0 ; i<nzone ; i++) {
00314     *(t[i]) += *(mi.t[i]) ;
00315     }
00316 }
00317 
00318 void Mtbl_cf::operator-=(const Mtbl_cf & mi) {
00319     
00320     // Protection
00321     assert(mg == mi.get_mg()) ;         // meme grille
00322     assert(base == mi.base) ;           // meme base
00323     assert(etat != ETATNONDEF) ;        // etat defini
00324     assert(mi.get_etat() != ETATNONDEF) ;   // etat defini
00325     
00326     // Cas particulier
00327     if (mi.get_etat() == ETATZERO) {
00328     return ;
00329     }
00330     
00331     // Cas general
00332 
00333     if (etat == ETATZERO) {
00334     annule_hard() ;
00335     }
00336     for (int i=0 ; i<nzone ; i++) {
00337     *(t[i]) -= *(mi.t[i]) ;
00338     }
00339 }
00340 

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