1 #ifndef DUNE_FEM_SIMPLEBLOCKVECTOR_HH 2 #define DUNE_FEM_SIMPLEBLOCKVECTOR_HH 7 #include <dune/common/densevector.hh> 8 #include <dune/common/dynvector.hh> 15 #include <dune/istl/bvector.hh> 21 template<
class BlockVector >
25 template<
class BlockVector >
26 struct DenseMatVecTraits<
Fem::SimpleBlockVectorBlock< BlockVector > >
46 template<
class Imp,
class Field >
66 const ThisType& operator= (
const ThisType &other )
68 if( &asImp() != &other )
81 const ThisType &operator+= (
const ThisType &other )
83 assert( asImp().size() == other.
size() );
84 const auto endit = asImp().end();
85 auto oit = other.
begin();
86 for(
auto it = asImp().begin(); it != endit; ++it, ++oit )
98 const ThisType &operator-= (
const ThisType &other )
100 assert( asImp().size() == other.
size() );
101 const auto endit = asImp().end();
102 auto oit = other.
begin();
103 for(
auto it = asImp().begin(); it != endit; ++it, ++oit )
117 assert( asImp().size() == other.
size() );
119 const auto endit = asImp().end();
121 for(
auto it = asImp().begin(); it != endit; ++it, ++oit )
132 const ThisType &operator*= (
const FieldType &scalar )
134 const auto endit = asImp().end();
135 for(
auto it = asImp().begin(); it != endit; ++it )
153 void axpy (
const FieldType &scalar,
const ThisType &other )
155 assert( asImp().size() == other.
size() );
156 const auto endit = asImp().end();
157 auto oit = other.
begin();
159 for(
auto it = asImp().begin(); it != endit; ++it, ++oit )
161 *it += scalar * (*oit);
171 std::fill( asImp().begin(), asImp().end(), FieldType( 0 ) );
180 assert( asImp().size() == other.
size() );
181 std::copy( other.
begin(), other.
end(), asImp().begin() );
184 ThisType&
asImp() {
return static_cast< ThisType&
> (*this); }
185 const ThisType&
asImp()
const {
return static_cast< ThisType&
> (*this); }
198 template<
class Container,
int BlockSize >
200 :
public BlockVectorInterface< SimpleBlockVector< Container, BlockSize>, typename Container::value_type >
204 typedef Container ArrayType;
237 enum { blockSize = BlockSize };
255 const ThisType& operator= (
const ThisType& other )
257 BaseType::operator=( other );
266 ConstDofBlockType operator[] (
const unsigned int i )
const 268 assert( i < size() );
269 return ConstDofBlockType( *
this, i*blockSize );
277 DofBlockType operator[] (
const unsigned int i )
279 assert( i < size() );
280 return DofBlockType( *
this, i*blockSize );
288 ConstDofBlockPtrType
blockPtr(
const unsigned int i )
const 290 return ConstDofBlockPtrType( this->
operator[] ( i ) );
300 return DofBlockPtrType( this->
operator[] ( i ) );
307 IteratorType
begin() {
return array().begin(); }
313 ConstIteratorType
begin()
const {
return array().begin(); }
319 IteratorType
end() {
return array().end(); }
325 ConstIteratorType
end()
const {
return array().end(); }
331 SizeType
size ()
const {
return array().size() / blockSize; }
337 SizeType
numDofs()
const {
return array().size(); }
339 FieldType*
data() {
return array().data(); }
340 const FieldType*
data()
const {
return array().data(); }
342 const ArrayType &
array ()
const {
return array_; }
343 ArrayType &
array () {
return array_; }
358 template<
class BlockVector >
361 typedef BlockVector BlockVectorType;
362 typedef typename BlockVectorType :: FieldType
FieldType;
363 typedef typename BlockVectorType::CounterType
CounterType;
372 static const unsigned int blockSize = BlockVector :: blockSize ;
380 : blockVector_( const_cast< BlockVectorType& > (blockVector) ),
381 blockBegin_( blockBegin )
387 : blockVector_( const_cast< BlockVectorType& > (other.blockVector_)),
388 blockBegin_( other.blockBegin_ )
391 size_type
size ()
const {
return blockSize; }
399 ThisType &operator= (
const ConstBlockType &other )
412 assert(index < blockSize);
413 return blockVector_.array()[blockBegin_ + index];
423 assert(index < blockSize);
424 return blockVector_.array()[blockBegin_ + index];
429 int dim()
const {
return blockSize; }
435 template<
class Block >
436 void copy (
const Block &other )
438 for(
unsigned int i=0; i < blockSize; ++i )
439 (*
this)[ i ] = other[ i ];
454 template<
class Container,
unsigned int BlockSize >
460 typedef Container ArrayType;
461 using BaseType :: array_;
462 using BaseType :: sequence_;
465 using BaseType :: array;
466 using BaseType :: blockSize ;
476 : BaseType( *(new Container( size*blockSize ) ) )
482 : BaseType( *(new Container( other.array().size() ) ) )
502 array().reserve( size*blockSize );
511 array().resize( size*blockSize );
523 template<
class F,
unsigned int BlockSize >
533 using BaseType :: sequence_;
537 using BaseType :: blockSize ;
547 : BaseType( allocateContainer( size*blockSize ) )
553 : BaseType( allocateContainer( other.array().size() ) )
573 container_->
reserve( size*blockSize );
582 container_->
resize( size*blockSize );
589 container_ =
new MutableContainer( size );
601 template<
class DofBlock >
608 typedef BlockVector< DofBlock >
ArrayType;
616 using BaseType :: sequence_;
620 enum { blockSize = DofBlock :: dimension };
624 template <
class EmbeddedIterator,
class V>
626 :
public ForwardIteratorFacade< Iterator< EmbeddedIterator,V >, V >
631 mutable EmbeddedIterator
it_;
640 ,
const EmbeddedIterator& end = EmbeddedIterator()
653 assert( it_ != end_ );
654 assert( index_ < blockSize );
655 return (*it_)[ index_ ];
662 if( index_ >= blockSize )
672 return (it_ == other.
it_) && (index_ == other.
index_);
709 const ThisType& operator= (
const ThisType& other )
713 array() = other.
array();
718 DofBlockPtrType
blockPtr(
const unsigned int i ) {
return &array()[ i ]; }
719 ConstDofBlockPtrType
blockPtr(
const unsigned int i )
const {
return &array()[ i ]; }
721 DofBlockType& operator[] (
const unsigned int i ) {
return array()[ i ]; }
722 ConstDofBlockType& operator[] (
const unsigned int i )
const {
return array()[ i ]; }
731 return ConstIteratorType( array().begin()
737 IteratorType
end() {
return IteratorType( array().
end() ); }
738 ConstIteratorType
end()
const {
return ConstIteratorType( array().
end() ); }
740 SizeType
size()
const {
return array().size(); }
752 array().reserve( size );
761 array().resize( size );
765 ArrayType&
array() { assert( array_ );
return *array_; }
766 const ArrayType&
array()
const { assert( array_ );
return *array_; }
776 #endif // DUNE_FEM_REFERENCEBLOCKVECTOR_HH BlockVector::SizeType size_type
Definition: defaultblockvectors.hh:31
BaseType::SizeType SizeType
Definition: defaultblockvectors.hh:538
ArrayType::size_type SizeType
Definition: defaultblockvectors.hh:687
IteratorType end()
Iterator pointing to the last dof.
Definition: defaultblockvectors.hh:319
ConstIteratorType begin() const
Const-iterator pointing to the first dof.
Definition: defaultblockvectors.hh:313
void copy(const Block &other)
Definition: defaultblockvectors.hh:436
Definition: envelope.hh:10
ConstDofBlockPtrType blockPtr(const unsigned int i) const
Accessor for a constant block.
Definition: defaultblockvectors.hh:288
ArrayType DofContainerType
Definition: defaultblockvectors.hh:212
ArrayType::value_type value_type
Typedef to make this class STL-compatible.
Definition: defaultblockvectors.hh:689
const DofBlock ConstDofBlockType
Definition: defaultblockvectors.hh:682
size_type size() const
Definition: defaultblockvectors.hh:391
ConstIteratorType begin() const
Definition: defaultblockvectors.hh:729
Fem::SimpleBlockVectorBlock< BlockVector > container_type
Definition: defaultblockvectors.hh:29
DofBlockType * DofBlockPtrType
Definition: defaultblockvectors.hh:684
void axpy(const FieldType &scalar, const ThisType &other)
Add a scalar multiple of another block vector to this block vector.
Definition: defaultblockvectors.hh:153
void resize(size_t nsize)
Definition: arrays.hh:491
ArrayType::const_iterator ConstIteratorType
Constant iterator to iterate over the dofs.
Definition: defaultblockvectors.hh:219
const ArrayType & array() const
Definition: defaultblockvectors.hh:766
MutableBlockVector(const ThisType &other)
Copy constructor.
Definition: defaultblockvectors.hh:481
const FieldType & vec_access(unsigned int index) const
Obtain a dof inside this block.
Definition: defaultblockvectors.hh:421
SimpleBlockVectorBlock< ThisType > ConstDofBlockType
Type of one constant block.
Definition: defaultblockvectors.hh:231
Imp ThisType
Type of derived class (implementation)
Definition: defaultblockvectors.hh:56
const ArrayType & array() const
Definition: defaultblockvectors.hh:342
SimpleBlockVector(ArrayType &array)
Constructor; use this to create a block vector with 'size' blocks.
Definition: defaultblockvectors.hh:246
ConstIteratorType end() const
Const-iterator pointing to the last dof.
Definition: defaultblockvectors.hh:325
static constexpr T sum(T a)
Definition: utility.hh:33
DebugCounter< size_t > CounterType
Definition: defaultblockvectors.hh:51
const EmbeddedIterator end_
Definition: defaultblockvectors.hh:633
IteratorType begin()
Iterator pointing to the first dof.
Definition: defaultblockvectors.hh:307
Definition: defaultblockvectors.hh:37
SizeType size() const
Returns the number of blocks.
Definition: defaultblockvectors.hh:331
StaticContainer & allocateContainer(const SizeType size)
Definition: defaultblockvectors.hh:587
This is the implementation of a block of SimpleBlockVector.
Definition: defaultblockvectors.hh:22
SizeType numDofs() const
Returns the number of dofs in the block vector.
Definition: defaultblockvectors.hh:337
int dim() const
Returns the size of the block.
Definition: defaultblockvectors.hh:429
Definition: defaultblockvectors.hh:625
SizeType size() const
Definition: defaultblockvectors.hh:740
SimpleBlockVectorBlock(const SimpleBlockVectorBlock< BlockVectorType > &other)
Copy constructor.
Definition: defaultblockvectors.hh:386
ArrayType * array_
Definition: defaultblockvectors.hh:770
Fem::SimpleBlockVectorBlock< BlockVector > derived_type
Definition: defaultblockvectors.hh:28
Definition: defaultblockvectors.hh:455
~MutableBlockVector()
Definition: defaultblockvectors.hh:487
void clear()
Clear this block vector, i.e. set each dof to 0.
Definition: defaultblockvectors.hh:169
BlockVectorType::SizeType size_type
Definition: defaultblockvectors.hh:369
Definition: coordinate.hh:4
void reserve(const int size)
Reserve memory.
Definition: defaultblockvectors.hh:500
Fem::Envelope< DofBlockType > DofBlockPtrType
Definition: defaultblockvectors.hh:233
FieldType value_type
Typedef to make this class STL-compatible.
Definition: defaultblockvectors.hh:224
ArrayType::iterator IteratorType
Iterator to iterate over the dofs.
Definition: defaultblockvectors.hh:217
ISTLBlockVector(ArrayType &array)
Constructor; use this to create a block vector with 'size' blocks.
Definition: defaultblockvectors.hh:697
Static Array Wrapper for simple C Vectors like double* and int*. This also works as base class for th...
Definition: arrays.hh:141
ConstIteratorType end() const
Definition: defaultblockvectors.hh:738
Field FieldType
Type of the field the dofs lie in.
Definition: defaultblockvectors.hh:59
bool equals(const Iterator &other) const
compare
Definition: defaultblockvectors.hh:670
BlockVectorType & blockVector_
Definition: defaultblockvectors.hh:443
Double operator*(const Double &a, const Double &b)
Definition: double.hh:495
IteratorType begin()
Definition: defaultblockvectors.hh:724
void reserve(size_t mSize)
Definition: arrays.hh:517
void reserve(const int size)
Reserve memory.
Definition: defaultblockvectors.hh:571
Iterator(const EmbeddedIterator &it, const EmbeddedIterator &end=EmbeddedIterator())
Default constructor.
Definition: defaultblockvectors.hh:638
int index_
Definition: defaultblockvectors.hh:635
const unsigned int blockBegin_
Definition: defaultblockvectors.hh:444
This is the reference implementation of a block vector as it is expected as the second template param...
Definition: defaultblockvectors.hh:199
Fem::Envelope< ConstDofBlockType > ConstDofBlockPtrType
Definition: defaultblockvectors.hh:234
void increment()
go to next dof
Definition: defaultblockvectors.hh:659
ElementType value_type
make consistent with std::vector
Definition: array.hh:43
EmbeddedIterator it_
Definition: defaultblockvectors.hh:631
ConstDofBlockPtrType blockPtr(const unsigned int i) const
Definition: defaultblockvectors.hh:719
void assign(const ThisType &other)
Definition: defaultblockvectors.hh:178
ArrayType::value_type FieldType
Type of the field the dofs lie in.
Definition: defaultblockvectors.hh:215
FieldType * data()
Definition: defaultblockvectors.hh:339
DofBlock DofBlockType
Definition: defaultblockvectors.hh:681
ThisType & asImp()
Definition: defaultblockvectors.hh:184
BaseType::SizeType SizeType
Definition: defaultblockvectors.hh:467
ConstDofBlockType * ConstDofBlockPtrType
Definition: defaultblockvectors.hh:685
ArrayType & array()
Definition: defaultblockvectors.hh:343
MutableBlockVector(SizeType size)
Constructor; use this to create a block vector with 'size' blocks.
Definition: defaultblockvectors.hh:546
ISTLBlockVector()
Definition: defaultblockvectors.hh:701
MutableBlockVector(const ThisType &other)
Copy constructor.
Definition: defaultblockvectors.hh:552
size_type vec_size() const
Definition: defaultblockvectors.hh:392
ArrayType & array()
Definition: defaultblockvectors.hh:765
void resize(SizeType size)
Resize the block vector.
Definition: defaultblockvectors.hh:509
const FieldType * data() const
Definition: defaultblockvectors.hh:340
SizeType size_type
Typedef to make this class STL-compatible.
Definition: defaultblockvectors.hh:226
Definition: defaultblockvectors.hh:47
V FieldType
Definition: defaultblockvectors.hh:629
unsigned int size_type
type of unsigned integral type of indexing
Definition: array.hh:58
void reserve(const int size)
Reserve memory.
Definition: defaultblockvectors.hh:750
const ThisType & asImp() const
Definition: defaultblockvectors.hh:185
IteratorType end()
Definition: defaultblockvectors.hh:737
Iterator< typename ArrayType::ConstIterator, const FieldType > ConstIteratorType
Definition: defaultblockvectors.hh:679
ArrayType & array_
Definition: defaultblockvectors.hh:349
SimpleBlockVectorBlock< ThisType > DofBlockType
Type of one (mutable) block.
Definition: defaultblockvectors.hh:229
CounterType sequence_
Definition: defaultblockvectors.hh:187
~MutableBlockVector()
Definition: defaultblockvectors.hh:558
void resize(SizeType size)
Resize the block vector.
Definition: defaultblockvectors.hh:580
DofBlockPtrType blockPtr(const unsigned int i)
Definition: defaultblockvectors.hh:718
MutableBlockVector(SizeType size)
Constructor; use this to create a block vector with 'size' blocks.
Definition: defaultblockvectors.hh:475
DofBlock::value_type FieldType
Definition: defaultblockvectors.hh:622
DofBlockPtrType blockPtr(const unsigned int i)
Accessor for a block.
Definition: defaultblockvectors.hh:298
void resize(SizeType size)
Resize the block vector.
Definition: defaultblockvectors.hh:759
BlockVector::FieldType value_type
Definition: defaultblockvectors.hh:30
BlockVectorInterface()
Definition: defaultblockvectors.hh:53
Iterator< typename ArrayType::Iterator, FieldType > IteratorType
Definition: defaultblockvectors.hh:678
SimpleBlockVectorBlock(const BlockVectorType &blockVector, unsigned int blockBegin)
Standard constructor for SimpleBlockVectorBlocks.
Definition: defaultblockvectors.hh:379
ArrayType DofContainerType
Definition: defaultblockvectors.hh:618
FieldType & vec_access(unsigned int index)
Obtain a dof inside this block.
Definition: defaultblockvectors.hh:410
ArrayType::size_type SizeType
Used for indexing the blocks, for example.
Definition: defaultblockvectors.hh:221
A vector using a DynamicArray as storage.
Definition: vector.hh:542
MutableContainer * container_
Definition: defaultblockvectors.hh:535
FieldType & dereference() const
return dof
Definition: defaultblockvectors.hh:651
Definition: defaultblockvectors.hh:602