21 #include "tensor_impl.hpp"
41 cerr <<
"Indices do not match in affecte_one_dom" << endl ;
48 for (
int j=0 ; j<so->
valence ; j++)
49 ind_so.
set(perm(j)) = ind(j) ;
85 for (
int i=0 ; i<t1.
valence ; i++)
88 for (
int i=0 ; i<res.n_comp ; i++) {
90 res.set(ind).set_domain(dd) = t1(ind)(dd) + t2(ind)(dd) ;
97 for (
int i=0 ; i<t1.
valence ; i++)
104 cerr <<
"Indices do not match in add_one_dom" << endl ;
108 for (
int i=0 ; i<res.n_comp ; i++) {
111 for (
int j=0 ; j<t1.
valence ; j++)
112 ind_t2.
set(perm(j)) = ind(j) ;
113 res.set(ind).set_domain(dd) = t1(ind)(dd) + t2(ind_t2)(dd) ;
120 res.set_parameters().set_m_quant() = m_res ;
131 for (
int i=0 ; i<res.
n_comp ; i++)
132 res.
cmp[i]->set_domain(dd) = t(res.
indices(i))(dd)+xx ;
145 for (
int i=0 ; i<res.
n_comp ; i++)
146 res.
cmp[i]->set_domain(dd) = t(res.
indices(i))(dd)+xx ;
183 for (
int i=0 ; i<t1.
valence ; i++)
186 for (
int i=0 ; i<res.n_comp ; i++) {
188 res.set(ind).set_domain(dd) = t1(ind)(dd) - t2(ind)(dd) ;
195 for (
int i=0 ; i<t1.
valence ; i++)
202 cerr <<
"Indices do not match in sub_one_dom" << endl ;
206 for (
int i=0 ; i<res.n_comp ; i++) {
209 for (
int j=0 ; j<t1.
valence ; j++)
210 ind_t2.
set(perm(j)) = ind(j) ;
211 res.set(ind).set_domain(dd) = t1(ind)(dd) - t2(ind_t2)(dd) ;
218 res.set_parameters().set_m_quant() = m_res ;
229 for (
int i=0 ; i<res.
n_comp ; i++)
230 res.
cmp[i]->set_domain(dd) = t(res.
indices(i))(dd)-xx ;
242 for (
int i=0 ; i<res.
n_comp ; i++)
243 res.
cmp[i]->set_domain(dd) = -t(res.
indices(i))(dd)+xx ;
255 bool do_name = true ;
265 for (
int i=0 ; i<t1.
valence ; i++)
267 for (
int i=0 ; i<t2.
valence ; i++)
275 for (
int i=0 ; i<res.n_comp ; i++) {
276 ind_res = res.indices(i) ;
277 for (
int j=0 ; j<t1.
valence ; j++)
278 ind1.
set(j) = ind_res(j) ;
279 for (
int j=0 ; j<t2.
valence ; j++)
281 res.set(ind_res).set_domain(dd) = (t1(ind1))(dd) * (t2(ind2))(dd) ;
287 res.set_parameters().set_m_quant() = m_res ;
297 for (
int i=0 ; i<t2.
valence ; i++)
300 for (
int i=0 ; i<t1.
valence ; i++) {
302 for (
int j=0 ; j<t2.
valence ; j++)
308 cerr <<
"Can not sum on indices of the same type in operator*" << endl ;
315 for (
int i=0 ; i<t1.
valence ; i++)
318 for (
int i=0 ; i<t2.
valence ; i++)
327 for (
int i=0 ; i<t1.
valence ; i++)
332 for (
int i=0 ; i<t2.
valence ; i++)
345 for (
int i=0 ; i<t1.
valence ; i++)
350 for (
int i=0 ; i<t2.
valence ; i++)
361 Index pos_res (res) ;
368 for (
int i=0 ; i<t1.
valence ; i++)
370 if (pos_t1(i)!=pos_t2(sum_1(i)))
375 for (
int i=0 ; i<t1.
valence ; i++)
377 pos_res.
set(conte) = pos_t1(i) ;
380 for (
int i=0 ; i<t2.
valence ; i++)
382 pos_res.
set(conte) = pos_t2(i) ;
385 int ind (res.position(pos_res)) ;
387 res.set(pos_res).set_domain(dd) = t1(pos_t1)(dd)*t2(pos_t2)(dd) ;
388 first.
set(ind) = false ;
391 res.set(pos_res).set_domain(dd) += t1(pos_t1)(dd)*t2(pos_t2)(dd) ;
394 while (pos_t2.
inc()) ;
396 while (pos_t1.
inc()) ;
401 res.set_parameters().set_m_quant() = m_res ;
417 for (
int i=0 ; i<t1.
valence ; i++)
419 if (pos_t1(i)!=pos_t2(sum_1(i)))
424 res.
set_domain(dd) = t1(pos_t1)(dd)*t2(pos_t2)(dd) ;
428 res.
set_domain(dd) += t1(pos_t1)(dd)*t2(pos_t2)(dd) ;
431 while (pos_t2.
inc()) ;
433 while (pos_t1.
inc()) ;
446 for (
int i=0 ; i<res.
n_comp ; i++)
447 res.
cmp[i]->set_domain(dd) = t(res.
indices(i))(dd)*xx ;
452 for (
int i=0 ; i<res.
valence ; i++)
463 for (
int i=0 ; i<res.
n_comp ; i++)
464 res.
cmp[i]->set_domain(dd) = t(res.
indices(i))(dd)*xx ;
469 for (
int i=0 ; i<res.
valence ; i++)
480 for (
int i=0 ; i<res.
n_comp ; i++)
481 res.
cmp[i]->set_domain(dd) = t(res.
indices(i))(dd)*mm ;
486 for (
int i=0 ; i<res.
valence ; i++)
497 for (
int i=0 ; i<res.
n_comp ; i++)
498 res.
cmp[i]->set_domain(dd) = t(res.
indices(i))(dd)*mm ;
503 for (
int i=0 ; i<res.
valence ; i++)
514 cerr <<
"Division only defined for a scalar" << endl ;
519 for (
int i=0 ; i<res.
n_comp ; i++)
520 res.
cmp[i]->set_domain(dd) = t1(res.
indices(i))(dd)/(*t2.
cmp[0])(dd) ;
525 for (
int i=0 ; i<res.
valence ; i++)
540 cerr <<
"Division only defined for a scalar" << endl ;
545 res.
cmp[0]->set_domain(dd) = x/(*t.
cmp[0])(dd) ;
557 for (
int i=0 ; i<res.
n_comp ; i++)
558 res.
cmp[i]->set_domain(dd) = t(res.
indices(i))(dd)/xx ;
563 for (
int i=0 ; i<res.
valence ; i++)
580 Tensor auxi (mult_one_dom(dd, t1(ind), t2(ind))) ;
581 for (
int i=1 ; i<t1.
n_comp ; i++) {
583 auxi = add_one_dom(dd, auxi, mult_one_dom(dd, t1(ind), t2(ind))) ;
593 cerr <<
"Names of indices must be affected in Tensor::do_summation" << endl ;
601 for (
int i=0 ; i<
valence ; i++)
602 for (
int j=i+1 ; j<
valence ; j++) {
606 if ((nsame(i)>1) || (nsame(j)>1)) {
607 cerr <<
"Too many identical indices in Tensor::do_summation_one_dom" << endl ;
613 cerr <<
"Can not sum on indices of the same type in Tensor::do_summation_one_dom" << endl ;
619 int valence_res = 0 ;
620 for (
int i=0 ; i<
valence ; i++)
625 if (valence_res > 0) {
627 char* name_ind_res =
new char[valence_res] ;
629 for (
int i=0 ; i<
valence ; i++)
638 for (
int i=0 ; i<valence_res ; i++)
640 delete [] name_ind_res ;
643 Index pos_res (res) ;
647 while (pos_res.inc()) ;
656 for (
int i=0 ; i<
valence ; i++)
657 if ((nsame(i)!=0) && (pos(sum_ind(i))!=pos(i)))
662 for (
int i=0 ; i<
valence ; i++)
664 pos_res.set(conte)=pos(i) ;
670 first.
set(ind) = false ;
686 for (
int i=0 ; i<
valence ; i++)
687 if (pos(sum_ind(i))!=pos(i))
706 cerr <<
"Partial_one_dom only defined with respect to cartesian basis so far" << endl ;
712 for (
int i=0 ; i<so.
valence ; i++)
717 type_res.
set(0) = COV ;
718 for (
int i=0 ; i<so.
valence ; i++)
728 for (
int i=0 ; i<so.
valence ; i++)
729 pos_so.
set(i) = pos(i+1) ;
730 res.
set(pos).
set_domain(dd) = so(pos_so)(dd).der_abs(pos(0)+1) ;
737 for (
int i=0 ; i<so.
valence ; i++)
749 cerr <<
"sqrt_one_dom only defined for scalars" << endl ;
reference set(const Index &pos)
Read/write of an element.
Describes the tensorial basis used by the various tensors.
int get_basis(int nd) const
Read only the basis in a given domain.
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.
int & set_m_quant()
Sets .
The class Scalar does not really implements scalars in the mathematical sense but rather tensorial co...
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
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.
void set_name_ind(int dd, char name)
Sets the name of one index ; the names must have been affected first.
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.
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...)
void set_name_affected()
Affects the name of the indices.
int(* give_place_index)(const Index &, int)
Pointer on the function that gives the storage location corresponding to a set of indices values....
Array< int > type_indice
1D array of integers of size valence containing the type of each index: COV for a covariant one and C...
Param_tensor parameters
Possible additional parameters relevant for the current Tensor.
Array< int >(* give_indices)(int, int, int)
Pointer on the function that gives the indices corresponding to a give storage location.
Param_tensor & set_parameters()
Read/write of the parameters.
Memory_mapped_array< Scalar * > cmp
Array of size n_comp of pointers onto the components.
const Param_tensor & get_parameters() const
Returns a pointer on the possible additional parameter.
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
char const * get_name_ind() const
int get_n_comp() const
Returns the number of stored components.
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.
int get_valence() const
Returns the valence.
virtual int position(const Array< int > &idx) const
Gives the location of a given component in the array used for storage (Array version).
bool is_name_affected() const
Check whether the names of the indices have been affected.
Tensor do_summation_one_dom(int dd) const
Does the inner contraction of the Tensor in a given domain.
int(* give_place_array)(const Array< int > &, int)
Pointer on the function that gives the storage location corresponding to a set of indices values....
const Space & get_space() const
Returns the Space.
Base_spectral & set_base()
Sets the basis of decomposition.