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