WaveBlocksND
localRemainder.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../types.hpp"
4 #include "../../utilities/evaluations.hpp"
5 
6 #include "../bases.hpp"
7 #include "localQuadratic.hpp"
8 #include "leadingLevelOwner.hpp"
9 
10 
11 namespace waveblocks
12 {
13  namespace potentials
14  {
15  namespace modules
16  {
17  namespace localRemainder
18  {
19  template <class Subtype, int N, int D>
20  struct Abstract {
24 
25 
26  local_quadratic_evaluation_type evaluate_local_remainder_at( const argument_type &arg,
27  const argument_type &q ) const
28  {
29  return static_cast<const Subtype*>(this)->evaluate_local_remainder_at_implementation( arg, q );
30  }
31 
32  template < template <typename...> class grid_in = std::vector,
33  template <typename...> class grid_out = grid_in >
34  grid_out<local_quadratic_evaluation_type > evaluate_local_remainder( const grid_in<argument_type > &args,
35  const argument_type &q ) const {
36  return utilities::evaluate_function_in_grid < argument_type,
37  local_quadratic_evaluation_type,
38  grid_in,
39  grid_out,
40  function_t > (
41  std::bind(
42  &Self::evaluate_local_remainder_at, this, std::placeholders::_1, q ),
43  args );
44  }
45  };
46 
47  template <class DiagDifference, class EvalImpl, class LocQuadraticImpl, int N, int D>
48  class General : public Abstract<General<DiagDifference, EvalImpl, LocQuadraticImpl, N, D>, N, D>, public EvalImpl, public LeadingLevelOwner<LocQuadraticImpl>
49  {
52 
53  public:
54 
55  General( potential_type pot,
56  typename LocQuadraticImpl::potential_type lead_pot,
57  typename LocQuadraticImpl::jacobian_type lead_jac,
58  typename LocQuadraticImpl::hessian_type lead_hess )
59  : EvalImpl(pot), LeadingLevelOwner<LocQuadraticImpl>( lead_pot, lead_jac, lead_hess ) {}
60 
61 
62  local_quadratic_evaluation_type evaluate_local_remainder_at_implementation(
63  const argument_type &arg,
64  const argument_type &q ) const {
65  auto u = LeadingLevelOwner<LocQuadraticImpl>::get_leading_level().evaluate_local_quadratic_at( arg, q );
66  return DiagDifference::apply(
67  EvalImpl::evaluate_at( arg ), u );
68  }
69  };
70 
71 
72  namespace helper
73  {
74  template <class LocQuadImpl, int N, int D>
78 
79  struct Inhomogenous {
80  static local_quadratic_evaluation_type apply(const potential_evaluation_type& V, const typename LocQuadImpl::local_quadratic_evaluation_type &u ) {
81  local_quadratic_evaluation_type C = V.template cast<local_quadratic_return_type>();
82 
83  for ( int i = 0; i < N; ++i ) {
84  C( i, i ) -= u( i );
85  }
86 
87  return C;
88  }
89  };
90  struct Homogenous {
91  static local_quadratic_evaluation_type apply(const potential_evaluation_type& V, const typename LocQuadImpl::local_quadratic_evaluation_type &u ) {
92  local_quadratic_evaluation_type C = V.template cast<local_quadratic_return_type>();
93 
94  for ( int i = 0; i < N; ++i ) {
95  C( i, i ) -= u;
96  }
97 
98  return C;
99  }
100  };
101  };
102 
103  template <class LocQuadImpl, int D>
104  struct DiagonalDifference<LocQuadImpl,1,D> {
107 
108  struct Homogenous {
109  static local_quadratic_evaluation_type apply(const potential_evaluation_type& V, const typename LocQuadImpl::local_quadratic_evaluation_type &u ) {
110  return V - u;
111  }
112  };
114  };
115  }
116 
117  template<class EvalImpl, class LocQuadraticImpl, int N, int D>
119 
120  template<class EvalImpl, class LocQuadraticImpl, int N, int D>
122 
123  }
124 
125  template<int N, int D>
127 
128  template<int N, int D>
130  }
131  }
132 }
Definition: coefficients_file_parser.cpp:10
static local_quadratic_evaluation_type apply(const potential_evaluation_type &V, const typename LocQuadImpl::local_quadratic_evaluation_type &u)
Definition: localRemainder.hpp:91
local_quadratic_evaluation_type evaluate_local_remainder_at(const argument_type &arg, const argument_type &q) const
Definition: localRemainder.hpp:26
G_out< R > evaluate_function_in_grid(const F< R(A)> &f, const G_in< A > &g)
Evaluate a function in multiple points at once.
Definition: evaluations.hpp:130
General< typename helper::DiagonalDifference< LocQuadraticImpl, N, D >::Homogenous, EvalImpl, LocQuadraticImpl, N, D > Homogenous
Definition: localRemainder.hpp:118
static local_quadratic_evaluation_type apply(const potential_evaluation_type &V, const typename LocQuadImpl::local_quadratic_evaluation_type &u)
Definition: localRemainder.hpp:80
Helper class to ease template specialzations.
Definition: bases.hpp:25
std::function< P > function_t
Definition: types.hpp:57
local_quadratic_evaluation_type evaluate_local_remainder_at_implementation(const argument_type &arg, const argument_type &q) const
Definition: localRemainder.hpp:62
grid_out< local_quadratic_evaluation_type > evaluate_local_remainder(const grid_in< argument_type > &args, const argument_type &q) const
Definition: localRemainder.hpp:34
#define IMPORT_TYPES_FROM(B)
Definition: bases.hpp:3
static local_quadratic_evaluation_type apply(const potential_evaluation_type &V, const typename LocQuadImpl::local_quadratic_evaluation_type &u)
Definition: localRemainder.hpp:109
Owned & get_leading_level()
Definition: leadingLevelOwner.hpp:20
Helper class for easier template specialization.
Definition: localQuadratic.hpp:71