NiHu  2.0
single_integral.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 NIHU_SINGLE_INTEGRAL_HPP_INCLUDED
26 #define NIHU_SINGLE_INTEGRAL_HPP_INCLUDED
27 
28 #include "global_definitions.hpp"
29 #include "../util/store_pattern.hpp"
30 #include "../util/plain_type.hpp"
31 #include "../util/product_type.hpp"
32 #include "../util/block_product.hpp"
33 #include "../util/materialize_sequence.hpp"
34 #include "gaussian_quadrature.hpp"
36 #include "formalism.hpp"
37 #include "jacobian_computer.hpp"
38 
39 namespace NiHu
40 {
41 
46 template <class TestField, class TrialField>
48 {
50  typedef typename block_product_result_type<
51  typename TestField::nset_t::shape_t,
52  Eigen::Matrix<double, TestField::quantity_dimension, TrialField::quantity_dimension>,
53  typename TrialField::nset_t::shape_t
54  >::type result_t;
55 };
56 
57 
63 template <class TestField, class TrialField, class Formalism = typename get_formalism<TestField, TrialField>::type>
65 {
66 public:
68  typedef TestField test_field_t;
70  typedef TrialField trial_field_t;
71 
75  typedef typename traits_t::result_t result_t;
76 
78  typedef typename test_field_t::elem_t elem_t;
80  typedef typename elem_t::lset_t lset_t;
81 
84 
86  typedef typename test_field_t::nset_t test_nset_t;
88  typedef typename trial_field_t::nset_t trial_nset_t;
89 
91  static unsigned const degree
92  = test_nset_t::polynomial_order
93  + trial_nset_t::polynomial_order
94  + lset_t::jacobian_order;
95 
96 public:
101  static result_t eval(
102  field_base<test_field_t> const &test_field,
103  field_base<trial_field_t> const &trial_field)
104  {
105  result_t result;
106  result.setZero();
107 
110  > > test_store_t;
111 
114  > > trial_store_t;
115 
116  auto acc = create_dual_field_type_accelerator(
117  test_store_t::get_data()[degree],
118  trial_store_t::get_data()[degree],
120 
121  // identity matrix instance for block product integration
122  enum {Rows = TestField::quantity_dimension, Cols = TrialField::quantity_dimension};
123  auto mat = Eigen::Matrix<double, Rows, Cols>::Identity();
124 
125  static bool printed = false;
126 
127  if (!printed) {
128  std::cout << "single_integral_impl::eval() called" << std::endl;
129  printed = true;
130  }
131 
132  for (auto it = acc.begin(); it != acc.end(); ++it)
133  {
134  auto jac = NiHu::jacobian_computer<elem_t>::eval(test_field.get_elem(), it.get_first()->get_xi());
135 
136  /*
137  result += block_product(it.get_first()->get_N(),
138  (mat * it.get_first()->get_w()*jac).eval(),
139  it.get_second()->get_N());
140  */
141 
142  result += block_product(
143  test_field.eval(it.get_first()->get_xi()),
144  (mat * it.get_first()->get_w()*jac).eval(),
145  trial_field.eval(it.get_second()->get_xi())
146  );
147  }
148 
149  return result;
150  }
151 };
152 
153 
159 template <class TestField, class TrialField>
160 class single_integral_impl<TestField, TrialField, formalism::collocational>
161 {
162 public:
164  typedef typename TestField::nset_t test_nset_t;
166  typedef typename TrialField::nset_t trial_nset_t;
167 
168  typedef typename TrialField::elem_t trial_elem_t;
169  typedef typename element_traits::lset<trial_elem_t>::type trial_lset_t;
170 
174  typedef typename traits_t::result_t result_t;
175 
179  static result_t eval(
180  field_base<TestField> const &test_field,
181  field_base<TrialField> const &trial_field)
182  {
183  result_t result;
184  result.setZero();
185 
186  enum {Rows = TestField::quantity_dimension, Cols = TrialField::quantity_dimension};
187  auto mat = Eigen::Matrix<double, Rows, Cols>::Identity();
188 
189  for (unsigned row = 0; row < test_nset_t::num_nodes; ++row)
190  {
191  auto N = trial_field.eval(test_nset_t::corner_at(row));
192  double weight = test_field.get_corner_angle(row);
193 
194  for (unsigned col = 0; col < trial_nset_t::num_nodes; ++col)
195  result.template block<Rows, Cols>(row*Rows, col*Cols) = weight * mat * N(col);
196  }
197 
198  return result;
199  }
200 };
201 
202 
208 template <class TestField, class TrialField, class = void>
210 {
211 public:
214 
218  static constexpr result_t eval(
219  field_base<TestField> const &,
220  field_base<TrialField> const &)
221  {
222  return result_t::Zero();
223  }
224 };
225 
226 
232 template <class TestField, class TrialField>
233 class single_integral<TestField, TrialField,
234  typename std::enable_if<
235  std::is_same<
236  typename TestField::elem_t,
237  typename TrialField::elem_t
238  >::value
239  >::type
240 > : public single_integral_impl<TestField, TrialField> {};
241 
242 }
243 
244 #endif /* NIHU_SINGLE_INTEGRAL_HPP_INCLUDED */
245 
NiHu::single_integral_impl< TestField, TrialField, formalism::collocational >::result_t
traits_t::result_t result_t
the result matrix type of the single integral
Definition: single_integral.hpp:174
gaussian_quadrature.hpp
implementation of Gaussian quadratures
NiHu::single_integral_impl< TestField, TrialField, formalism::collocational >::traits_t
single_integral_traits< TestField, TrialField > traits_t
the traits class
Definition: single_integral.hpp:172
NiHu::single_integral_traits::result_t
block_product_result_type< typename TestField::nset_t::shape_t, Eigen::Matrix< double, TestField::quantity_dimension, TrialField::quantity_dimension >, typename TrialField::nset_t::shape_t >::type result_t
result type of the single integral residual
Definition: single_integral.hpp:54
NiHu::store
Storage class with a static member.
Definition: store_pattern.hpp:34
NiHu::iteration::diagonal
parallel
Definition: dual_range.hpp:36
NiHu::single_integral::result_t
single_integral_traits< TestField, TrialField >::result_t result_t
the result matrix type
Definition: single_integral.hpp:213
NiHu::single_integral_impl::trial_nset_t
trial_field_t::nset_t trial_nset_t
N-set of the trial field.
Definition: single_integral.hpp:88
formalism.hpp
return weak form formalism from the test and trial field types
NiHu::single_integral_traits
traits class of NiHu::single_integral
Definition: single_integral.hpp:47
NiHu::single_integral_impl< TestField, TrialField, formalism::collocational >::test_nset_t
TestField::nset_t test_nset_t
N-set of the test field.
Definition: single_integral.hpp:164
global_definitions.hpp
global constants governing some accuracy parameters
NiHu::single_integral_impl::degree
static const unsigned degree
the polynomial degree of the product of the n-sets and the jacobian
Definition: single_integral.hpp:92
NiHu::single_integral_impl::quadrature_family_t
gauss_family_tag quadrature_family_t
the quadrature family
Definition: single_integral.hpp:83
NiHu::single_integral_impl::lset_t
elem_t::lset_t lset_t
L-set of the elem.
Definition: single_integral.hpp:80
NiHu::single_integral_impl::eval
static result_t eval(field_base< test_field_t > const &test_field, field_base< trial_field_t > const &trial_field)
evaluate single integral on a given field
Definition: single_integral.hpp:101
NiHu::element_traits::lset
The geometrical shape set of the element.
Definition: element.hpp:102
NiHu::single_integral
single integral for different element types
Definition: single_integral.hpp:209
NiHu::single_integral_impl::test_nset_t
test_field_t::nset_t test_nset_t
N-set of the test field.
Definition: single_integral.hpp:86
NiHu::field_type_accelerator_pool
Definition: field_type_accelerator.hpp:348
NiHu::single_integral_impl::test_field_t
TestField test_field_t
template parameter as nested type
Definition: single_integral.hpp:68
NiHu::single_integral_impl::traits_t
single_integral_traits< test_field_t, trial_field_t > traits_t
the traits class
Definition: single_integral.hpp:73
NiHu::single_integral_impl
single integral over an element for the general case
Definition: single_integral.hpp:64
NiHu::field_base::get_elem
const elem_t & get_elem() const
return underlying element
Definition: field.hpp:149
NiHu::field_base
CRTP base class of all fields.
Definition: field.hpp:111
NiHu::single_integral_impl< TestField, TrialField, formalism::collocational >::trial_nset_t
TrialField::nset_t trial_nset_t
N-set of the trial field.
Definition: single_integral.hpp:166
NiHu::block_product
block_product_result_type< leftDerived, mat, rightDerived >::type block_product(Eigen::MatrixBase< leftDerived > const &l, mat const &m, Eigen::MatrixBase< rightDerived > const &r)
compute a block product l * m * r^T
Definition: block_product.hpp:170
NiHu::GLOBAL_MAX_ORDER
const unsigned GLOBAL_MAX_ORDER
the maximal order of accelerated quadratures and field type accelerators
Definition: global_definitions.hpp:41
NiHu::block_product_result_type
metafunction returning the value type of a block product
Definition: block_product.hpp:154
NiHu::single_integral_impl< TestField, TrialField, formalism::collocational >::eval
static result_t eval(field_base< TestField > const &test_field, field_base< TrialField > const &trial_field)
evaluate collocational integral on a given field
Definition: single_integral.hpp:179
NiHu::single_integral_impl::trial_field_t
TrialField trial_field_t
template parameter as nested type
Definition: single_integral.hpp:70
NiHu::jacobian_computer
Definition: jacobian_computer.hpp:8
NiHu::single_integral::eval
static constexpr result_t eval(field_base< TestField > const &, field_base< TrialField > const &)
specialisation of single_integral::eval for the empty case
Definition: single_integral.hpp:218
NiHu::single_integral_impl::result_t
traits_t::result_t result_t
the result matrix type
Definition: single_integral.hpp:75
NiHu::single_integral_impl::elem_t
test_field_t::elem_t elem_t
Elem type.
Definition: single_integral.hpp:78
NiHu::acceleration::hard
real acceleration
Definition: field_type_acceleration_option.hpp:35
NiHu::gauss_family_tag
tag for the family of Gaussian quadratures
Definition: gaussian_quadrature.hpp:517
field_type_accelerator.hpp
Acceleration of field types by storing shape functions for each quadrature point.