LORENE
tensor_sym_calculus.C
1/*
2 * Tensor calculus for class Tensor_sym
3 *
4 *
5 */
6
7/*
8 * Copyright (c) 2004 Eric Gourgoulhon & Jerome Novak
9 *
10 * Copyright (c) 1999-2001 Philippe Grandclement (for preceding class Tenseur)
11 *
12 * This file is part of LORENE.
13 *
14 * LORENE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * LORENE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with LORENE; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30
31
32
33/*
34 * $Id: tensor_sym_calculus.C,v 1.6 2016/12/05 16:18:18 j_novak Exp $
35 * $Log: tensor_sym_calculus.C,v $
36 * Revision 1.6 2016/12/05 16:18:18 j_novak
37 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
38 *
39 * Revision 1.5 2014/10/13 08:53:44 j_novak
40 * Lorene classes and functions now belong to the namespace Lorene.
41 *
42 * Revision 1.4 2014/10/06 15:13:20 j_novak
43 * Modified #include directives to use c++ syntax.
44 *
45 * Revision 1.3 2004/02/26 22:50:33 e_gourgoulhon
46 * Added methods derive_cov, derive_con and derive_lie.
47 *
48 * Revision 1.2 2004/01/30 12:44:53 e_gourgoulhon
49 * Added Tensor_sym operator*(const Tensor_sym&, const Tensor_sym& ).
50 *
51 * Revision 1.1 2004/01/08 09:22:40 e_gourgoulhon
52 * First version.
53 *
54 *
55 * $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_sym_calculus.C,v 1.6 2016/12/05 16:18:18 j_novak Exp $
56 *
57 */
58
59// Headers C
60#include <cstdlib>
61#include <cassert>
62#include <cmath>
63
64// Headers Lorene
65#include "tensor.h"
66
67// Tensorial product
68//------------------
69
70namespace Lorene {
71Tensor_sym operator*(const Tensor_sym& t1, const Tensor& t2) {
72
73 assert (t1.mp == t2.mp) ;
74
75 int val_res = t1.valence + t2.valence ;
76
77 Itbl tipe(val_res) ;
78
79 for (int i=0 ; i<t1.valence ; i++)
80 tipe.set(i) = t1.type_indice(i) ;
81 for (int i=0 ; i<t2.valence ; i++)
82 tipe.set(i+t1.valence) = t2.type_indice(i) ;
83
84
85 const Base_vect* triad_res = t1.get_triad() ;
86
87 if ( t2.valence != 0 ) {
88 assert ( *(t2.get_triad()) == *triad_res ) ;
89 }
90
91 Tensor_sym res(*t1.mp, val_res, tipe, *triad_res, t1.sym_index1(),
92 t1.sym_index2()) ;
93
94 Itbl jeux_indice_t1(t1.valence) ;
95 Itbl jeux_indice_t2(t2.valence) ;
96
97 for (int i=0 ; i<res.n_comp ; i++) {
98 Itbl jeux_indice_res(res.indices(i)) ;
99 for (int j=0 ; j<t1.valence ; j++)
100 jeux_indice_t1.set(j) = jeux_indice_res(j) ;
101 for (int j=0 ; j<t2.valence ; j++)
102 jeux_indice_t2.set(j) = jeux_indice_res(j+t1.valence) ;
103
104 res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
105 }
106
107 return res ;
108}
109
110
111Tensor_sym operator*(const Tensor& t1, const Tensor_sym& t2) {
112
113 assert (t1.mp == t2.mp) ;
114
115 int val_res = t1.valence + t2.valence ;
116
117 Itbl tipe(val_res) ;
118
119 for (int i=0 ; i<t1.valence ; i++)
120 tipe.set(i) = t1.type_indice(i) ;
121 for (int i=0 ; i<t2.valence ; i++)
122 tipe.set(i+t1.valence) = t2.type_indice(i) ;
123
124
125 const Base_vect* triad_res = t2.get_triad() ;
126
127 if ( t1.valence != 0 ) {
128 assert ( *(t1.get_triad()) == *triad_res ) ;
129 }
130
131 int ids1 = t2.sym_index1() + t1.valence ; // symmetry index 1 of the result
132 int ids2 = t2.sym_index2() + t1.valence ; // symmetry index 2 of the result
133
134 Tensor_sym res(*t2.mp, val_res, tipe, *triad_res, ids1, ids2) ;
135
136 Itbl jeux_indice_t1(t1.valence) ;
137 Itbl jeux_indice_t2(t2.valence) ;
138
139 for (int i=0 ; i<res.n_comp ; i++) {
140 Itbl jeux_indice_res(res.indices(i)) ;
141 for (int j=0 ; j<t1.valence ; j++)
142 jeux_indice_t1.set(j) = jeux_indice_res(j) ;
143 for (int j=0 ; j<t2.valence ; j++)
144 jeux_indice_t2.set(j) = jeux_indice_res(j+t1.valence) ;
145
146 res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
147 }
148
149 return res ;
150}
151
152
153
154Tensor_sym operator*(const Tensor_sym& t1, const Tensor_sym& t2) {
155
156 assert (t1.mp == t2.mp) ;
157
158 int val_res = t1.valence + t2.valence ;
159
160 Itbl tipe(val_res) ;
161
162 for (int i=0 ; i<t1.valence ; i++)
163 tipe.set(i) = t1.type_indice(i) ;
164 for (int i=0 ; i<t2.valence ; i++)
165 tipe.set(i+t1.valence) = t2.type_indice(i) ;
166
167
168 const Base_vect* triad_res = t1.get_triad() ;
169
170 assert ( *(t2.get_triad()) == *triad_res ) ;
171
172 Tensor_sym res(*t1.mp, val_res, tipe, *triad_res, t1.sym_index1(),
173 t1.sym_index2()) ;
174
175 Itbl jeux_indice_t1(t1.valence) ;
176 Itbl jeux_indice_t2(t2.valence) ;
177
178 for (int i=0 ; i<res.n_comp ; i++) {
179 Itbl jeux_indice_res(res.indices(i)) ;
180 for (int j=0 ; j<t1.valence ; j++)
181 jeux_indice_t1.set(j) = jeux_indice_res(j) ;
182 for (int j=0 ; j<t2.valence ; j++)
183 jeux_indice_t2.set(j) = jeux_indice_res(j+t1.valence) ;
184
185 res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
186 }
187
188 return res ;
189}
190
191 //--------------------------//
192 // Covariant derivatives //
193 //--------------------------//
194
195const Tensor_sym& Tensor_sym::derive_cov(const Metric& gam) const {
196
197 const Tensor_sym* p_resu =
198 dynamic_cast<const Tensor_sym*>( &(Tensor::derive_cov(gam)) ) ;
199
200 assert(p_resu != 0x0) ;
201
202 return *p_resu ;
203
204}
205
206
207const Tensor_sym& Tensor_sym::derive_con(const Metric& gam) const {
208
209 const Tensor_sym* p_resu =
210 dynamic_cast<const Tensor_sym*>( &(Tensor::derive_con(gam)) ) ;
211
212 assert(p_resu != 0x0) ;
213
214 return *p_resu ;
215
216}
217
218 //--------------------------//
219 // Lie derivative //
220 //--------------------------//
221
222Tensor_sym Tensor_sym::derive_lie(const Vector& vv) const {
223
225
226 compute_derive_lie(vv, resu) ;
227
228 return resu ;
229
230}
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249}
Vectorial bases (triads) with respect to which the tensorial components are defined.
Definition base_vect.h:105
Basic integer array class.
Definition itbl.h:122
int & set(int i)
Read/write of a particular element (index i ) (1D case).
Definition itbl.h:247
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
Tensor_sym derive_lie(const Vector &v) const
Computes the Lie derivative of this with respect to some vector field v.
int sym_index1() const
Number of the first symmetric index (0<= id_sym1 < valence ).
Definition tensor.h:1162
const Tensor_sym & derive_cov(const Metric &gam) const
Returns the covariant derivative of this with respect to some metric .
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
Definition tensor.h:301
virtual Itbl indices(int pos) const
Returns the indices of a component given by its position in the array cmp .
Definition tensor_sym.C:313
int sym_index2() const
Number of the second symmetric index (id_sym1 < id_sym2 < valence ).
Definition tensor.h:1167
const Tensor & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of this with respect to some metric , by raising the last inde...
Definition tensor.C:1023
int id_sym1
Number of the first symmetric index (0<= id_sym1 < valence ).
Definition tensor.h:1057
Tensor(const Map &map, int val, const Itbl &tipe, const Base_vect &triad_i)
Standard constructor.
Definition tensor.C:211
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...).
Definition tensor.h:304
Tensor_sym(const Map &map, int val, const Itbl &tipe, const Base_vect &triad_i, int index_sym1, int index_sym2)
Standard constructor.
Definition tensor_sym.C:72
int id_sym2
Number of the second symmetric index (id_sym1 < id_sym2 < valence ).
Definition tensor.h:1062
void compute_derive_lie(const Vector &v, Tensor &resu) const
Computes the Lie derivative of this with respect to some vector field v (protected method; the public...
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition tensor.h:879
int n_comp
Number of stored components, depending on the symmetry.
Definition tensor.h:318
const Tensor_sym & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of this with respect to some metric , by raising the last inde...
const Tensor & derive_cov(const Metric &gam) const
Returns the covariant derivative of this with respect to some metric .
Definition tensor.C:1011
Itbl type_indice
1D array of integers (class Itbl ) of size valence containing the type of each index: COV for a cov...
Definition tensor.h:316
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition tensor.C:663
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
Definition tensor.h:309
Lorene prototypes.
Definition app_hor.h:67