KADATH
ope_change_basis.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 "ope_eq.hpp"
21 #include "scalar.hpp"
22 #include "tensor_impl.hpp"
23 #include "tensor.hpp"
24 namespace Kadath {
25 Ope_change_basis::Ope_change_basis (const System_of_eqs* zesys, int base, Ope_eq* target) : Ope_eq(zesys, target->get_dom(), 1), target_basis(base) {
26  parts[0] = target ;
27 }
28 
30 }
31 
33 
34  Term_eq target (parts[0]->action()) ;
35  // Check it is a tensor
36  if (target.type_data != TERM_T) {
37  cerr << "Ope_dn only defined with respect for a tensor" << endl ;
38  abort() ;
39  }
40 
41  switch (target_basis) {
42  case SPHERICAL_BASIS: {
43  Tensor res_val (target.val_t->get_space().get_domain(dom)->change_basis_cart_to_spher(dom, *target.val_t)) ;
44  if (target.der_t==0x0) {
45  return Term_eq(dom, res_val) ;
46  }
47  else {
48  Tensor res_der (target.val_t->get_space().get_domain(dom)->change_basis_cart_to_spher(dom, *target.der_t)) ;
49  return Term_eq (dom, res_val, res_der) ;
50  }
51  }
52  case CARTESIAN_BASIS: {
53  Tensor res_val (target.val_t->get_space().get_domain(dom)->change_basis_spher_to_cart(dom, *target.val_t)) ;
54  if (target.der_t==0x0) {
55  return Term_eq(dom, res_val) ;
56  }
57  else {
58  Tensor res_der (target.val_t->get_space().get_domain(dom)->change_basis_spher_to_cart(dom, *target.der_t)) ;
59  return Term_eq (dom, res_val, res_der) ;
60  }
61  }
62  default:
63  cerr << "Unknown target tensorial basis in Ope_change_basis::action" << endl ;
64  abort() ;
65  }
66 }}
virtual Tensor change_basis_cart_to_spher(int dd, const Tensor &so) const
Changes the tensorial basis from Cartsian to spherical in a given domain.
Definition: domain.cpp:1357
virtual Tensor change_basis_spher_to_cart(int dd, const Tensor &so) const
Changes the tensorial basis from spherical to Cartesian in a given domain.
Definition: domain.cpp:1363
Ope_change_basis(const System_of_eqs *syst, int target, Ope_eq *so)
Constructor.
int target_basis
The desired tensorial basis.
Definition: ope_eq.hpp:1320
~Ope_change_basis() override
Destructor.
Term_eq action() const override
Computes the action of the current Ope_eq using its various parts.
Abstract class that describes the various operators that can appear in the equations.
Definition: ope_eq.hpp:32
MMPtr_array< Ope_eq > parts
Pointers of the various parts of the current operator.
Definition: ope_eq.hpp:38
int dom
Index of the Domain where the operator is defined.
Definition: ope_eq.hpp:36
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
Class used to describe and solve a system of equations.
Tensor handling.
Definition: tensor.hpp:149
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
This class is intended to describe the manage objects appearing in the equations.
Definition: term_eq.hpp:62
Tensor * der_t
Pointer on the variation, if the Term_eq is a Tensor.
Definition: term_eq.hpp:69
const int type_data
Flag describing the type of data :
Definition: term_eq.hpp:75
Tensor * val_t
Pointer on the value, if the Term_eq is a Tensor.
Definition: term_eq.hpp:68