20 #include "headcpp.hpp"
23 #include "tensor_impl.hpp"
40 for (
int i=0 ; i<
n_comp ; i++) {
42 *
cmp[i] = *t.
cmp[place_t] ;
50 cerr <<
"Indices do not match in Tensor::operator=" << endl ;
54 for (
int i=0 ; i<
n_comp ; i++) {
58 ind_t.
set(perm(j)) = ind(j) ;
65 for (
int i=0 ; i<
n_comp ; i++)
81 for (
int i=0 ; i<
n_comp ; i++) {
83 *
cmp[i] += *t.
cmp[place_t] ;
91 cerr <<
"Indices do not match in Tensor::operator+=" << endl ;
95 for (
int i=0 ; i<
n_comp ; i++) {
99 ind_t.
set(perm(j)) = ind(j) ;
100 set(ind) += t(ind_t) ;
113 for (
int i=0 ; i<
valence ; i++)
116 for (
int i=0 ; i<
n_comp ; i++) {
118 *
cmp[i] -= *t.
cmp[place_t] ;
126 cerr <<
"Indices do not match in Tensor::operator-=" << endl ;
130 for (
int i=0 ; i<
n_comp ; i++) {
133 for (
int j=0 ; j<
valence ; j++)
134 ind_t.
set(perm(j)) = ind(j) ;
135 set(ind) -= t(ind_t) ;
156 for (
int i=0 ; i<res.
valence ; i++)
160 for (
int i=0 ; i<res.
n_comp ; i++) {
162 res.
set(ind) = - (t(ind)) ;
196 for (
int i=0 ; i<res.
n_comp ; i++){
198 res.
set(ind) = res(ind)+xx ;
205 for (
int i=0 ; i<res.
n_comp ; i++){
207 res.
set(ind) = res(ind)+xx ;
241 for (
int i=0 ; i<res.
n_comp ; i++){
243 res.
set(ind) = res(ind)-xx ;
250 for (
int i=0 ; i<res.
n_comp ; i++){
252 res.
set(ind) = -res(ind)+xx ;
267 for (
int ic=0 ; ic<res.
n_comp ; ic++) {
285 for (
int i=0 ; i<res.
n_comp ; i++) {
302 for (
int i=0 ; i<res.
n_comp ; i++) {
335 for (
int i=0 ; i<t1.
valence ; i++)
337 for (
int i=0 ; i<t2.
valence ; i++)
345 for (
int i=0 ; i<res.n_comp ; i++) {
346 ind_res = res.indices(i) ;
347 for (
int j=0 ; j<t1.
valence ; j++)
348 ind1.
set(j) = ind_res(j) ;
349 for (
int j=0 ; j<t2.
valence ; j++)
351 res.set(ind_res) = t1(ind1) * t2(ind2) ;
363 for (
int i=0 ; i<t2.
valence ; i++)
366 for (
int i=0 ; i<t1.
valence ; i++) {
368 for (
int j=0 ; j<t2.
valence ; j++)
374 cerr <<
"Can not sum on indices of the same type in operator*" << endl ;
381 for (
int i=0 ; i<t1.
valence ; i++)
384 for (
int i=0 ; i<t2.
valence ; i++)
392 for (
int i=0 ; i<t1.
valence ; i++)
397 for (
int i=0 ; i<t2.
valence ; i++)
410 for (
int i=0 ; i<t1.
valence ; i++)
415 for (
int i=0 ; i<t2.
valence ; i++)
426 Index pos_res (res) ;
433 for (
int i=0 ; i<t1.
valence ; i++)
435 if (pos_t1(i)!=pos_t2(sum_1(i)))
440 for (
int i=0 ; i<t1.
valence ; i++)
442 pos_res.
set(conte) = pos_t1(i) ;
445 for (
int i=0 ; i<t2.
valence ; i++)
447 pos_res.
set(conte) = pos_t2(i) ;
451 int ind (res.position(pos_res)) ;
453 res.set(pos_res) = t1(pos_t1)*t2(pos_t2) ;
454 first.
set(ind) = false ;
457 res.set(pos_res) += t1(pos_t1)*t2(pos_t2) ;
460 while (pos_t2.
inc()) ;
462 while (pos_t1.
inc()) ;
478 for (
int i=0 ; i<t1.
valence ; i++)
480 if (pos_t1(i)!=pos_t2(sum_1(i)))
485 res = t1(pos_t1)*t2(pos_t2) ;
489 res += t1(pos_t1)*t2(pos_t2) ;
492 while (pos_t2.
inc()) ;
494 while (pos_t1.
inc()) ;
513 for (
int i=0 ; i<res.
n_comp ; i++) {
523 if ( x ==
double(0) ) {
524 cerr <<
"Division by 0 in Tensor / double !" << endl ;
533 for (
int i=0 ; i<res.
n_comp ; i++) {
543 return t / double(m) ;
561 for (
int d=0 ; d<ndom ; d++)
562 if (!so(indices)(d).check_if_zero()) {
568 double value = so(indices)(d)(pos) ;
593 for (
int d=0 ; d<ndom ; d++)
594 if (!so(indices)(d).check_if_zero()) {
600 double value = so(indices)(d)(pos) ;
reference set(const Index &pos)
Read/write of an element.
Describes the tensorial basis used by the various tensors.
Dim_array const & get_nbr_points() const
Returns the number of points.
Class that gives the position inside a multi-dimensional Array.
int & set(int i)
Read/write of the position in a given dimension.
void set_start()
Sets the position to zero in all dimensions.
bool inc(int increm, int var=0)
Increments the position of the Index.
The class Scalar does not really implements scalars in the mathematical sense but rather tensorial co...
void coef_i() const
Computes the values in the configuration space.
const Domain * get_domain(int i) const
returns a pointer on the domain.
int get_nbr_domains() const
Returns the number of Domains.
bool name_affected
Indicator that states if the indices have been given names.
Memory_mapped_array< char > name_indice
If the indices haves names they are stored here.
virtual Tensor & operator=(const Tensor &)
Assignment to a Tensor.
Base_tensor basis
Tensorial basis with respect to which the tensor components are defined.
bool find_indices(const Tensor &tt, Array< int > &output_ind) const
Checks whether the current Tensor and tt have compatible indices (i.e.
void operator-=(const Tensor &)
-= Tensor
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...)
Array< int > type_indice
1D array of integers of size valence containing the type of each index: COV for a covariant one and C...
Memory_mapped_array< Scalar * > cmp
Array of size n_comp of pointers onto the components.
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
void operator+=(const Tensor &)
+= Tensor
int get_n_comp() const
Returns the number of stored components.
Scalar & set()
Read/write for a Scalar.
virtual Array< int > indices(int pos) const
Gives the values of the indices corresponding to a location in the array used for storage of the comp...
int n_comp
Number of stored components, depending on the symmetry.
const Space & espace
The Space.
virtual int position(const Array< int > &idx) const
Gives the location of a given component in the array used for storage (Array version).
const Space & get_space() const
Returns the Space.