RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
scale.hh
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the C++-library RFFGen. */
4 /* Copyright 2015 Lars Lubkoll */
5 /* */
6 /* RFFGen 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 /* RFFGen 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 RFFGen. If not, see <http://www.gnu.org/licenses/>. */
18 /* */
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 
21 #ifndef RFFGEN_MATHEMATICAL_OPERATIONS_SCALE_HH
22 #define RFFGEN_MATHEMATICAL_OPERATIONS_SCALE_HH
23 
24 #include <type_traits>
25 #include <utility>
26 
27 #include "../Util/base.hh"
28 #include "../Util/derivativeWrappers.hh"
29 #include "../Util/indexedType.hh"
30 
31 namespace RFFGen
32 {
36  template <class> struct Chainer;
41  namespace MathematicalOperations
42  {
46  template <class> struct FunctionConceptCheck;
56  template <class F, class = FunctionConceptCheck<F> >
57  struct Scale : Base , Chainer< Scale< F , FunctionConceptCheck<F> > >
58  {
59  using Chainer< Scale< F , FunctionConceptCheck<F> > >::operator();
61  Scale() = default;
62 
68  template <class InitF>
69  Scale(double a_, const InitF& f_) : a(a_), f(f_)
70  {
71  updateResultOfD0();
72  }
73 
75  template <class Arg>
76  void update(Arg const& arg)
77  {
78  f.update(arg);
79  updateResultOfD0();
80  }
81 
83  template <int index, class Arg>
84  void updateVariable(const Arg& x)
85  {
86  f.template updateVariable<index>(x);
87  }
88 
90  const auto& d0() const noexcept
91  {
92  return resultOfD0;
93  }
94 
99  template < int idx , class Arg ,
100  class IndexedArg = IndexedType<Arg,idx> ,
101  class = std::enable_if_t< D1<F,IndexedArg>::present> >
102  auto d1(Arg const& dx) const
103  {
104  return a * f.template d1<idx>(dx);
105  }
106 
112  template < int idx , int idy , class ArgX , class ArgY ,
113  class IndexedArgX = IndexedType<ArgX,idx> ,
114  class IndexedArgY = IndexedType<ArgY,idy> ,
115  class = std::enable_if_t< D2<F,IndexedArgX,IndexedArgY>::present> >
116  auto d2(ArgX const& dx, ArgY const& dy) const
117  {
118  return a * f.template d2<idx,idy>(dx,dy);
119  }
120 
127  template < int idx , int idy , int idz , class ArgX , class ArgY , class ArgZ ,
128  class IndexedArgX = IndexedType<ArgX,idx> ,
129  class IndexedArgY = IndexedType<ArgY,idy> ,
130  class IndexedArgZ = IndexedType<ArgZ,idz> ,
131  class = std::enable_if_t< D3<F,IndexedArgX,IndexedArgY,IndexedArgZ>::present > >
132  auto d3(ArgX const& dx, ArgY const& dy, ArgZ const& dz) const
133  {
134  return a * f.template d3<idx,idy,idz>(dx,dy,dz);
135  }
136 
137  private:
138  void updateResultOfD0()
139  {
140  resultOfD0 = a * f.d0();
141  }
142 
143  double a = 1.;
144  F f;
145  std::remove_const_t<std::remove_reference_t<decltype(std::declval<F>().d0())> > resultOfD0;
146  };
147  }
148 }
149 
150 #endif // RFFGEN_MATHEMATICAL_OPERATIONS_SCALE_HH
void update(Arg const &arg)
Reset point of evaluation.
Definition: scale.hh:76
const auto & d0() const noexcept
Function value.
Definition: scale.hh:90
Scaling of some function with a double (F must satisfy the requirements of Concepts::FunctionConce...
Definition: scale.hh:57
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
auto d1(Arg const &dx) const
First directional derivative.
Definition: scale.hh:102
void updateVariable(const Arg &x)
Propagate call to updateVariable() to f.
Definition: scale.hh:84
Scale(double a_, const InitF &f_)
Constructor passing arguments to function constructor.
Definition: scale.hh:69
auto d3(ArgX const &dx, ArgY const &dy, ArgZ const &dz) const
Third directional derivative.
Definition: scale.hh:132
Scale()=default
Default constructor. May leave member variables uninitialized! Call update before using evaluation...
auto d2(ArgX const &dx, ArgY const &dy) const
Second directional derivative.
Definition: scale.hh:116