3#ifndef DUNE_ISTL_VBVECTOR_HH
4#define DUNE_ISTL_VBVECTOR_HH
12#include <dune/common/iteratorfacades.hh>
39 template<
class B,
class A=std::allocator<B> >
46 typedef Imp::BlockVectorWindow<B,A> window_type;
53 using field_type =
typename Imp::BlockTraits<B>::field_type;
87 [[deprecated(
"Use free function blockLevel(). Will be removed after 2.8.")]]
112 block = windowAllocator_.allocate(nblocks);
113 new (block) window_type[nblocks];
135 this->n = _nblocks*m;
138 this->p = allocator_.allocate(this->n);
139 new (this->p)B[this->n];
152 block = windowAllocator_.allocate(nblocks);
153 new (block) window_type[nblocks];
157 block[i].set(m,this->p+(i*m));
177 this->p = allocator_.allocate(this->n);
178 new (this->p)B[this->n];
181 for (
size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
194 block = windowAllocator_.allocate(nblocks);
195 new (block) window_type[nblocks];
198 block[0].set(a.block[0].getsize(),this->p);
200 block[i].set(a.block[i].getsize(),block[i-1].getptr()+block[i-1].getsize());
219 allocator_.deallocate(this->p,this->n);
224 block[--i].~window_type();
225 windowAllocator_.deallocate(block,nblocks);
239 allocator_.deallocate(this->p,this->n);
244 block[--i].~window_type();
245 windowAllocator_.deallocate(block,nblocks);
254 block = windowAllocator_.allocate(nblocks);
255 new (block) window_type[nblocks];
275 allocator_.deallocate(this->p,this->n);
280 block[--i].~window_type();
281 windowAllocator_.deallocate(block,nblocks);
285 this->n = _nblocks*m;
288 this->p = allocator_.allocate(this->n);
289 new (this->p)B[this->n];
302 block = windowAllocator_.allocate(nblocks);
303 new (block) window_type[nblocks];
307 block[i].set(m,this->p+(i*m));
326 if (this->n!=a.n || nblocks!=a.nblocks)
333 allocator_.deallocate(this->p,this->n);
338 block[--i].~window_type();
339 windowAllocator_.deallocate(block,nblocks);
347 this->p = allocator_.allocate(this->n);
348 new (this->p)B[this->n];
361 block = windowAllocator_.allocate(nblocks);
362 new (block) window_type[nblocks];
375 block[0].set(a.block[0].getsize(),this->p);
377 block[i].set(a.block[i].getsize(),block[i-1].getptr()+block[i-1].getsize());
381 for (
size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
396 (
static_cast<Imp::block_vector_unmanaged<B,A>&
>(*this)) = k;
417 return target->getsize();
422 target->setsize(
size);
430 SizeProxy(window_type& t)
475 if (not isEnd && i==v.nblocks && not v.initialized)
499 return (i!=it.i) || (&v!=&it.v);
505 return (i==it.i) && (&v==&it.v);
517 v.block[i].setsize(_k);
543#ifdef DUNE_ISTL_WITH_CHECKING
544 if (initialized) DUNE_THROW(
ISTLError,
"no CreateIterator in initialized state");
563#ifdef DUNE_ISTL_WITH_CHECKING
564 if (i>=nblocks) DUNE_THROW(
ISTLError,
"index out of range");
572#ifdef DUNE_ISTL_WITH_CHECKING
573 if (i<0 || i>=nblocks) DUNE_THROW(
ISTLError,
"index out of range");
579 template <
class T,
class R>
581 :
public RandomAccessIteratorFacade<RealIterator<T,R>, T, R>
611 return (p+i)==(it.p+it.i);
712 return Iterator(block,std::min(i,nblocks));
742 if (this->initialized)
743 DUNE_THROW(
ISTLError,
"Attempt to re-allocate already initialized VariableBlockVector");
748 this->n += block[i].size();
755 this->p = allocator_.allocate(this->n);
756 new (this->p)B[this->n];
764 this->block[0].setptr(this->p);
766 block[j].setptr(block[j-1].getptr()+block[j-1].getsize());
769 this->initialized =
true;
778 typename std::allocator_traits<A>::template rebind_alloc<window_type> windowAllocator_;
Helper functions for determining the vector/matrix block level.
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Definition: allocator.hh:9
A vector of blocks with memory management.
Definition: bvector.hh:393
derive error class from the base class in common
Definition: istlexception.hh:17
A Vector of blocks with different blocksizes.
Definition: vbvector.hh:44
RealIterator< value_type, window_type & > Iterator
Definition: vbvector.hh:647
VariableBlockVector()
Definition: vbvector.hh:95
friend class CreateIterator
Definition: vbvector.hh:538
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: vbvector.hh:53
A allocator_type
export the allocator type
Definition: vbvector.hh:56
VariableBlockVector(size_type _nblocks, size_type m)
Definition: vbvector.hh:132
size_type size() const
Definition: vbvector.hh:733
size_type N() const
number of blocks in the vector (are of variable size here)
Definition: vbvector.hh:724
VariableBlockVector(const VariableBlockVector &a)
copy constructor, has copy semantics
Definition: vbvector.hh:170
VariableBlockVector(size_type _nblocks)
Definition: vbvector.hh:106
~VariableBlockVector()
free dynamic memory
Definition: vbvector.hh:213
window_type & operator[](size_type i)
random access to blocks
Definition: vbvector.hh:561
CreateIterator createend()
get create iterator pointing to one after the last block
Definition: vbvector.hh:550
Iterator beforeBegin() const
Definition: vbvector.hh:670
CreateIterator createbegin()
get initial create iterator
Definition: vbvector.hh:541
VariableBlockVector & operator=(const VariableBlockVector &a)
assignment
Definition: vbvector.hh:320
static constexpr auto blocklevel
Definition: vbvector.hh:88
ConstIterator rend() const
end ConstIterator
Definition: vbvector.hh:704
A::size_type size_type
The size type for the index access.
Definition: vbvector.hh:71
ConstIterator find(size_type i) const
random access returning iterator (end if not contained)
Definition: vbvector.hh:716
ConstIterator beforeEnd() const
Definition: vbvector.hh:698
Iterator find(size_type i)
random access returning iterator (end if not contained)
Definition: vbvector.hh:710
const window_type & const_reference
Export type used for const references to container entries.
Definition: vbvector.hh:68
RealIterator< const value_type, const window_type & > ConstIterator
Const iterator.
Definition: vbvector.hh:679
Iterator end()
end Iterator
Definition: vbvector.hh:656
ConstIterator begin() const
begin ConstIterator
Definition: vbvector.hh:685
BlockVector< B, A > value_type
Type of the elements of the outer vector, i.e., dynamic vectors of B.
Definition: vbvector.hh:78
ConstIterator end() const
end ConstIterator
Definition: vbvector.hh:691
BlockVector< B, A > block_type
Same as value_type, here for historical reasons.
Definition: vbvector.hh:82
void resize(size_type _nblocks, size_type m)
same effect as constructor with same argument
Definition: vbvector.hh:268
window_type & reference
Export type used for references to container entries.
Definition: vbvector.hh:62
void resize(size_type _nblocks)
same effect as constructor with same argument
Definition: vbvector.hh:232
Iterator beforeEnd()
Definition: vbvector.hh:663
Iterator begin()
begin Iterator
Definition: vbvector.hh:650
Iterator class for sequential creation of blocks.
Definition: vbvector.hh:441
bool operator==(const CreateIterator &it) const
equality
Definition: vbvector.hh:503
size_type index() const
dereferencing
Definition: vbvector.hh:509
SizeProxy reference
reference type
Definition: vbvector.hh:461
size_type * pointer
pointer type
Definition: vbvector.hh:458
bool operator!=(const CreateIterator &it) const
inequality
Definition: vbvector.hh:497
~CreateIterator()
Definition: vbvector.hh:469
size_type value_type
value type
Definition: vbvector.hh:447
CreateIterator(VariableBlockVector &_v, int _i, bool _isEnd)
constructor
Definition: vbvector.hh:464
void setblocksize(size_type _k)
set size of current block
Definition: vbvector.hh:515
size_type & operator*()
Access size of current block.
Definition: vbvector.hh:526
std::output_iterator_tag iterator_category
iterator category
Definition: vbvector.hh:444
CreateIterator & operator++()
prefix increment
Definition: vbvector.hh:480
void difference_type
difference type (unused)
Definition: vbvector.hh:455
Iterator class for sequential access.
Definition: vbvector.hh:582
RealIterator(window_type *_p, size_type _i)
constructor
Definition: vbvector.hh:592
bool equals(const RealIterator &it) const
equality
Definition: vbvector.hh:609
size_type index() const
Return the index of the entry this iterator is pointing to.
Definition: vbvector.hh:637
window_type & elementAt(std::ptrdiff_t offset) const
Definition: vbvector.hh:631
void decrement()
prefix decrement
Definition: vbvector.hh:603
void advance(std::ptrdiff_t d)
Definition: vbvector.hh:620
void increment()
prefix increment
Definition: vbvector.hh:597
RealIterator()
constructor, no arguments
Definition: vbvector.hh:585
std::ptrdiff_t distanceTo(const RealIterator &o) const
Definition: vbvector.hh:625
window_type & dereference() const
dereferencing
Definition: vbvector.hh:615