LORENE
tenseur_sym_arithm.C
1 /*
2  * Arithmetics functions for the Tenseur_sym class.
3  *
4  * These functions are not member functions of the Tenseur_sym class.
5  *
6  * (see file tenseur.h for documentation).
7  *
8  */
9 
10 /*
11  * Copyright (c) 1999-2001 Philippe Grandclement
12  * Copyright (c) 2000-2001 Eric Gourgoulhon
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_sym_arithm_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_sym_arithm.C,v 1.7 2014/10/13 08:53:42 j_novak Exp $" ;
34 
35 /*
36  * $Id: tenseur_sym_arithm.C,v 1.7 2014/10/13 08:53:42 j_novak Exp $
37  * $Log: tenseur_sym_arithm.C,v $
38  * Revision 1.7 2014/10/13 08:53:42 j_novak
39  * Lorene classes and functions now belong to the namespace Lorene.
40  *
41  * Revision 1.6 2014/10/06 15:13:19 j_novak
42  * Modified #include directives to use c++ syntax.
43  *
44  * Revision 1.5 2003/06/20 14:54:17 f_limousin
45  * Put an assert on "poids" into comments
46  *
47  * Revision 1.4 2002/10/16 14:37:15 j_novak
48  * Reorganization of #include instructions of standard C++, in order to
49  * use experimental version 3 of gcc.
50  *
51  * Revision 1.3 2002/09/06 14:49:25 j_novak
52  * Added method lie_derive for Tenseur and Tenseur_sym.
53  * Corrected various errors for derive_cov and arithmetic.
54  *
55  * Revision 1.2 2002/08/07 16:14:11 j_novak
56  * class Tenseur can now also handle tensor densities, this should be transparent to older codes
57  *
58  * Revision 1.1.1.1 2001/11/20 15:19:30 e_gourgoulhon
59  * LORENE
60  *
61  * Revision 2.3 2000/02/09 19:30:36 eric
62  * MODIF IMPORTANTE: la triade de decomposition est desormais passee en
63  * argument des constructeurs.
64  *
65  * Revision 2.2 2000/02/08 19:06:40 eric
66  * Les fonctions arithmetiques ne sont plus amies.
67  * Modif de diverses operations (notament division avec double)
68  * Ajout de nouvelles operations (par ex. Tenseur + double, etc...)
69  *
70  * Revision 2.1 2000/01/11 11:15:00 eric
71  * Gestion de la base vectorielle (triad).
72  *
73  * Revision 2.0 1999/12/02 17:18:52 phil
74  * *** empty log message ***
75  *
76  *
77  * $Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_sym_arithm.C,v 1.7 2014/10/13 08:53:42 j_novak Exp $
78  *
79  */
80 
81 // Headers C
82 #include <cstdlib>
83 #include <cassert>
84 #include <cmath>
85 
86 // Headers Lorene
87 #include "tenseur.h"
88 
89  //********************//
90  // OPERATEURS UNAIRES //
91  //********************//
92 
93 namespace Lorene {
95 
96  return t ;
97 
98 }
99 
100 
102 
103  assert (t.get_etat() != ETATNONDEF) ;
104  if (t.get_etat() == ETATZERO)
105  return t ;
106  else {
107  Tenseur_sym res(*(t.get_mp()), t.get_valence(), t.get_type_indice(),
108  *(t.get_triad()), t.get_metric(), t.get_poids() ) ;
109 
110  res.set_etat_qcq();
111  for (int i=0 ; i<res.get_n_comp() ; i++) {
112  Itbl indices (res.donne_indices(i)) ;
113  res.set(indices) = -t(indices) ;
114  }
115  return res ;
116  }
117 }
118 
119 
120  //**********//
121  // ADDITION //
122  //**********//
123 
124 Tenseur_sym operator+(const Tenseur_sym & t1, const Tenseur_sym & t2) {
125 
126  assert ((t1.get_etat() != ETATNONDEF) && (t2.get_etat() != ETATNONDEF)) ;
127  assert (t1.get_valence() == t2.get_valence()) ;
128  assert (t1.get_mp() == t2.get_mp()) ;
129  if (t1.get_valence() != 0) {
130  assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
131  }
132 
133  for (int i=0 ; i<t1.get_valence() ; i++)
134  assert(t1.get_type_indice(i) == t2.get_type_indice(i)) ;
135  assert (t1.get_metric() == t2.get_metric()) ;
136  assert (fabs(t1.get_poids() - t2.get_poids())<1.e-10) ;
137 
138  if (t1.get_etat() == ETATZERO)
139  return t2 ;
140  else if (t2.get_etat() == ETATZERO)
141  return t1 ;
142  else {
143  Tenseur_sym res(*(t1.get_mp()), t1.get_valence(),
144  t1.get_type_indice(), *(t1.get_triad()),
145  t1.get_metric(), t1.get_poids() ) ;
146 
147  res.set_etat_qcq() ;
148  for (int i=0 ; i<res.get_n_comp() ; i++) {
149  Itbl indices (res.donne_indices(i)) ;
150  res.set(indices) = t1(indices) + t2(indices) ;
151  }
152  return res ;
153  }
154 }
155 
156 
157 
158  //**************//
159  // SOUSTRACTION //
160  //**************//
161 
162 
163 Tenseur_sym operator-(const Tenseur_sym & t1, const Tenseur_sym & t2) {
164 
165  return (t1 + (-t2)) ;
166 
167 }
168 
169 
170  //****************//
171  // MULTIPLICATION //
172  //****************//
173 
174 Tenseur_sym operator*(double x, const Tenseur_sym& t) {
175 
176  assert (t.get_etat() != ETATNONDEF) ;
177  if ( (t.get_etat() == ETATZERO) || (x == double(1)) )
178  return t ;
179  else {
180  Tenseur_sym res(*(t.get_mp()), t.get_valence(), t.get_type_indice(),
181  *(t.get_triad()), t.get_metric(), t.get_poids() ) ;
182 
183  if ( x == double(0) )
184  res.set_etat_zero() ;
185  else {
186  res.set_etat_qcq() ;
187  for (int i=0 ; i<res.get_n_comp() ; i++) {
188  Itbl indices (res.donne_indices(i)) ;
189  res.set(indices) = x*t(indices) ;
190  }
191  }
192  return res ;
193  }
194 }
195 
196 
197 Tenseur_sym operator* (const Tenseur_sym& t, double x) {
198  return x * t ;
199 }
200 
202  return double(m) * t ;
203 }
204 
205 
207  return double(m) * t ;
208 }
209 
210 
211 
212  //**********//
213  // DIVISION //
214  //**********//
215 
216 Tenseur_sym operator/ (const Tenseur_sym& t1, const Tenseur& t2) {
217 
218  // Protections
219  assert(t1.get_etat() != ETATNONDEF) ;
220  assert(t2.get_etat() != ETATNONDEF) ;
221  assert(t2.get_valence() == 0) ; // t2 doit etre un scalaire !
222  assert(t1.get_mp() == t2.get_mp()) ;
223 
224  double poids_res = t1.get_poids() - t2.get_poids() ;
225  poids_res = (fabs(poids_res) < 1.e-10 ? 0. : poids_res) ;
226  const Metrique* met_res = 0x0 ;
227  if (poids_res != 0.) {
228  // assert((t1.get_metric() != 0x0) || (t2.get_metric() != 0x0)) ;
229  if (t1.get_metric() != 0x0) met_res = t1.get_metric() ;
230  else met_res = t2.get_metric() ;
231  }
232 
233  // Cas particuliers
234  if (t2.get_etat() == ETATZERO) {
235  cout << "Division by 0 in Tenseur_sym / Tenseur !" << endl ;
236  abort() ;
237  }
238  if (t1.get_etat() == ETATZERO) {
239  Tenseur_sym resu(t1) ;
240  resu.set_poids(poids_res) ;
241  resu.set_metric(*met_res) ;
242  return resu ;
243  }
244 
245  // Cas general
246 
247  assert(t1.get_etat() == ETATQCQ) ; // sinon...
248  assert(t2.get_etat() == ETATQCQ) ; // sinon...
249 
250  Tenseur_sym res(*(t1.get_mp()), t1.get_valence(), t1.get_type_indice(),
251  *(t1.get_triad()), met_res, poids_res ) ;
252 
253  res.set_etat_qcq() ;
254  for (int i=0 ; i<res.get_n_comp() ; i++) {
255  Itbl indices (res.donne_indices(i)) ;
256  res.set(indices) = t1(indices) / t2() ; // Cmp / Cmp
257  }
258  return res ;
259 
260 }
261 
262 
263 Tenseur_sym operator/ (const Tenseur_sym& t, double x) {
264 
265  assert (t.get_etat() != ETATNONDEF) ;
266 
267  if ( x == double(0) ) {
268  cout << "Division by 0 in Tenseur_sym / double !" << endl ;
269  abort() ;
270  }
271 
272  if ( (t.get_etat() == ETATZERO) || (x == double(1)) )
273  return t ;
274  else {
275  Tenseur_sym res(*(t.get_mp()), t.get_valence(), t.get_type_indice(),
276  *(t.get_triad()), t.get_metric(), t.get_poids() ) ;
277 
278  res.set_etat_qcq() ;
279  for (int i=0 ; i<res.get_n_comp() ; i++) {
280  Itbl indices (res.donne_indices(i)) ;
281  res.set(indices) = t(indices) / x ; // Cmp / double
282  }
283  return res ;
284  }
285 }
286 
287 
288 
290 
291  return t / double(m) ;
292 }
293 
294 
295 }
Basic integer array class.
Definition: itbl.h:122
Class intended to describe tensors with a symmetry on the two last indices *** DEPRECATED : use class...
Definition: tenseur.h:1253
virtual Itbl donne_indices(int place) const
Returns the indices of a component given by its position in the Cmp 1-D array c .
Definition: tenseur_sym.C:252
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition: tenseur.h:301
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Definition: tenseur.C:824
int get_type_indice(int i) const
Returns the type of the index number i .
Definition: tenseur.h:726
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tenseur.C:636
double get_poids() const
Returns the weight.
Definition: tenseur.h:738
const Map * get_mp() const
Returns pointer on the mapping.
Definition: tenseur.h:699
void set_etat_zero()
Sets the logical state to ETATZERO (zero state).
Definition: tenseur.C:645
void set_poids(double weight)
Sets the weight for a tensor density.
Definition: tenseur.C:680
void set_metric(const Metrique &met)
Sets the pointer on the metric for a tensor density.
Definition: tenseur.C:685
const Metrique * get_metric() const
Returns a pointer on the metric defining the conformal factor for tensor densities.
Definition: tenseur.h:745
int get_valence() const
Returns the valence.
Definition: tenseur.h:710
int get_n_comp() const
Returns the number of components.
Definition: tenseur.h:713
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition: tenseur.h:704
int get_etat() const
Returns the logical state.
Definition: tenseur.h:707
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
Cmp operator-(const Cmp &)
- Cmp
Definition: cmp_arithm.C:108
Cmp operator/(const Cmp &, const Cmp &)
Cmp / Cmp.
Definition: cmp_arithm.C:457
Cmp operator+(const Cmp &)
Definition: cmp_arithm.C:104
Lorene prototypes.
Definition: app_hor.h:64