LORENE
tenseur_sym_operateur.C
1 /*
2  * Copyright (c) 1999-2001 Philippe Grandclement
3  * Copyright (c) 1999-2001 Eric Gourgoulhon
4  * Copyright (c) 2002 Jerome Novak
5  *
6  * This file is part of LORENE.
7  *
8  * LORENE is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * LORENE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with LORENE; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  */
23 
24 
25 
26 
27 /*
28  * $Id: tenseur_sym_operateur.C,v 1.9 2016/12/05 16:18:17 j_novak Exp $
29  * $Log: tenseur_sym_operateur.C,v $
30  * Revision 1.9 2016/12/05 16:18:17 j_novak
31  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
32  *
33  * Revision 1.8 2014/10/13 08:53:43 j_novak
34  * Lorene classes and functions now belong to the namespace Lorene.
35  *
36  * Revision 1.7 2014/10/06 15:13:19 j_novak
37  * Modified #include directives to use c++ syntax.
38  *
39  * Revision 1.6 2003/03/03 19:41:34 f_limousin
40  * Suppression of an assert on a metric associated with a tensor.
41  *
42  * Revision 1.5 2002/10/16 14:37:15 j_novak
43  * Reorganization of #include instructions of standard C++, in order to
44  * use experimental version 3 of gcc.
45  *
46  * Revision 1.4 2002/09/10 13:44:17 j_novak
47  * The method "manipule" of one indice has been removed for Tenseur_sym objects
48  * (the result cannot be a Tenseur_sym).
49  * The method "sans_trace" now computes the traceless part of a Tenseur (or
50  * Tenseur_sym) of valence 2.
51  *
52  * Revision 1.3 2002/09/06 14:49:26 j_novak
53  * Added method lie_derive for Tenseur and Tenseur_sym.
54  * Corrected various errors for derive_cov and arithmetic.
55  *
56  * Revision 1.2 2002/08/07 16:14:12 j_novak
57  * class Tenseur can now also handle tensor densities, this should be transparent to older codes
58  *
59  * Revision 1.1.1.1 2001/11/20 15:19:30 e_gourgoulhon
60  * LORENE
61  *
62  * Revision 2.2 2000/02/09 19:32:22 eric
63  * MODIF IMPORTANTE: la triade de decomposition est desormais passee en
64  * argument des constructeurs.
65  *
66  * Revision 2.1 2000/01/11 11:15:08 eric
67  * Gestion de la base vectorielle (triad).
68  *
69  * Revision 2.0 1999/12/02 17:19:02 phil
70  * *** empty log message ***
71  *
72  *
73  * $Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_sym_operateur.C,v 1.9 2016/12/05 16:18:17 j_novak Exp $
74  *
75  */
76 
77 // Headers C
78 #include <cstdlib>
79 #include <cassert>
80 #include <cmath>
81 
82 // Headers Lorene
83 #include "tenseur.h"
84 #include "metrique.h"
85 
86 namespace Lorene {
87 Tenseur_sym operator*(const Tenseur& t1, const Tenseur_sym& t2) {
88 
89  assert ((t1.get_etat() != ETATNONDEF) && (t2.etat != ETATNONDEF)) ;
90  assert (t1.get_mp() == t2.mp) ;
91 
92  int val_res = t1.get_valence() + t2.valence ;
93  double poids_res = t1.get_poids() + t2.poids ;
94  poids_res = (fabs(poids_res) < 1.e-10 ? 0. : poids_res) ;
95  const Metrique* met_res = 0x0 ;
96  if (poids_res != 0.) {
97  // assert((t1.get_metric() != 0x0) || (t2.metric != 0x0)) ;
98  if (t1.get_metric() != 0x0) met_res = t1.get_metric() ;
99  else met_res = t2.metric ;
100  }
101 
102  Itbl tipe (val_res) ;
103  tipe.set_etat_qcq() ;
104  for (int i=0 ; i<t1.get_valence() ; i++)
105  tipe.set(i) = t1.get_type_indice(i) ;
106  for (int i=0 ; i<t2.valence ; i++)
107  tipe.set(i+t1.get_valence()) = t2.type_indice(i) ;
108 
109 
110  if ( t1.get_valence() != 0 ) {
111  assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
112  }
113 
114  Tenseur_sym res(*t1.get_mp(), val_res, tipe, *(t2.get_triad()),
115  met_res, poids_res) ;
116 
117 
118  if ((t1.get_etat() == ETATZERO) || (t2.etat == ETATZERO))
119  res.set_etat_zero() ;
120  else {
121  res.set_etat_qcq() ;
122  Itbl jeux_indice_t1 (t1.get_valence()) ;
123  jeux_indice_t1.set_etat_qcq() ;
124  Itbl jeux_indice_t2 (t2.valence) ;
125  jeux_indice_t2.set_etat_qcq() ;
126 
127  for (int i=0 ; i<res.n_comp ; i++) {
128  Itbl jeux_indice_res(res.donne_indices(i)) ;
129  for (int j=0 ; j<t1.get_valence() ; j++)
130  jeux_indice_t1.set(j) = jeux_indice_res(j) ;
131  for (int j=0 ; j<t2.valence ; j++)
132  jeux_indice_t2.set(j) = jeux_indice_res(j+t1.get_valence()) ;
133 
134  res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
135  }
136  }
137  return res ;
138 }
139 
140 Tenseur_sym manipule (const Tenseur_sym& t1, const Metrique& met) {
141 
142  Tenseur* auxi ;
143  Tenseur* auxi_old = new Tenseur(t1) ;
144 
145  for (int i=0 ; i<t1.valence ; i++) {
146  auxi = new Tenseur(manipule(*auxi_old, met, i)) ;
147  delete auxi_old ;
148  auxi_old = new Tenseur(*auxi) ;
149  delete auxi ;
150  }
151 
152  Tenseur_sym result(*auxi_old) ;
153  delete auxi_old ;
154  return result ;
155 }
156 
158  const Metrique* met)
159 {
160  assert ( (t.get_etat() != ETATNONDEF) && (x.get_etat() != ETATNONDEF) ) ;
161  assert(x.get_valence() == 1) ;
162  assert(x.get_type_indice(0) == CON) ;
163  assert(x.get_poids() == 0.) ;
164  assert(t.get_mp() == x.get_mp()) ;
165 
166  int val = t.get_valence() ;
167  double poids = t.get_poids() ;
168  Itbl tipe (val+1) ;
169  tipe.set_etat_qcq() ;
170  tipe.set(0) = COV ;
171  Itbl tipx(2) ;
172  tipx.set_etat_qcq() ;
173  tipx.set(0) = COV ;
174  tipx.set(1) = CON ;
175  for (int i=0 ; i<val ; i++)
176  tipe.set(i+1) = t.get_type_indice(i) ;
177  Tenseur_sym dt(*t.get_mp(), val+1, tipe, *t.get_triad(), t.get_metric(),
178  poids) ;
179  Tenseur dx(*x.get_mp(), 2, tipx, x.get_triad()) ;
180  if (met == 0x0) {
181  dx = x.gradient() ;
182  dt = t.gradient() ;
183  }
184  else {
185  dx = x.derive_cov(*met) ;
186  dt = t.derive_cov(*met) ;
187  }
188  Tenseur_sym resu(contract(x,0,dt,0)) ;
189  Tenseur* auxi ;
190  if ((val!=0)&&(t.get_etat()!=ETATZERO)&&(x.get_etat()!=ETATZERO)) {
191  assert(t.get_triad()->identify() == x.get_triad()->identify()) ;
192 
193  for (int i=0 ; i<val ; i++) {
194  if (t.get_type_indice(i) == COV) {
195  auxi = new Tenseur(contract(t,i,dx,1)) ;
196 
197  Itbl indices_aux(val) ;
198  indices_aux.set_etat_qcq() ;
199  for (int j=0 ; j<resu.get_n_comp() ; j++) {
200 
201  Itbl indices (resu.donne_indices(j)) ;
202  indices_aux.set(val-1) = indices(i) ;
203  for (int idx=0 ; idx<val-1 ; idx++)
204  if (idx<i)
205  indices_aux.set(idx) = indices(idx) ;
206  else
207  indices_aux.set(idx) = indices(idx+1) ;
208 
209  resu.set(indices) += (*auxi)(indices_aux) ;
210  }
211  }
212  else {
213  auxi = new Tenseur(contract(t,i,dx,0)) ;
214 
215  Itbl indices_aux(val) ;
216  indices_aux.set_etat_qcq() ;
217 
218  //On range comme il faut :
219  for (int j=0 ; j<resu.get_n_comp() ; j++) {
220 
221  Itbl indices (resu.donne_indices(j)) ;
222  indices_aux.set(val-1) = indices(i) ;
223  for (int idx=0 ; idx<val-1 ; idx++)
224  if (idx<i)
225  indices_aux.set(idx) = indices(idx) ;
226  else
227  indices_aux.set(idx) = indices(idx+1) ;
228  resu.set(indices) -= (*auxi)(indices_aux) ;
229  }
230  }
231  delete auxi ;
232  }
233  }
234  if ((poids != 0.)&&(t.get_etat()!=ETATZERO)&&(x.get_etat()!=ETATZERO))
235  resu = resu + poids*contract(dx,0,1)*t ;
236 
237  return resu ;
238 }
239 
240 Tenseur_sym sans_trace(const Tenseur_sym& t, const Metrique& metre)
241 {
242  assert(t.get_etat() != ETATNONDEF) ;
243  assert(metre.get_etat() != ETATNONDEF) ;
244  assert(t.get_valence() == 2) ;
245 
246  Tenseur_sym resu(t) ;
247  if (resu.get_etat() == ETATZERO) return resu ;
248  assert(resu.get_etat() == ETATQCQ) ;
249 
250  int t0 = t.get_type_indice(0) ;
251  int t1 = t.get_type_indice(1) ;
252  Itbl mix(2) ;
253  mix.set_etat_qcq() ;
254  mix.set(0) = (t0 == t1 ? -t0 : t0) ;
255  mix.set(1) = t1 ;
256 
257  Tenseur tmp(*t.get_mp(), 2, mix, *t.get_triad(), t.get_metric(),
258  t.get_poids()) ;
259  if (t0 == t1)
260  tmp = manipule(t, metre, 0) ;
261  else
262  tmp = t ;
263 
264  Tenseur trace(contract(tmp, 0, 1)) ;
265 
266  if (t0 == t1) {
267  switch (t0) {
268  case COV : {
269  resu = resu - 1./3.*trace * metre.cov() ;
270  break ;
271  }
272  case CON : {
273  resu = resu - 1./3.*trace * metre.con() ;
274  break ;
275  }
276  default :
277  cout << "Erreur bizarre dans sans_trace!" << endl ;
278  abort() ;
279  break ;
280  }
281  }
282  else {
283  Tenseur_sym delta(*t.get_mp(), 2, mix, *t.get_triad(),
284  t.get_metric(), t.get_poids()) ;
285  delta.set_etat_qcq() ;
286  for (int i=0; i<3; i++)
287  for (int j=i; j<3; j++)
288  delta.set(i,j) = (i==j ? 1 : 0) ;
289  resu = resu - trace/3. * delta ;
290  }
291  resu.set_std_base() ;
292  return resu ;
293 }
294 }
Itbl type_indice
Array of size valence contening the type of each index, COV for a covariant one and CON for a contrav...
Definition: tenseur.h:321
const Map *const mp
Reference mapping.
Definition: tenseur.h:309
double get_poids() const
Returns the weight.
Definition: tenseur.h:741
int get_type_indice(int i) const
Returns the type of the index number i .
Definition: tenseur.h:729
int & set(int i)
Read/write of a particular element (index i ) (1D case)
Definition: itbl.h:247
int n_comp
Number of components, depending on the symmetry.
Definition: tenseur.h:323
void set_std_base()
Set the standard spectal basis of decomposition for each component.
Definition: tenseur.C:1186
Class intended to describe tensors with a symmetry on the two last indices *** DEPRECATED : use class...
Definition: tenseur.h:1256
Lorene prototypes.
Definition: app_hor.h:67
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
int etat
Logical state ETATZERO , ETATQCQ or ETATNONDEF.
Definition: tenseur.h:324
Basic integer array class.
Definition: itbl.h:122
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:261
int get_valence() const
Returns the valence.
Definition: tenseur.h:713
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Definition: tenseur.C:840
const Map * get_mp() const
Returns pointer on the mapping.
Definition: tenseur.h:702
const Metrique * get_metric() const
Returns a pointer on the metric defining the conformal factor for tensor densities.
Definition: tenseur.h:748
int valence
Valence.
Definition: tenseur.h:310
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition: tenseur.h:707
Tenseur lie_derive(const Tenseur &t, const Tenseur &x, const Metrique *=0x0)
Lie Derivative of t with respect to x .
double poids
For tensor densities: the weight.
Definition: tenseur.h:326
virtual int identify() const =0
Returns a number to identify the sub-classe of Base_vect the object belongs to.
int get_etat() const
Returns the logical state.
Definition: tenseur.h:710
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: itbl.C:264
Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
int get_n_comp() const
Returns the number of components.
Definition: tenseur.h:716
Tenseur sans_trace(const Tenseur &tens, const Metrique &metre)
Computes the traceless part of a Tenseur of valence 2.
const Metrique * metric
For tensor densities: the metric defining the conformal factor.
Definition: tenseur.h:328
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tenseur.C:652
const Tenseur & derive_cov(const Metrique &met) const
Returns the covariant derivative of *this , with respect to met .
Definition: tenseur.C:1570
void set_etat_zero()
Sets the logical state to ETATZERO (zero state).
Definition: tenseur.C:661
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition: tenseur.h:304
const Tenseur & gradient() const
Returns the gradient of *this (Cartesian coordinates)
Definition: tenseur.C:1558
Tenseur manipule(const Tenseur &, const Metrique &, int idx)
Raise or lower the index idx depending on its type, using the given Metrique .