NiHu  2.0
x2p_integral.hpp
Go to the documentation of this file.
1 
7 #ifndef NIHU_X2P_INTEGRAL_HPP_INCLUDED
8 #define NIHU_X2P_INTEGRAL_HPP_INCLUDED
9 
11 #include "core/field.hpp"
12 #include "fmm_operator.hpp"
14 #include "kron_identity.hpp"
15 #include "core/jacobian_computer.hpp"
16 #include "util/matrix_traits.hpp"
17 #include "util/type2tag.hpp"
18 
19 #include <type_traits> // std::enable_if
20 
21 
22 namespace NiHu
23 {
24 namespace fmm
25 {
26 
31 template <class Operator, class TestField>
33 
34 template <class Operator, class TestField>
36 {
37  typedef typename std::decay<Operator>::type operator_t;
38  typedef TestField test_input_t;
39  typedef typename operator_t::trial_input_t trial_input_t;
40  typedef Eigen::Matrix<
41  typename scalar<typename operator_t::result_t>::type,
42  num_rows<typename operator_t::result_t>::value *TestField::nset_t::num_nodes,
44  > result_t;
45 };
46 
47 
49 template <class Operator, class TestField>
50 class x2p_integral
51  : public integral_operator_expression<x2p_integral<Operator, TestField> >
52  , public fmm_operator<typename std::decay<Operator>::type::fmm_tag>
53 {
54 public:
56 
57  typedef typename std::decay<Operator>::type operator_t;
58  typedef TestField test_field_t;
59 
60  typedef typename base_t::trial_input_t trial_input_t;
61  typedef typename base_t::test_input_t test_input_t;
62  typedef typename base_t::result_t result_t;
63 
64  typedef typename test_field_t::elem_t elem_t;
65  typedef typename test_field_t::nset_t nset_t;
66 
67  typedef typename elem_t::domain_t domain_t;
68  typedef typename domain_t::xi_t xi_t;
69  typedef NiHu::gaussian_quadrature<domain_t> quadrature_t;
70 
71  static size_t const op_num_rows = num_rows<typename operator_t::result_t>::value;
72 
73  static size_t const result_rows =
74  op_num_rows * nset_t::num_nodes;
75 
76  x2p_integral(Operator &&op, size_t order)
77  : m_op(std::forward<Operator>(op))
78  , m_quadrature(unsigned(order))
79  {
80  }
81 
82  size_t rows(test_input_t const &) const
83  {
84  return result_rows;
85  }
86 
87  size_t cols(trial_input_t const &from) const
88  {
89  return m_op.cols(from);
90  }
91 
98  result_t operator()(test_input_t const &to, trial_input_t const &from) const
99  {
100 #if 0
101  static bool printed = false;
102 #endif
103 
104  result_t mat = result_t::Zero(result_rows, cols(from));
105  elem_t const &elem = to.get_elem();
106  // traverse quadrature elements
107  for (auto const &q : m_quadrature)
108  {
109  xi_t const &xi = q.get_xi();
110  double w = q.get_w();
111  typename operator_t::test_input_t tsi(elem, xi);
112  double jac = jacobian_computer<elem_t>::eval(elem, xi);
113  auto N = (nset_t::template eval_shape<0>(xi) * (w * jac)).eval();
114 
115  mat += create_kron_identity<op_num_rows>(N) * m_op(tsi, from);
116 #if 0
117  if (!printed) {
118  printed = true;
119  mexPrintf("Size of kmat in m2p integral: %d x %d\n", mat.rows(), mat.cols());
120  }
121 #endif
122 #if 0
123  auto op = m_op(tsi, from);
124  for (Eigen::Index i = 0; i < N.rows(); ++i)
125  mat.block(i * op_num_rows, 0, op_num_rows, cols(from)) += N(i, 0) * op;
126 
127  if (!printed) {
128  printed = true;
129  mexPrintf("Size of op in m2p integral: %d x %d\n", op.rows(), op.cols());
130  }
131 #endif
132  }
133  return mat;
134  }
135 
136 private:
138  Operator m_op;
140  quadrature_t m_quadrature;
141 };
142 
143 
144 
146 template <class Operator, class TestField>
147 class x2p_integral<Operator, NiHu::dirac_field<TestField> >
148  : public integral_operator_expression<x2p_integral<Operator, NiHu::dirac_field<TestField> > >
149  , public fmm_operator<typename std::decay<Operator>::type::fmm_tag>
150 {
151 public:
152  typedef typename std::decay<Operator>::type operator_t;
153  typedef TestField test_field_t;
154 
156 
157  typedef typename base_t::trial_input_t trial_input_t;
158  typedef typename base_t::test_input_t test_input_t;
159  typedef typename base_t::result_t result_t;
160 
161  typedef typename test_field_t::elem_t elem_t;
162  typedef typename test_field_t::nset_t nset_t;
163 
164  typedef typename elem_t::domain_t domain_t;
165  typedef typename domain_t::xi_t xi_t;
167 
168  static size_t const result_rows =
170 
171  x2p_integral(Operator &&op, size_t order = 0)
172  : m_op(std::forward<Operator>(op))
173  {
174  }
175 
176  size_t rows(test_input_t const &) const
177  {
178  return result_rows;
179  }
180 
181  size_t cols(trial_input_t const &from) const
182  {
183  return m_op.cols(from);
184  }
185 
186  result_t operator()(test_input_t const &to, trial_input_t const &from) const
187  {
188  result_t mat = result_t::Zero(result_rows, cols(from));
190  for (size_t N = 0; N < nset_t::num_nodes; ++N)
191  {
192  // get the node in intrinsic coordinates
193  xi_t const &xi = nset_t::corner_at(N);
194  // form the test input
195  typename operator_t::test_input_t tsi(to.get_elem(), xi);
196  // compute the operator and place in result's block
197  mat.block(N * M, 0, M, cols(from)) = m_op(tsi, from);
198  }
199 
200  return mat;
201  }
202 
203 private:
205  Operator m_op;
206 };
207 
208 template <class Operator, class FieldTag>
210 create_x2p_integral(Operator &&op, size_t order, FieldTag)
211 {
212  typedef typename tag2type<FieldTag>::type test_field_t;
213  return x2p_integral<Operator, test_field_t>(std::forward<Operator>(op), order);
214 }
215 
216 } // end of namespace fmm
217 } // namespace NiHu
218 
219 #endif /* NIHU_X2P_INTEGRAL_HPP_INCLUDED */
fmm_operator.hpp
FMM operator types and tags.
gaussian_quadrature.hpp
implementation of Gaussian quadratures
NiHu::volume_element
class describing a volume element that has no normal vector
Definition: element.hpp:455
type2tag.hpp
Assign a tag to a type.
NiHu::gaussian_quadrature< domain_t >
kron_identity.hpp
Kronecker product of a matrix by an Identity matrix.
NiHu::tag2type
Metafunction recovering the type from a tag.
Definition: type2tag.hpp:28
NiHu::fmm::integral_operator_expression
the base class of every integral operator
Definition: integral_operator_expression.hpp:28
field.hpp
implementation of fields and field views
NiHu::num_rows
metafunction returning the number of compile time rows
Definition: matrix_traits.hpp:16
NiHu::fmm::fmm_operator
Operator defining its tag type.
Definition: fmm_operator.hpp:85
NiHu::fmm::integral_operator_expression_traits
the traits structure of an integral operator
Definition: integral_operator_expression.hpp:33
NiHu::volume_element::domain_t
typename base_t::domain_t domain_t
the domain type
Definition: element.hpp:637
NiHu::fmm::x2p_integral::operator()
result_t operator()(test_input_t const &to, trial_input_t const &from) const
evaluate the operator between two inputs
Definition: x2p_integral.hpp:98
integral_operator_expression.hpp
Arithmetics of integral operators.
NiHu::fmm::x2p_integral
integrate an x2p-operator over a test field
Definition: x2p_integral.hpp:32
NiHu::jacobian_computer
Definition: jacobian_computer.hpp:8
NiHu::num_cols
metafunction returning the number of compile time columns
Definition: matrix_traits.hpp:41
NiHu::dirac_field
dirac view of a field
Definition: field.hpp:175
matrix_traits.hpp
compile time properties of matrices