NiHu  2.0
field_type_accelerator.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 
22 
23 #ifndef FIELD_TYPE_ACCELERATOR_HPP_INCLUDED
24 #define FIELD_TYPE_ACCELERATOR_HPP_INCLUDED
25 
26 #include "field.hpp"
28 #include "global_definitions.hpp"
29 #include "quadrature.hpp"
30 #include "../util/casted_iterator.hpp"
31 #include "../util/dual_range.hpp"
32 #include "../util/pool_pattern.hpp"
33 
34 #include <iterator>
35 
36 namespace NiHu
37 {
38 
39 
45 template<class Field, class Family, class Acceleration>
47 
49 template <class Field, class Family>
50 class field_type_accelerator_elem<Field, Family, acceleration::soft> :
51  public quadrature_elem<
52  typename Field::elem_t::domain_t::xi_t,
53  typename Field::elem_t::domain_t::scalar_t
54  >
55 {
56 public:
58  typedef quadrature_elem<
59  typename Field::elem_t::domain_t::xi_t, typename Field::domain_t::scalar_t
60  > base_t;
61 
65  typename Field::nset_t::shape_t get_N(void) const
66  {
67  return Field::nset_t::template eval_shape<0>(base_t::get_xi());
68  }
69 };
70 
71 
73 template <class Field, class Family>
74 class field_type_accelerator_elem<Field, Family, acceleration::hard> :
75  public quadrature_elem<
76  typename Field::elem_t::domain_t::xi_t,
77  typename Field::elem_t::domain_t::scalar_t
78  >
79 {
80 public:
82  typedef quadrature_elem<
83  typename Field::elem_t::domain_t::xi_t,
84  typename Field::elem_t::domain_t::scalar_t
85  > base_t;
86 
91  base_t(base),
92  m_nset(Field::nset_t::template eval_shape<0>(base_t::get_xi()))
93  {
94  }
95 
99  typename Field::nset_t::shape_t const &get_N(void) const
100  {
101  return m_nset;
102  }
103 
104 protected:
106  typename Field::nset_t::shape_t m_nset;
107 };
108 
109 
110 
111 // forward declaration
112 template <class Field, class Family, class Acceleration, class Enable = void>
114 
119 template <class Field, class Family>
121  Field, Family, acceleration::hard,
122  typename std::enable_if<!field_traits::is_dirac<Field>::value>::type
123  > :
124  public eigen_std_vector<
125  field_type_accelerator_elem<Field, Family, acceleration::hard>
126  >::type
127 {
128 public:
131  Field, Family, acceleration::hard
134  typedef typename eigen_std_vector<accelerator_elem_t>::type base_t;
135 
137  typedef typename quadrature_type<
138  Family, typename Field::elem_t::domain_t
139  >::type quadrature_t;
140 
145  {
146  this->reserve(quadrature.size());
147  for (unsigned i = 0; i < quadrature.size(); ++i)
148  this->push_back(accelerator_elem_t(quadrature[i]));
149  }
150 
154  field_type_accelerator(unsigned order) :
156  {
157  }
158 };
159 
160 
165 template <class Field, class Family>
166 class field_type_accelerator<Field, Family, acceleration::soft,
167  typename std::enable_if<!field_traits::is_dirac<Field>::value>::type
168  > :
169  public quadrature_type<Family, typename Field::elem_t::domain_t>::type
170 {
171 public:
177  typedef casted_iterator<
178  typename base_t::const_iterator,
181 
185  const_iterator begin(void) const
186  {
187  return base_t::cbegin();
188  }
189 
193  const_iterator end(void) const
194  {
195  return base_t::cend();
196  }
197 };
198 
199 
201 struct index_t
202 {
204  index_t(unsigned idx) : m_idx(idx) {}
206  unsigned m_idx;
207 };
208 
209 
213 template <class NSet>
215  public index_t
216 {
217 public:
221  constexpr typename NSet::scalar_t get_w(void) const
222  {
223  return 1.0;
224  }
225 
229  constexpr typename NSet::shape_t get_N(void) const
230  {
231  return NSet::shape_t::Unit(index_t::m_idx);
232  }
233 
237  constexpr typename NSet::xi_t get_xi(void) const
238  {
239  return NSet::corner_at(index_t::m_idx);
240  }
241 };
242 
245  : public std::iterator<std::input_iterator_tag, index_t>
246 {
247 public:
248 
253  m_idx(idx)
254  {
255  }
256 
261  {
262  ++m_idx.m_idx;
263  return *this;
264  }
265 
271  {
272  return m_idx.m_idx != other.m_idx.m_idx;
273  }
274 
280  {
281  return !(*this != other);
282  }
283 
287  index_t const &operator*() const
288  {
289  return m_idx;
290  }
291 
295  index_t const *operator->() const
296  {
297  return &m_idx;
298  }
299 
300 private:
301  index_t m_idx;
302 };
303 
304 
309 template <class Field, class Family, class Acceleration>
310 class field_type_accelerator<Field, Family, Acceleration,
311  typename std::enable_if<field_traits::is_dirac<Field>::value>::type
312  >
313 {
314 public:
316  typename Field::nset_t
318 
321  {
322  }
323 
324  typedef casted_iterator<
326  accelerator_elem_t
327  > const_iterator;
328 
332  constexpr static const_iterator begin(void)
333  {
335  }
336 
340  constexpr static const_iterator end(void)
341  {
342  return dirac_field_type_accelerator_iterator(index_t(Field::num_dofs));
343  }
344 };
345 
346 
347 template <class Field, class Family, class Acceleration, unsigned MaxOrder>
349  public pool<field_type_accelerator<Field, Family, acceleration::hard>, MaxOrder>
350 {
351 public:
353 
356  base_t()
357  {
358  }
359 };
360 
361 
366 template <class Field, class Family, unsigned MaxOrder>
367 class field_type_accelerator_pool<Field, Family, acceleration::soft, MaxOrder> :
368  public pool<typename quadrature_type<Family, typename Field::elem_t::domain_t>::type, MaxOrder>
369 {
370 public:
373 
376  base_t()
377  {
378  }
379 
381  accelerator_t const &operator[](unsigned idx) const
382  {
383  return static_cast<accelerator_t const &>(base_t::operator[](idx));
384  }
385 };
386 
387 
388 template <class TestAccelerator, class TrialAccelerator, class IterationMode>
390  public dual_range<
391  IterationMode,
392  typename TestAccelerator::const_iterator,
393  typename TrialAccelerator::const_iterator
394  >
395 {
396 public:
397  typedef dual_range<
398  IterationMode,
399  typename TestAccelerator::const_iterator,
400  typename TrialAccelerator::const_iterator
401  > base_t;
402 
404  TestAccelerator const &test_accelerator,
405  TrialAccelerator const &trial_accelerator
406  ) : base_t(
407  test_accelerator.begin(), test_accelerator.end(),
408  trial_accelerator.begin(), trial_accelerator.end())
409  {
410  }
411 };
412 
413 template <class TestAccelerator, class TrialAccelerator, class IterationMode>
415  create_dual_field_type_accelerator(
416  TestAccelerator const &test_acc,
417  TrialAccelerator const &trial_acc,
418  IterationMode
419  )
420 {
422  test_acc, trial_acc);
423 }
424 
425 }
426 
427 
428 #endif // FIELD_TYPE_ACCELERATOR_HPP_INCLUDED
429 
NiHu::field_type_accelerator_pool< Field, Family, acceleration::soft, MaxOrder >::field_type_accelerator_pool
field_type_accelerator_pool()
this user-specified default constructor is needed by clang
Definition: field_type_accelerator.hpp:375
NiHu::field_type_accelerator< Field, Family, acceleration::hard, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::quadrature_t
quadrature_type< Family, typename Field::elem_t::domain_t >::type quadrature_t
the quadrature type
Definition: field_type_accelerator.hpp:139
NiHu::field_type_accelerator_elem< Field, Family, acceleration::hard >::m_nset
Field::nset_t::shape_t m_nset
the accelerated n-set
Definition: field_type_accelerator.hpp:106
NiHu::field_type_accelerator_pool< Field, Family, acceleration::soft, MaxOrder >::operator[]
const accelerator_t & operator[](unsigned idx) const
constant index oprerator
Definition: field_type_accelerator.hpp:381
NiHu::eigen_std_vector
Convert T to an std::vector<T> with Eigen allocator.
Definition: eigen_utils.hpp:41
NiHu::dirac_field_type_accelerator_elem::get_xi
constexpr NSet::xi_t get_xi(void) const
return quadrature point location
Definition: field_type_accelerator.hpp:237
NiHu::field_type_accelerator_elem
Stores a quadrature point and a shape function vector.
Definition: field_type_accelerator.hpp:46
NiHu::field_type_accelerator< Field, Family, acceleration::soft, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::base_t
quadrature_type< Family, typename Field::elem_t::domain_t >::type base_t
the base type
Definition: field_type_accelerator.hpp:173
NiHu::field_type_accelerator< Field, Family, acceleration::soft, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::begin
const_iterator begin(void) const
return begin iterator
Definition: field_type_accelerator.hpp:185
NiHu::dirac_field_type_accelerator_iterator::operator==
bool operator==(dirac_field_type_accelerator_iterator const &other) const
check equality
Definition: field_type_accelerator.hpp:279
NiHu::dirac_field_type_accelerator_iterator::dirac_field_type_accelerator_iterator
dirac_field_type_accelerator_iterator(index_t const &idx)
constructor
Definition: field_type_accelerator.hpp:252
quadrature.hpp
implementation of class NiHu::quadrature_elem, NiHu::quadrature_base
NiHu::dual_range
a combination of two ranges
Definition: dual_range.hpp:154
NiHu::dirac_field_type_accelerator_iterator::operator!=
bool operator!=(dirac_field_type_accelerator_iterator const &other) const
check inequality
Definition: field_type_accelerator.hpp:270
global_definitions.hpp
global constants governing some accuracy parameters
NiHu::index_t::m_idx
unsigned m_idx
the underlying index value
Definition: field_type_accelerator.hpp:206
NiHu::field_type_accelerator_elem< Field, Family, acceleration::hard >::get_N
const Field::nset_t::shape_t & get_N(void) const
return shape function
Definition: field_type_accelerator.hpp:99
NiHu::casted_iterator
iterator class provides access to its value_t after static cast
Definition: casted_iterator.hpp:37
NiHu::dirac_field_type_accelerator_iterator::operator++
dirac_field_type_accelerator_iterator & operator++()
increment operator
Definition: field_type_accelerator.hpp:260
NiHu::field_type_accelerator< Field, Family, acceleration::soft, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::end
const_iterator end(void) const
return end iterator
Definition: field_type_accelerator.hpp:193
NiHu::quadrature_elem
a quadrature element is a base point and a weight
Definition: quadrature.hpp:39
field.hpp
implementation of fields and field views
NiHu::field_type_accelerator< Field, Family, Acceleration, typename std::enable_if< field_traits::is_dirac< Field >::value >::type >::field_type_accelerator
field_type_accelerator(unsigned)
default constructor
Definition: field_type_accelerator.hpp:320
NiHu::quadrature_type
metafunction to assign a quadrature type to a quadrature family and a domain
Definition: quadrature.hpp:326
NiHu::field_type_accelerator< Field, Family, acceleration::soft, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::const_iterator
casted_iterator< typename base_t::const_iterator, accelerator_elem_t > const_iterator
the iterator type
Definition: field_type_accelerator.hpp:180
NiHu::field_type_accelerator< Field, Family, acceleration::hard, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::accelerator_elem_t
field_type_accelerator_elem< Field, Family, acceleration::hard > accelerator_elem_t
the accelerator element type
Definition: field_type_accelerator.hpp:132
NiHu::pool
Class storing a vector of class instances.
Definition: pool_pattern.hpp:41
NiHu::dual_field_type_accelerator
Definition: field_type_accelerator.hpp:389
NiHu::field_type_accelerator_elem< Field, Family, acceleration::soft >::get_N
Field::nset_t::shape_t get_N(void) const
return shape function
Definition: field_type_accelerator.hpp:65
NiHu::field_type_accelerator< Field, Family, acceleration::hard, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::field_type_accelerator
field_type_accelerator(quadrature_t const &quadrature)
contructor from a quadrature
Definition: field_type_accelerator.hpp:144
NiHu::dirac_field_type_accelerator_iterator::operator->
const index_t * operator->() const
pointer dereference operator
Definition: field_type_accelerator.hpp:295
NiHu::field_type_accelerator_pool
Definition: field_type_accelerator.hpp:348
NiHu::field_type_accelerator< Field, Family, Acceleration, typename std::enable_if< field_traits::is_dirac< Field >::value >::type >::begin
constexpr static const_iterator begin(void)
return begin iterator
Definition: field_type_accelerator.hpp:332
NiHu::field_type_accelerator_elem< Field, Family, acceleration::hard >::field_type_accelerator_elem
field_type_accelerator_elem(base_t const &base)
constructor computing the shape function
Definition: field_type_accelerator.hpp:90
NiHu::index_t::index_t
index_t(unsigned idx)
constructor
Definition: field_type_accelerator.hpp:204
NiHu::field_type_accelerator< Field, Family, acceleration::hard, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::base_t
eigen_std_vector< accelerator_elem_t >::type base_t
the base type
Definition: field_type_accelerator.hpp:134
NiHu::field_type_accelerator< Field, Family, acceleration::hard, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::field_type_accelerator
field_type_accelerator(unsigned order)
constructor from quadrature order
Definition: field_type_accelerator.hpp:154
field_type_acceleration_option.hpp
definition of field type acceleration options
NiHu::dirac_field_type_accelerator_elem::get_w
constexpr NSet::scalar_t get_w(void) const
return quadrature weight
Definition: field_type_accelerator.hpp:221
NiHu::dirac_field_type_accelerator_iterator
an iterator class used for the dirac accelerators
Definition: field_type_accelerator.hpp:244
NiHu::pool< field_type_accelerator< Field, Family, acceleration::hard >, MaxOrder >::operator[]
const field_type_accelerator< Field, Family, acceleration::hard > & operator[](unsigned idx) const
Index operator.
Definition: pool_pattern.hpp:63
NiHu::field_type_accelerator< Field, Family, Acceleration, typename std::enable_if< field_traits::is_dirac< Field >::value >::type >::end
constexpr static const_iterator end(void)
return end iterator
Definition: field_type_accelerator.hpp:340
NiHu::index_t
an index class defined to use as a base class
Definition: field_type_accelerator.hpp:201
NiHu::field_type_accelerator
Definition: field_type_accelerator.hpp:113
NiHu::field_type_accelerator_elem< Field, Family, acceleration::hard >::base_t
quadrature_elem< typename Field::elem_t::domain_t::xi_t, typename Field::elem_t::domain_t::scalar_t > base_t
the base type
Definition: field_type_accelerator.hpp:85
NiHu::field_type_accelerator< Field, Family, acceleration::soft, typename std::enable_if<!field_traits::is_dirac< Field >::value >::type >::accelerator_elem_t
field_type_accelerator_elem< Field, Family, acceleration::soft > accelerator_elem_t
the accelerator element type
Definition: field_type_accelerator.hpp:175
NiHu::dirac_field_type_accelerator_elem
accelerator elem for a Dirac field
Definition: field_type_accelerator.hpp:214
NiHu::field_type_accelerator_elem< Field, Family, acceleration::soft >::base_t
quadrature_elem< typename Field::elem_t::domain_t::xi_t, typename Field::domain_t::scalar_t > base_t
the base type
Definition: field_type_accelerator.hpp:60
NiHu::dirac_field_type_accelerator_iterator::operator*
const index_t & operator*() const
dereference operator
Definition: field_type_accelerator.hpp:287
NiHu::field_type_accelerator_elem< Field, Family, acceleration::soft >
specialisation of NiHu::field_type_accelerator_elem for the soft case
Definition: field_type_accelerator.hpp:50
NiHu::field_type_accelerator_pool::field_type_accelerator_pool
field_type_accelerator_pool()
this user-specified default constructor is needed by clang
Definition: field_type_accelerator.hpp:355
NiHu::acceleration::hard
real acceleration
Definition: field_type_acceleration_option.hpp:35
NiHu::field_type_accelerator_elem< Field, Family, acceleration::hard >
specialisation of NiHu::field_type_accelerator_elem for the hard acceleration case
Definition: field_type_accelerator.hpp:74
NiHu::dirac_field_type_accelerator_elem::get_N
constexpr NSet::shape_t get_N(void) const
return shape set vector
Definition: field_type_accelerator.hpp:229