mtbl_cf_math.C

00001 /*
00002  * Mathematical functions related to the Mtbl_cf class
00003  */
00004 
00005 /*
00006  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00007  *
00008  *   This file is part of LORENE.
00009  *
00010  *   LORENE is free software; you can redistribute it and/or modify
00011  *   it under the terms of the GNU General Public License as published by
00012  *   the Free Software Foundation; either version 2 of the License, or
00013  *   (at your option) any later version.
00014  *
00015  *   LORENE is distributed in the hope that it will be useful,
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *   GNU General Public License for more details.
00019  *
00020  *   You should have received a copy of the GNU General Public License
00021  *   along with LORENE; if not, write to the Free Software
00022  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 
00027 char mtbl_cf_math_C[] = "$Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf_math.C,v 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon Exp $" ;
00028 
00029 /*
00030  * $Id: mtbl_cf_math.C,v 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon Exp $
00031  * $Log: mtbl_cf_math.C,v $
00032  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00033  * LORENE
00034  *
00035  * Revision 1.3  2000/02/25  10:57:40  eric
00036  * Suppressions des appels a nettoie().
00037  *
00038  * Revision 1.2  1999/10/29  15:46:20  eric
00039  * *** empty log message ***
00040  *
00041  * Revision 1.1  1999/10/29  15:08:13  eric
00042  * Initial revision
00043  *
00044  *
00045  * $Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf_math.C,v 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon Exp $
00046  *
00047  */
00048 
00049 // Headers C
00050 // ---------
00051 #include <math.h>
00052 #include <stdlib.h>
00053 
00054 // Headers Lorene
00055 // --------------
00056 #include "mtbl_cf.h"
00057 
00058 
00059                 //----------------//
00060                 // Absolute value //
00061                 //----------------//
00062 
00063 Mtbl_cf abs(const Mtbl_cf& ti)
00064 {
00065     // Protection
00066     assert(ti.get_etat() != ETATNONDEF) ;
00067     
00068     // Cas ETATZERO
00069     if (ti.get_etat() == ETATZERO) {
00070     return ti ;
00071     }
00072     
00073     // Cas general
00074 
00075     assert(ti.get_etat() == ETATQCQ) ;  // sinon...
00076 
00077     Mtbl_cf to(ti.get_mg(), ti.base) ;          // Mtbl_cf resultat
00078    
00079     to.set_etat_qcq() ;
00080 
00081     int nzone = ti.get_nzone() ;
00082 
00083     for (int l=0 ; l<nzone ; l++) {
00084     *(to.t[l]) = abs( *(ti.t[l]) ) ;    
00085     }
00086 
00087     return to ;
00088 }
00089 
00090 
00091 
00092 
00093             //-------------------------------//
00094                     //            max                //
00095             //-------------------------------//
00096 
00097 Tbl max(const Mtbl_cf& mti) {
00098 
00099     // Protection
00100     assert(mti.get_etat() != ETATNONDEF) ;
00101     
00102     int nz = mti.get_nzone() ;
00103     
00104     Tbl resu(nz) ; 
00105     
00106     if (mti.get_etat() == ETATZERO) {
00107     resu.annule_hard() ; 
00108     }
00109     else {      // Cas general
00110 
00111     assert(mti.get_etat() == ETATQCQ) ;     // sinon....
00112 
00113     resu.set_etat_qcq() ; 
00114     for (int l=0 ; l<nz ; l++) {
00115         resu.set(l) = max( *(mti.t[l]) ) ;
00116     }
00117     }
00118      
00119     return resu ; 
00120 }
00121 
00122             //-------------------------------//
00123                     //            min                //
00124             //-------------------------------//
00125 
00126 Tbl min(const Mtbl_cf& mti) {
00127 
00128     // Protection
00129     assert(mti.get_etat() != ETATNONDEF) ;
00130     
00131     int nz = mti.get_nzone() ;
00132     
00133     Tbl resu(nz) ; 
00134     
00135     if (mti.get_etat() == ETATZERO) {
00136     resu.annule_hard() ; 
00137     }
00138     else {      // Cas general
00139 
00140     assert(mti.get_etat() == ETATQCQ) ;     // sinon....
00141     
00142     resu.set_etat_qcq() ; 
00143     for (int l=0 ; l<nz ; l++) {
00144         resu.set(l) = min( *(mti.t[l]) ) ;
00145     }
00146     }
00147      
00148     return resu ; 
00149 }
00150 
00151             //-------------------------------//
00152                     //            norme              //
00153             //-------------------------------//
00154 
00155 Tbl norme(const Mtbl_cf& mti) {
00156 
00157     // Protection
00158     assert(mti.get_etat() != ETATNONDEF) ;
00159     
00160     int nz = mti.get_nzone() ;
00161     
00162     Tbl resu(nz) ; 
00163     
00164     if (mti.get_etat() == ETATZERO) {
00165     resu.annule_hard() ; 
00166     }
00167     else {      // Cas general
00168 
00169     assert(mti.get_etat() == ETATQCQ) ;     // sinon....
00170     
00171     resu.set_etat_qcq() ; 
00172     for (int l=0 ; l<nz ; l++) {
00173         resu.set(l) = norme( *(mti.t[l]) ) ;
00174     }
00175     }
00176      
00177     return resu ; 
00178 }
00179 
00180             //-------------------------------//
00181                     //          diffrel              //
00182             //-------------------------------//
00183 
00184 Tbl diffrel(const Mtbl_cf& mt1, const Mtbl_cf& mt2) {
00185     
00186     // Protections
00187     assert(mt1.get_etat() != ETATNONDEF) ;
00188     assert(mt2.get_etat() != ETATNONDEF) ;
00189     
00190     int nz = mt1.get_nzone() ;
00191     Tbl resu(nz) ; 
00192     
00193     Mtbl_cf diff = mt1 - mt2 ; 
00194     
00195     Tbl normdiff = norme(diff) ; 
00196     Tbl norme2 = norme(mt2) ;
00197     
00198     assert(normdiff.get_etat() == ETATQCQ) ;     
00199     assert(norme2.get_etat() == ETATQCQ) ; 
00200 
00201     resu.set_etat_qcq() ; 
00202     for (int l=0; l<nz; l++) {
00203     if ( norme2(l) == double(0) ) {
00204         resu.set(l) = normdiff(l) ; 
00205     }
00206     else{
00207         resu.set(l) = normdiff(l) / norme2(l) ;             
00208     }
00209     }
00210     
00211     return resu ; 
00212     
00213 }
00214 
00215             //-------------------------------//
00216                     //          diffrelmax           //
00217             //-------------------------------//
00218 
00219 Tbl diffrelmax(const Mtbl_cf& mt1, const Mtbl_cf& mt2) {
00220     
00221     // Protections
00222     assert(mt1.get_etat() != ETATNONDEF) ;
00223     assert(mt2.get_etat() != ETATNONDEF) ;
00224     
00225     int nz = mt1.get_nzone() ;
00226     Tbl resu(nz) ; 
00227     
00228     Tbl max2 = max(abs(mt2)) ;
00229 
00230     Mtbl_cf diff = mt1 - mt2 ; 
00231     Tbl maxdiff = max(abs(diff)) ; 
00232     
00233     assert(maxdiff.get_etat() == ETATQCQ) ;     
00234     assert(max2.get_etat() == ETATQCQ) ; 
00235 
00236     resu.set_etat_qcq() ; 
00237     for (int l=0; l<nz; l++) {
00238     if ( max2(l) == double(0) ) {
00239         resu.set(l) = maxdiff(l) ; 
00240     }
00241     else{
00242         resu.set(l) = maxdiff(l) / max2(l) ;            
00243     }
00244     }
00245     
00246     return resu ; 
00247     
00248 }

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