3 #ifndef DUNE_ISTL_VBVECTOR_HH
4 #define DUNE_ISTL_VBVECTOR_HH
12 #include <dune/common/iteratorfacades.hh>
37 template<
class B,
class A=std::allocator<B> >
44 typedef Imp::BlockVectorWindow<B,A> window_type;
51 using field_type =
typename Imp::BlockTraits<B>::field_type;
85 static constexpr
unsigned int blocklevel = Imp::BlockTraits<B>::blockLevel()+2;
109 block = windowAllocator_.allocate(nblocks);
110 new (block) window_type[nblocks];
132 this->n = _nblocks*m;
135 this->p = allocator_.allocate(this->n);
136 new (this->p)B[this->n];
149 block = windowAllocator_.allocate(nblocks);
150 new (block) window_type[nblocks];
154 block[i].set(m,this->p+(i*m));
174 this->p = allocator_.allocate(this->n);
175 new (this->p)B[this->n];
178 for (
size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
191 block = windowAllocator_.allocate(nblocks);
192 new (block) window_type[nblocks];
195 block[0].set(a.block[0].getsize(),this->p);
197 block[i].set(a.block[i].getsize(),block[i-1].getptr()+block[i-1].getsize());
216 allocator_.deallocate(this->p,this->n);
221 block[--i].~window_type();
222 windowAllocator_.deallocate(block,nblocks);
236 allocator_.deallocate(this->p,this->n);
241 block[--i].~window_type();
242 windowAllocator_.deallocate(block,nblocks);
251 block = windowAllocator_.allocate(nblocks);
252 new (block) window_type[nblocks];
272 allocator_.deallocate(this->p,this->n);
277 block[--i].~window_type();
278 windowAllocator_.deallocate(block,nblocks);
282 this->n = _nblocks*m;
285 this->p = allocator_.allocate(this->n);
286 new (this->p)B[this->n];
299 block = windowAllocator_.allocate(nblocks);
300 new (block) window_type[nblocks];
304 block[i].set(m,this->p+(i*m));
323 if (this->n!=a.n || nblocks!=a.nblocks)
330 allocator_.deallocate(this->p,this->n);
335 block[--i].~window_type();
336 windowAllocator_.deallocate(block,nblocks);
344 this->p = allocator_.allocate(this->n);
345 new (this->p)B[this->n];
358 block = windowAllocator_.allocate(nblocks);
359 new (block) window_type[nblocks];
372 block[0].set(a.block[0].getsize(),this->p);
374 block[i].set(a.block[i].getsize(),block[i-1].getptr()+block[i-1].getsize());
378 for (
size_type i=0; i<this->n; i++) this->p[i]=a.p[i];
393 (
static_cast<Imp::block_vector_unmanaged<B,A>&
>(*this)) = k;
414 return target->getsize();
419 target->setsize(
size);
427 SizeProxy(window_type& t)
472 if (not isEnd && i==v.nblocks && not v.initialized)
496 return (i!=it.i) || (&v!=&it.v);
502 return (i==it.i) && (&v==&it.v);
514 v.block[i].setsize(_k);
540 #ifdef DUNE_ISTL_WITH_CHECKING
541 if (initialized) DUNE_THROW(
ISTLError,
"no CreateIterator in initialized state");
560 #ifdef DUNE_ISTL_WITH_CHECKING
561 if (i>=nblocks) DUNE_THROW(
ISTLError,
"index out of range");
569 #ifdef DUNE_ISTL_WITH_CHECKING
570 if (i<0 || i>=nblocks) DUNE_THROW(
ISTLError,
"index out of range");
576 template <
class T,
class R>
578 :
public RandomAccessIteratorFacade<RealIterator<T,R>, T, R>
608 return (p+i)==(it.p+it.i);
709 return Iterator(block,std::min(i,nblocks));
739 if (this->initialized)
740 DUNE_THROW(
ISTLError,
"Attempt to re-allocate already initialized VariableBlockVector");
745 this->n += block[i].size();
752 this->p = allocator_.allocate(this->n);
753 new (this->p)B[this->n];
761 this->block[0].setptr(this->p);
763 block[j].setptr(block[j-1].getptr()+block[j-1].getsize());
766 this->initialized =
true;
775 typename std::allocator_traits<A>::template rebind_alloc<window_type> windowAllocator_;
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Definition: allocator.hh:7
A vector of blocks with memory management.
Definition: bvector.hh:403
derive error class from the base class in common
Definition: istlexception.hh:16
A Vector of blocks with different blocksizes.
Definition: vbvector.hh:42
RealIterator< value_type, window_type & > Iterator
Definition: vbvector.hh:644
VariableBlockVector()
Definition: vbvector.hh:92
friend class CreateIterator
Definition: vbvector.hh:535
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition: vbvector.hh:51
A allocator_type
export the allocator type
Definition: vbvector.hh:54
VariableBlockVector(size_type _nblocks, size_type m)
Definition: vbvector.hh:129
size_type size() const
Definition: vbvector.hh:730
static constexpr unsigned int blocklevel
Definition: vbvector.hh:85
size_type N() const
number of blocks in the vector (are of variable size here)
Definition: vbvector.hh:721
VariableBlockVector(const VariableBlockVector &a)
copy constructor, has copy semantics
Definition: vbvector.hh:167
VariableBlockVector(size_type _nblocks)
Definition: vbvector.hh:103
~VariableBlockVector()
free dynamic memory
Definition: vbvector.hh:210
CreateIterator createend()
get create iterator pointing to one after the last block
Definition: vbvector.hh:547
Iterator beforeBegin() const
Definition: vbvector.hh:667
CreateIterator createbegin()
get initial create iterator
Definition: vbvector.hh:538
VariableBlockVector & operator=(const VariableBlockVector &a)
assignment
Definition: vbvector.hh:317
ConstIterator rend() const
end ConstIterator
Definition: vbvector.hh:701
A::size_type size_type
The size type for the index access.
Definition: vbvector.hh:69
ConstIterator find(size_type i) const
random access returning iterator (end if not contained)
Definition: vbvector.hh:713
ConstIterator beforeEnd() const
Definition: vbvector.hh:695
Iterator find(size_type i)
random access returning iterator (end if not contained)
Definition: vbvector.hh:707
const window_type & const_reference
Export type used for const references to container entries.
Definition: vbvector.hh:66
RealIterator< const value_type, const window_type & > ConstIterator
Const iterator.
Definition: vbvector.hh:676
Iterator end()
end Iterator
Definition: vbvector.hh:653
ConstIterator begin() const
begin ConstIterator
Definition: vbvector.hh:682
BlockVector< B, A > value_type
Type of the elements of the outer vector, i.e., dynamic vectors of B.
Definition: vbvector.hh:76
window_type & operator[](size_type i)
random access to blocks
Definition: vbvector.hh:558
ConstIterator end() const
end ConstIterator
Definition: vbvector.hh:688
BlockVector< B, A > block_type
Same as value_type, here for historical reasons.
Definition: vbvector.hh:80
void resize(size_type _nblocks, size_type m)
same effect as constructor with same argument
Definition: vbvector.hh:265
window_type & reference
Export type used for references to container entries.
Definition: vbvector.hh:60
void resize(size_type _nblocks)
same effect as constructor with same argument
Definition: vbvector.hh:229
Iterator beforeEnd()
Definition: vbvector.hh:660
Iterator begin()
begin Iterator
Definition: vbvector.hh:647
Iterator class for sequential creation of blocks.
Definition: vbvector.hh:438
bool operator==(const CreateIterator &it) const
equality
Definition: vbvector.hh:500
size_type index() const
dereferencing
Definition: vbvector.hh:506
SizeProxy reference
reference type
Definition: vbvector.hh:458
CreateIterator & operator++()
prefix increment
Definition: vbvector.hh:477
size_type * pointer
pointer type
Definition: vbvector.hh:455
bool operator!=(const CreateIterator &it) const
inequality
Definition: vbvector.hh:494
~CreateIterator()
Definition: vbvector.hh:466
size_type value_type
value type
Definition: vbvector.hh:444
CreateIterator(VariableBlockVector &_v, int _i, bool _isEnd)
constructor
Definition: vbvector.hh:461
void setblocksize(size_type _k)
set size of current block
Definition: vbvector.hh:512
std::output_iterator_tag iterator_category
iterator category
Definition: vbvector.hh:441
size_type & operator*()
Access size of current block.
Definition: vbvector.hh:523
void difference_type
difference type (unused)
Definition: vbvector.hh:452
Iterator class for sequential access.
Definition: vbvector.hh:579
RealIterator(window_type *_p, size_type _i)
constructor
Definition: vbvector.hh:589
window_type & dereference() const
dereferencing
Definition: vbvector.hh:612
bool equals(const RealIterator &it) const
equality
Definition: vbvector.hh:606
size_type index() const
Return the index of the entry this iterator is pointing to.
Definition: vbvector.hh:634
void decrement()
prefix decrement
Definition: vbvector.hh:600
void advance(std::ptrdiff_t d)
Definition: vbvector.hh:617
void increment()
prefix increment
Definition: vbvector.hh:594
window_type & elementAt(std::ptrdiff_t offset) const
Definition: vbvector.hh:628
RealIterator()
constructor, no arguments
Definition: vbvector.hh:582
std::ptrdiff_t distanceTo(const RealIterator &o) const
Definition: vbvector.hh:622