KADATH
domain_fourD_periodic_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 "fourD_periodic.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "tensor.hpp"
27 namespace Kadath {
28 
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_fourD_periodic_nucleus::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) = 4 ;
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 
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 
96 }
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_cos_phi(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_sin_phi(const Val_domain &) const
Multiplication by .
virtual Val_domain mult_cos_theta(const Val_domain &) const
Multiplication by .
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.
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_cos_phi() const
Multiplication by .