NiHu  2.0
integral_operator_expression.hpp
Go to the documentation of this file.
1 
7 #ifndef NIHU_INTEGRAL_OPERATOR_EXPRESSION_HPP_INCLUDED
8 #define NIHU_INTEGRAL_OPERATOR_EXPRESSION_HPP_INCLUDED
9 
10 #include "fmm_operator.hpp"
11 #include "local_operator.hpp"
12 
13 #include "util/matrix_traits.hpp"
14 #include "util/plain_type.hpp"
15 #include "util/product_type.hpp"
16 
17 #include <type_traits>
18 #include <utility>
19 
20 namespace NiHu
21 {
22 namespace fmm
23 {
24 
27 template <class Derived>
29 
32 template <class Derived>
34 
37 template <class C>
39  : public std::is_base_of<
40  integral_operator_expression<typename std::decay<C>::type>,
41  typename std::decay<C>::type> {};
42 
43 
47 template <class LhsDerived, class RhsDerived>
49 
50 template <class LhsDerived, class RhsDerived>
51 struct is_local_operator<integral_operator_sum<LhsDerived, RhsDerived> >
52  : public std::integral_constant<bool,
53  is_local_operator<typename std::decay<LhsDerived>::type>::value &&
54  is_local_operator<typename std::decay<RhsDerived>::type>::value> {};
55 
59 template <class LhsDerived, class RhsDerived>
61 
62 template <class LhsDerived, class RhsDerived>
63 struct is_local_operator<integral_operator_diff<LhsDerived, RhsDerived> >
64  : public std::integral_constant<bool,
65  is_local_operator<typename std::decay<LhsDerived>::type>::value &&
66  is_local_operator<typename std::decay<RhsDerived>::type>::value> {};
67 
71 template <class LhsDerived, class Scalar>
73 
74 template <class LhsDerived, class Scalar>
75 struct is_local_operator<integral_operator_scaled<LhsDerived, Scalar> >
76  : public is_local_operator<typename std::decay<LhsDerived>::type> {};
77 
81 template <class LhsDerived, class RhsDerived>
83 
84 template <class LhsDerived, class RhsDerived>
85 struct is_local_operator<integral_operator_src_concatenated<LhsDerived, RhsDerived> >
86  : public std::integral_constant<bool,
87  is_local_operator<typename std::decay<LhsDerived>::type>::value &&
88  is_local_operator<typename std::decay<RhsDerived>::type>::value> {};
89 
90 template <class Derived>
92 {
93 public:
94  typedef Derived derived_t;
96 
97  typedef typename traits_t::trial_input_t trial_input_t;
98  typedef typename traits_t::test_input_t test_input_t;
99  typedef typename traits_t::result_t result_t;
100 
102  derived_t const &derived() const
103  {
104  return *(static_cast<derived_t const *>(this));
105  }
106 
109  {
110  return *(static_cast<derived_t *>(this));
111  }
112 
116  size_t rows(test_input_t const &ti) const
117  {
118  return derived().rows(ti);
119  }
120 
124  size_t cols(trial_input_t const &ti) const
125  {
126  return derived().cols(ti);
127  }
128 
133  result_t operator()(test_input_t const &tsi, trial_input_t const &tri) const
134  {
135  return derived()(tsi, tri);
136  }
137 };
138 
143 template <class Lhs, class Rhs, typename std::enable_if<
144  is_integral_operator_expression<Lhs>::value &
145  is_integral_operator_expression<Rhs>::value, int>::type = 0>
146 integral_operator_sum<Lhs, Rhs> operator+(Lhs &&lhs, Rhs &&rhs)
147 {
149  std::forward<Lhs>(lhs), std::forward<Rhs>(rhs));
150 }
151 
152 
157 template <class Lhs, class Rhs, typename std::enable_if<
158  is_integral_operator_expression<Lhs>::value &
159  is_integral_operator_expression<Rhs>::value, int>::type = 0>
161 {
163  std::forward<Lhs>(lhs), std::forward<Rhs>(rhs));
164 }
165 
166 
171 template <class Lhs, class Scalar,
172  typename std::enable_if<is_integral_operator_expression<Lhs>::value, int>::type = 0>
174 {
176  std::forward<Lhs>(lhs), std::forward<Scalar>(c));
177 }
178 
183 template <class Scalar, class Rhs,
184  typename std::enable_if<is_integral_operator_expression<Rhs>::value, int>::type = 0>
185 integral_operator_scaled<Rhs, Scalar>
186 operator *(Scalar &&c, Rhs &&rhs)
187 {
189  std::forward<Rhs>(rhs), std::forward<Scalar>(c));
190 }
191 
192 
196 template <class Lhs, class Rhs>
198 {
199  typedef typename std::decay<Lhs>::type lhs_derived_t;
203 };
204 
205 
209 template <class Lhs, class Rhs>
211 {
212  typedef typename std::decay<Lhs>::type lhs_derived_t;
216 };
217 
218 
219 template <class Lhs, class Rhs>
221  : public integral_operator_expression<integral_operator_sum<Lhs, Rhs> >
222  , public fmm_operator<typename std::decay<Lhs>::type::fmm_tag>
223 {
224 public:
226  typedef typename base_t::test_input_t test_input_t;
227  typedef typename base_t::trial_input_t trial_input_t;
228  typedef typename base_t::result_t result_t;
229 
230  integral_operator_sum(Lhs &&lhs, Rhs &&rhs)
231  : m_lhs(std::forward<Lhs>(lhs))
232  , m_rhs(std::forward<Rhs>(rhs))
233  {
234  }
235 
236  size_t rows(test_input_t const &ti) const
237  {
238  return m_lhs.rows(ti);
239  }
240 
241  size_t cols(trial_input_t const &ti) const
242  {
243  return m_lhs.cols(ti);
244  }
245 
246  result_t operator()(test_input_t const &tsi, trial_input_t const &tri) const
247  {
248  return m_lhs(tsi, tri) + m_rhs(tsi, tri);
249  }
250 
251 private:
252  Lhs m_lhs;
253  Rhs m_rhs;
254 };
255 
256 
257 template <class Lhs, class Rhs>
258 class integral_operator_diff
259  : public integral_operator_expression<integral_operator_diff<Lhs, Rhs> >
260  , public fmm_operator<typename std::decay<Lhs>::type::fmm_tag>
261 {
262 public:
263  typedef integral_operator_expression<integral_operator_diff<Lhs, Rhs> > base_t;
264  typedef typename base_t::test_input_t test_input_t;
265  typedef typename base_t::trial_input_t trial_input_t;
266  typedef typename base_t::result_t result_t;
267 
268  integral_operator_diff(Lhs &&lhs, Rhs &&rhs)
269  : m_lhs(std::forward<Lhs>(lhs))
270  , m_rhs(std::forward<Rhs>(rhs))
271  {
272  }
273 
274  size_t rows(test_input_t const &ti) const
275  {
276  return m_lhs.rows(ti);
277  }
278 
279  size_t cols(trial_input_t const &ti) const
280  {
281  return m_lhs.cols(ti);
282  }
283 
284  result_t operator()(test_input_t const &tsi, trial_input_t const &tri) const
285  {
286  return m_lhs(tsi, tri) - m_rhs(tsi, tri);
287  }
288 
289 private:
290  Lhs m_lhs;
291  Rhs m_rhs;
292 };
293 
294 
298 template <class Lhs, class Scalar>
300 {
301  typedef typename std::decay<Lhs>::type lhs_derived_t;
302  typedef typename std::decay<Scalar>::type scalar_t;
303 
306 
307  typedef typename NiHu::plain_type<
308  typename NiHu::product_type<
309  scalar_t,
311  >::type
312  >::type result_t;
313 };
314 
318 template <class Lhs, class Scalar>
320  : public integral_operator_expression<integral_operator_scaled<Lhs, Scalar> >
321  , public fmm_operator<typename std::decay<Lhs>::type::fmm_tag>
322 {
323 public:
325  typedef typename base_t::test_input_t test_input_t;
326  typedef typename base_t::trial_input_t trial_input_t;
327  typedef typename base_t::result_t result_t;
328 
329  integral_operator_scaled(Lhs &&lhs, Scalar &&c)
330  : m_lhs(std::forward<Lhs>(lhs))
331  , m_c(std::forward<Scalar>(c))
332  {
333  }
334 
335  size_t rows(test_input_t const &ti) const
336  {
337  return m_lhs.rows(ti);
338  }
339 
340  size_t cols(trial_input_t const &ti) const
341  {
342  return m_lhs.cols(ti);
343  }
344 
345  result_t operator()(test_input_t const &tsi, trial_input_t const &tri) const
346  {
347  return m_lhs(tsi, tri) * m_c;
348  }
349 
350 private:
351  Lhs m_lhs;
352  Scalar m_c;
353 };
354 
355 
359 template <class Lhs, class Rhs>
361 {
362  typedef typename std::decay<Lhs>::type lhs_derived_t;
363  typedef typename std::decay<Rhs>::type rhs_derived_t;
364  static int const lhs_cols = num_cols<typename lhs_derived_t::result_t>::value;
365  static int const lhs_rows = num_rows<typename lhs_derived_t::result_t>::value;
366  static int const rhs_cols = num_cols<typename rhs_derived_t::result_t>::value;
367  typedef typename scalar<typename lhs_derived_t::result_t>::type scalar_t;
368  typedef Eigen::Matrix<scalar_t, lhs_rows, lhs_cols + rhs_cols> result_t;
371 };
372 
373 
374 template <class Lhs, class Rhs>
376  : public integral_operator_expression<integral_operator_src_concatenated<Lhs, Rhs> >
377  , public fmm_operator<typename std::decay<Lhs>::type::fmm_tag>
378 {
379 public:
381  typedef typename base_t::test_input_t test_input_t;
382  typedef typename base_t::trial_input_t trial_input_t;
383  typedef typename base_t::result_t result_t;
384 
385  integral_operator_src_concatenated(Lhs &&lhs, Rhs &&rhs)
386  : m_lhs(std::forward<Lhs>(lhs))
387  , m_rhs(std::forward<Rhs>(rhs))
388  {
389  }
390 
391  size_t rows(test_input_t const &ti) const
392  {
393  return m_lhs.rows(ti);
394  }
395 
396  size_t cols(trial_input_t const &ti) const
397  {
398  return m_lhs.cols(ti) + m_rhs.cols(ti);
399  }
400 
401  result_t operator()(test_input_t const &tsi, trial_input_t const &tri) const
402  {
403  result_t res(rows(tsi), cols(tri));
404  res.leftCols(m_lhs.cols(tri)) = m_lhs(tsi, tri);
405  res.rightCols(m_rhs.cols(tri)) = m_rhs(tsi, tri);
406  return res;
407  }
408 
409 private:
410  Lhs m_lhs;
411  Rhs m_rhs;
412 };
413 
414 template <class Lhs, class Rhs>
415 auto src_concatenate(Lhs &&lhs, Rhs &&rhs)
416 {
417  return integral_operator_src_concatenated<Lhs, Rhs>(std::forward<Lhs>(lhs), std::forward<Rhs>(rhs));
418 }
419 
420 
421 } // end of namespace fmm
422 } // namespace NiHu
423 
424 #endif /* NIHU_INTEGRAL_OPERATOR_EXPRESSION_HPP_INCLUDED */
NiHu::fmm::p2p_integral< identity_p2p_operator, TestField, TrialField >
Definition: p2p_integral.hpp:115
NiHu::fmm::is_local_operator
Metafunction to tell if an operator is local.
Definition: local_operator.hpp:25
fmm_operator.hpp
FMM operator types and tags.
product_type.hpp
Product type calculations.
NiHu::fmm::integral_operator_diff
the difference of two integral operators
Definition: integral_operator_expression.hpp:60
NiHu::fmm::integral_operator_expression::rows
size_t rows(test_input_t const &ti) const
return rows of the integral operator' result
Definition: integral_operator_expression.hpp:116
NiHu::fmm::integral_operator_expression::operator()
result_t operator()(test_input_t const &tsi, trial_input_t const &tri) const
evaluate the integral operator
Definition: integral_operator_expression.hpp:133
NiHu::fmm::integral_operator_expression
the base class of every integral operator
Definition: integral_operator_expression.hpp:28
NiHu::fmm::integral_operator_src_concatenated
source-concatenation of two integral operators
Definition: integral_operator_expression.hpp:82
NiHu::fmm::integral_operator_expression::cols
size_t cols(trial_input_t const &ti) const
return columns of the integral operator' result
Definition: integral_operator_expression.hpp:124
NiHu::fmm::integral_operator_scaled
scalar times an integral operator
Definition: integral_operator_expression.hpp:72
NiHu::fmm::is_integral_operator_expression
metafunction to determine if C is an integral operator expression
Definition: integral_operator_expression.hpp:38
NiHu::num_rows
metafunction returning the number of compile time rows
Definition: matrix_traits.hpp:16
NiHu::fmm::integral_operator_sum
the sum of two integral operators
Definition: integral_operator_expression.hpp:48
NiHu::plain_type
Plain object type of a class.
Definition: plain_type.hpp:45
NiHu::operator*
scaled_integral_operator< Scalar, typename std::enable_if< is_integral_operator< IntOp >::value, IntOp >::type > operator*(Scalar &&scalar, IntOp &&intop)
factory operator to create a scaled integral operator
Definition: integral_operator.hpp:189
NiHu::fmm::fmm_operator
Operator defining its tag type.
Definition: fmm_operator.hpp:85
plain_type.hpp
Plain type calculations.
NiHu::fmm::integral_operator_expression_traits
the traits structure of an integral operator
Definition: integral_operator_expression.hpp:33
NiHu::fmm::integral_operator_expression::derived
const derived_t & derived() const
CRTP helper function.
Definition: integral_operator_expression.hpp:102
local_operator.hpp
Interface of local operator.
NiHu::fmm::operator-
integral_operator_diff< Lhs, Rhs > operator-(Lhs &&lhs, Rhs &&rhs)
factory function to create the difference of two integral operators
Definition: integral_operator_expression.hpp:160
NiHu::num_cols
metafunction returning the number of compile time columns
Definition: matrix_traits.hpp:41
NiHu::product_type
Metafunction returning the product type of two classes.
Definition: product_type.hpp:37
matrix_traits.hpp
compile time properties of matrices
NiHu::fmm::integral_operator_expression::derived
derived_t & derived()
CRTP helper function.
Definition: integral_operator_expression.hpp:108