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> >
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!)" );
324 if(this->
n > capacity)
366 new (this->
p)B[capacity];
373 for(size_type i=0; i < block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to)
423 this->
reserve(size, copyOldValues);
448 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
472 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
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> >
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
764 for (size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) += y.p[i];
772 #ifdef DUNE_ISTL_WITH_CHECKING
775 for (size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) -= y.p[i];
783 #ifdef DUNE_ISTL_WITH_CHECKING
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> >
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)
base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:60
CompressedBlockVectorWindow(const compressed_block_vector_unmanaged< B, A > &_a)
construct from base class object with reference semantics!
Definition: bvector.hh:977
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:217
A::size_type size_type
The size type for the index access.
Definition: bvector.hh:57
The number of blocklevels we contain.
Definition: bvector.hh:604
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:611
BlockVector()
makes empty vector
Definition: bvector.hh:285
size_type dim() const
dimension of the vector space
Definition: bvector.hh:223
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:824
B block_type
export the type representing the components
Definition: bvector.hh:262
A::size_type size_type
The type for the index access.
Definition: bvector.hh:599
size_type n
Definition: basearray.hh:763
BlockVector(const block_vector_unmanaged< B, A > &_a)
construct from base class object
Definition: bvector.hh:452
Implements several basic array containers.
FieldTraits< field_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:199
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
B * p
Definition: basearray.hh:251
void reserve(size_type capacity, bool copyOldValues=true)
Reserve space.
Definition: bvector.hh:357
FieldTraits< field_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:864
FieldTraits< B >::field_type field_type
Definition: bvector.hh:547
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
iterator end()
end iterator
Definition: basearray.hh:683
Iterator implementation class.
Definition: basearray.hh:78
derive error class from the base class in common
Definition: istlexception.hh:16
void set(size_type _n, B *_p, size_type *_j)
set size and pointer
Definition: bvector.hh:1024
block_vector_unmanaged & operator/=(const field_type &k)
vector space division by scalar
Definition: bvector.hh:107
CompressedBlockVectorWindow(const CompressedBlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:969
block_vector_unmanaged & axpy(const field_type &a, const block_vector_unmanaged &y)
vector space axpy operation
Definition: bvector.hh:114
compressed_block_vector_unmanaged & operator=(const field_type &k)
Definition: bvector.hh:747
BlockVector(const BlockVector &a)
copy constructor
Definition: bvector.hh:431
A vector of blocks with memory management.
Definition: bvector.hh:252
compressed_base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:740
compressed_block_vector_unmanaged & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bvector.hh:791
void setindexptr(size_type *_j)
set pointer only
Definition: bvector.hh:1044
iterator find(size_type i)
random access returning iterator (end if not contained)
Definition: basearray.hh:703
block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:233
B * p
Definition: basearray.hh:764
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)
Assignment from a scalar.
Definition: bvector.hh:71
B * getptr()
get pointer
Definition: bvector.hh:1050
Matrix & A
Definition: matrixmatrix.hh:216
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:277
FieldTraits< field_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:856
size_type dim() const
dimension of the vector space
Definition: bvector.hh:881
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:280
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
BlockVectorWindow()
makes empty array
Definition: bvector.hh:616
compressed_block_vector_unmanaged & axpy(const field_type &a, const V &y)
vector space axpy operation
Definition: bvector.hh:781
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:952
A::size_type size_type
The type for the index access.
Definition: bvector.hh:743
B::field_type field_type
export the type representing the field
Definition: bvector.hh:259
B value_type
for STL compatibility
Definition: bvector.hh:66
void setptr(B *_p)
set pointer only
Definition: bvector.hh:692
A::size_type size_type
The type for the index access.
Definition: bvector.hh:940
B::field_type field_type
export the type representing the field
Definition: bvector.hh:931
BlockVectorWindow(const BlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:627
BlockVectorWindow(const block_vector_unmanaged< B, A > &_a)
construct from base class object with reference semantics!
Definition: bvector.hh:634
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
compressed_base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:737
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:175
block_vector_unmanaged & operator-=(const block_vector_unmanaged &y)
vector space subtraction
Definition: bvector.hh:90
The number of blocklevel we contain.
Definition: bvector.hh:273
FieldTraits< B >::real_type real_type
Definition: bvector.hh:548
field_type operator*(const compressed_block_vector_unmanaged &y) const
scalar product
Definition: bvector.hh:808
size_type n
Definition: basearray.hh:250
compressed_block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:891
A::size_type size_type
The type for the index access.
Definition: bvector.hh:268
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:318
B block_type
export the type representing the components
Definition: bvector.hh:934
B::field_type field_type
export the type representing the field
Definition: bvector.hh:590
void set(size_type _n, B *_p)
set size and pointer
Definition: bvector.hh:679
B * getptr()
get pointer
Definition: bvector.hh:698
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 block_type
export the type representing the components
Definition: bvector.hh:731
const B * getptr() const
get pointer
Definition: bvector.hh:1062
size_type * getindexptr()
get pointer
Definition: bvector.hh:1056
size_type * j
Definition: basearray.hh:765
const size_type * getindexptr() const
get pointer
Definition: bvector.hh:1068
block_vector_unmanaged & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bvector.hh:100
CompressedBlockVectorWindow(B *_p, size_type *_j, size_type _n)
make array from given pointers and size
Definition: bvector.hh:961
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
A allocator_type
export the allocator type
Definition: bvector.hh:54
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:840
void setptr(B *_p)
set pointer only
Definition: bvector.hh:1038
A allocator_type
export the allocator type
Definition: bvector.hh:937
CompressedBlockVectorWindow & operator=(const CompressedBlockVectorWindow &a)
assignment
Definition: bvector.hh:990
CompressedBlockVectorWindow()
makes empty array
Definition: bvector.hh:957
Definition: bvector.hh:721
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:400
B block_type
export the type representing the components
Definition: bvector.hh:51
compressed_block_vector_unmanaged & operator+=(const V &y)
vector space addition
Definition: bvector.hh:759
FieldTraits< field_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:207
iterator class for sequential access
Definition: basearray.hh:580
void resize(size_type size, bool copyOldValues=true)
Resize the vector.
Definition: bvector.hh:419
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:183
BlockVector & operator=(const BlockVector &a)
assignment
Definition: bvector.hh:487
The number of block level this vector contains.
Definition: bvector.hh:945
A allocator_type
export the allocator type
Definition: bvector.hh:596
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:167
B block_type
export the type representing the components
Definition: bvector.hh:593
size_type getsize()
get size
Definition: bvector.hh:704
A allocator_
Definition: bvector.hh:535
BlockVectorWindow & operator=(const BlockVectorWindow &a)
assignment
Definition: bvector.hh:646
Definition: bvector.hh:583
Definition: basearray.hh:19
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:734
B::field_type field_type
export the type representing the field
Definition: bvector.hh:48
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
void setsize(size_type _n)
set size only
Definition: bvector.hh:686
A allocator_type
export the allocator type
Definition: bvector.hh:265
size_type getsize() const
get size
Definition: bvector.hh:1073
compressed_block_vector_unmanaged & operator-=(const V &y)
vector space subtraction
Definition: bvector.hh:770
size_type capacity_
Definition: bvector.hh:533
Definition: bvector.hh:924
An unmanaged vector of blocks.
Definition: bvector.hh:41
bool includesindexset(const V &y)
return true if index sets coincide
Definition: bvector.hh:896
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:832
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
~BlockVector()
free dynamic memory
Definition: bvector.hh:476
compressed_block_vector_unmanaged & operator/=(const field_type &k)
vector space division by scalar
Definition: bvector.hh:798