tenseur_math.C

00001 /*
00002  *  Mathematical functions for the Tenseur class.
00003  *
00004  *  These functions are not member functions of the Tenseur class.
00005  *
00006  *  (see file tenseur.h for documentation).
00007  *
00008  */
00009 
00010 /*
00011  *   Copyright (c) 2000-2001 Eric Gourgoulhon
00012  *   Copyright (c) 2001 Jerome Novak
00013  *
00014  *   This file is part of LORENE.
00015  *
00016  *   LORENE is free software; you can redistribute it and/or modify
00017  *   it under the terms of the GNU General Public License as published by
00018  *   the Free Software Foundation; either version 2 of the License, or
00019  *   (at your option) any later version.
00020  *
00021  *   LORENE is distributed in the hope that it will be useful,
00022  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *   GNU General Public License for more details.
00025  *
00026  *   You should have received a copy of the GNU General Public License
00027  *   along with LORENE; if not, write to the Free Software
00028  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029  *
00030  */
00031 
00032 
00033 char tenseur_math_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_math.C,v 1.3 2002/08/08 15:10:45 j_novak Exp $" ;
00034 
00035 
00036 /*
00037  * $Id: tenseur_math.C,v 1.3 2002/08/08 15:10:45 j_novak Exp $
00038  * $Log: tenseur_math.C,v $
00039  * Revision 1.3  2002/08/08 15:10:45  j_novak
00040  * The flag "plat" has been added to the class Metrique to show flat metrics.
00041  *
00042  * Revision 1.2  2002/08/07 16:14:11  j_novak
00043  * class Tenseur can now also handle tensor densities, this should be transparent to older codes
00044  *
00045  * Revision 1.1.1.1  2001/11/20 15:19:30  e_gourgoulhon
00046  * LORENE
00047  *
00048  * Revision 2.1  2001/06/18  13:56:25  novak
00049  * Ajout de la fonction abs() pour les scalaires
00050  *
00051  * Revision 2.0  2000/02/08 19:06:32  eric
00052  * *** empty log message ***
00053  *
00054  *
00055  * $Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_math.C,v 1.3 2002/08/08 15:10:45 j_novak Exp $
00056  *
00057  */
00058 
00059 // Headers Lorene
00060 #include "tenseur.h"
00061 
00062                 //--------------//
00063                 // Exponential  //
00064                 //--------------//
00065 
00066 Tenseur exp (const Tenseur& t) {
00067     
00068     assert (t.get_etat() != ETATNONDEF) ;
00069     assert (t.get_valence() == 0) ; // Scalaire uniquement ...
00070     
00071     Tenseur res( *(t.get_mp()) ) ;
00072     res.set_etat_qcq() ;
00073     if (t.get_etat() == ETATZERO)
00074     res.set() = 1 ;
00075     else 
00076     res.set() = exp( t() ) ;
00077     return res ;
00078 }
00079 
00080 
00081                 //---------------------//
00082                 // Neperian logarithm  //
00083                 //---------------------//
00084 
00085 Tenseur log (const Tenseur& t) {
00086     
00087     assert (t.get_etat() != ETATNONDEF) ;
00088     assert (t.get_valence() == 0) ; // Scalaire uniquement ...
00089     
00090     Tenseur res( *(t.get_mp()) ) ;
00091     res.set_etat_qcq() ;
00092     res.set() = log(t()) ;
00093     return res ;
00094 }
00095 
00096                 //-------------//
00097                 // Square root //
00098                 //-------------//
00099 
00100 Tenseur sqrt(const Tenseur& t) {
00101     
00102     assert (t.get_etat() != ETATNONDEF) ;
00103     assert (t.get_valence() == 0) ; // Scalaire uniquement ...
00104 
00105     Tenseur res( *(t.get_mp()), t.get_metric(), 0.5*t.get_poids() ) ;
00106     res.set_etat_qcq() ;
00107     res.set() = sqrt(t()) ;
00108     return res ;
00109 }
00110 
00111                 //----------------//
00112                 // Absolute value //
00113                 //----------------//
00114 
00115 Tenseur abs(const Tenseur& t) {
00116     
00117     assert (t.get_etat() != ETATNONDEF) ;
00118     assert (t.get_valence() == 0) ; // Scalaire uniquement ...
00119     
00120     Tenseur res( *(t.get_mp()), t.get_metric(), t.get_poids() ) ;
00121     res.set_etat_qcq() ;
00122     res.set() = abs(t()) ;
00123     return res ;
00124 }
00125 
00126                 //--------------//
00127                 // Power^double //
00128                 //--------------//
00129 
00130 Tenseur pow (const Tenseur& t, double a) {
00131     
00132     assert (t.get_etat() != ETATNONDEF) ;
00133     assert (t.get_valence() == 0) ; // Scalaire uniquement ...
00134         
00135     Tenseur res( *(t.get_mp()), t.get_metric(), a*t.get_poids() ) ;
00136     res.set_etat_qcq() ;
00137     if (t.get_etat() == ETATZERO)
00138       if (a > double(0)) {
00139     res.set_etat_zero() ;
00140     res.set_std_base() ;
00141     return res ; 
00142       }
00143       else {
00144     cout << "pow(Tenseur, double) : ETATZERO^x with x <= 0 !" << endl ; 
00145     abort() ;
00146       } 
00147     else {
00148       assert(t.get_etat() == ETATQCQ) ;
00149       res.set() = pow( t(), a ) ;
00150     }
00151     res.set_std_base() ;
00152     return res ;
00153 }
00154 
00155                 //--------------//
00156                 //   Power^int  //
00157                 //--------------//
00158 
00159 Tenseur pow (const Tenseur& t, int n) {
00160     
00161     assert (t.get_etat() != ETATNONDEF) ;
00162     assert (t.get_valence() == 0) ; // Scalaire uniquement ...
00163         
00164     Tenseur res( *(t.get_mp()), t.get_metric(), n*t.get_poids() ) ;
00165     res.set_etat_qcq() ;
00166     if (t.get_etat() == ETATZERO)
00167       if (n > double(0)) {
00168     res.set_etat_zero() ;
00169     return res ; 
00170       }
00171       else {
00172     cout << "pow(Tenseur, int) : ETATZERO^n with n <= 0 !" << endl ; 
00173     abort() ;
00174       } 
00175     else {
00176       assert(t.get_etat() == ETATQCQ) ;
00177       res.set() = pow( t(), n ) ;
00178     }
00179     return res ;
00180 }
00181 

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