DUNE-FEM (unstable)

eigenvector.hh
1#ifndef EIGENVECTOR_HH
2#define EIGENVECTOR_HH
3
4#ifdef HAVE_EIGEN
5
6#include <algorithm>
7#include <iostream>
8
11
12#include <Eigen/Dense>
13
14namespace Dune
15{
16
17 namespace Fem
18 {
19 // forward declaration
20 template< class K > class EigenVector;
21 }
22
23 // specialization of DenseMatVecTraits for EigenVector
24 template< class K >
25 struct DenseMatVecTraits< Fem::EigenVector< K > >
26 {
27 typedef Fem::EigenVector< K > derived_type;
28 typedef Eigen::Matrix< K, Eigen::Dynamic, 1 > container_type;
29 typedef K value_type;
30 typedef unsigned int size_type;
31 };
32
33 template< class K >
34 struct FieldTraits< Fem::EigenVector< K > >
35 {
36 typedef typename FieldTraits< K >::field_type field_type;
37 typedef typename FieldTraits< K >::real_type real_type;
38 };
39
40
41 namespace Fem
42 {
43
48 template< class K >
49 class EigenVector : public DenseVector< EigenVector< K > >
50 {
51 typedef EigenVector< K > ThisType;
52 typedef DenseVector< ThisType > BaseType;
53
54 public:
55 typedef typename BaseType::size_type size_type;
56 typedef size_type SizeType;
57 typedef typename BaseType::value_type value_type;
58 typedef value_type FieldType;
59 typedef typename DenseMatVecTraits< ThisType >::container_type container_type;
60 typedef container_type DofStorageType;
61
63 explicit EigenVector( size_type size = 0 )
64 : data_( size )
65 {}
66
68 EigenVector( size_type size, const value_type& s )
69 : data_( size )
70 {
71 std::fill( data_.begin(), data_.end(), s );
72 }
73
75 template< class T >
76 EigenVector( const DenseVector< T >& v )
77 : data_( v.size() )
78 {
79 std::copy( v.begin(), v.end(), data_.begin() );
80 }
81
83 EigenVector &operator=( const EigenVector& other )
84 {
85 data_.resize( other.size() );
86 std::copy( other.begin(), other.end(), data_.begin() );
87 return *this;
88 }
89
90 const value_type& operator[]( size_type index ) const
91 {
92 return data_( index );
93 }
94
95 value_type& operator[]( size_type index )
96 {
97 return data_( index );
98 }
99
101 const DofStorageType& coefficients() const
102 {
103 return data_;
104 }
105
107 DofStorageType& coefficients()
108 {
109 return data_;
110 }
111
113 const value_type* data() const
114 {
115 return data_.data();
116 }
117
119 value_type* data()
120 {
121 return data_.data();
122 }
123
125 void reserve( size_type newSize )
126 {
127 data_.resize( newSize );
128 }
129
131 void resize( size_type newSize )
132 {
133 data_.resize( newSize );
134 }
135
137 void resize( size_type newSize, const value_type& s )
138 {
139 data_.resize( newSize );
140 std::fill( data_.begin(), data_.end(), s );
141 }
142
143 size_type size() const
144 {
145 return data_.size();
146 }
147
148 private:
149 DofStorageType data_;
150 };
151
163 template< class K >
164 inline std::istream& operator>>( std::istream& in, EigenVector< K >& v )
165 {
166 EigenVector< K > w(v);
167 for( typename EigenVector< K >::size_type i = 0; i < w.size(); ++i )
168 in >> w[ i ];
169 if(in)
170 v = w;
171 return in;
172 }
173
174 } // namespace Fem
175
176} // namespace Dune
177
178#endif
179
180#endif // #ifndef EIGENVECTOR_HH
Implements the dense vector interface, with an exchangeable storage class.
Type traits to determine the type of reals (when working with complex numbers)
Stream & operator>>(Stream &stream, std::tuple< Ts... > &t)
Read a std::tuple.
Definition: streamoperators.hh:43
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)