dune-fem  2.8-git
function/tuplediscretefunction/functor.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_FUNCTOR_HH
2 #define DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_FUNCTOR_HH
3 
6 
7 
8 namespace Dune
9 {
10 
11  namespace Fem
12  {
13 
14  // DofBlockFunctor
15  // ---------------
16 
17  template< class ... DofVectors, class Functor >
18  struct DofBlockFunctor< TupleDofVector< DofVectors ... >, Functor >
19  {
20  typedef TupleDofVector< DofVectors ... > DofVector;
21  DofBlockFunctor ( DofVector &dofVector, Functor functor )
22  : dofVector_( dofVector ), functor_( std::move( functor ) ) {}
23 
24  template< class GlobalKey >
25  void operator() ( std::size_t local, const GlobalKey &globalKey ) const
26  {
27  const int localBlockSize
28  = std::decay< decltype( std::get< GlobalKey::component() >( dofVector_ ) ) >::type::blockSize;
29 
30  const int index = globalKey.index();
31  functor_( local,
32  std::get< GlobalKey::component() >( dofVector_ ) [ index / localBlockSize ][ index % localBlockSize ] );
33  }
34 
35  private:
36  DofVector &dofVector_;
37  Functor functor_;
38  };
39 
40 
41  // DofBlockFunctor
42  // ---------------
43 
44  template< class ... DofVectors, class Functor >
45  struct DofBlockFunctor< const TupleDofVector< DofVectors ... >, Functor >
46  {
47  typedef TupleDofVector< DofVectors ... > DofVector;
48  DofBlockFunctor ( const DofVector &dofVector, Functor functor )
49  : dofVector_( dofVector ), functor_( std::move( functor ) ) {}
50 
51  template< class GlobalKey >
52  void operator() ( std::size_t local, const GlobalKey &globalKey ) const
53  {
54  const int localBlockSize
55  = std::decay< decltype( std::get< GlobalKey::component() >( dofVector_ ) ) >::type::blockSize;
56 
57  const int index = globalKey.index();
58  functor_( local,
59  std::get< GlobalKey::component() >( dofVector_ ) [ index / localBlockSize ][ index % localBlockSize ] );
60  }
61 
62  private:
63  const DofVector &dofVector_;
64  Functor functor_;
65  };
66 
67  } // namespace Fem
68 
69 } // namespace Dune
70 
71 #endif // #ifndef DUNE_FEM_FUNCTION_TUPLEDISCRETEFUNCTION_FUNCTOR_HH
Definition: bindguard.hh:11
std::tuple_element< i, Tuple >::type & get(Dune::TypeIndexedTuple< Tuple, Types > &tuple)
Definition: typeindexedtuple.hh:122
Definition: function/common/functor.hh:106
void operator()(std::size_t local, const GlobalKey &globalKey) const
Definition: function/common/functor.hh:115
Definition: tuplediscretefunction/dofvector.hh:30
DofBlockFunctor(DofVector &dofVector, Functor functor)
Definition: function/tuplediscretefunction/functor.hh:21
TupleDofVector< DofVectors ... > DofVector
Definition: function/tuplediscretefunction/functor.hh:20
DofBlockFunctor(const DofVector &dofVector, Functor functor)
Definition: function/tuplediscretefunction/functor.hh:48
TupleDofVector< DofVectors ... > DofVector
Definition: function/tuplediscretefunction/functor.hh:47