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
34
35
36/*
37 * $Id: tenseur_math.C,v 1.5 2016/12/05 16:18:16 j_novak Exp $
38 * $Log: tenseur_math.C,v $
39 * Revision 1.5 2016/12/05 16:18:16 j_novak
40 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
41 *
42 * Revision 1.4 2014/10/13 08:53:42 j_novak
43 * Lorene classes and functions now belong to the namespace Lorene.
44 *
45 * Revision 1.3 2002/08/08 15:10:45 j_novak
46 * The flag "plat" has been added to the class Metrique to show flat metrics.
47 *
48 * Revision 1.2 2002/08/07 16:14:11 j_novak
49 * class Tenseur can now also handle tensor densities, this should be transparent to older codes
50 *
51 * Revision 1.1.1.1 2001/11/20 15:19:30 e_gourgoulhon
52 * LORENE
53 *
54 * Revision 2.1 2001/06/18 13:56:25 novak
55 * Ajout de la fonction abs() pour les scalaires
56 *
57 * Revision 2.0 2000/02/08 19:06:32 eric
58 * *** empty log message ***
59 *
60 *
61 * $Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_math.C,v 1.5 2016/12/05 16:18:16 j_novak Exp $
62 *
63 */
64
65// Headers Lorene
66#include "tenseur.h"
67
68 //--------------//
69 // Exponential //
70 //--------------//
71
72namespace Lorene {
73Tenseur exp (const Tenseur& t) {
74
75 assert (t.get_etat() != ETATNONDEF) ;
76 assert (t.get_valence() == 0) ; // Scalaire uniquement ...
77
78 Tenseur res( *(t.get_mp()) ) ;
79 res.set_etat_qcq() ;
80 if (t.get_etat() == ETATZERO)
81 res.set() = 1 ;
82 else
83 res.set() = exp( t() ) ;
84 return res ;
85}
86
87
88 //---------------------//
89 // Neperian logarithm //
90 //---------------------//
91
92Tenseur log (const Tenseur& t) {
93
94 assert (t.get_etat() != ETATNONDEF) ;
95 assert (t.get_valence() == 0) ; // Scalaire uniquement ...
96
97 Tenseur res( *(t.get_mp()) ) ;
98 res.set_etat_qcq() ;
99 res.set() = log(t()) ;
100 return res ;
101}
102
103 //-------------//
104 // Square root //
105 //-------------//
106
108
109 assert (t.get_etat() != ETATNONDEF) ;
110 assert (t.get_valence() == 0) ; // Scalaire uniquement ...
111
112 Tenseur res( *(t.get_mp()), t.get_metric(), 0.5*t.get_poids() ) ;
113 res.set_etat_qcq() ;
114 res.set() = sqrt(t()) ;
115 return res ;
116}
117
118 //----------------//
119 // Absolute value //
120 //----------------//
121
122Tenseur abs(const Tenseur& t) {
123
124 assert (t.get_etat() != ETATNONDEF) ;
125 assert (t.get_valence() == 0) ; // Scalaire uniquement ...
126
127 Tenseur res( *(t.get_mp()), t.get_metric(), t.get_poids() ) ;
128 res.set_etat_qcq() ;
129 res.set() = abs(t()) ;
130 return res ;
131}
132
133 //--------------//
134 // Power^double //
135 //--------------//
136
137Tenseur pow (const Tenseur& t, double a) {
138
139 assert (t.get_etat() != ETATNONDEF) ;
140 assert (t.get_valence() == 0) ; // Scalaire uniquement ...
141
142 Tenseur res( *(t.get_mp()), t.get_metric(), a*t.get_poids() ) ;
143 res.set_etat_qcq() ;
144 if (t.get_etat() == ETATZERO)
145 if (a > double(0)) {
146 res.set_etat_zero() ;
147 res.set_std_base() ;
148 return res ;
149 }
150 else {
151 cout << "pow(Tenseur, double) : ETATZERO^x with x <= 0 !" << endl ;
152 abort() ;
153 }
154 else {
155 assert(t.get_etat() == ETATQCQ) ;
156 res.set() = pow( t(), a ) ;
157 }
158 res.set_std_base() ;
159 return res ;
160}
161
162 //--------------//
163 // Power^int //
164 //--------------//
165
166Tenseur pow (const Tenseur& t, int n) {
167
168 assert (t.get_etat() != ETATNONDEF) ;
169 assert (t.get_valence() == 0) ; // Scalaire uniquement ...
170
171 Tenseur res( *(t.get_mp()), t.get_metric(), n*t.get_poids() ) ;
172 res.set_etat_qcq() ;
173 if (t.get_etat() == ETATZERO)
174 if (n > double(0)) {
175 res.set_etat_zero() ;
176 return res ;
177 }
178 else {
179 cout << "pow(Tenseur, int) : ETATZERO^n with n <= 0 !" << endl ;
180 abort() ;
181 }
182 else {
183 assert(t.get_etat() == ETATQCQ) ;
184 res.set() = pow( t(), n ) ;
185 }
186 return res ;
187}
188
189}
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition tenseur.h:304
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Definition tenseur.C:830
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition tenseur.C:642
const Map * get_mp() const
Returns pointer on the mapping.
Definition tenseur.h:702
double get_poids() const
Returns the weight.
Definition tenseur.h:741
void set_std_base()
Set the standard spectal basis of decomposition for each component.
Definition tenseur.C:1176
void set_etat_zero()
Sets the logical state to ETATZERO (zero state).
Definition tenseur.C:651
int get_valence() const
Returns the valence.
Definition tenseur.h:713
const Metrique * get_metric() const
Returns a pointer on the metric defining the conformal factor for tensor densities.
Definition tenseur.h:748
int get_etat() const
Returns the logical state.
Definition tenseur.h:710
Cmp sqrt(const Cmp &)
Square root.
Definition cmp_math.C:223
Cmp exp(const Cmp &)
Exponential.
Definition cmp_math.C:273
Cmp pow(const Cmp &, int)
Power .
Definition cmp_math.C:351
Cmp abs(const Cmp &)
Absolute value.
Definition cmp_math.C:413
Cmp log(const Cmp &)
Neperian logarithm.
Definition cmp_math.C:299
Lorene prototypes.
Definition app_hor.h:67