4 #ifndef DUNE_BVECTOR_HH
5 #define DUNE_BVECTOR_HH
12 #include <dune/common/static_assert.hh>
13 #include <dune/common/promotiontraits.hh>
14 #include <dune/common/dotproduct.hh>
15 #include <dune/common/ftraits.hh>
41 template<
class B,
class A=std::allocator<B> >
83 #ifdef DUNE_ISTL_WITH_CHECKING
84 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
86 for (
size_type i=0; i<this->
n; ++i) (*
this)[i] += y[i];
93 #ifdef DUNE_ISTL_WITH_CHECKING
94 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
96 for (
size_type i=0; i<this->
n; ++i) (*
this)[i] -= y[i];
103 for (
size_type i=0; i<this->
n; ++i) (*
this)[i] *= k;
110 for (
size_type i=0; i<this->
n; ++i) (*
this)[i] /= k;
117 #ifdef DUNE_ISTL_WITH_CHECKING
118 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
132 template<
class OtherB,
class OtherA>
135 typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
137 #ifdef DUNE_ISTL_WITH_CHECKING
138 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
141 sum += PromotedType(((*
this)[i])*y[i]);
153 template<
class OtherB,
class OtherA>
156 typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
158 #ifdef DUNE_ISTL_WITH_CHECKING
159 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
161 for (
size_type i=0; i<this->
n; ++i) sum += ((*
this)[i]).
dot(y[i]);
168 typename FieldTraits<field_type>::real_type
one_norm ()
const
170 typename FieldTraits<field_type>::real_type sum=0;
171 for (
size_type i=0; i<this->
n; ++i) sum += (*
this)[i].one_norm();
178 typename FieldTraits<field_type>::real_type sum=0;
179 for (
size_type i=0; i<this->
n; ++i) sum += (*
this)[i].one_norm_real();
184 typename FieldTraits<field_type>::real_type
two_norm ()
const
186 typename FieldTraits<field_type>::real_type sum=0;
187 for (
size_type i=0; i<this->
n; ++i) sum += (*
this)[i].two_norm2();
192 typename FieldTraits<field_type>::real_type
two_norm2 ()
const
194 typename FieldTraits<field_type>::real_type sum=0;
195 for (
size_type i=0; i<this->
n; ++i) sum += (*
this)[i].two_norm2();
202 typename FieldTraits<field_type>::real_type max=0;
210 typename FieldTraits<field_type>::real_type max=0;
228 d += (*
this)[i].dim();
252 template<
class B,
class A=std::allocator<B> >
321 dune_static_assert( (std::numeric_limits<S>::is_integer),
322 "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
325 if(this->
n > capacity)
367 new (this->
p)B[capacity];
374 for(
size_type i=0; i < block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to)
424 this->
reserve(size, copyOldValues);
523 return this->
operator=(static_cast<const BlockVector&>(a));
545 template<
class B,
class A>
555 template<
class K,
class A>
557 std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
561 for (size_type i=0; i<v.size(); i++)
562 s << v[i] << std::endl;
583 template<
class B,
class A=std::allocator<B> >
650 #ifdef DUNE_ISTL_WITH_CHECKING
651 if (this->
n!=a.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
666 return this->
operator=(static_cast<const BlockVectorWindow&>(a));
721 template<
class B,
class A=std::allocator<B> >
762 #ifdef DUNE_ISTL_WITH_CHECKING
765 for (
size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) += y.p[i];
773 #ifdef DUNE_ISTL_WITH_CHECKING
776 for (
size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) -= y.p[i];
784 #ifdef DUNE_ISTL_WITH_CHECKING
787 for (
size_type i=0; i<y.n; ++i) (this->
operator[](y.j[i])).axpy(a,y.p[i]);
794 for (
size_type i=0; i<this->
n; ++i) (this->
p)[i] *= k;
801 for (
size_type i=0; i<this->
n; ++i) (this->
p)[i] /= k;
811 #ifdef DUNE_ISTL_WITH_CHECKING
813 DUNE_THROW(
ISTLError,
"index set mismatch");
817 sum += (this->
p)[i] * y[(this->
j)[i]];
825 typename FieldTraits<field_type>::real_type
one_norm ()
const
827 typename FieldTraits<field_type>::real_type sum=0;
828 for (
size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].one_norm();
835 typename FieldTraits<field_type>::real_type sum=0;
836 for (
size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].one_norm_real();
841 typename FieldTraits<field_type>::real_type
two_norm ()
const
843 typename FieldTraits<field_type>::real_type sum=0;
844 for (
size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].two_norm2();
849 typename FieldTraits<field_type>::real_type
two_norm2 ()
const
851 typename FieldTraits<field_type>::real_type sum=0;
852 for (
size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].two_norm2();
859 typename FieldTraits<field_type>::real_type max=0;
867 typename FieldTraits<field_type>::real_type max=0;
886 d += (this->
p)[i].dim();
899 typename V::ConstIterator e=this->
end();
901 if (this->
find(y.j[i])==e)
924 template<
class B,
class A=std::allocator<B> >
994 #ifdef DUNE_ISTL_WITH_CHECKING
995 if (this->
n!=a.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
1011 return this->
operator=(static_cast<const CompressedBlockVectorWindow&>(a));
base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:61
CompressedBlockVectorWindow(const compressed_block_vector_unmanaged< B, A > &_a)
construct from base class object with reference semantics!
Definition: bvector.hh:978
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:218
A::size_type size_type
The size type for the index access.
Definition: bvector.hh:58
The number of blocklevels we contain.
Definition: bvector.hh:605
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:612
BlockVector()
makes empty vector
Definition: bvector.hh:286
size_type dim() const
dimension of the vector space
Definition: bvector.hh:224
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:825
B block_type
export the type representing the components
Definition: bvector.hh:263
A::size_type size_type
The type for the index access.
Definition: bvector.hh:600
size_type n
Definition: basearray.hh:777
BlockVector(const block_vector_unmanaged< B, A > &_a)
construct from base class object
Definition: bvector.hh:453
FieldTraits< field_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:200
BlockVectorWindow(B *_p, size_type _n)
make array from given pointer and size
Definition: bvector.hh:621
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:609
B * p
Definition: basearray.hh:251
void reserve(size_type capacity, bool copyOldValues=true)
Reserve space.
Definition: bvector.hh:358
FieldTraits< field_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:865
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:154
iterator end()
end iterator
Definition: basearray.hh:697
void set(size_type _n, B *_p, size_type *_j)
set size and pointer
Definition: bvector.hh:1025
block_vector_unmanaged & operator/=(const field_type &k)
vector space division by scalar
Definition: bvector.hh:108
CompressedBlockVectorWindow(const CompressedBlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:970
block_vector_unmanaged & axpy(const field_type &a, const block_vector_unmanaged &y)
vector space axpy operation
Definition: bvector.hh:115
Iterator implementation class.
Definition: basearray.hh:78
compressed_block_vector_unmanaged & operator=(const field_type &k)
Definition: bvector.hh:748
BlockVector(const BlockVector &a)
copy constructor
Definition: bvector.hh:432
A vector of blocks with memory management.
Definition: bvector.hh:253
compressed_base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:741
compressed_block_vector_unmanaged & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bvector.hh:792
void setindexptr(size_type *_j)
set pointer only
Definition: bvector.hh:1045
iterator find(size_type i)
random access returning iterator (end if not contained)
Definition: basearray.hh:717
block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:234
B * p
Definition: basearray.hh:778
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:876
block_vector_unmanaged & operator=(const field_type &k)
Assignment from a scalar.
Definition: bvector.hh:72
FieldTraits< B >::real_type real_type
Definition: bvector.hh:549
B * getptr()
get pointer
Definition: bvector.hh:1051
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:278
FieldTraits< field_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:857
size_type dim() const
dimension of the vector space
Definition: bvector.hh:882
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:281
B::field_type field_type
export the type representing the field
Definition: bvector.hh:729
FieldTraits< B >::field_type field_type
Definition: bvector.hh:548
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:291
BlockVectorWindow()
makes empty array
Definition: bvector.hh:617
compressed_block_vector_unmanaged & axpy(const field_type &a, const V &y)
vector space axpy operation
Definition: bvector.hh:782
A simple array container for objects of type B.
Definition: basearray.hh:40
compressed_block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:953
A::size_type size_type
The type for the index access.
Definition: bvector.hh:744
B::field_type field_type
export the type representing the field
Definition: bvector.hh:260
B value_type
for STL compatibility
Definition: bvector.hh:67
void setptr(B *_p)
set pointer only
Definition: bvector.hh:693
A::size_type size_type
The type for the index access.
Definition: bvector.hh:941
B::field_type field_type
export the type representing the field
Definition: bvector.hh:932
A::size_type size_type
the type for the index access
Definition: basearray.hh:53
BlockVectorWindow(const BlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:628
BlockVectorWindow(const block_vector_unmanaged< B, A > &_a)
construct from base class object with reference semantics!
Definition: bvector.hh:635
block_vector_unmanaged & operator+=(const block_vector_unmanaged &y)
vector space addition
Definition: bvector.hh:81
A::size_type size_type
The type used for the index access.
Definition: basearray.hh:556
base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:64
compressed_base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:738
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:176
block_vector_unmanaged & operator-=(const block_vector_unmanaged &y)
vector space subtraction
Definition: bvector.hh:91
field_type operator*(const compressed_block_vector_unmanaged &y) const
scalar product
Definition: bvector.hh:809
Matrix & A
Definition: matrixmatrix.hh:216
size_type n
Definition: basearray.hh:250
compressed_block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:892
A::size_type size_type
The type for the index access.
Definition: bvector.hh:269
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:319
B block_type
export the type representing the components
Definition: bvector.hh:935
B::field_type field_type
export the type representing the field
Definition: bvector.hh:591
iterator class for sequential access
Definition: basearray.hh:594
void set(size_type _n, B *_p)
set size and pointer
Definition: bvector.hh:680
B * getptr()
get pointer
Definition: bvector.hh:699
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:133
B block_type
export the type representing the components
Definition: bvector.hh:732
const B * getptr() const
get pointer
Definition: bvector.hh:1063
size_type * getindexptr()
get pointer
Definition: bvector.hh:1057
size_type * j
Definition: basearray.hh:779
const size_type * getindexptr() const
get pointer
Definition: bvector.hh:1069
block_vector_unmanaged & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bvector.hh:101
CompressedBlockVectorWindow(B *_p, size_type *_j, size_type _n)
make array from given pointers and size
Definition: bvector.hh:962
compressed_block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:950
void setsize(size_type _n)
set size only
Definition: bvector.hh:1033
A allocator_type
export the allocator type
Definition: bvector.hh:55
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:841
derive error class from the base class in common
Definition: istlexception.hh:16
void setptr(B *_p)
set pointer only
Definition: bvector.hh:1039
A allocator_type
export the allocator type
Definition: bvector.hh:938
CompressedBlockVectorWindow & operator=(const CompressedBlockVectorWindow &a)
assignment
Definition: bvector.hh:991
CompressedBlockVectorWindow()
makes empty array
Definition: bvector.hh:958
Definition: bvector.hh:722
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:401
B block_type
export the type representing the components
Definition: bvector.hh:52
compressed_block_vector_unmanaged & operator+=(const V &y)
vector space addition
Definition: bvector.hh:760
FieldTraits< field_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:208
Implements several basic array containers.
void resize(size_type size, bool copyOldValues=true)
Resize the vector.
Definition: bvector.hh:420
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:184
BlockVector & operator=(const BlockVector &a)
assignment
Definition: bvector.hh:488
The number of block level this vector contains.
Definition: bvector.hh:946
A allocator_type
export the allocator type
Definition: bvector.hh:597
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:168
B block_type
export the type representing the components
Definition: bvector.hh:594
The number of blocklevel we contain.
Definition: bvector.hh:274
size_type getsize()
get size
Definition: bvector.hh:705
A allocator_
Definition: bvector.hh:536
BlockVectorWindow & operator=(const BlockVectorWindow &a)
assignment
Definition: bvector.hh:647
Definition: bvector.hh:584
size_type size() const
number of blocks in the array (are of size 1 here)
Definition: basearray.hh:236
A allocator_type
export the allocator type
Definition: bvector.hh:735
B::field_type field_type
export the type representing the field
Definition: bvector.hh:49
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:849
void setsize(size_type _n)
set size only
Definition: bvector.hh:687
A allocator_type
export the allocator type
Definition: bvector.hh:266
size_type getsize() const
get size
Definition: bvector.hh:1074
compressed_block_vector_unmanaged & operator-=(const V &y)
vector space subtraction
Definition: bvector.hh:771
size_type capacity_
Definition: bvector.hh:534
Definition: bvector.hh:925
An unmanaged vector of blocks.
Definition: bvector.hh:42
bool includesindexset(const V &y)
return true if index sets coincide
Definition: bvector.hh:897
A simple array container with non-consecutive index set.
Definition: basearray.hh:543
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:833
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:192
~BlockVector()
free dynamic memory
Definition: bvector.hh:477
compressed_block_vector_unmanaged & operator/=(const field_type &k)
vector space division by scalar
Definition: bvector.hh:799