NiHu  2.0
conditional_precompute.hpp
Go to the documentation of this file.
1 // This file is a part of NiHu, a C++ BEM template library.
2 //
3 // Copyright (C) 2012-2019 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2019 Peter Rucz <rucz@hit.bme.hu>
5 //
6 // This program 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 // This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18 
23 #ifndef CONDITIONAL_PRECOMPUTE_HPP_INCLUDED
24 #define CONDITIONAL_PRECOMPUTE_HPP_INCLUDED
25 
27 #include <type_traits>
28 
29 namespace NiHu
30 {
31 
33 namespace matrix_function_complexity
34 {
36  struct zero { typedef zero type; };
38  struct constant { typedef constant type; };
40  struct general { typedef general type; };
41 }
42 
43 
49 template <class Complexity, class Func, class ...Args>
51 {
52 public:
56  typedef decltype( Func::eval(std::declval<Args>()...) ) functor_ret_type;
59 
61  static return_type eval(Args const &...args)
62  {
63  return Func::eval(args...);
64  }
65 };
66 
67 
69 template <class Func, class...Args>
70 class conditional_precompute<matrix_function_complexity::constant, Func, Args...>
71 {
72 public:
76  typedef decltype( Func::eval(std::declval<Args>()...) ) functor_ret_type;
78  typedef typename std::add_lvalue_reference<
79  typename std::add_const<functor_ret_type>::type
81 
83  static return_type eval(Args const &...args)
84  {
85  static const functor_ret_type m_stored = Func::eval(args...);
86  return m_stored;
87  }
88 };
89 
90 
92 template <class Func, class...Args>
93 class conditional_precompute<matrix_function_complexity::zero, Func, Args...>
94 {
95 public:
99  typedef decltype( Func::eval(std::declval<Args>()...) ) functor_ret_type;
101  typedef decltype(functor_ret_type::Zero()) return_type;
102 
104  static constexpr return_type eval(Args const &...)
105  {
106  return functor_ret_type::Zero();
107  }
108 };
109 
110 
111 template <class Complexity, class Func, class ...Args>
113 {
114 public:
118  typedef decltype( Func::eval(std::declval<Args>()...) ) functor_ret_type;
121 
122  template <class...ConstrArgs>
123  conditional_precompute_instance(ConstrArgs const &...)
124  {
125  }
126 
128  return_type operator()(Args const &...args) const
129  {
130  return Func::eval(args...);
131  }
132 };
133 
134 
135 template <class Func, class...Args>
136 class conditional_precompute_instance<matrix_function_complexity::constant, Func, Args...>
137 {
138 public:
142  typedef decltype( Func::eval(std::declval<Args>()...) ) functor_ret_type;
144  typedef typename std::add_lvalue_reference<
145  typename std::add_const<functor_ret_type>::type
147 
148  conditional_precompute_instance(Args const &...args)
149  : m_stored(Func::eval(args...))
150  {
151  }
152 
154  template <class...EvalArgs>
155  return_type operator()(EvalArgs const &...) const
156  {
157  return m_stored;
158  }
159 
160 private:
161  const functor_ret_type m_stored;
162 };
163 
164 
165 template <class Func, class...Args>
166 class conditional_precompute_instance<matrix_function_complexity::zero, Func, Args...>
167 {
168 public:
172  typedef decltype( Func::eval(std::declval<Args>()...) ) functor_ret_type;
174  typedef decltype(functor_ret_type::Zero()) return_type;
175 
176  conditional_precompute_instance(Args const &...args)
177  {
178  }
179 
181  template <class...EvalArgs>
182  return_type constexpr operator()(EvalArgs const &...) const
183  {
184  return functor_ret_type::Zero();
185  }
186 };
187 
188 } // end of namespace NiHu
189 
190 #endif // CONDITIONAL_PRECOMPUTE_HPP_INCLUDED
191 
NiHu::conditional_precompute< matrix_function_complexity::constant, Func, Args... >::type
conditional_precompute type
self-returning
Definition: conditional_precompute.hpp:74
NiHu::conditional_precompute::eval
static return_type eval(Args const &...args)
return object computed by the function class
Definition: conditional_precompute.hpp:61
NiHu::conditional_precompute_instance< matrix_function_complexity::constant, Func, Args... >::return_type
std::add_lvalue_reference< typename std::add_const< functor_ret_type >::type >::type return_type
the return type of the static function eval
Definition: conditional_precompute.hpp:146
global_definitions.hpp
global constants governing some accuracy parameters
NiHu::conditional_precompute::type
conditional_precompute type
self-returning
Definition: conditional_precompute.hpp:54
NiHu::conditional_precompute< matrix_function_complexity::zero, Func, Args... >::type
conditional_precompute type
self-returning
Definition: conditional_precompute.hpp:97
NiHu::conditional_precompute< shape_complexity< Derived, Order >::type, shape_function< Derived, Order >, domain< Derived >::type::xi_t >::return_type
functor_ret_type return_type
the return type of the static function eval
Definition: conditional_precompute.hpp:58
NiHu::conditional_precompute_instance::type
conditional_precompute_instance type
self-returning
Definition: conditional_precompute.hpp:116
NiHu::conditional_precompute_instance< matrix_function_complexity::zero, Func, Args... >::operator()
constexpr return_type operator()(EvalArgs const &...) const
return object computed by the function class
Definition: conditional_precompute.hpp:182
NiHu::conditional_precompute_instance< matrix_function_complexity::constant, Func, Args... >::type
conditional_precompute_instance type
self-returning
Definition: conditional_precompute.hpp:140
NiHu::conditional_precompute_instance
Definition: conditional_precompute.hpp:112
NiHu::conditional_precompute_instance::operator()
return_type operator()(Args const &...args) const
return object computed by the function class
Definition: conditional_precompute.hpp:128
NiHu::conditional_precompute
Conditionally precompute and store objects.
Definition: conditional_precompute.hpp:50
NiHu::conditional_precompute_instance::functor_ret_type
decltype(Func::eval(std::declval< Args >()...)) typedef functor_ret_type
the return type of the Func function class
Definition: conditional_precompute.hpp:118
NiHu::conditional_precompute_instance< matrix_function_complexity::constant, Func, Args... >::operator()
return_type operator()(EvalArgs const &...) const
return object computed by the function class
Definition: conditional_precompute.hpp:155
NiHu::matrix_function_complexity::constant
the returned matrix is constant and can be stored
Definition: conditional_precompute.hpp:38
NiHu::matrix_function_complexity::general
the returned matrix should be computed on the fly
Definition: conditional_precompute.hpp:40
NiHu::conditional_precompute_instance< matrix_function_complexity::zero, Func, Args... >::type
conditional_precompute_instance type
self-returning
Definition: conditional_precompute.hpp:170
NiHu::conditional_precompute_instance< location_complexity< Derived, Order >::type, location_impl< Derived, Order >, coords_type< Derived >::type, shape_set_traits::domain< lset< Derived >::type >::type::xi_t >::return_type
functor_ret_type return_type
the return type of the static function eval
Definition: conditional_precompute.hpp:120
NiHu::matrix_function_complexity::zero
the returned matrix is a zero expression
Definition: conditional_precompute.hpp:36
NiHu::conditional_precompute::functor_ret_type
decltype(Func::eval(std::declval< Args >()...)) typedef functor_ret_type
the return type of the function class
Definition: conditional_precompute.hpp:56
NiHu::conditional_precompute< matrix_function_complexity::constant, Func, Args... >::return_type
std::add_lvalue_reference< typename std::add_const< functor_ret_type >::type >::type return_type
the return type of the static function eval
Definition: conditional_precompute.hpp:80