KADATH
ope_pow.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 namespace Kadath {
24 Ope_pow::Ope_pow (const System_of_eqs*zesys, int nn, Ope_eq* target) : Ope_eq(zesys,target->get_dom(), 1), power(nn) {
25  parts[0] = target ;
26 }
27 
29 }
30 
32  if (power==0)
33  return Term_eq (dom, 1., 0.) ;
34  else {
35  Term_eq res_p0 (parts[0]->action()) ;
36  // Check of type and valence :
37  //int valence = res_p0.get_val_t().get_valence() ;
38  //if (valence !=0) {
39  if (res_p0.get_type_data()==TERM_T and res_p0.get_p_val_t()->get_valence() !=0) {
40  cerr << "Ope_pow only defined for scalars" << endl ;
41  abort() ;
42  }
43  Term_eq auxi (dom, res_p0.get_type_data()) ;
44  auxi = (power>0) ? res_p0 : Term_eq(dom, 1., 0.) / res_p0 ;
45  Term_eq res (auxi) ;
46  for (int i=1 ; i<fabs(power) ; i++)
47  res = res * auxi ;
48  return res ;
49  }
50 }
51 }
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
Term_eq action() const override
Computes the action of the current Ope_eq using its various parts.
Definition: ope_pow.cpp:31
Ope_pow(const System_of_eqs *syst, int pow, Ope_eq *so)
Constructor.
Definition: ope_pow.cpp:24
int power
The exponent (an integer, possibly negative).
Definition: ope_eq.hpp:110
~Ope_pow() override
Destructor.
Definition: ope_pow.cpp:28
Class used to describe and solve a system of equations.
int get_valence() const
Returns the valence.
Definition: tensor.hpp:509
This class is intended to describe the manage objects appearing in the equations.
Definition: term_eq.hpp:62
const Tensor * get_p_val_t() const
Definition: term_eq.hpp:123
int get_type_data() const
Definition: term_eq.hpp:131