LORENE
tensor_sym_arithm.C
1/*
2 * Arithmetics Tensor_sym
3 *
4 * (see file tensor.h for documentation)
5 *
6 */
7
8/*
9 * Copyright (c) 2004 Eric Gourgoulhon & Jerome Novak
10 *
11 * Copyright (c) 1999-2001 Philippe Grandclement (for preceding class Tenseur)
12 *
13 * This file is part of LORENE.
14 *
15 * LORENE is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * LORENE is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with LORENE; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 */
30
31
32
33
34/*
35 * $Id: tensor_sym_arithm.C,v 1.4 2016/12/05 16:18:18 j_novak Exp $
36 * $Log: tensor_sym_arithm.C,v $
37 * Revision 1.4 2016/12/05 16:18:18 j_novak
38 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
39 *
40 * Revision 1.3 2014/10/13 08:53:44 j_novak
41 * Lorene classes and functions now belong to the namespace Lorene.
42 *
43 * Revision 1.2 2014/10/06 15:13:20 j_novak
44 * Modified #include directives to use c++ syntax.
45 *
46 * Revision 1.1 2004/01/08 09:22:40 e_gourgoulhon
47 * First version.
48 *
49 *
50 * $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_sym_arithm.C,v 1.4 2016/12/05 16:18:18 j_novak Exp $
51 *
52 */
53
54// Headers C
55#include <cstdlib>
56#include <cassert>
57#include <cmath>
58
59// Headers Lorene
60#include "tensor.h"
61 //********************//
62 // OPERATEURS UNAIRES //
63 //********************//
64
65namespace Lorene {
67
68 return t ;
69
70}
71
72
74
75 Tensor_sym res(tt.get_mp(), tt.get_valence(), tt.get_index_type(),
76 *(tt.get_triad()), tt.sym_index1(), tt.sym_index2()) ;
77
78 for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
79 Itbl ind = res.indices(ic) ;
80 res.set(ind) = -tt(ind) ;
81 }
82 return res ;
83
84}
85
86 //**********//
87 // ADDITION //
88 //**********//
89
90
92
93 assert (t1.get_valence() == t2.get_valence()) ;
94 assert (t1.get_mp() == t2.get_mp()) ;
95 assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
96
97 for (int id=0 ; id<t1.get_valence() ; id++)
98 assert(t1.get_index_type(id) == t2.get_index_type(id)) ;
99
100 int ids1 = t1.sym_index1() ;
101 int ids2 = t1.sym_index2() ;
102
103 assert(t2.sym_index1() == ids1) ;
104 assert(t2.sym_index2() == ids2) ;
105
106 Tensor_sym res(t1.get_mp(), t1.get_valence(), t1.get_index_type(),
107 *(t1.get_triad()), ids1, ids2) ;
108
109 for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
110 Itbl ind = res.indices(ic) ;
111 res.set(ind) = t1(ind) + t2(ind) ;
112 }
113 return res ;
114
115}
116
117 //**************//
118 // SOUSTRACTION //
119 //**************//
120
121
123
124 assert (t1.get_valence() == t2.get_valence()) ;
125 assert (t1.get_mp() == t2.get_mp()) ;
126 assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
127
128 for (int id=0 ; id<t1.get_valence() ; id++)
129 assert(t1.get_index_type(id) == t2.get_index_type(id)) ;
130
131 int ids1 = t1.sym_index1() ;
132 int ids2 = t1.sym_index2() ;
133
134 assert(t2.sym_index1() == ids1) ;
135 assert(t2.sym_index2() == ids2) ;
136
137 Tensor_sym res(t1.get_mp(), t1.get_valence(), t1.get_index_type(),
138 *(t1.get_triad()), ids1, ids2) ;
139
140 for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
141 Itbl ind = res.indices(ic) ;
142 res.set(ind) = t1(ind) - t2(ind) ;
143 }
144 return res ;
145
146}
147
148
149
150 //****************//
151 // MULTIPLICATION //
152 //****************//
153
154
155Tensor_sym operator*(const Scalar& t1, const Tensor_sym& t2) {
156
157 assert (&(t1.get_mp()) == &(t2.get_mp())) ;
158
159 if (t1.get_etat() == ETATUN) return t2 ;
160
161 Tensor_sym res(t2.get_mp(), t2.get_valence(), t2.get_index_type(),
162 *(t2.get_triad()), t2.sym_index1(), t2.sym_index2()) ;
163
164 for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
165 Itbl ind = res.indices(ic) ;
166 res.set(ind) = t1 * t2(ind) ;
167 }
168
169 return res ;
170}
171
172
173Tensor_sym operator*(const Tensor_sym& t2, const Scalar& t1) {
174
175 return t1*t2 ;
176}
177
178
179
180Tensor_sym operator*(double x, const Tensor_sym& tt) {
181
182 Tensor_sym res(tt.get_mp(), tt.get_valence(), tt.get_index_type(),
183 *(tt.get_triad()), tt.sym_index1(), tt.sym_index2()) ;
184
185 for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
186 Itbl ind = res.indices(ic) ;
187 res.set(ind) = x * tt(ind) ;
188 }
189
190 return res ;
191
192}
193
194
195Tensor_sym operator*(const Tensor_sym& t, double x) {
196 return x * t ;
197}
198
199
201 return double(m) * t ;
202}
203
204
206 return double(m) * t ;
207}
208
209
210 //**********//
211 // DIVISION //
212 //**********//
213
214Tensor_sym operator/(const Tensor_sym& t1, const Scalar& s2) {
215
216 // Protections
217 assert(s2.get_etat() != ETATNONDEF) ;
218 assert(t1.get_mp() == s2.get_mp()) ;
219
220 // Cas particuliers
221 if (s2.get_etat() == ETATZERO) {
222 cout << "Division by 0 in Tensor_sym / Scalar !" << endl ;
223 abort() ;
224 }
225
226 if (s2.get_etat() == ETATUN) return t1 ;
227
228 Tensor_sym res(t1.get_mp(), t1.get_valence(), t1.get_index_type(),
229 *(t1.get_triad()), t1.sym_index1(), t1.sym_index2()) ;
230
231 for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
232 Itbl ind = res.indices(ic) ;
233 res.set(ind) = t1(ind) / s2 ;
234 }
235
236 return res ;
237
238}
239
240
241Tensor_sym operator/(const Tensor_sym& tt, double x) {
242
243 if ( x == double(0) ) {
244 cout << "Division by 0 in Tensor_sym / double !" << endl ;
245 abort() ;
246 }
247
248 if ( x == double(1) ) return tt ;
249 else {
250 Tensor_sym res(tt.get_mp(), tt.get_valence(), tt.get_index_type(),
251 *(tt.get_triad()), tt.sym_index1(), tt.sym_index2()) ;
252
253 for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
254 Itbl ind = res.indices(ic) ;
255 res.set(ind) = tt(ind) / x ;
256 }
257
258 return res ;
259 }
260
261}
262
263
265
266 return t / double(m) ;
267}
268
269
270}
Basic integer array class.
Definition itbl.h:122
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:393
int get_etat() const
Returns the logical state ETATNONDEF (undefined), ETATZERO (null) or ETATQCQ (ordinary).
Definition scalar.h:560
Symmetric tensors (with respect to two of their arguments).
Definition tensor.h:1050
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:111
Cmp operator/(const Cmp &, const Cmp &)
Cmp / Cmp.
Definition cmp_arithm.C:460
Cmp operator+(const Cmp &)
Definition cmp_arithm.C:107
const Map & get_mp() const
Returns the mapping.
Definition tensor.h:874
int sym_index1() const
Number of the first symmetric index (0<= id_sym1 < valence ).
Definition tensor.h:1162
int get_index_type(int i) const
Gives the type (covariant or contravariant) of the index number i .
Definition tensor.h:899
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
int get_valence() const
Returns the valence.
Definition tensor.h:882
int get_n_comp() const
Returns the number of stored components.
Definition tensor.h:885
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition tensor.h:879
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition tensor.C:663
Lorene prototypes.
Definition app_hor.h:67
Coord x
x coordinate centered on the grid
Definition map.h:738