1#ifndef DUNE_FEM_SIMPLEBLOCKVECTOR_HH
2#define DUNE_FEM_SIMPLEBLOCKVECTOR_HH
8#include <dune/common/densevector.hh>
9#include <dune/common/dynvector.hh>
18#include <dune/istl/bvector.hh>
37 template<
class Imp,
class Field >
55 if( &
asImp() != &other )
66 assert(
asImp().size() == other.size() );
67 const auto endit =
asImp().end();
68 auto oit = other.begin();
69 for(
auto it =
asImp().begin(); it != endit; ++it, ++oit )
79 assert(
asImp().size() == other.size() );
80 const auto endit =
asImp().end();
81 auto oit = other.begin();
82 for(
auto it =
asImp().begin(); it != endit; ++it, ++oit )
92 assert(
asImp().size() == other.size() );
94 const auto endit =
asImp().end();
95 auto oit = other.asImp().begin();
96 for(
auto it =
asImp().begin(); it != endit; ++it, ++oit )
109 const auto endit =
asImp().end();
110 for(
auto it =
asImp().begin(); it != endit; ++it )
126 assert(
asImp().size() == other.size() );
127 const auto endit =
asImp().end();
128 auto oit = other.begin();
129 for(
auto it =
asImp().begin(); it != endit; ++it, ++oit )
130 *it += scalar * (*oit);
155 void memMoveBackward(
const size_t length,
const size_t oldStartIdx,
const size_t newStartIdx)
157 assert( newStartIdx >= oldStartIdx );
159 size_t newIdx = newStartIdx + length - 1;
160 assert( newIdx <
asImp().size() );
162 for(
size_t oldIdx = oldStartIdx + length-1; oldIdx >= oldStartIdx; --oldIdx, --newIdx )
164 assert( oldIdx <
asImp().size() );
171 void memMoveForward(
const size_t length,
const size_t oldStartIdx,
const size_t newStartIdx)
173 assert( newStartIdx <= oldStartIdx );
174 const size_t upperBound = oldStartIdx + length;
176 size_t newIdx = newStartIdx;
177 for(
size_t oldIdx = oldStartIdx; oldIdx<upperBound; ++oldIdx, ++newIdx )
192 assert(
asImp().size() == other.size() );
193 std::copy( other.begin(), other.end(),
asImp().begin() );
211 template<
class Container,
int BlockSize >
213 :
public BlockVectorInterface< SimpleBlockVector< Container, BlockSize>, typename Container::value_type >
217 typedef Container ArrayType;
252 template <
class Array>
262 typedef Dune::DynamicVector< K >
Array;
283 assert( i <
size() );
290 assert( i <
size() );
343 template<
class Container,
unsigned int BlockSize >
348 typedef SimpleBlockVector < Container, BlockSize >
BaseType;
350 typedef Container ArrayType;
379 doSetMemoryFactor(
array_, memFactor );
403 template <
class T,
class Allocator>
406 array_.setMemoryFactor( memFactor );
409 template <
class Array>
410 void doSetMemoryFactor( Array& ,
const double memFactor ) {}
423 template<
class Field,
unsigned int BlockSize >
465 assert( container_ );
472 assert( container_ );
491 template<
class DofBlock >
497 typedef BlockVector< DofBlock > ArrayType;
500 typedef Dune::DynamicVector< DofBlock > ArrayType;
518 template <
class EmbeddedIterator,
class V>
520 :
public ForwardIteratorFacade< Iterator< EmbeddedIterator,V >, V >
525 mutable EmbeddedIterator
it_;
534 ,
const EmbeddedIterator&
end = EmbeddedIterator()
Definition: bindguard.hh:11
Definition: defaultblockvectors.hh:26
Definition: defaultblockvectors.hh:40
CounterType sequence_
Definition: defaultblockvectors.hh:199
void memMoveBackward(const size_t length, const size_t oldStartIdx, const size_t newStartIdx)
move memory blocks backwards
Definition: defaultblockvectors.hh:155
Field FieldType
Type of the field the dofs lie in.
Definition: defaultblockvectors.hh:50
Imp ThisType
Type of derived class (implementation)
Definition: defaultblockvectors.hh:47
DebugCounter< size_t > CounterType
Definition: defaultblockvectors.hh:42
std::size_t usedMemorySize() const
Definition: defaultblockvectors.hh:143
void axpy(const FieldType &scalar, const ThisType &other)
Add a scalar multiple of another block vector to this block vector.
Definition: defaultblockvectors.hh:124
const ThisType & operator*=(const FieldType &scalar)
Scale this block vector.
Definition: defaultblockvectors.hh:107
void copyContent(const size_t newIndex, const size_t oldIndex)
Definition: defaultblockvectors.hh:149
ThisType & asImp()
Definition: defaultblockvectors.hh:196
BlockVectorInterface()
Definition: defaultblockvectors.hh:44
const ThisType & operator-=(const ThisType &other)
Subtract another block vector from *this.
Definition: defaultblockvectors.hh:77
const ThisType & asImp() const
Definition: defaultblockvectors.hh:197
const ThisType & operator+=(const ThisType &other)
Add another block vector to *this.
Definition: defaultblockvectors.hh:64
void setMemoryFactor(const double memFactor)
set memory overestimate factor, here does nothing
Definition: defaultblockvectors.hh:185
void memMoveForward(const size_t length, const size_t oldStartIdx, const size_t newStartIdx)
move memory blocks forward
Definition: defaultblockvectors.hh:171
FieldType operator*(const ThisType &other) const
Scalar product between *this and another block vector.
Definition: defaultblockvectors.hh:90
void assign(const ThisType &other)
Definition: defaultblockvectors.hh:190
void clear()
Clear this block vector, i.e. set each dof to 0.
Definition: defaultblockvectors.hh:136
const ThisType & operator=(const ThisType &other)
Copy assignment operator.
Definition: defaultblockvectors.hh:53
This is the reference implementation of a block vector as it is expected as the second template param...
Definition: defaultblockvectors.hh:214
ArrayType::size_type SizeType
Used for indexing the blocks, for example.
Definition: defaultblockvectors.hh:231
SubVector< DofContainerType, StaticOffsetSubMapper< BlockSize > > DofBlockType
Type of one (mutable) block.
Definition: defaultblockvectors.hh:239
Fem::Envelope< DofBlockType > DofBlockPtrType
Definition: defaultblockvectors.hh:243
SizeType numDofs() const
Number of dofs in the block vector.
Definition: defaultblockvectors.hh:322
SizeType size() const
Number of blocks.
Definition: defaultblockvectors.hh:319
ArrayType DofContainerType
Definition: defaultblockvectors.hh:222
ArrayType::const_iterator ConstIteratorType
Constant iterator to iterate over the dofs.
Definition: defaultblockvectors.hh:229
ConstIteratorType end() const
Const-iterator pointing to the last dof.
Definition: defaultblockvectors.hh:316
ArrayType::value_type FieldType
Type of the field the dofs lie in.
Definition: defaultblockvectors.hh:225
const ArrayType & array() const
Definition: defaultblockvectors.hh:327
Hybrid::IndexRange< int, blockSize > BlockIndices
Definition: defaultblockvectors.hh:249
ConstDofBlockPtrType blockPtr(const unsigned int i) const
Constant access for the i-th block.
Definition: defaultblockvectors.hh:295
ConstIteratorType begin() const
Const-iterator pointing to the first dof.
Definition: defaultblockvectors.hh:310
const ThisType & operator=(const ThisType &other)
Copy assignment operator.
Definition: defaultblockvectors.hh:274
ArrayType & array_
Definition: defaultblockvectors.hh:331
ArrayType::iterator IteratorType
Iterator to iterate over the dofs.
Definition: defaultblockvectors.hh:227
IteratorType end()
Iterator pointing to the last dof.
Definition: defaultblockvectors.hh:313
SimpleBlockVector(ArrayType &array)
Constructor.
Definition: defaultblockvectors.hh:269
DofBlockPtrType blockPtr(const unsigned int i)
Access the i-th block.
Definition: defaultblockvectors.hh:301
ArrayType & array()
Definition: defaultblockvectors.hh:328
SizeType size_type
Typedef to make this class STL-compatible.
Definition: defaultblockvectors.hh:236
@ blockSize
Definition: defaultblockvectors.hh:247
FieldType value_type
Typedef to make this class STL-compatible.
Definition: defaultblockvectors.hh:234
DofBlockType ConstDofBlockType
Type of one constant block.
Definition: defaultblockvectors.hh:241
IteratorType begin()
Iterator pointing to the first dof.
Definition: defaultblockvectors.hh:307
ConstDofBlockType operator[](const unsigned int i) const
Constant access the i-th block.
Definition: defaultblockvectors.hh:281
FieldType * data()
Definition: defaultblockvectors.hh:324
Fem::Envelope< ConstDofBlockType > ConstDofBlockPtrType
Definition: defaultblockvectors.hh:244
const FieldType * data() const
Definition: defaultblockvectors.hh:325
Definition: defaultblockvectors.hh:254
static const FieldType * data(const Array &array)
Definition: defaultblockvectors.hh:256
static FieldType * data(Array &array)
Definition: defaultblockvectors.hh:255
static const FieldType * data(const Array &array)
Definition: defaultblockvectors.hh:264
static FieldType * data(Array &array)
Definition: defaultblockvectors.hh:263
Dune::DynamicVector< K > Array
Definition: defaultblockvectors.hh:262
Definition: defaultblockvectors.hh:346
MutableBlockVector(const ThisType &other)
Copy constructor.
Definition: defaultblockvectors.hh:365
void reserve(const int size)
Reserve memory.
Definition: defaultblockvectors.hh:390
BaseType::SizeType SizeType
Definition: defaultblockvectors.hh:357
~MutableBlockVector()
Definition: defaultblockvectors.hh:371
MutableBlockVector(SizeType size)
Construct a block vector with 'size' blocks (not initialized)
Definition: defaultblockvectors.hh:360
void resize(SizeType size)
Resize the block vector.
Definition: defaultblockvectors.hh:396
void setMemoryFactor(const double memFactor)
set memory overestimate factor, here does nothing
Definition: defaultblockvectors.hh:377
MutableBlockVector(const ThisType &other)
Copy constructor.
Definition: defaultblockvectors.hh:448
void resize(SizeType size)
Resize the block vector.
Definition: defaultblockvectors.hh:470
std::unique_ptr< MutableContainer > container_
Definition: defaultblockvectors.hh:436
MutableBlockVector(SizeType size)
Construct a block vector with 'size' blocks (not initialized)
Definition: defaultblockvectors.hh:442
BaseType::SizeType SizeType
Definition: defaultblockvectors.hh:439
void reserve(const int size)
Reserve memory.
Definition: defaultblockvectors.hh:463
StaticContainer & allocateContainer(const SizeType size)
Definition: defaultblockvectors.hh:478
Definition: defaultblockvectors.hh:494
ArrayType & array()
Definition: defaultblockvectors.hh:649
const ThisType & operator=(const ThisType &other)
Copy assignment operator.
Definition: defaultblockvectors.hh:593
ConstIteratorType begin() const
Definition: defaultblockvectors.hh:613
void reserve(const int size)
Reserve memory.
Definition: defaultblockvectors.hh:637
DofBlock DofBlockType
Definition: defaultblockvectors.hh:575
IteratorType end()
Definition: defaultblockvectors.hh:621
DofBlock::value_type FieldType
Definition: defaultblockvectors.hh:515
SizeType numDofs() const
Number of dofs in the block vector.
Definition: defaultblockvectors.hh:627
ConstDofBlockType * ConstDofBlockPtrType
Definition: defaultblockvectors.hh:579
ConstIteratorType end() const
Definition: defaultblockvectors.hh:622
ArrayType DofContainerType
Definition: defaultblockvectors.hh:510
DofBlockType * DofBlockPtrType
Definition: defaultblockvectors.hh:578
SizeType size() const
Definition: defaultblockvectors.hh:624
ISTLBlockVector(const ThisType &)=default
DofBlockType & operator[](const unsigned int i)
Definition: defaultblockvectors.hh:605
ArrayType::value_type value_type
Typedef to make this class STL-compatible.
Definition: defaultblockvectors.hh:583
const ArrayType & array() const
Definition: defaultblockvectors.hh:650
ArrayType::size_type SizeType
Definition: defaultblockvectors.hh:581
Iterator< typename ArrayType::ConstIterator, const FieldType > ConstIteratorType
Definition: defaultblockvectors.hh:573
Hybrid::IndexRange< int, blockSize > BlockIndices
Definition: defaultblockvectors.hh:513
IteratorType begin()
Definition: defaultblockvectors.hh:608
DofBlockPtrType blockPtr(const unsigned int i)
Definition: defaultblockvectors.hh:602
ISTLBlockVector()=default
Iterator< typename ArrayType::Iterator, FieldType > IteratorType
Definition: defaultblockvectors.hh:572
@ blockSize
Definition: defaultblockvectors.hh:512
ISTLBlockVector(ArrayType *array)
Constructor.
Definition: defaultblockvectors.hh:586
const DofBlock ConstDofBlockType
Definition: defaultblockvectors.hh:576
ArrayType * array_
Definition: defaultblockvectors.hh:654
ConstDofBlockPtrType blockPtr(const unsigned int i) const
Definition: defaultblockvectors.hh:603
void resize(SizeType size)
Resize the block vector.
Definition: defaultblockvectors.hh:643
Definition: defaultblockvectors.hh:521
void increment()
go to next dof
Definition: defaultblockvectors.hh:553
EmbeddedIterator end_
Definition: defaultblockvectors.hh:527
EmbeddedIterator it_
Definition: defaultblockvectors.hh:525
int index_
Definition: defaultblockvectors.hh:529
V FieldType
Definition: defaultblockvectors.hh:523
bool equals(const Iterator &other) const
compare
Definition: defaultblockvectors.hh:564
Iterator(const EmbeddedIterator &it, const EmbeddedIterator &end=EmbeddedIterator())
Default constructor.
Definition: defaultblockvectors.hh:532
FieldType & dereference() const
return dof
Definition: defaultblockvectors.hh:545
A counter only present if NDEBUG is not defined.
Definition: debug.hh:30
An implementation of DenseVector which uses a C-array of fixed size as storage.
Definition: dynamicarray.hh:148
An implementation of DenseVector which uses a C-array of dynamic size as storage.
Definition: dynamicarray.hh:244
Definition: envelope.hh:11
An implementation of DenseVector to extract a portion, not necessarly contiguos, of a vector.
Definition: subvector.hh:161
Index mapper with static size which simply adds an offset to the index.
Definition: subvector.hh:121