RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
shiftedInvariant.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_LINEAR_ALGEBRA_SHIFTED_INVARIANT_HH
22 #define RFFGEN_LINEAR_ALGEBRA_SHIFTED_INVARIANT_HH
23 
24 #include <type_traits>
25 
26 #include "../constant.hh"
27 #include "../Util/base.hh"
28 #include "../Util/derivativeWrappers.hh"
29 #include "../Util/evaluateIfPresent.hh"
30 #include "../Util/indexedType.hh"
31 
32 namespace RFFGen
33 {
34  namespace LinearAlgebra
35  {
42  template <class Invariant, int offset>
44  {
45  public:
46  ShiftedInvariant() = default;
47 
51  template <class Matrix>
52  ShiftedInvariant(Matrix const& A) : inv(A)
53  {
54  update(A);
55  }
56 
61  template <class Matrix>
62  ShiftedInvariant(const Matrix& A, const Constant<Matrix>& M) : inv(A,M)
63  {
64  update(A);
65  }
66 
71  template <class Matrix>
72  ShiftedInvariant(const Matrix& A, const Matrix& M) : ShiftedInvariant(A,Constant<Matrix>(M))
73  {}
74 
76  template <class Matrix>
77  void update(Matrix const& A)
78  {
79  inv.update(A);
80  resultOfD0 = inv.d0() - offset;
81  }
82 
84  auto d0() const noexcept
85  {
86  return resultOfD0;
87  }
88 
94  template < int id , class Arg ,
95  class IndexedArg = IndexedType<Arg,id> ,
96  class = std::enable_if_t<EvaluateIfPresent< D1<Invariant,IndexedArg> >::present> >
97  auto d1(const Arg& dA1) const
98  {
99  return EvaluateIfPresent< D1<Invariant,IndexedArg> > ( inv, dA1 )();
100  }
101 
108  template < int idx, int idy, class ArgX , class ArgY ,
109  class IndexedArgX = IndexedType<ArgX,idx> ,
110  class IndexedArgY = IndexedType<ArgY,idx> ,
111  class = std::enable_if_t<EvaluateIfPresent< D2<Invariant,IndexedArgX,IndexedArgY> >::present> >
112  auto d2(const ArgX& dA1, const ArgY& dA2) const
113  {
114  return EvaluateIfPresent< D2<Invariant,IndexedArgX,IndexedArgY> >(inv,dA1,dA2)();
115  }
116 
124  template < int idx , int idy , int idz , class ArgX , class ArgY , class ArgZ ,
125  class IndexedArgX = IndexedType<ArgX,idx> ,
126  class IndexedArgY = IndexedType<ArgY,idy> ,
127  class IndexedArgZ = IndexedType<ArgZ,idz> ,
128  class = std::enable_if_t< EvaluateIfPresent< D3<Invariant,IndexedArgX,IndexedArgY,IndexedArgZ> >::present > >
129  auto d3(ArgX const& dA1, ArgY const& dA2, ArgZ const& dA3) const
130  {
131  return EvaluateIfPresent< D3<Invariant,IndexedArgX,IndexedArgY,IndexedArgZ> >(inv,dA1,dA2,dA3)();
132  }
133 
134  private:
135  Invariant inv;
136  std::remove_const_t<std::remove_reference_t<decltype(std::declval<Invariant>().d0())> > resultOfD0 = 0.;
137  };
138  }
139 }
140 
141 #endif // RFFGEN_LINEAR_ALGEBRA_SHIFTED_INVARIANT_HH
ShiftedInvariant(Matrix const &A)
Definition: shiftedInvariant.hh:52
void update(Matrix const &A)
Reset matrix to compute shifted invariant from.
Definition: shiftedInvariant.hh:77
auto d0() const noexcept
Value of the shifted invariant.
Definition: shiftedInvariant.hh:84
auto d1(const Arg &dA1) const
First directional derivative of the (scaled) shifted invariant.
Definition: shiftedInvariant.hh:97
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Possibly scaled, shifted invariant , where for the first two (principal,modified) invariants and fo...
Definition: shiftedInvariant.hh:43
auto d2(const ArgX &dA1, const ArgY &dA2) const
Second directional derivative of the (scaled) shifted invariant.
Definition: shiftedInvariant.hh:112
auto d3(ArgX const &dA1, ArgY const &dA2, ArgZ const &dA3) const
Third directional derivative of the (scaled) shifted invariant.
Definition: shiftedInvariant.hh:129
Wrap a constant.
Definition: constant.hh:41
Invariant
Enum to statically choose invariant traits.
Definition: invariants.hh:37
ShiftedInvariant(const Matrix &A, const Constant< Matrix > &M)
Definition: shiftedInvariant.hh:62
ShiftedInvariant(const Matrix &A, const Matrix &M)
Definition: shiftedInvariant.hh:72