DUNE-FEM (unstable)

functor.hh
1#ifndef DUNE_FEM_FUNCTION_COMMON_FUNCTOR_HH
2#define DUNE_FEM_FUNCTION_COMMON_FUNCTOR_HH
3
4#include <cstddef>
5
6#include <utility>
7
8#include <dune/fem/common/hybrid.hh>
9#include <dune/fem/misc/functor.hh>
10#include <dune/fem/space/basisfunctionset/functor.hh>
11
12namespace Dune
13{
14
15 namespace Fem
16 {
17
18 // LeftAdd
19 // -------
20
21 template< class Vector >
22 struct LeftAdd
23 {
24 LeftAdd ( const Vector &vector )
25 : vector_( vector )
26 {}
27
28 template< class Value >
29 void operator() ( const std::size_t index, Value &&value ) const
30 {
31 value += vector_[ index ];
32 }
33 private:
34 const Vector &vector_;
35 };
36
37
38 // LeftAddScaled
39 // -------------
40
41 template< class Vector, class Scalar >
42 struct LeftAddScaled
43 {
44 LeftAddScaled ( const Vector &vector, const Scalar &s )
45 : vector_( vector ),
46 s_( s )
47 {}
48
49 template< class Value >
50 void operator() ( const std::size_t index, Value &&value ) const
51 {
52 axpy( s_, vector_[ index ], std::forward< Value >( value ) );
53 }
54 private:
55 const Vector &vector_;
56 const Scalar &s_;
57 };
58
59
60 // LeftAssign
61 // ----------
62
63 template< class Vector >
64 struct LeftAssign
65 {
66 LeftAssign ( const Vector &vector )
67 : vector_( vector )
68 {}
69
70 template< class Value >
71 void operator() ( const std::size_t index, Value &&value ) const
72 {
73 value = vector_[ index ];
74 }
75 private:
76 const Vector &vector_;
77 };
78
79
80 // AssignReference
81 // ---------------
82
83 template< class Vector >
84 struct AssignVectorReference
85 {
86 AssignVectorReference ( Vector &vector )
87 : vector_( vector )
88 {}
89
90 template< class Value >
91 void operator() ( const std::size_t index, Value &&value ) const
92 {
93 vector_.bind( index, std::forward< Value > ( value ) );
94 }
95
96 protected:
97 Vector &vector_;
98 };
99
100
101 // DofBlockFunctor
102 // ---------------
103
104 template< class DofVector, class Functor >
105 struct DofBlockFunctor
106 {
107 typedef typename DofVector::BlockIndices BlockIndices;
108 static constexpr std::size_t blockSize = Hybrid::size( BlockIndices() );
109
110 DofBlockFunctor ( DofVector &dofVector, Functor functor )
111 : dofVector_( dofVector ), functor_( functor )
112 {}
113
114 template < class GlobalKey >
115 void operator () ( std::size_t local, const GlobalKey& globalKey ) const
116 {
117 Hybrid::forEach( BlockIndices(), [ this, local, &globalKey ] ( auto &&i ) {
118 functor_( local*blockSize + i, dofVector_[ globalKey ][ i ] );
119 } );
120 }
121
122 private:
123 DofVector &dofVector_;
124 Functor functor_;
125 };
126
127
128 // dofBlockFunctor
129 // ---------------
130
131 template< class DofVector, class Functor >
132 static inline DofBlockFunctor< DofVector, Functor > dofBlockFunctor ( DofVector &dofVector, Functor functor )
133 {
134 return DofBlockFunctor< DofVector, Functor >( dofVector, std::move( functor ) );
135 }
136
137 } // namespace Fem
138
139} // namespace Dune
140
141#endif // #ifndef DUNE_FEM_FUNCTION_COMMON_FUNCTOR_HH
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
typename Overloads::ScalarType< std::decay_t< V > >::type Scalar
Element type of some SIMD type.
Definition: interface.hh:235
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)