KADATH
domain_shell_inner_adapted_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 #include "utilities.hpp"
22 #include "adapted.hpp"
23 #include "point.hpp"
24 #include "array_math.hpp"
25 #include "scalar.hpp"
26 #include "tensor_impl.hpp"
27 #include "tensor.hpp"
28 
29 namespace Kadath {
31 
32  // Lust start from spherical tensorial basis
33  if (so.get_basis().get_basis(dd) != SPHERICAL_BASIS) {
34  cerr << "The input tensorial basis must be spherical in Domain_shell_inner_adapted::change_basis_spher_to_cart" << endl ;
35  abort() ;
36  }
37 
38  // Need to remove the symetry :
39  int val = so.get_valence() ;
40  Array<int> type_ind (so.get_index_type()) ;
41  Tensor res (so.get_space(), val, type_ind, so.get_basis()) ;
42 
43  if (so.is_name_affected()) {
44  res.set_name_affected() ;
45  for (int i=0 ; i<val ; i++)
46  res.set_name_ind (i, so.get_name_ind()[i]) ;
47  }
48  for (int i=0 ; i<res.get_n_comp() ; i++)
49  res.set(res.indices(i)).set_domain(dd) = so(res.indices(i))(dd) ;
50 
51  // Loop on the number of indices :
52  Dim_array dimother (so.get_valence()-1) ;
53  for (int i=0 ; i<so.get_valence()-1 ; i++)
54  dimother.set(i) = 3 ;
55 
56  for (int ind=0 ; ind<so.get_valence() ; ind++) {
57 
58 
59  Index posother (dimother) ;
60  do {
61 
62 
63  Index posr (so) ;
64  Index post (so) ;
65  Index posp (so) ;
66  int pos_inother= 0 ;
67  for (int conte=0 ; conte<so.get_valence() ; conte++) {
68  if (conte==ind) {
69  posr.set(conte) = 0 ;
70  post.set(conte) = 1 ;
71  posp.set(conte) = 2 ;
72  }
73  else {
74  posr.set(conte) = posother(pos_inother) ;
75  post.set(conte) = posother(pos_inother) ;
76  posp.set(conte) = posother(pos_inother) ;
77  pos_inother ++ ;
78  }
79  }
80 
81  Val_domain tmp (res(posr)(dd).mult_sin_theta() + res(post)(dd).mult_cos_theta()) ;
82  Val_domain vx (tmp.mult_cos_phi() - res(posp)(dd).mult_sin_phi()) ;
83  Val_domain vy (tmp.mult_sin_phi() + res(posp)(dd).mult_cos_phi()) ;
84  Val_domain vz (res(posr)(dd).mult_cos_theta() - res(post)(dd).mult_sin_theta()) ;
85  res.set(posr).set_domain(dd) = vx ;
86  res.set(post).set_domain(dd) = vy ;
87  res.set(posp).set_domain(dd) = vz ;
88  }
89  while (posother.inc()) ;
90  }
91 
92  res.set_basis(dd) = CARTESIAN_BASIS ;
93  return res ;
94 }
95 
97  // Must start from spherical tensorial basis
98  if (so.get_basis().get_basis(dd) != CARTESIAN_BASIS) {
99  cerr << "The input tensorial basis must be cartesian in Domain_shell_inner_adapted::change_basis_cart_to_spher" << endl ;
100  abort() ;
101  }
102  // Need to remove the symetry :
103  int val = so.get_valence() ;
104  Array<int> type_ind (so.get_index_type()) ;
105  Tensor res (so.get_space(), val, type_ind, so.get_basis()) ;
106 
107  if (so.is_name_affected()) {
108  res.set_name_affected() ;
109  for (int i=0 ; i<val ; i++)
110  res.set_name_ind (i, so.get_name_ind()[i]) ;
111  }
112  for (int i=0 ; i<res.get_n_comp() ; i++)
113  res.set(res.indices(i)).set_domain(dd) = so(res.indices(i))(dd) ;
114 
115 
116  // Loop on the number of indices :
117  Dim_array dimother (so.get_valence()-1) ;
118  for (int i=0 ; i<so.get_valence()-1 ; i++)
119  dimother.set(i) = 3 ;
120 
121  for (int ind=0 ; ind<so.get_valence() ; ind++) {
122 
123 
124  Index posother (dimother) ;
125  do {
126  Index posx (so) ;
127  Index posy (so) ;
128  Index posz (so) ;
129  int pos_inother= 0 ;
130  for (int conte=0 ; conte<so.get_valence() ; conte++) {
131  if (conte==ind) {
132  posx.set(conte) = 0 ;
133  posy.set(conte) = 1 ;
134  posz.set(conte) = 2 ;
135  }
136  else {
137  posx.set(conte) = posother(pos_inother) ;
138  posy.set(conte) = posother(pos_inother) ;
139  posz.set(conte) = posother(pos_inother) ;
140  pos_inother ++ ;
141  }
142  }
143 
144  Val_domain tmp (res(posx)(dd).mult_cos_phi() + res(posy)(dd).mult_sin_phi()) ;
145  Val_domain vr (tmp.mult_sin_theta() + res(posz)(dd).mult_cos_theta()) ;
146  Val_domain vt (tmp.mult_cos_theta() - res(posz)(dd).mult_sin_theta()) ;
147  Val_domain vp (-res(posx)(dd).mult_sin_phi() + res(posy)(dd).mult_cos_phi()) ;
148 
149  res.set(posx).set_domain(dd) = vr ;
150  res.set(posy).set_domain(dd) = vt ;
151  res.set(posz).set_domain(dd) = vp ;
152  }
153  while (posother.inc()) ;
154  }
155 
156 
157  res.set_basis(dd) = SPHERICAL_BASIS ;
158  return res ;
159 }
160 }
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, const Tensor &) const
Changes the tensorial basis from Cartsian to spherical in a given domain.
virtual Val_domain mult_sin_theta(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_cos_phi(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_sin_phi(const Val_domain &) const
Multiplication by .
virtual Tensor change_basis_spher_to_cart(int, const Tensor &) const
Changes the tensorial basis from spherical to Cartesian in a given domain.
virtual Val_domain mult_cos_theta(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 .