1#ifndef DUNE_FEM_FUNCTION_HIERARCHICAL_DOFVECTOR_HH
2#define DUNE_FEM_FUNCTION_HIERARCHICAL_DOFVECTOR_HH
7#include <dune/common/ftraits.hh>
10#include <dune/istl/bvector.hh>
11#include <dune/istl/multitypeblockvector.hh>
28 struct BlockIndicesFor;
31 template<
class K,
int dim,
class A >
32 struct BlockIndicesFor< BlockVector< FieldVector< K, dim >, A > >
37 template<
class... V >
38 struct BlockIndicesFor< MultiTypeBlockVector< V... > >
44 struct BlockIndicesFor< const T >
46 typedef typename BlockIndicesFor< T >::Type Type;
58 template<
class DofContainer >
63 typedef typename Impl::BlockIndicesFor< DofContainer >::Type
BlockIndices;
67 : data_( data ), baseIndex_( baseIndex )
71 : data_( other.data_ ), baseIndex_( other.baseIndex_ )
74 template<
class Index >
75 decltype( auto )
operator[] (
const Index &index )
const
77 return access( data_, baseIndex_, index );
80 template<
class Index >
81 decltype( auto )
operator[] (
const Index &index )
83 return access( data_, baseIndex_, index );
88 template<
class... V, std::size_t component,
class I, I offset,
class SI >
91 return access( data[ std::integral_constant< std::size_t, component >() ], baseIndex, index.
subIndex() );
94 template<
class... V, std::size_t component,
class I, I offset,
class SI >
97 return access( data[ std::integral_constant< std::size_t, component >() ], baseIndex, index.
subIndex() );
100 template<
class K,
int n,
class A >
101 static const K &access (
const BlockVector< FieldVector< K, n >, A > &data, std::size_t baseIndex,
int index )
103 return data[ baseIndex ][ index ];
106 template<
class K,
int n,
class A >
107 static K &access ( BlockVector< FieldVector< K, n >, A > &data, std::size_t baseIndex,
int index )
109 return data[ baseIndex ][ index ];
114 std::size_t baseIndex_;
137 typedef typename FieldTraits< DofContainerType >::field_type
FieldType;
181 IteratorType begin () { DUNE_THROW( NotImplemented,
"HierarchicalDofVector does not provide iterators" ); }
183 ConstIteratorType end ()
const { DUNE_THROW( NotImplemented,
"HierarchicalDofVector does not provide iterators" ); }
184 IteratorType end () { DUNE_THROW( NotImplemented,
"HierarchicalDofVector does not provide iterators" ); }
211 template<
class... V >
217 template<
class B,
class A >
220 data.reserve(
size );
223 template<
class... V >
229 template<
class B,
class A >
235 template<
class... V >
236 static SizeType size (
const MultiTypeBlockVector< V... > &data )
238 return data[ std::integral_constant< std::size_t, 0 > () ].size();
241 template<
class B,
class A >
242 static SizeType size (
const BlockVector< B, A > &data )
257 struct SpecialArrayFeatures;
264 return used( array.
array() );
272 memMoveBackward( array.
array(), length, oldStartIdx, newStartIdx );
277 memMoveForward( array.
array(), length, oldStartIdx, newStartIdx );
282 assign( array.
array(), newIndex, oldIndex );
287 template<
class... V >
288 static std::size_t used (
const MultiTypeBlockVector< V... > &array )
290 std::size_t used( 0 );
291 Hybrid::forEach( std::index_sequence_for< V... >(), [ &array, &used ] (
auto &&i ) {
297 template<
class B,
class A >
298 static std::size_t used (
const BlockVector< B, A > &array )
300 return array.size() *
sizeof( B );
303 template<
class... V >
304 static void memMoveBackward ( MultiTypeBlockVector< V... > &array,
int length,
int oldStartIdx,
int newStartIdx )
306 Hybrid::forEach( std::index_sequence_for< V... >(), [ &array, length, oldStartIdx, newStartIdx ] (
auto &&i ) {
307 SpecialArrayFeatures< HierarchicalDofVector< DC > >::memMoveBackward( array[ i ], length, oldStartIdx, newStartIdx );
311 template<
class B,
class A >
312 static void memMoveBackward ( BlockVector< B, A > &array,
int length,
int oldStartIdx,
int newStartIdx )
314 for(
int oldIdx = oldStartIdx+length-1, newIdx = newStartIdx + length-1; oldIdx >= oldStartIdx; --oldIdx, --newIdx )
315 array[ newIdx ] = array[ oldIdx ];
318 template<
class... V >
319 static void memMoveForward ( MultiTypeBlockVector< V... > &array,
int length,
int oldStartIdx,
int newStartIdx )
321 Hybrid::forEach( std::index_sequence_for< V... >(), [ &array, length, oldStartIdx, newStartIdx ] (
auto &&i ) {
322 SpecialArrayFeatures< HierarchicalDofVector< DC > >::memMoveForward( array[ i ], length, oldStartIdx, newStartIdx );
326 template<
class B,
class A >
327 static void memMoveForward ( BlockVector< B, A > &array,
int length,
int oldStartIdx,
int newStartIdx )
329 for(
int oldIdx = oldStartIdx, newIdx = newStartIdx; oldIdx < oldStartIdx+length; ++oldIdx, ++newIdx )
330 array[ newIdx ] = array[ oldIdx ];
333 template<
class... V >
334 static void assign ( MultiTypeBlockVector< V... > &array,
int newIndex,
int oldIndex )
336 Hybrid::forEach( std::index_sequence_for< V... >(), [ &array, newIndex, oldIndex ] (
auto &&i ) {
337 SpecialArrayFeatures< HierarchicalDofVector< DC > >::assign( array[ i ], newIndex, oldIndex );
341 template<
class B,
class A >
342 static void assign ( BlockVector< B, A > &array,
int newIndex,
int oldIndex )
344 array[ newIndex ] = array[ oldIndex ];
Definition: bindguard.hh:11
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
Definition: hybrid.hh:142
const SubIndex & subIndex() const
Definition: hybrid.hh:179
Definition: defaultblockvectors.hh:26
Definition: hierarchical/dofvector.hh:60
static constexpr std::size_t blockSize
Definition: hierarchical/dofvector.hh:64
HierarchicalDofBlock(const HierarchicalDofBlock< std::remove_const_t< DofContainer > > &other)
Definition: hierarchical/dofvector.hh:70
Impl::BlockIndicesFor< DofContainer >::Type BlockIndices
Definition: hierarchical/dofvector.hh:63
HierarchicalDofBlock(DofContainer &data, std::size_t baseIndex)
Definition: hierarchical/dofvector.hh:66
Definition: hierarchical/dofvector.hh:122
Definition: hierarchical/dofvector.hh:131
FieldType value_type
Definition: hierarchical/dofvector.hh:141
DofContainerType & array() noexcept
obtain underlaying DoF storage
Definition: hierarchical/dofvector.hh:168
void memMoveForward(int length, int oldStartIdx, int newStartIdx)
Definition: hierarchical/dofvector.hh:199
HierarchicalDofVector(SizeType size)
Definition: hierarchical/dofvector.hh:150
void resize(SizeType size)
Definition: hierarchical/dofvector.hh:171
Impl::BlockIndicesFor< DC >::Type BlockIndices
Definition: hierarchical/dofvector.hh:144
void reserve(SizeType size)
Definition: hierarchical/dofvector.hh:170
IteratorType begin()
Definition: hierarchical/dofvector.hh:181
void axpy(const FieldType &scalar, const ThisType &other)
Definition: hierarchical/dofvector.hh:161
static constexpr std::size_t blockSize
Definition: hierarchical/dofvector.hh:145
void clear()
Definition: hierarchical/dofvector.hh:163
ConstIteratorType begin() const
Definition: hierarchical/dofvector.hh:180
HierarchicalDofBlock< DofContainerType > DofBlockType
Definition: hierarchical/dofvector.hh:148
std::size_t SizeType
Definition: hierarchical/dofvector.hh:139
void setMemoryFactor(double memFactor)
Definition: hierarchical/dofvector.hh:191
FieldTraits< DofContainerType >::field_type FieldType
Definition: hierarchical/dofvector.hh:137
ThisType & operator+=(const ThisType &other)
Definition: hierarchical/dofvector.hh:155
void copyContent(int newIndex, int oldIndex)
Definition: hierarchical/dofvector.hh:204
ConstDofBlockType operator[](SizeType i) const
Definition: hierarchical/dofvector.hh:152
IteratorType end()
Definition: hierarchical/dofvector.hh:184
ThisType & operator*=(const FieldType &scalar)
Definition: hierarchical/dofvector.hh:157
HierarchicalDofBlock< const DofContainerType > ConstDofBlockType
Definition: hierarchical/dofvector.hh:147
SizeType size() const
Definition: hierarchical/dofvector.hh:173
ThisType & operator-=(const ThisType &other)
Definition: hierarchical/dofvector.hh:156
std::size_t usedMemorySize() const
Definition: hierarchical/dofvector.hh:186
FieldType * IteratorType
Definition: hierarchical/dofvector.hh:178
FieldType operator*(const ThisType &other) const
Definition: hierarchical/dofvector.hh:159
ConstIteratorType end() const
Definition: hierarchical/dofvector.hh:183
SizeType size_type
Definition: hierarchical/dofvector.hh:142
const FieldType * ConstIteratorType
Definition: hierarchical/dofvector.hh:177
DC DofContainerType
Definition: hierarchical/dofvector.hh:135
const DofContainerType & array() const noexcept
obtain underlaying DoF storage
Definition: hierarchical/dofvector.hh:166
void memMoveBackward(int length, int oldStartIdx, int newStartIdx)
Definition: hierarchical/dofvector.hh:194
static void memMoveForward(HierarchicalDofVector< DC > &array, int length, int oldStartIdx, int newStartIdx)
Definition: hierarchical/dofvector.hh:275
static void memMoveBackward(HierarchicalDofVector< DC > &array, int length, int oldStartIdx, int newStartIdx)
Definition: hierarchical/dofvector.hh:270
static void setMemoryFactor(HierarchicalDofVector< DC > &array, double memFactor)
Definition: hierarchical/dofvector.hh:267
static std::size_t used(const HierarchicalDofVector< DC > &array)
Definition: hierarchical/dofvector.hh:262
static void assign(HierarchicalDofVector< DC > &array, int newIndex, int oldIndex)
Definition: hierarchical/dofvector.hh:280