dune-fem  2.4.1-rc
misc/functor.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_MISC_FUNCTOR_HH
2 #define DUNE_FEM_MISC_FUNCTOR_HH
3 
4 #include <cstddef>
5 
6 namespace Dune
7 {
8 
9  namespace Fem
10  {
11 
12  // DefaultAssign
13  // -------------
14 
16  {
17  template< class T, class U >
18  void operator() ( const T &a, U &b ) const
19  {
20  b = a;
21  }
22  };
23 
24 
25 
26  // AssignFunctor
27  // -------------
28 
29  template< class Array, class Assign = DefaultAssign >
31  {
32  explicit AssignFunctor ( Array &array, const Assign &assign = Assign() )
33  : array_( array ),
34  assign_( assign )
35  {}
36 
37  template< class Value >
38  void operator() ( const std::size_t local, const Value &value )
39  {
40  assign_( value, array_[ local ] );
41  }
42 
43  private:
44  Array &array_;
45  Assign assign_;
46  };
47 
48  template< class T, class Assign >
49  struct AssignFunctor< T *, Assign >
50  {
51  explicit AssignFunctor ( T *array, const Assign &assign = Assign() )
52  : array_( array ),
53  assign_( assign )
54  {}
55 
56  template< class Value >
57  void operator() ( const std::size_t local, const Value &value )
58  {
59  assign_( value, array_[ local ] );
60  }
61 
62  private:
63  T *array_;
64  Assign assign_;
65  };
66 
67 
68 
69  // AssignSingleFunctor
70  // -------------------
71 
72  template< class Value >
74  {
75  explicit AssignSingleFunctor ( const std::size_t i, Value &value )
76  : localFixed_( i ),
77  value_( value )
78  {}
79 
80  void operator() ( const std::size_t local, const Value &globalKey )
81  {
82  if( local == localFixed_ )
83  value_ = globalKey;
84  }
85 
86  private:
87  std::size_t localFixed_;
88  Value &value_;
89  };
90 
91  template <class Mapper2, class Entity2, class Functor>
93  {
94  explicit MatrixFunctor( const Mapper2 &mapper2, const Entity2 &entity2, Functor functor )
95  : mapper2_(mapper2),
96  entity2_(entity2),
97  functor_(functor)
98  {}
99  void operator() ( const std::size_t local1, const typename Functor::GlobalKey &globalKey1 )
100  {
101  functor_.set(local1,globalKey1);
102  mapper2_.mapEach(entity2_, functor_);
103  }
104  private:
105  const Mapper2 &mapper2_;
106  const Entity2 &entity2_;
107  Functor functor_;
108  };
109 
110  } // namespace Fem
111 
112 } // namespace Dune
113 
114 #endif // #ifndef DUNE_FEM_MISC_FUNCTOR_HH
AssignFunctor(Array &array, const Assign &assign=Assign())
Definition: misc/functor.hh:32
AssignFunctor(T *array, const Assign &assign=Assign())
Definition: misc/functor.hh:51
Definition: misc/functor.hh:92
AssignSingleFunctor(const std::size_t i, Value &value)
Definition: misc/functor.hh:75
Definition: misc/functor.hh:30
Definition: coordinate.hh:4
MatrixFunctor(const Mapper2 &mapper2, const Entity2 &entity2, Functor functor)
Definition: misc/functor.hh:94
Definition: misc/functor.hh:15
Definition: misc/functor.hh:73
void operator()(const T &a, U &b) const
Definition: misc/functor.hh:18