NiHu  2.0
integral_transform.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 
25 #ifndef PROJECTION_HPP_INCLUDED
26 #define PROJECTION_HPP_INCLUDED
27 
28 #include "integral_transform_forward.hpp"
29 
30 #include "../util/crtp_base.hpp"
31 #include "function_space.hpp"
32 #include "integral_operator.hpp"
33 #include "assembly.hpp"
34 
35 namespace NiHu
36 {
37 
42 template <class Derived>
44 {
45 public:
47 
54  template <class TestSpace, class Result>
56  function_space_base<TestSpace> const &test_space,
57  Result &result) const
58  {
59  derived().test_on_into(test_space, result);
60  }
61 };
62 
63 
67 template <class Proj>
68 struct is_integral_transform : std::is_base_of<
69  integral_transform_base<typename std::decay<Proj>::type>,
70  typename std::decay<Proj>::type
71 >{};
72 
73 
78 template <class LDerived, class RDerived>
80  public integral_transform_base<integral_transform_sum<LDerived, RDerived> >
81 {
82 public:
87  integral_transform_sum(LDerived &&left, RDerived &&right) :
88  m_lhs(std::forward<LDerived>(left)),
89  m_rhs(std::forward<RDerived>(right))
90  {
91  }
92 
99  template <class TestSpace, class Result>
101  function_space_base<TestSpace> const &test_space,
102  Result &result) const
103  {
104  m_lhs.test_on_into(test_space, result);
105  m_rhs.test_on_into(test_space, result);
106  }
107 
108 private:
110  LDerived m_lhs;
112  RDerived m_rhs;
113 };
114 
115 
117 template <class Left, class Right>
118 integral_transform_sum<
119  typename std::enable_if<is_integral_transform<Left>::value, Left>::type,
120  typename std::enable_if<is_integral_transform<Right>::value, Right>::type
121 >
122  operator+(Left &&left, Right &&right)
123 {
125  std::forward<Left>(left),
126  std::forward<Right>(right));
127 }
128 
129 
133 template <class Operator, class TrialSpace>
135  : public integral_transform_base<integral_transform<Operator, TrialSpace> >
136 {
137 public:
142  integral_transform(integral_operator_base<Operator> const &op, TrialSpace && trial) :
143  m_op(op.derived()),
144  m_trial_space(std::forward<TrialSpace>(trial))
145  {
146  }
147 
148 
149 private:
150  template <class TestSpace, class Result>
151  void test_on_into_impl(
152  std::true_type,
153  function_space_base<TestSpace> const &test_space,
154  Result &result) const
155  {
156  if (&test_space.get_mesh() == &m_trial_space.get_mesh()) // singular possible
157  {
159  result, m_op, test_space, m_trial_space);
160  }
161  else // singular impossible
162  {
163  assembly<TestSpace, typename std::decay<TrialSpace>::type, std::false_type>::eval_into(
164  result, m_op, test_space, m_trial_space);
165  }
166  }
167 
168  template <class TestSpace, class Result>
169  void test_on_into_impl(
170  std::false_type,
171  function_space_base<TestSpace> const &test_space,
172  Result &result) const
173  {
174  assembly<TestSpace, typename std::decay<TrialSpace>::type, std::false_type>::eval_into(
175  result, m_op, test_space, m_trial_space);
176  }
177 
178 public:
185  template <class TestSpace, class Result>
187  function_space_base<TestSpace> const &test_space,
188  Result &result) const
189  {
190  test_on_into_impl(
191  typename std::is_same<
192  typename std::decay<TrialSpace>::type::mesh_t,
193  typename std::decay<TestSpace>::type::mesh_t
194  >::type(),
195  test_space, result);
196  }
197 
198 
199 private:
201  Operator m_op;
203  TrialSpace m_trial_space;
204 };
205 
206 }
207 
208 #endif
209 
NiHu::integral_transform
Proxy class of a NiHu::integral_operator applied on a NiHu::function_space.
Definition: integral_transform.hpp:134
NiHu::integral_transform_base
CRTP base class of all integral_transform expressions.
Definition: integral_transform.hpp:43
NIHU_CRTP_HELPERS
#define NIHU_CRTP_HELPERS
define CRTP helper function
Definition: crtp_base.hpp:29
NiHu::function_space_base
CRTP base class of function spaces.
Definition: function_space.hpp:44
NiHu::integral_transform_sum::integral_transform_sum
integral_transform_sum(LDerived &&left, RDerived &&right)
constructor from two integral_transform expressions
Definition: integral_transform.hpp:87
NiHu::integral_transform_sum::test_on_into
void test_on_into(function_space_base< TestSpace > const &test_space, Result &result) const
test a integral_transform with a test function space
Definition: integral_transform.hpp:100
NiHu::integral_transform::test_on_into
void test_on_into(function_space_base< TestSpace > const &test_space, Result &result) const
test an integral_transform with a test function space
Definition: integral_transform.hpp:186
NiHu::integral_transform_sum
proxy class representing a sum of two integral_transforms
Definition: integral_transform.hpp:79
NiHu::integral_transform::integral_transform
integral_transform(integral_operator_base< Operator > const &op, TrialSpace &&trial)
constructor from an operator and a function space
Definition: integral_transform.hpp:142
assembly.hpp
assemble WR matrices from field wr submatrices
NiHu::function_space_base::get_mesh
const mesh_t & get_mesh() const
return reference to the underlying mesh
Definition: function_space.hpp:71
function_space.hpp
declaration of class function_space
integral_operator.hpp
declaration of class NiHu::integral_operator
NiHu::integral_operator_base
CRTP base of integral operator expressions.
Definition: integral_operator.hpp:46
NiHu::is_integral_transform
metafunction determining if argument is integral_transform expression
Definition: integral_transform.hpp:68
NiHu::assembly
assemble result matrix from field wr submatrices
Definition: assembly.hpp:39
NiHu::integral_transform_base::test_on_into
NIHU_CRTP_HELPERS void test_on_into(function_space_base< TestSpace > const &test_space, Result &result) const
test a integral_transform with a test function space
Definition: integral_transform.hpp:55