NiHu  2.0
weighted_residual.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-2014 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2014 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 
24 #ifndef WEIGHTED_RESIDUAL_HPP_INCLUDED
25 #define WEIGHTED_RESIDUAL_HPP_INCLUDED
26 
27 #include <type_traits>
28 
29 #include "../tmp/bool.hpp"
30 #include "../util/crtp_base.hpp"
31 #include "result_matrix.hpp"
32 #include "function_space.hpp"
33 #include "integral_transform.hpp"
34 
35 
36 namespace NiHu
37 {
38 
42 template <class Derived>
43 class wr_base
44 {
45 public:
47 
53  template <class result_t>
54  result_t &eval(result_t &result) const
55  {
56  return derived().eval(result);
57  }
58 };
59 
60 
65 template <class TestSpace, class Projection>
67  public wr_base<weighted_residual<TestSpace, Projection> >
68 {
69 public:
75  TestSpace &&test,
76  Projection &&proj) :
77  m_test(std::forward<TestSpace>(test)),
78  m_proj(std::forward<Projection>(proj))
79  {
80  }
81 
87  template <class result_t>
88  result_t &eval(result_t &result) const
89  {
90  m_proj.test_on_into(m_test, result);
91  return result;
92  }
93 
94 private:
96  TestSpace m_test;
98  Projection m_proj;
99 };
100 
101 
105 template <class Wr>
106 struct is_weighted_residual : std::is_base_of<
107  wr_base<typename std::decay<Wr>::type>,
108  typename std::decay<Wr>::type
109 >{};
110 
111 
116 template <class Left, class Right>
117 class wr_sum :
118  public wr_base<wr_sum<Left, Right> >
119 {
120 public:
125  wr_sum(Left &&left, Right &&right) :
126  m_lhs(std::forward<Left>(left)), m_rhs(std::forward<Right>(right))
127  {
128  }
129 
135  template <class result_t>
136  result_t &eval(result_t &result) const
137  {
138  m_lhs.eval(result);
139  m_rhs.eval(result);
140  return result;
141  }
142 
143 private:
144  Left m_lhs;
145  Right m_rhs;
146 };
147 
148 
155 template <class LeftWr, class RightWr>
156 wr_sum<
157  typename std::enable_if<is_weighted_residual<LeftWr>::value, LeftWr>::type,
158  typename std::enable_if<is_weighted_residual<RightWr>::value, RightWr>::type
159 >
160  operator+(LeftWr &&lhs, RightWr &&rhs)
161 {
163  std::forward<LeftWr>(lhs),
164  std::forward<RightWr>(rhs));
165 }
166 
167 
168 
176 template <class Test, class Proj>
177 weighted_residual<
178  typename std::enable_if<is_function_space<Test>::value, Test>::type,
179  typename std::enable_if<is_integral_transform<Proj>::value, Proj>::type
180 >
181  operator *(Test &&test, Proj &&proj)
182 {
184  std::forward<Test>(test),
185  std::forward<Proj>(proj));
186 }
187 
188 
189 
197 template <class WR, class Res>
198 typename std::enable_if<
199  is_weighted_residual<WR>::value && is_result_matrix<Res>::value,
200  Res &
201 >::type
202 operator << (Res &res, WR &&wr)
203 {
204  wr.eval(res);
205  return res;
206 }
207 
208 } // end of namespace NiHu
209 
210 #endif // ifndef WEIGHTED_RESIDUAL_HPP_INCLUDED
211 
NiHu::wr_base::eval
NIHU_CRTP_HELPERS result_t & eval(result_t &result) const
evaluate weighted residual into matrix
Definition: weighted_residual.hpp:54
NiHu::wr_sum
the sum of two weighted residual expressions
Definition: weighted_residual.hpp:117
integral_transform.hpp
declaration of integral_transform classes
NiHu::is_weighted_residual
metafunction determining if argument is weighted_residual expression
Definition: weighted_residual.hpp:106
NiHu::wr_sum::eval
result_t & eval(result_t &result) const
evaluate wr sum into result
Definition: weighted_residual.hpp:136
NIHU_CRTP_HELPERS
#define NIHU_CRTP_HELPERS
define CRTP helper function
Definition: crtp_base.hpp:29
NiHu::weighted_residual
A weighted residual proxy storing a function_space and an integral_transform.
Definition: weighted_residual.hpp:66
result_matrix.hpp
Encapsulates different result matrix types.
NiHu::weighted_residual::eval
result_t & eval(result_t &result) const
evaluate wr into result
Definition: weighted_residual.hpp:88
NiHu::wr_sum::wr_sum
wr_sum(Left &&left, Right &&right)
constructor
Definition: weighted_residual.hpp:125
function_space.hpp
declaration of class function_space
NiHu::weighted_residual::weighted_residual
weighted_residual(TestSpace &&test, Projection &&proj)
constructor from test reference and integral_transform reference
Definition: weighted_residual.hpp:74
NiHu::wr_base
base class of all weighted residual expressions
Definition: weighted_residual.hpp:43