5 #ifndef DUNE_ISTL_VBVECTOR_HH 6 #define DUNE_ISTL_VBVECTOR_HH 14 #include <dune/common/ftraits.hh> 15 #include <dune/common/indexediterator.hh> 16 #include <dune/common/iteratorfacades.hh> 43 template<
class B,
class A=std::allocator<B> >
49 using Base = Imp::block_vector_unmanaged<B,typename A::size_type>;
52 using window_type = Imp::BlockVectorWindow<B,A>;
55 using VectorWindows = std::vector<window_type, typename std::allocator_traits<A>::template rebind_alloc<window_type>>;
58 static_assert(not std::is_same_v<B,bool>,
"Block type 'bool' not supported by VariableBlockVector.");
65 using field_type =
typename Imp::BlockTraits<B>::field_type;
128 storage_(numBlocks*blockSize)
135 block[i].
set(blockSize,this->p+(i*blockSize));
143 Base(static_cast<const Base&>(a)),
150 if (block.size()>0) {
151 block[0].set(block[0].getsize(),this->p);
153 block[i].
set(block[i].getsize(),block[i-1].getptr()+block[i-1].getsize());
157 initialized = a.initialized;
181 swap(storage_, other.storage_);
182 swap(block, other.block);
183 swap(initialized, other.initialized);
185 other.syncBaseArray();
203 block.resize(numBlocks);
213 storage_.resize(numBlocks*blockSize);
214 block.resize(numBlocks);
219 block[i].
set(blockSize,this->p+(i*blockSize));
230 (
static_cast<Imp::block_vector_unmanaged<B,size_type>&
>(*this)) = k;
251 return target->getsize();
256 target->setsize(
size);
264 SizeProxy (window_type& t) :
311 if (not isEnd && i==v->block.size() && not v->initialized)
335 return not (*
this == it);
341 return (i==it.i) && (v==it.v);
353 v->block[i].setsize(_k);
364 return {v->block[i]};
379 #ifdef DUNE_ISTL_WITH_CHECKING 380 if (initialized) DUNE_THROW(
ISTLError,
"no CreateIterator in initialized state");
399 #ifdef DUNE_ISTL_WITH_CHECKING 400 if (i>=block.size()) DUNE_THROW(
ISTLError,
"index out of range");
408 #ifdef DUNE_ISTL_WITH_CHECKING 409 if (i<0 || i>=block.size()) DUNE_THROW(
ISTLError,
"index out of range");
414 using Iterator = IndexedIterator<typename VectorWindows::iterator>;
446 using ConstIterator = IndexedIterator<typename VectorWindows::const_iterator>;
487 tmp+=std::min(i, block.size());
495 tmp+=std::min(i, block.size());
521 if (this->initialized)
522 DUNE_THROW(
ISTLError,
"Attempt to re-allocate already initialized VariableBlockVector");
526 for(
size_type i = 0; i < block.size(); i++)
527 storageNeeded += block[i].
size();
529 storage_.resize(storageNeeded);
533 block[0].setptr(this->p);
535 block[j].setptr(block[j-1].getptr()+block[j-1].getsize());
538 this->initialized =
true;
541 void syncBaseArray () noexcept
543 this->p = storage_.data();
544 this->n = storage_.size();
547 VectorWindows block = {};
548 std::vector<B, A> storage_ = {};
549 bool initialized =
false;
555 template<
class B,
class A>
ConstIterator beforeBegin() const
Definition: vbvector.hh:472
A allocator_type
export the allocator type
Definition: vbvector.hh:68
bool operator==(const CreateIterator &it) const
equality
Definition: vbvector.hh:339
derive error class from the base class in common
Definition: istlexception.hh:19
void setblocksize(size_type _k)
set size of current block
Definition: vbvector.hh:351
size_type & operator*()
Access size of current block.
Definition: vbvector.hh:362
void resize(size_type numBlocks)
same effect as constructor with same argument
Definition: vbvector.hh:196
FieldTraits< B >::real_type real_type
Definition: vbvector.hh:559
A Vector of blocks with different blocksizes.
Definition: vbvector.hh:44
ConstIterator begin() const
begin ConstIterator
Definition: vbvector.hh:452
CreateIterator createbegin()
get initial create iterator
Definition: vbvector.hh:377
IndexedIterator< typename VectorWindows::iterator > Iterator
Definition: vbvector.hh:414
Iterator beforeEnd()
Definition: vbvector.hh:430
VariableBlockVector(size_type numBlocks, size_type blockSize)
Construct a vector with given number of blocks each having a constant size.
Definition: vbvector.hh:125
bool operator!=(const CreateIterator &it) const
inequality
Definition: vbvector.hh:333
VariableBlockVector()
Constructor without arguments makes an empty vector.
Definition: vbvector.hh:102
window_type & operator[](size_type i)
random access to blocks
Definition: vbvector.hh:397
window_type & reference
Export type used for references to container entries.
Definition: vbvector.hh:74
const window_type & const_reference
Export type used for const references to container entries.
Definition: vbvector.hh:80
size_type value_type
value type
Definition: vbvector.hh:281
FieldTraits< B >::field_type field_type
Definition: vbvector.hh:558
SizeProxy reference
reference type
Definition: vbvector.hh:295
Iterator find(size_type i)
random access returning iterator (end if not contained)
Definition: vbvector.hh:484
VariableBlockVector(const VariableBlockVector &a)
Copy constructor, has copy semantics.
Definition: vbvector.hh:142
VariableBlockVector(size_type numBlocks)
Construct a vector with given number of blocks, but size of each block is not yet known...
Definition: vbvector.hh:112
~CreateIterator()
Definition: vbvector.hh:304
size_type size() const noexcept
Definition: vbvector.hh:511
std::output_iterator_tag iterator_category
iterator category
Definition: vbvector.hh:278
Helper functions for determining the vector/matrix block level.
ConstIterator end() const
end ConstIterator
Definition: vbvector.hh:458
void swap(VariableBlockVector &other) noexcept
Exchange the storage and internal state with other.
Definition: vbvector.hh:178
CreateIterator(VariableBlockVector &_v, int _i, bool _isEnd)
constructor
Definition: vbvector.hh:298
ConstIterator const_iterator
Export the const iterator type using std naming rules.
Definition: vbvector.hh:449
This file implements a vector space as a tensor product of a given vector space. The number of compon...
size_type N() const noexcept
number of blocks in the vector (are of variable size here)
Definition: vbvector.hh:502
ConstIterator beforeEnd() const
Definition: vbvector.hh:465
IndexedIterator< typename VectorWindows::const_iterator > ConstIterator
Const iterator.
Definition: vbvector.hh:446
ConstIterator find(size_type i) const
random access returning iterator (end if not contained)
Definition: vbvector.hh:492
Iterator beforeBegin()
Definition: vbvector.hh:437
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: vbvector.hh:65
size_type index() const
dereferencing
Definition: vbvector.hh:345
ConstIterator rend() const
end ConstIterator
Definition: vbvector.hh:478
friend void swap(VariableBlockVector &lhs, VariableBlockVector &rhs) noexcept
Free function to swap the storage and internal state of lhs with rhs.
Definition: vbvector.hh:190
Iterator end()
end Iterator
Definition: vbvector.hh:423
Iterator begin()
begin Iterator
Definition: vbvector.hh:417
friend class CreateIterator
Definition: vbvector.hh:374
VariableBlockVector & operator=(VariableBlockVector tmp)
Copy and move assignment.
Definition: vbvector.hh:171
Iterator class for sequential creation of blocks.
Definition: vbvector.hh:274
~VariableBlockVector()=default
CreateIterator & operator++()
prefix increment
Definition: vbvector.hh:316
Iterator iterator
Export the iterator type using std naming rules.
Definition: vbvector.hh:443
void resize(size_type numBlocks, size_type blockSize)
same effect as constructor with same argument
Definition: vbvector.hh:210
size_type * pointer
pointer type
Definition: vbvector.hh:292
Definition: allocator.hh:11
typename A::size_type size_type
The size type for the index access.
Definition: vbvector.hh:83
A vector of blocks with memory management.
Definition: bvector.hh:391
CreateIterator createend()
get create iterator pointing to one after the last block
Definition: vbvector.hh:386
VariableBlockVector(VariableBlockVector &&tmp)
Move constructor:
Definition: vbvector.hh:161
void difference_type
difference type (unused)
Definition: vbvector.hh:289