dune-fem  2.4.1-rc
function/common/functor.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_FUNCTION_COMMON_FUNCTOR_HH
2 #define DUNE_FEM_FUNCTION_COMMON_FUNCTOR_HH
3 
4 #include <utility>
5 
8 
9 namespace Dune
10 {
11 
12  namespace Fem
13  {
14 
15  // LeftAdd
16  // -------
17 
18  template< class Vector >
19  struct LeftAdd
20  {
21  LeftAdd ( const Vector &vector )
22  : vector_( vector )
23  {}
24 
25  template< class Value >
26  void operator() ( const std::size_t index, Value &&value ) const
27  {
28  value += vector_[ index ];
29  }
30  private:
31  const Vector &vector_;
32  };
33 
34 
35  // LeftAddScaled
36  // -------------
37 
38  template< class Vector, class Scalar >
40  {
41  LeftAddScaled ( const Vector &vector, const Scalar &s )
42  : vector_( vector ),
43  s_( s )
44  {}
45 
46  template< class Value >
47  void operator() ( const std::size_t index, Value &&value ) const
48  {
49  axpy( s_, vector_[ index ], std::forward< Value >( value ) );
50  }
51  private:
52  const Vector &vector_;
53  const Scalar &s_;
54  };
55 
56 
57  // LeftAssign
58  // ----------
59 
60  template< class Vector >
61  struct LeftAssign
62  {
63  LeftAssign ( const Vector &vector )
64  : vector_( vector )
65  {}
66 
67  template< class Value >
68  void operator() ( const std::size_t index, Value &&value ) const
69  {
70  value = vector_[ index ];
71  }
72  private:
73  const Vector &vector_;
74  };
75 
76 
77  // AssignReference
78  // ---------------
79 
80  template< class Vector >
82  {
83  AssignVectorReference ( Vector &vector )
84  : vector_( vector )
85  {}
86 
87  template< class Value >
88  void operator() ( const std::size_t index, Value &&value ) const
89  {
90  vector_.bind( index, std::forward< Value > ( value ) );
91  }
92 
93  protected:
94  Vector &vector_;
95  };
96 
97  // DofBlockTraits
98  // --------------
99 
100  template<class DiscreteFunction >
102  {
103  typedef typename DiscreteFunction::DofBlockPtrType DofBlockPtrType;
104  typedef typename DiscreteFunction::DofBlockType DofBlockType;
105  };
106 
107  template<class DiscreteFunction >
108  struct DofBlockTraits<const DiscreteFunction>
109  {
110  typedef typename DiscreteFunction::ConstDofBlockPtrType DofBlockPtrType;
111  typedef typename DiscreteFunction::ConstDofBlockType DofBlockType;
112  };
113 
114 
115  // DofBlockFunctor
116  // ---------------
117 
118  template< class DiscreteFunction, class Functor >
120  {
123 
124  static const int blockSize = DiscreteFunction::DiscreteFunctionSpaceType::localBlockSize;
125 
126  DofBlockFunctor ( DiscreteFunction &df, Functor &functor )
127  : df_( df ), functor_( functor )
128  {}
129 
130  template < class GlobalKey >
131  void operator () ( const std::size_t local, const GlobalKey& globalKey )
132  {
133  DofBlockPtrType blockPtr = df_.block( globalKey );
134  DofBlockType &block = *( blockPtr );
135  for( int i = 0; i < blockSize; ++i )
136  functor_( local*blockSize + i, block[ i ] );
137  }
138  private:
139  DiscreteFunction &df_;
140  Functor &functor_;
141  };
142 
143  } // namespace Fem
144 
145 } // namespace Dune
146 
147 #endif // #ifndef DUNE_FEM_FUNCTION_COMMON_FUNCTOR_HH
Vector & vector_
Definition: function/common/functor.hh:94
Definition: function/common/functor.hh:39
DiscreteFunction::DofBlockType DofBlockType
Definition: function/common/functor.hh:104
LeftAssign(const Vector &vector)
Definition: function/common/functor.hh:63
DofBlockTraits< DiscreteFunction >::DofBlockType DofBlockType
Definition: function/common/functor.hh:122
LeftAddScaled(const Vector &vector, const Scalar &s)
Definition: function/common/functor.hh:41
DiscreteFunction::DofBlockPtrType DofBlockPtrType
Definition: function/common/functor.hh:103
Definition: function/common/functor.hh:119
void axpy(const T &a, const T &x, T &y)
Definition: space/basisfunctionset/functor.hh:37
Definition: function/common/functor.hh:19
DofBlockFunctor(DiscreteFunction &df, Functor &functor)
Definition: function/common/functor.hh:126
Definition: coordinate.hh:4
void operator()(const std::size_t index, Value &&value) const
Definition: function/common/functor.hh:26
Definition: function/common/functor.hh:81
DiscreteFunction::ConstDofBlockPtrType DofBlockPtrType
Definition: function/common/functor.hh:110
AssignVectorReference(Vector &vector)
Definition: function/common/functor.hh:83
DiscreteFunction::ConstDofBlockType DofBlockType
Definition: function/common/functor.hh:111
Definition: function/common/functor.hh:101
DofBlockTraits< DiscreteFunction >::DofBlockPtrType DofBlockPtrType
Definition: function/common/functor.hh:121
Definition: function/common/functor.hh:61
LeftAdd(const Vector &vector)
Definition: function/common/functor.hh:21