DUNE-FEM (unstable)

functor.hh
1#ifndef DUNE_FEM_BASEFUNCTIONSET_FUNCTOR_HH
2#define DUNE_FEM_BASEFUNCTIONSET_FUNCTOR_HH
3
6
7#include <dune/fem/misc/functor.hh>
8#include <dune/fem/common/explicitfieldvector.hh>
9
10namespace Dune
11{
12
13 namespace Fem
14 {
15
16 // Internal Forward Declarations
17 // -----------------------------
18
19 template< class T >
20 inline void axpy ( const T &a, const T &x, T &y );
21
22 template< class K, int SIZE >
23 inline void axpy ( const typename FieldTraits< K >::field_type &a,
24 const FieldVector< K, SIZE > &x,
25 FieldVector< K, SIZE > &y );
26
27 template< class K, int ROWS, int COLS >
28 inline void axpy ( const typename FieldTraits< K >::field_type &a,
29 const FieldMatrix< K, ROWS, COLS > &x,
30 FieldMatrix< K, ROWS, COLS > &y );
31
32
33
34 // axpy
35 // ----
36
37 template< class T >
38 inline void axpy ( const T &a, const T &x, T &y )
39 {
40 y += a*x;
41 }
42
43 template< class K, int SIZE >
44 inline void axpy ( const typename FieldTraits< K >::field_type &a,
45 const FieldVector< K, SIZE > &x,
46 FieldVector< K, SIZE > &y )
47 {
48 for( int i = 0; i < SIZE; ++i )
49 axpy( a, x[ i ], y[ i ] );
50 }
51
52 template< class K, int ROWS, int COLS >
53 inline void axpy ( const typename FieldTraits< K >::field_type &a,
54 const FieldMatrix< K, ROWS, COLS > &x,
55 FieldMatrix< K, ROWS, COLS > &y )
56 {
57 y.axpy( a, x );
58 }
59
60
61
62 // scalarProduct
63 // -------------
64
65 inline double scalarProduct ( const double &a, const double &b ) { return a * b; }
66
67 template< class T >
68 inline typename T::field_type scalarProduct ( const T &a, const T &b )
69 {
70 return a * b;
71 }
72
73 template< class K, int ROWS, int COLS >
74 inline K scalarProduct ( const FieldMatrix< K, ROWS, COLS > &a, const FieldMatrix< K, ROWS, COLS > &b )
75 {
76 K s( 0 );
77 for( int r = 0; r < ROWS; ++r )
78 s += a[ r ] * b[ r ];
79 return s;
80 }
81
82 template< class K, int ROWS, int COLS, int R >
83 inline K scalarProduct ( const FieldVector< FieldMatrix< K, ROWS, COLS >, R> &a, const FieldVector< FieldMatrix< K, ROWS, COLS >, R> &b )
84 {
85 K s( 0 );
86 for (int i=0; i<R; ++i)
87 for( int r = 0; r < ROWS; ++r )
88 s += a[ i ][ r ] * b[ i ][ r ];
89 return s;
90 }
91
92 template< class K, int ROWS, int COLS, int R >
93 inline K scalarProduct ( const ExplicitFieldVector< FieldMatrix< K, ROWS, COLS >, R> &a, const ExplicitFieldVector< FieldMatrix< K, ROWS, COLS >, R> &b )
94 {
95 K s( 0 );
96 for (int i=0; i<R; ++i)
97 for( int r = 0; r < ROWS; ++r )
98 s += a[ i ][ r ] * b[ i ][ r ];
99 return s;
100 }
101
102
103 // AxpyFunctor
104 // -----------
105
106 template< class Vector, class Value >
107 struct AxpyFunctor
108 {
109 AxpyFunctor ( const Vector &vector, Value &value )
110 : vector_( vector ),
111 value_( value )
112 {}
113
114 template< class V >
115 void operator() ( const std::size_t i, const V &v )
116 {
117 axpy( vector_[ i ], v, value_ );
118 }
119
120 private:
121 const Vector &vector_;
122 Value &value_;
123 };
124
125
126
127 // FunctionalAxpyFunctor
128 // ---------------------
129
130 template< class Value, class Vector >
131 struct FunctionalAxpyFunctor
132 {
133 FunctionalAxpyFunctor ( const Value &value, Vector &vector )
134 : value_( value ),
135 vector_( vector )
136 {}
137
138 template< class V >
139 void operator() ( const std::size_t i, const V &v )
140 {
141 vector_[ i ] += scalarProduct( v, value_ );
142 }
143
144 private:
145 const Value &value_;
146 Vector &vector_;
147 };
148
149 } // namespace Fem
150
151} // namespace Dune
152
153#endif // #ifndef DUNE_FEM_BASEFUNCTIONSET_FUNCTOR_HH
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
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)