KADATH
ope_sqrt_nonstd.cpp
1 /*
2  Copyright 2018 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 namespace Kadath {
24 Ope_sqrt_nonstd::Ope_sqrt_nonstd (const System_of_eqs* zesys, Ope_eq* target) : Ope_eq(zesys, target->get_dom(), 1) {
25  parts[0] = target ;
26 }
27 
29 }
30 
32 
33  Term_eq target (parts[0]->action()) ;
34  switch (target.type_data) {
35  case TERM_T : {
36 
37  // Check it is a scalar
38  if (target.val_t->get_valence() != 0) {
39  cerr << "Ope_sqrt_nonstd only defined with respect for a scalar" << endl ;
40  abort() ;
41  }
42 
43 
44  // To get the base
45  Val_domain rho (target.val_t->get_space().get_domain(dom)) ;
46  rho= 1 ;
47  rho.std_base() ;
48  rho = target.val_t->get_space().get_domain(dom)->mult_r(target.val_t->get_space().get_domain(dom)->mult_sin_theta(rho)) ;
49 
50  // The value
51  Tensor resval (*target.val_t, false) ;
52 
53  for (int i=0 ; i<target.val_t->get_n_comp() ; i++) {
54  Array<int> ind (target.val_t->indices(i)) ;
55  Val_domain value ((*target.val_t)(ind)(dom)) ;
56  if (value.check_if_zero())
57  resval.set(ind).set_domain(dom).set_zero() ;
58  else {
59  resval.set(ind).set_domain(dom) = sqrt(value) ;
60  // Force the base
61  resval.set(ind).set_domain(dom).set_base() = rho.get_base() ;
62  }
63  }
64 
65  if (target.der_t!=0x0) {
66  Tensor resder (*target.der_t, false) ;
67  for (int i=0 ; i<target.der_t->get_n_comp() ; i++) {
68  Array<int> ind (target.der_t->indices(i)) ;
69  Val_domain valder ((*target.der_t)(ind)(dom)) ;
70  Val_domain value ((*target.val_t)(ind)(dom)) ;
71  if (valder.check_if_zero())
72  resder.set(ind).set_domain(dom).set_zero() ;
73  else {
74  resder.set(ind).set_domain(dom) = target.val_t->get_space().get_domain(dom)->div_sin_theta(valder)/2./
75  target.val_t->get_space().get_domain(dom)->div_sin_theta(resval(ind)(dom)) ;
76  }
77  }
78  Term_eq res (dom, resval, resder) ;
79  return res ;
80  }
81  else {
82  Term_eq res (dom, resval) ;
83  return res ;
84  }
85  }
86  break ;
87  case TERM_D : {
88  if (target.der_d==0x0) {
89  Term_eq res (dom, sqrt(*target.val_d)) ;
90  return res ;
91  }
92  else {
93  Term_eq res (dom, sqrt(*target.val_d), (*target.der_d)/2./sqrt(*target.val_d)) ;
94  return res ;
95  }
96  }
97  break ;
98  default : {
99  cerr << "Unknown storage in Term_eq..." << endl ;
100  abort() ;
101  }
102  }
103  cerr << "Warning should not be here in Ope_sqrt_nonstd::action..." << endl ;
104  abort() ;
105 }
106 }
virtual Val_domain mult_sin_theta(const Val_domain &) const
Multiplication by .
Definition: domain.cpp:1236
virtual Val_domain div_sin_theta(const Val_domain &) const
Division by .
Definition: domain.cpp:1248
virtual Val_domain mult_r(const Val_domain &so) const
Multiplication by .
Definition: domain.cpp:1303
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
~Ope_sqrt_nonstd() override
Destructor.
Ope_sqrt_nonstd(const System_of_eqs *syst, Ope_eq *so)
Constructor.
Term_eq action() const override
Computes the action of the current Ope_eq using its various parts.
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
Definition: scalar.hpp:555
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
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
Definition: tensor_impl.hpp:91
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
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
double * val_d
Pointer on the value, if the Term_eq is a double.
Definition: term_eq.hpp:66
double * der_d
Pointer on the variation if the Term_eq is a double.
Definition: term_eq.hpp:67
Tensor * val_t
Pointer on the value, if the Term_eq is a Tensor.
Definition: term_eq.hpp:68
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
void set_zero()
Sets the Val_domain to zero (logical state to zero and arrays destroyed).
Definition: val_domain.cpp:223
bool check_if_zero() const
Check whether the logical state is zero or not.
Definition: val_domain.hpp:142
void std_base()
Sets the standard basis of decomposition.
Definition: val_domain.cpp:246
Base_spectral & set_base()
Sets the basis of decomposition.
Definition: val_domain.hpp:126
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122