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
33char 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
69namespace Lorene {
70Tenseur 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
89Tenseur 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
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
119Tenseur 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
134Tenseur 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
163Tenseur 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}
Time evolution with partial storage (*** under development ***).
Definition evolution.h:371
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition tenseur.h:301
const Map * get_mp() const
Returns pointer on the mapping.
Definition tenseur.h:699
double get_poids() const
Returns the weight.
Definition tenseur.h:738
int get_valence() const
Returns the valence.
Definition tenseur.h:710
const Metrique * get_metric() const
Returns a pointer on the metric defining the conformal factor for tensor densities.
Definition tenseur.h:745
int get_etat() const
Returns the logical state.
Definition tenseur.h:707
Cmp sqrt(const Cmp &)
Square root.
Definition cmp_math.C:220
Cmp exp(const Cmp &)
Exponential.
Definition cmp_math.C:270
Cmp pow(const Cmp &, int)
Power .
Definition cmp_math.C:348
Cmp abs(const Cmp &)
Absolute value.
Definition cmp_math.C:410
Cmp log(const Cmp &)
Neperian logarithm.
Definition cmp_math.C:296
Lorene prototypes.
Definition app_hor.h:64