dune-fem 2.12-git
Loading...
Searching...
No Matches
subvector.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SUBVECTOR_HH
2#define DUNE_FEM_SUBVECTOR_HH
3
4#include <algorithm>
5
8
10
11namespace Dune
12{
13
14 namespace Fem
15 {
16 // forward declaration
17 template< class K, class M > class SubVector;
18 }
19
20 // specialization of DenseMatVecTraits for SubVector
21 template< class K, class M >
30
31 template< class K, class M >
37
38 namespace Fem
39 {
40
42 template< class IM >
44 : public BartonNackmanInterface< IndexMapperInterface< IM >, IM >
45 {
48
49 public:
51 typedef IM IndexMapperType;
52
55
57 unsigned int operator[] ( unsigned int index ) const
58 {
59 return asImp().operator[]( index );
60 }
61
63 unsigned int range () const
64 {
65 return asImp().range();
66 }
67
69 unsigned int size () const
70 {
71 return asImp().size();
72 }
73
74 protected:
75 using BaseType::asImp;
76 };
77
78
79
82 : public IndexMapperInterface< OffsetSubMapper >
83 {
86
87 public:
88 OffsetSubMapper( unsigned int size, unsigned int offset )
89 : size_( size ), offset_( offset )
90 {}
91
92 OffsetSubMapper( const ThisType& ) = default;
93 OffsetSubMapper( ThisType&& ) = default;
94
95 unsigned int size() const
96 {
97 return size_;
98 }
99
100 unsigned int range() const
101 {
102 return size_;
103 }
104
105 unsigned int operator[]( unsigned int i) const
106 {
107 return i+offset_;
108 }
109
110 private:
111 const unsigned int size_;
112 const unsigned int offset_;
113 };
114
115
116
118 template<unsigned int dim>
120 : public IndexMapperInterface< StaticOffsetSubMapper< dim > >
121 {
124
125 public:
126 StaticOffsetSubMapper( unsigned int offset )
127 : offset_( offset )
128 {}
129
130 StaticOffsetSubMapper( const ThisType& ) = default;
132
133 static constexpr unsigned int size()
134 {
135 return dim;
136 }
137
138 static constexpr unsigned int range()
139 {
140 return dim;
141 }
142
143 unsigned int operator[]( unsigned int i) const
144 {
145 return i+offset_;
146 }
147
148 private:
149 const unsigned int offset_;
150 };
151
152
153
159 template< class BaseVectorImp, class IndexMapperImp >
160 class SubVector : public DenseVector< SubVector< BaseVectorImp, IndexMapperImp > >
161 {
164
165 public:
168
169 using BaseType::operator=;
170
172 typedef BaseVectorImp BaseVectorType;
173
175 typedef IndexMapperImp IndexMapperType;
176
179
181 explicit SubVector( BaseVectorType& baseVector, IndexMapperType&& indexMapper )
182 : baseVector_( baseVector ), indexMapper_( indexMapper )
183 {}
184
185 SubVector( const ThisType & other )
186 : baseVector_( other.baseVector_ ), indexMapper_( other.indexMapper_ )
187 {}
188
190 ThisType& operator=( const ThisType & other)
191 {
192 std::copy( other.begin(), other.end(), this->begin() );
193 return *this;
194 }
195
196 void clear()
197 {
198 std::fill( this->begin(), this->end(), FieldType(0) );
199 }
200
201 void resize( size_type )
202 {}
203
205 {
206 return baseVector_[ indexMapper_[ i ] ];
207 }
208
210 {
211 return baseVector_[ indexMapper_[ i ] ];
212 }
213
215 {
216 return indexMapper_.size();
217 }
218
219 private:
220 BaseVectorType& baseVector_;
221 IndexMapperType indexMapper_;
222 };
223
224
225 } // namespace Fem
226
227} // namespace Dune
228
229#endif
size_type dim() const
std::ptrdiff_t index() const
Traits::value_type value_type
constexpr Iterator end()
Traits::size_type size_type
constexpr Iterator begin()
Definition bartonnackmaninterface.hh:17
const Implementation & asImp() const
Definition bartonnackmaninterface.hh:37
An implementation of DenseVector to extract a portion, not necessarly contiguos, of a vector.
Definition subvector.hh:161
void resize(size_type)
Definition subvector.hh:201
const value_type & operator[](size_type i) const
Definition subvector.hh:204
SubVector(const ThisType &other)
Definition subvector.hh:185
value_type & operator[](size_type i)
Definition subvector.hh:209
ThisType & operator=(const ThisType &other)
Copy entries.
Definition subvector.hh:190
BaseType::value_type value_type
Definition subvector.hh:167
BaseType::size_type size_type
Definition subvector.hh:166
size_type size() const
Definition subvector.hh:214
void clear()
Definition subvector.hh:196
BaseVectorImp BaseVectorType
Type of the base vector.
Definition subvector.hh:172
value_type FieldType
Type of vector elements.
Definition subvector.hh:178
IndexMapperImp IndexMapperType
Type of the index mapper.
Definition subvector.hh:175
SubVector(BaseVectorType &baseVector, IndexMapperType &&indexMapper)
Constructor.
Definition subvector.hh:181
Fem::SubVector< K, M > derived_type
Definition subvector.hh:24
FieldTraits< typenameDenseMatVecTraits< Fem::SubVector< K, M > >::value_type >::real_type real_type
Definition subvector.hh:35
FieldTraits< typenameDenseMatVecTraits< Fem::SubVector< K, M > >::value_type >::field_type field_type
Definition subvector.hh:34
Abstract index mapper interface.
Definition subvector.hh:45
unsigned int operator[](unsigned int index) const
Maps an index onto another one.
Definition subvector.hh:57
unsigned int size() const
Returns the map's size.
Definition subvector.hh:69
const Implementation & asImp() const
Definition bartonnackmaninterface.hh:37
ThisType IndexMapperInterfaceType
Type of the interface.
Definition subvector.hh:54
unsigned int range() const
Returns the map's range.
Definition subvector.hh:63
IM IndexMapperType
Type of the implementation (Barton-Nackman)
Definition subvector.hh:51
Index mapper which simply adds an offset to the index.
Definition subvector.hh:83
OffsetSubMapper(ThisType &&)=default
OffsetSubMapper(unsigned int size, unsigned int offset)
Definition subvector.hh:88
unsigned int size() const
Definition subvector.hh:95
unsigned int operator[](unsigned int i) const
Definition subvector.hh:105
unsigned int range() const
Definition subvector.hh:100
OffsetSubMapper(const ThisType &)=default
Index mapper with static size which simply adds an offset to the index.
Definition subvector.hh:121
StaticOffsetSubMapper(ThisType &&)=default
static constexpr unsigned int size()
Definition subvector.hh:133
StaticOffsetSubMapper(const ThisType &)=default
StaticOffsetSubMapper(unsigned int offset)
Definition subvector.hh:126
unsigned int operator[](unsigned int i) const
Definition subvector.hh:143
static constexpr unsigned int range()
Definition subvector.hh:138
T copy(T... args)
T fill(T... args)
T forward(T... args)