LORENE
tenseur_math.C
1 /*
2  * Mathematical functions for the Tenseur class.
3  *
4  * These functions are not member functions of the Tenseur class.
5  *
6  * (see file tenseur.h for documentation).
7  *
8  */
9 
10 /*
11  * Copyright (c) 2000-2001 Eric Gourgoulhon
12  * Copyright (c) 2001 Jerome Novak
13  *
14  * This file is part of LORENE.
15  *
16  * LORENE is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * LORENE is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with LORENE; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  *
30  */
31 
32 
33 char tenseur_math_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_math.C,v 1.4 2014/10/13 08:53:42 j_novak Exp $" ;
34 
35 
36 /*
37  * $Id: tenseur_math.C,v 1.4 2014/10/13 08:53:42 j_novak Exp $
38  * $Log: tenseur_math.C,v $
39  * Revision 1.4 2014/10/13 08:53:42 j_novak
40  * Lorene classes and functions now belong to the namespace Lorene.
41  *
42  * Revision 1.3 2002/08/08 15:10:45 j_novak
43  * The flag "plat" has been added to the class Metrique to show flat metrics.
44  *
45  * Revision 1.2 2002/08/07 16:14:11 j_novak
46  * class Tenseur can now also handle tensor densities, this should be transparent to older codes
47  *
48  * Revision 1.1.1.1 2001/11/20 15:19:30 e_gourgoulhon
49  * LORENE
50  *
51  * Revision 2.1 2001/06/18 13:56:25 novak
52  * Ajout de la fonction abs() pour les scalaires
53  *
54  * Revision 2.0 2000/02/08 19:06:32 eric
55  * *** empty log message ***
56  *
57  *
58  * $Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_math.C,v 1.4 2014/10/13 08:53:42 j_novak Exp $
59  *
60  */
61 
62 // Headers Lorene
63 #include "tenseur.h"
64 
65  //--------------//
66  // Exponential //
67  //--------------//
68 
69 namespace Lorene {
70 Tenseur exp (const Tenseur& t) {
71 
72  assert (t.get_etat() != ETATNONDEF) ;
73  assert (t.get_valence() == 0) ; // Scalaire uniquement ...
74 
75  Tenseur res( *(t.get_mp()) ) ;
76  res.set_etat_qcq() ;
77  if (t.get_etat() == ETATZERO)
78  res.set() = 1 ;
79  else
80  res.set() = exp( t() ) ;
81  return res ;
82 }
83 
84 
85  //---------------------//
86  // Neperian logarithm //
87  //---------------------//
88 
89 Tenseur log (const Tenseur& t) {
90 
91  assert (t.get_etat() != ETATNONDEF) ;
92  assert (t.get_valence() == 0) ; // Scalaire uniquement ...
93 
94  Tenseur res( *(t.get_mp()) ) ;
95  res.set_etat_qcq() ;
96  res.set() = log(t()) ;
97  return res ;
98 }
99 
100  //-------------//
101  // Square root //
102  //-------------//
103 
104 Tenseur sqrt(const Tenseur& t) {
105 
106  assert (t.get_etat() != ETATNONDEF) ;
107  assert (t.get_valence() == 0) ; // Scalaire uniquement ...
108 
109  Tenseur res( *(t.get_mp()), t.get_metric(), 0.5*t.get_poids() ) ;
110  res.set_etat_qcq() ;
111  res.set() = sqrt(t()) ;
112  return res ;
113 }
114 
115  //----------------//
116  // Absolute value //
117  //----------------//
118 
119 Tenseur abs(const Tenseur& t) {
120 
121  assert (t.get_etat() != ETATNONDEF) ;
122  assert (t.get_valence() == 0) ; // Scalaire uniquement ...
123 
124  Tenseur res( *(t.get_mp()), t.get_metric(), t.get_poids() ) ;
125  res.set_etat_qcq() ;
126  res.set() = abs(t()) ;
127  return res ;
128 }
129 
130  //--------------//
131  // Power^double //
132  //--------------//
133 
134 Tenseur pow (const Tenseur& t, double a) {
135 
136  assert (t.get_etat() != ETATNONDEF) ;
137  assert (t.get_valence() == 0) ; // Scalaire uniquement ...
138 
139  Tenseur res( *(t.get_mp()), t.get_metric(), a*t.get_poids() ) ;
140  res.set_etat_qcq() ;
141  if (t.get_etat() == ETATZERO)
142  if (a > double(0)) {
143  res.set_etat_zero() ;
144  res.set_std_base() ;
145  return res ;
146  }
147  else {
148  cout << "pow(Tenseur, double) : ETATZERO^x with x <= 0 !" << endl ;
149  abort() ;
150  }
151  else {
152  assert(t.get_etat() == ETATQCQ) ;
153  res.set() = pow( t(), a ) ;
154  }
155  res.set_std_base() ;
156  return res ;
157 }
158 
159  //--------------//
160  // Power^int //
161  //--------------//
162 
163 Tenseur pow (const Tenseur& t, int n) {
164 
165  assert (t.get_etat() != ETATNONDEF) ;
166  assert (t.get_valence() == 0) ; // Scalaire uniquement ...
167 
168  Tenseur res( *(t.get_mp()), t.get_metric(), n*t.get_poids() ) ;
169  res.set_etat_qcq() ;
170  if (t.get_etat() == ETATZERO)
171  if (n > double(0)) {
172  res.set_etat_zero() ;
173  return res ;
174  }
175  else {
176  cout << "pow(Tenseur, int) : ETATZERO^n with n <= 0 !" << endl ;
177  abort() ;
178  }
179  else {
180  assert(t.get_etat() == ETATQCQ) ;
181  res.set() = pow( t(), n ) ;
182  }
183  return res ;
184 }
185 
186 }
Lorene::Tenseur::set_etat_zero
void set_etat_zero()
Sets the logical state to ETATZERO (zero state).
Definition: tenseur.C:645
Lorene::Tenseur
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition: tenseur.h:301
Lorene::Tenseur::set
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Definition: tenseur.C:824
Lorene::log
Cmp log(const Cmp &)
Neperian logarithm.
Definition: cmp_math.C:296
Lorene::exp
Cmp exp(const Cmp &)
Exponential.
Definition: cmp_math.C:270
Lorene
Lorene prototypes.
Definition: app_hor.h:64
Lorene::Tenseur::get_metric
const Metrique * get_metric() const
Returns a pointer on the metric defining the conformal factor for tensor densities.
Definition: tenseur.h:745
Lorene::abs
Cmp abs(const Cmp &)
Absolute value.
Definition: cmp_math.C:410
Lorene::pow
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:348
Lorene::Tenseur::get_etat
int get_etat() const
Returns the logical state.
Definition: tenseur.h:707
Lorene::Tenseur::get_valence
int get_valence() const
Returns the valence.
Definition: tenseur.h:710
Lorene::sqrt
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:220
Lorene::Tenseur::get_mp
const Map * get_mp() const
Returns pointer on the mapping.
Definition: tenseur.h:699
Lorene::Tenseur::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tenseur.C:636
Lorene::Tenseur::get_poids
double get_poids() const
Returns the weight.
Definition: tenseur.h:738
Lorene::Tenseur::set_std_base
void set_std_base()
Set the standard spectal basis of decomposition for each component.
Definition: tenseur.C:1170