DUNE-FEM (unstable)

functor.hh
1#ifndef DUNE_FEM_MISC_FUNCTOR_HH
2#define DUNE_FEM_MISC_FUNCTOR_HH
3
4#include <cstddef>
5
6namespace Dune
7{
8
9 namespace Fem
10 {
11
12 // DefaultAssign
13 // -------------
14
15 struct DefaultAssign
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 >
30 struct AssignFunctor
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 ) const
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 ) const
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 >
73 struct AssignSingleFunctor
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 ) const
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>
92 struct MatrixFunctor
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 ) const
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
Dune namespace.
Definition: alignedallocator.hh:13
void assign(T &dst, const T &src, bool mask)
masked Simd assignment (scalar version)
Definition: simd.hh:447
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)