KADATH
domain_nucleus_change_basis_tensor.cpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "headcpp.hpp"
21 
22 #include "utilities.hpp"
23 #include "spheric.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "tensor.hpp"
27 namespace Kadath {
29 
30  // Lust start from spherical tensorial basis
31  if (so.get_basis().get_basis(dd) != SPHERICAL_BASIS) {
32  cerr << "The input tensorial basis must be spherical in Domain_nucleus::change_basis_spher_to_cart" << endl ;
33  abort() ;
34  }
35 
36  // Need to remove the symetry :
37  int val = so.get_valence() ;
38  Array<int> type_ind (so.get_index_type()) ;
39  Tensor res (so.get_space(), val, type_ind, so.get_basis()) ;
40 
41  if (so.is_name_affected()) {
42  res.set_name_affected() ;
43  for (int i=0 ; i<val ; i++)
44  res.set_name_ind (i, so.get_name_ind()[i]) ;
45  }
46  for (int i=0 ; i<res.get_n_comp() ; i++)
47  res.set(res.indices(i)).set_domain(dd) = so(res.indices(i))(dd) ;
48 
49  // Loop on the number of indices :
50  Dim_array dimother (so.get_valence()-1) ;
51  for (int i=0 ; i<so.get_valence()-1 ; i++)
52  dimother.set(i) = 3 ;
53 
54  for (int ind=0 ; ind<so.get_valence() ; ind++) {
55 
56 
57  Index posother (dimother) ;
58  do {
59 
60 
61  Index posr (so) ;
62  Index post (so) ;
63  Index posp (so) ;
64  int pos_inother= 0 ;
65  for (int conte=0 ; conte<so.get_valence() ; conte++) {
66  if (conte==ind) {
67  posr.set(conte) = 0 ;
68  post.set(conte) = 1 ;
69  posp.set(conte) = 2 ;
70  }
71  else {
72  posr.set(conte) = posother(pos_inother) ;
73  post.set(conte) = posother(pos_inother) ;
74  posp.set(conte) = posother(pos_inother) ;
75  pos_inother ++ ;
76  }
77  }
78 
79  Val_domain tmp (res(posr)(dd).mult_sin_theta() + res(post)(dd).mult_cos_theta()) ;
80  Val_domain vx (tmp.mult_cos_phi() - res(posp)(dd).mult_sin_phi()) ;
81  Val_domain vy (tmp.mult_sin_phi() + res(posp)(dd).mult_cos_phi()) ;
82  Val_domain vz (res(posr)(dd).mult_cos_theta() - res(post)(dd).mult_sin_theta()) ;
83  res.set(posr).set_domain(dd) = vx ;
84  res.set(post).set_domain(dd) = vy ;
85  res.set(posp).set_domain(dd) = vz ;
86  }
87  while (posother.inc()) ;
88  }
89 
90  res.set_basis(dd) = CARTESIAN_BASIS ;
91  return res ;
92 }
93 
95  // Must start from spherical tensorial basis
96  if (so.get_basis().get_basis(dd) != CARTESIAN_BASIS) {
97  cerr << "The input tensorial basis must be cartesian in Domain_nucleus::change_basis_cart_to_spher" << endl ;
98  abort() ;
99  }
100  // Need to remove the symetry :
101  int val = so.get_valence() ;
102  Array<int> type_ind (so.get_index_type()) ;
103  Tensor res (so.get_space(), val, type_ind, so.get_basis()) ;
104 
105  if (so.is_name_affected()) {
106  res.set_name_affected() ;
107  for (int i=0 ; i<val ; i++)
108  res.set_name_ind (i, so.get_name_ind()[i]) ;
109  }
110  for (int i=0 ; i<res.get_n_comp() ; i++)
111  res.set(res.indices(i)).set_domain(dd) = so(res.indices(i))(dd) ;
112 
113 
114  // Loop on the number of indices :
115  Dim_array dimother (so.get_valence()-1) ;
116  for (int i=0 ; i<so.get_valence()-1 ; i++)
117  dimother.set(i) = 3 ;
118 
119  for (int ind=0 ; ind<so.get_valence() ; ind++) {
120 
121 
122  Index posother (dimother) ;
123  do {
124  Index posx (so) ;
125  Index posy (so) ;
126  Index posz (so) ;
127  int pos_inother= 0 ;
128  for (int conte=0 ; conte<so.get_valence() ; conte++) {
129  if (conte==ind) {
130  posx.set(conte) = 0 ;
131  posy.set(conte) = 1 ;
132  posz.set(conte) = 2 ;
133  }
134  else {
135  posx.set(conte) = posother(pos_inother) ;
136  posy.set(conte) = posother(pos_inother) ;
137  posz.set(conte) = posother(pos_inother) ;
138  pos_inother ++ ;
139  }
140  }
141 
142  Val_domain tmp (res(posx)(dd).mult_cos_phi() + res(posy)(dd).mult_sin_phi()) ;
143  Val_domain vr (tmp.mult_sin_theta() + res(posz)(dd).mult_cos_theta()) ;
144  Val_domain vt (tmp.mult_cos_theta() - res(posz)(dd).mult_sin_theta()) ;
145  Val_domain vp (-res(posx)(dd).mult_sin_phi() + res(posy)(dd).mult_cos_phi()) ;
146 
147  res.set(posx).set_domain(dd) = vr ;
148  res.set(posy).set_domain(dd) = vt ;
149  res.set(posz).set_domain(dd) = vp ;
150  }
151  while (posother.inc()) ;
152  }
153 
154 
155  res.set_basis(dd) = SPHERICAL_BASIS ;
156  return res ;
157 }}
int get_basis(int nd) const
Read only the basis in a given domain.
Definition: base_tensor.hpp:93
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
int & set(int i)
Read/write of the size of a given dimension.
Definition: dim_array.hpp:54
virtual Tensor change_basis_cart_to_spher(int dd, const Tensor &) const
Changes the tensorial basis from Cartsian to spherical in a given domain.
virtual Tensor change_basis_spher_to_cart(int dd, const Tensor &) const
Changes the tensorial basis from spherical to Cartesian in a given domain.
virtual Val_domain mult_sin_theta(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_cos_theta(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_sin_phi(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_cos_phi(const Val_domain &) const
Multiplication by .
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
int & set(int i)
Read/write of the position in a given dimension.
Definition: index.hpp:72
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
Definition: scalar.hpp:555
Tensor handling.
Definition: tensor.hpp:149
void set_name_ind(int dd, char name)
Sets the name of one index ; the names must have been affected first.
void set_name_affected()
Affects the name of the indices.
Definition: tensor.hpp:435
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
Definition: tensor_impl.hpp:91
char const * get_name_ind() const
Definition: tensor.hpp:424
int get_index_type(int i) const
Gives the type (covariant or contravariant) of a given index.
Definition: tensor.hpp:526
const Base_tensor & get_basis() const
Returns the vectorial basis (triad) on which the components are defined.
Definition: tensor.hpp:504
int get_n_comp() const
Returns the number of stored components.
Definition: tensor.hpp:514
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...
Definition: tensor.hpp:484
int get_valence() const
Returns the valence.
Definition: tensor.hpp:509
bool is_name_affected() const
Check whether the names of the indices have been affected.
Definition: tensor.hpp:429
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
int & set_basis(int dd)
Assigns a new tensorial basis in a given domain.
Definition: tensor.hpp:331
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
Val_domain mult_sin_phi() const
Multiplication by .
Val_domain mult_sin_theta() const
Multiplication by .
Val_domain mult_cos_phi() const
Multiplication by .
Val_domain mult_cos_theta() const
Multiplication by .