4 #ifndef DUNE_ISTL_BVECTOR_HH 5 #define DUNE_ISTL_BVECTOR_HH 12 #include <dune/common/promotiontraits.hh> 13 #include <dune/common/dotproduct.hh> 14 #include <dune/common/ftraits.hh> 40 template<
class B,
class A=std::allocator<B> >
73 for (size_type i=0; i<this->
n; i++)
82 #ifdef DUNE_ISTL_WITH_CHECKING 83 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
85 for (size_type i=0; i<this->
n; ++i) (*
this)[i] += y[i];
92 #ifdef DUNE_ISTL_WITH_CHECKING 93 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
95 for (size_type i=0; i<this->
n; ++i) (*
this)[i] -= y[i];
102 for (size_type i=0; i<this->
n; ++i) (*
this)[i] *= k;
109 for (size_type i=0; i<this->
n; ++i) (*
this)[i] /= k;
116 #ifdef DUNE_ISTL_WITH_CHECKING 117 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
119 for (size_type i=0; i<this->
n; ++i) (*
this)[i].
axpy(a,y[i]);
131 template<
class OtherB,
class OtherA>
134 typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
136 #ifdef DUNE_ISTL_WITH_CHECKING 137 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
139 for (size_type i=0; i<this->
n; ++i) {
140 sum += PromotedType(((*
this)[i])*y[i]);
152 template<
class OtherB,
class OtherA>
155 typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
157 #ifdef DUNE_ISTL_WITH_CHECKING 158 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
160 for (size_type i=0; i<this->
n; ++i) sum += ((*
this)[i]).
dot(y[i]);
167 typename FieldTraits<field_type>::real_type
one_norm ()
const 169 typename FieldTraits<field_type>::real_type sum=0;
170 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].one_norm();
177 typename FieldTraits<field_type>::real_type sum=0;
178 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].one_norm_real();
183 typename FieldTraits<field_type>::real_type
two_norm ()
const 185 typename FieldTraits<field_type>::real_type sum=0;
186 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].two_norm2();
191 typename FieldTraits<field_type>::real_type
two_norm2 ()
const 193 typename FieldTraits<field_type>::real_type sum=0;
194 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].two_norm2();
201 typename FieldTraits<field_type>::real_type max=0;
202 for (size_type i=0; i<this->
n; ++i) max = std::max(max,(*
this)[i].
infinity_norm());
209 typename FieldTraits<field_type>::real_type max=0;
226 for (size_type i=0; i<this->
n; i++)
227 d += (*
this)[i].dim();
251 template<
class B,
class A=std::allocator<B> >
273 blocklevel = B::blocklevel+1
295 this->
p = this->allocator_.allocate(capacity_);
297 new(this->
p)B[capacity_];
320 static_assert(std::numeric_limits<S>::is_integer,
321 "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
322 size_type capacity = _capacity;
324 if(this->
n > capacity)
327 capacity_ = capacity;
330 this->
p = this->allocator_.allocate(capacity_);
331 new (this->
p)B[capacity_];
357 void reserve(size_type capacity,
bool copyOldValues=
true)
365 this->
p = this->allocator_.allocate(capacity);
366 new (this->
p)B[capacity];
373 for(size_type i=0; i < block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to)
381 this->allocator_.deallocate(pold,capacity_);
390 capacity_ = capacity;
423 this->reserve(size, copyOldValues);
439 this->
p = this->allocator_.allocate(capacity_);
440 new (this->
p)B[capacity_];
448 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
462 this->
p = this->allocator_.allocate(capacity_);
463 new (this->
p)B[capacity_];
472 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
482 this->allocator_.deallocate(this->
p,capacity_);
498 this->allocator_.deallocate(this->
p,capacity_);
502 this->
p = this->allocator_.allocate(capacity_);
503 new (this->
p)B[capacity_];
512 for (size_type i=0; i<this->
n; i++)
522 return this->
operator=(static_cast<const BlockVector&>(a));
544 template<
class B,
class A>
554 template<
class K,
class A>
556 std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
560 for (size_type i=0; i<v.size(); i++)
561 s << v[i] << std::endl;
582 template<
class B,
class A=std::allocator<B> >
604 blocklevel = B::blocklevel+1
649 #ifdef DUNE_ISTL_WITH_CHECKING 650 if (this->
n!=a.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
656 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
665 return this->
operator=(static_cast<const BlockVectorWindow&>(a));
679 void set (size_type _n, B* _p)
720 template<
class B,
class A=std::allocator<B> >
749 for (size_type i=0; i<this->
n; i++)
761 #ifdef DUNE_ISTL_WITH_CHECKING 762 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
764 for (size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) += y.p[i];
772 #ifdef DUNE_ISTL_WITH_CHECKING 773 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
775 for (size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) -= y.p[i];
783 #ifdef DUNE_ISTL_WITH_CHECKING 784 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
786 for (size_type i=0; i<y.n; ++i) (this->
operator[](y.j[i])).axpy(a,y.p[i]);
793 for (size_type i=0; i<this->
n; ++i) (this->
p)[i] *= k;
800 for (size_type i=0; i<this->
n; ++i) (this->
p)[i] /= k;
810 #ifdef DUNE_ISTL_WITH_CHECKING 812 DUNE_THROW(
ISTLError,
"index set mismatch");
815 for (size_type i=0; i<this->
n; ++i)
816 sum += (this->
p)[i] * y[(this->j)[i]];
824 typename FieldTraits<field_type>::real_type
one_norm ()
const 826 typename FieldTraits<field_type>::real_type sum=0;
827 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].one_norm();
834 typename FieldTraits<field_type>::real_type sum=0;
835 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].one_norm_real();
840 typename FieldTraits<field_type>::real_type
two_norm ()
const 842 typename FieldTraits<field_type>::real_type sum=0;
843 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].two_norm2();
848 typename FieldTraits<field_type>::real_type
two_norm2 ()
const 850 typename FieldTraits<field_type>::real_type sum=0;
851 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].two_norm2();
858 typename FieldTraits<field_type>::real_type max=0;
859 for (size_type i=0; i<this->
n; ++i) max = std::max(max,(this->
p)[i].
infinity_norm());
866 typename FieldTraits<field_type>::real_type max=0;
884 for (size_type i=0; i<this->
n; i++)
885 d += (this->
p)[i].dim();
898 typename V::ConstIterator e=this->
end();
899 for (size_type i=0; i<y.n; i++)
900 if (this->
find(y.j[i])==e)
923 template<
class B,
class A=std::allocator<B> >
945 blocklevel = B::blocklevel+1
993 #ifdef DUNE_ISTL_WITH_CHECKING 994 if (this->
n!=a.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
1000 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
1001 for (size_type i=0; i<this->
n; i++) this->j[i]=a.
j[i];
1010 return this->
operator=(static_cast<const CompressedBlockVectorWindow&>(a));
1024 void set (size_type _n, B* _p, size_type* _j)
size_type * getindexptr()
get pointer
Definition: bvector.hh:1056
B::field_type field_type
export the type representing the field
Definition: bvector.hh:48
compressed_block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:952
base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:60
B::field_type field_type
export the type representing the field
Definition: bvector.hh:931
A::size_type size_type
The type for the index access.
Definition: bvector.hh:268
A::size_type size_type
The size type for the index access.
Definition: bvector.hh:57
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:217
BlockVectorWindow(B *_p, size_type _n)
make array from given pointer and size
Definition: bvector.hh:620
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:608
compressed_block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:949
void setsize(size_type _n)
set size only
Definition: bvector.hh:1032
B block_type
export the type representing the components
Definition: bvector.hh:731
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:400
FieldTraits< B >::field_type field_type
Definition: bvector.hh:547
A allocator_type
export the allocator type
Definition: bvector.hh:937
Implements several basic array containers.
Definition: bvector.hh:924
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:277
const B * getptr() const
get pointer
Definition: bvector.hh:1062
FieldTraits< field_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:864
BlockVector(const BlockVector &a)
copy constructor
Definition: bvector.hh:431
const size_type * getindexptr() const
get pointer
Definition: bvector.hh:1068
size_type n
Definition: basearray.hh:763
size_type dim() const
dimension of the vector space
Definition: bvector.hh:223
iterator class for sequential access
Definition: basearray.hh:580
derive error class from the base class in common
Definition: istlexception.hh:16
CompressedBlockVectorWindow(B *_p, size_type *_j, size_type _n)
make array from given pointers and size
Definition: bvector.hh:961
B::field_type field_type
export the type representing the field
Definition: bvector.hh:728
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:290
compressed_block_vector_unmanaged & axpy(const field_type &a, const V &y)
vector space axpy operation
Definition: bvector.hh:781
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:832
~BlockVector()
free dynamic memory
Definition: bvector.hh:476
void setptr(B *_p)
set pointer only
Definition: bvector.hh:1038
A simple array container for objects of type B.
Definition: basearray.hh:40
CompressedBlockVectorWindow()
makes empty array
Definition: bvector.hh:957
BlockVectorWindow()
makes empty array
Definition: bvector.hh:616
size_type getsize() const
get size
Definition: bvector.hh:1073
block_vector_unmanaged & operator/=(const field_type &k)
vector space division by scalar
Definition: bvector.hh:107
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:167
B::field_type field_type
export the type representing the field
Definition: bvector.hh:259
void setptr(B *_p)
set pointer only
Definition: bvector.hh:692
BlockVector()
makes empty vector
Definition: bvector.hh:285
Definition: bvector.hh:721
A allocator_type
export the allocator type
Definition: bvector.hh:734
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:318
CompressedBlockVectorWindow(const compressed_block_vector_unmanaged< B, A > &_a)
construct from base class object with reference semantics!
Definition: bvector.hh:977
FieldTraits< field_type >::real_type two_norm2() const
Square of the two-norm (the sum over the squared values of the entries)
Definition: bvector.hh:848
B block_type
export the type representing the components
Definition: bvector.hh:51
Iterator implementation class.
Definition: basearray.hh:78
void reserve(size_type capacity, bool copyOldValues=true)
Reserve space.
Definition: bvector.hh:357
size_type capacity_
Definition: bvector.hh:533
FieldTraits< field_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:199
A::size_type size_type
The type for the index access.
Definition: bvector.hh:743
size_type dim() const
dimension of the vector space
Definition: bvector.hh:881
FieldTraits< field_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:207
BlockVectorWindow(const block_vector_unmanaged< B, A > &_a)
construct from base class object with reference semantics!
Definition: bvector.hh:634
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:875
block_vector_unmanaged & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bvector.hh:100
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:183
block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:233
bool includesindexset(const V &y)
return true if index sets coincide
Definition: bvector.hh:896
size_type n
Definition: basearray.hh:250
FieldTraits< field_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:856
BlockVector(const block_vector_unmanaged< B, A > &_a)
construct from base class object
Definition: bvector.hh:452
BlockVectorWindow(const BlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:627
B block_type
export the type representing the components
Definition: bvector.hh:593
B::field_type field_type
export the type representing the field
Definition: bvector.hh:590
B * p
Definition: basearray.hh:764
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:175
FieldTraits< field_type >::real_type two_norm2() const
Square of the two-norm (the sum over the squared values of the entries)
Definition: bvector.hh:191
Definition: bvector.hh:583
FieldTraits< B >::real_type real_type
Definition: bvector.hh:548
B * p
Definition: basearray.hh:251
size_type getsize()
get size
Definition: bvector.hh:704
PromotionTraits< field_type, typename OtherB::field_type >::PromotedType operator*(const block_vector_unmanaged< OtherB, OtherA > &y) const
indefinite vector dot product which corresponds to Petsc's VecTDot
Definition: bvector.hh:132
B * getptr()
get pointer
Definition: bvector.hh:1050
B * getptr()
get pointer
Definition: bvector.hh:698
block_vector_unmanaged & operator=(const field_type &k)
Assignment from a scalar.
Definition: bvector.hh:71
compressed_base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:740
A simple array container with non-consecutive index set.
Definition: basearray.hh:543
B block_type
export the type representing the components
Definition: bvector.hh:262
compressed_block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:891
size_type size() const
number of blocks in the array (are of size 1 here)
Definition: basearray.hh:236
CompressedBlockVectorWindow(const CompressedBlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:969
A allocator_
Definition: bvector.hh:535
A allocator_type
export the allocator type
Definition: bvector.hh:265
block_vector_unmanaged & operator+=(const block_vector_unmanaged &y)
vector space addition
Definition: bvector.hh:80
base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:63
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:611
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:824
A::size_type size_type
The type for the index access.
Definition: bvector.hh:940
size_type * j
Definition: basearray.hh:765
void setindexptr(size_type *_j)
set pointer only
Definition: bvector.hh:1044
void resize(size_type size, bool copyOldValues=true)
Resize the vector.
Definition: bvector.hh:419
A vector of blocks with memory management.
Definition: bvector.hh:252
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:280
A allocator_type
export the allocator type
Definition: bvector.hh:596
block_vector_unmanaged & operator-=(const block_vector_unmanaged &y)
vector space subtraction
Definition: bvector.hh:90
An unmanaged vector of blocks.
Definition: bvector.hh:41
iterator find(size_type i)
random access returning iterator (end if not contained)
Definition: basearray.hh:186
PromotionTraits< field_type, typename OtherB::field_type >::PromotedType dot(const block_vector_unmanaged< OtherB, OtherA > &y) const
vector dot product which corresponds to Petsc's VecDot
Definition: bvector.hh:153
block_vector_unmanaged & axpy(const field_type &a, const block_vector_unmanaged &y)
vector space axpy operation
Definition: bvector.hh:114
iterator end()
end iterator
Definition: basearray.hh:166
A::size_type size_type
The type for the index access.
Definition: bvector.hh:599
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:840
B block_type
export the type representing the components
Definition: bvector.hh:934
void setsize(size_type _n)
set size only
Definition: bvector.hh:686
compressed_base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:737
B value_type
for STL compatibility
Definition: bvector.hh:66
Definition: basearray.hh:19
A allocator_type
export the allocator type
Definition: bvector.hh:54