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> 28 template<
class B,
class A=std::allocator<B> >
44 template<
class B,
class A=std::allocator<B> >
83 for (size_type i=0; i<this->
n; 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 #ifdef DUNE_ISTL_WITH_CHECKING 103 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
105 for (size_type i=0; i<this->
n; ++i) (*
this)[i] -= y[i];
112 for (size_type i=0; i<this->
n; ++i) (*
this)[i] *= k;
119 for (size_type i=0; i<this->
n; ++i) (*
this)[i] /= k;
126 #ifdef DUNE_ISTL_WITH_CHECKING 127 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
129 for (size_type i=0; i<this->
n; ++i) (*
this)[i].
axpy(a,y[i]);
141 template<
class OtherB,
class OtherA>
144 typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
146 #ifdef DUNE_ISTL_WITH_CHECKING 147 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
149 for (size_type i=0; i<this->
n; ++i) {
150 sum += PromotedType(((*
this)[i])*y[i]);
162 template<
class OtherB,
class OtherA>
165 typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
167 #ifdef DUNE_ISTL_WITH_CHECKING 168 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
170 for (size_type i=0; i<this->
n; ++i) sum += ((*
this)[i]).
dot(y[i]);
177 typename FieldTraits<field_type>::real_type
one_norm ()
const 179 typename FieldTraits<field_type>::real_type sum=0;
180 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].one_norm();
187 typename FieldTraits<field_type>::real_type sum=0;
188 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].one_norm_real();
193 typename FieldTraits<field_type>::real_type
two_norm ()
const 195 typename FieldTraits<field_type>::real_type sum=0;
196 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].two_norm2();
201 typename FieldTraits<field_type>::real_type
two_norm2 ()
const 203 typename FieldTraits<field_type>::real_type sum=0;
204 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].two_norm2();
210 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
212 using real_type =
typename FieldTraits<ft>::real_type;
216 for (
auto const &x : *
this) {
217 real_type
const a = x.infinity_norm();
225 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
227 using real_type =
typename FieldTraits<ft>::real_type;
231 for (
auto const &x : *
this) {
232 real_type
const a = x.infinity_norm_real();
240 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
242 using real_type =
typename FieldTraits<ft>::real_type;
247 for (
auto const &x : *
this) {
248 real_type
const a = x.infinity_norm();
258 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
260 using real_type =
typename FieldTraits<ft>::real_type;
265 for (
auto const &x : *
this) {
266 real_type
const a = x.infinity_norm_real();
286 for (size_type i=0; i<this->
n; i++)
287 d += (*
this)[i].dim();
311 template<
class B,
class A=std::allocator<B> >
333 blocklevel = B::blocklevel+1
355 this->
p = this->allocator_.allocate(capacity_);
357 new(this->
p)B[capacity_];
370 capacity_ = l.size();
372 this->
p = this->allocator_.allocate(capacity_);
374 new(this->
p)B[capacity_];
376 std::copy_n(l.begin(), l.size(), this->
p);
400 static_assert(std::numeric_limits<S>::is_integer,
401 "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
402 size_type capacity = _capacity;
404 if(this->
n > capacity)
407 capacity_ = capacity;
410 this->
p = this->allocator_.allocate(capacity_);
411 new (this->
p)B[capacity_];
437 void reserve(size_type capacity,
bool copyOldValues=
true)
445 this->
p = this->allocator_.allocate(capacity);
446 new (this->
p)B[capacity];
453 for(size_type i=0; i < block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to)
461 this->allocator_.deallocate(pold,capacity_);
470 capacity_ = capacity;
503 this->reserve(size, copyOldValues);
519 this->
p = this->allocator_.allocate(capacity_);
520 new (this->
p)B[capacity_];
528 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
538 this->allocator_.deallocate(this->
p,capacity_);
554 this->allocator_.deallocate(this->
p,capacity_);
558 this->
p = this->allocator_.allocate(capacity_);
559 new (this->
p)B[capacity_];
568 for (size_type i=0; i<this->
n; i++)
583 template<
class OtherAlloc>
586 resize(other.
size());
587 for(std::size_t i=0; i<other.
size(); ++i)
588 (*
this)[i] = other[i];
604 template<
class B,
class A>
614 template<
class K,
class A>
616 std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
620 for (size_type i=0; i<v.size(); i++)
621 s << v[i] << std::endl;
645 template<
class B,
class A>
647 template<
class B,
class A=std::allocator<B> >
670 blocklevel = B::blocklevel+1
703 #ifdef DUNE_ISTL_WITH_CHECKING 704 if (this->
n!=a.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
710 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
726 void set (size_type _n, B* _p)
769 template<
class B,
class A=std::allocator<B> >
798 for (size_type i=0; i<this->
n; i++)
810 #ifdef DUNE_ISTL_WITH_CHECKING 811 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
813 for (size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) += y.p[i];
821 #ifdef DUNE_ISTL_WITH_CHECKING 822 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
824 for (size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) -= y.p[i];
832 #ifdef DUNE_ISTL_WITH_CHECKING 833 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
835 for (size_type i=0; i<y.n; ++i) (this->
operator[](y.j[i])).axpy(a,y.p[i]);
842 for (size_type i=0; i<this->
n; ++i) (this->
p)[i] *= k;
849 for (size_type i=0; i<this->
n; ++i) (this->
p)[i] /= k;
859 #ifdef DUNE_ISTL_WITH_CHECKING 861 DUNE_THROW(
ISTLError,
"index set mismatch");
864 for (size_type i=0; i<this->
n; ++i)
865 sum += (this->
p)[i] * y[(this->j)[i]];
873 typename FieldTraits<field_type>::real_type
one_norm ()
const 875 typename FieldTraits<field_type>::real_type sum=0;
876 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].one_norm();
883 typename FieldTraits<field_type>::real_type sum=0;
884 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].one_norm_real();
889 typename FieldTraits<field_type>::real_type
two_norm ()
const 891 typename FieldTraits<field_type>::real_type sum=0;
892 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].two_norm2();
897 typename FieldTraits<field_type>::real_type
two_norm2 ()
const 899 typename FieldTraits<field_type>::real_type sum=0;
900 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].two_norm2();
906 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
908 using real_type =
typename FieldTraits<ft>::real_type;
912 for (
auto const &x : *
this) {
913 real_type
const a = x.infinity_norm();
921 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
923 using real_type =
typename FieldTraits<ft>::real_type;
927 for (
auto const &x : *
this) {
928 real_type
const a = x.infinity_norm_real();
936 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
938 using real_type =
typename FieldTraits<ft>::real_type;
943 for (
auto const &x : *
this) {
944 real_type
const a = x.infinity_norm();
954 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
956 using real_type =
typename FieldTraits<ft>::real_type;
961 for (
auto const &x : *
this) {
962 real_type
const a = x.infinity_norm_real();
982 for (size_type i=0; i<this->
n; i++)
983 d += (this->
p)[i].dim();
996 typename V::ConstIterator e=this->
end();
997 for (size_type i=0; i<y.n; i++)
998 if (this->
find(y.j[i])==e)
1023 template<
class B,
class A=std::allocator<B> >
1045 blocklevel = B::blocklevel+1
1080 #ifdef DUNE_ISTL_WITH_CHECKING 1081 if (this->
n!=a.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
1087 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
1088 for (size_type i=0; i<this->
n; i++) this->j[i]=a.
j[i];
1104 void set (size_type _n, B* _p, size_type* _j)
block_vector_unmanaged & operator-=(const block_vector_unmanaged &y)
vector space subtraction
Definition: bvector.hh:100
A::size_type size_type
The size type for the index access.
Definition: bvector.hh:61
BlockVectorWindow(B *_p, size_type _n)
make array from given pointer and size
Definition: bvector.hh:686
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:674
block_vector_unmanaged & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bvector.hh:110
BlockVectorWindow()
makes empty array
Definition: bvector.hh:682
Definition: bvector.hh:1024
void setsize(size_type _n)
set size only
Definition: bvector.hh:1112
FieldTraits< ft >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:226
A vector of blocks with memory management.
Definition: bvector.hh:312
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:177
size_type n
Definition: basearray.hh:256
size_type getsize()
get size
Definition: bvector.hh:751
A simple array container with non-consecutive index set.
Definition: basearray.hh:526
iterator end()
end iterator
Definition: basearray.hh:178
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:873
Iterator implementation class.
Definition: basearray.hh:84
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:277
A::size_type size_type
The type for the index access.
Definition: bvector.hh:665
block_vector_unmanaged & axpy(const field_type &a, const block_vector_unmanaged &y)
vector space axpy operation
Definition: bvector.hh:124
B * p
Definition: basearray.hh:747
compressed_block_vector_unmanaged & axpy(const field_type &a, const V &y)
vector space axpy operation
Definition: bvector.hh:830
CompressedBlockVectorWindow(const CompressedBlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:1069
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:973
FieldTraits< ft >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:922
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:881
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:201
block_vector_unmanaged & operator=(const field_type &k)
Assignment from a scalar.
Definition: bvector.hh:81
const B * getptr() const
get pointer
Definition: bvector.hh:1142
BlockVector(const BlockVector &a)
copy constructor
Definition: bvector.hh:511
B * getptr()
get pointer
Definition: bvector.hh:745
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:677
B block_type
export the type representing the components
Definition: bvector.hh:1034
B::field_type field_type
export the type representing the field
Definition: bvector.hh:777
bool includesindexset(const V &y)
return true if index sets coincide
Definition: bvector.hh:994
void setindexptr(size_type *_j)
set pointer only
Definition: bvector.hh:1124
FieldTraits< B >::field_type field_type
Definition: bvector.hh:607
size_type * j
Definition: basearray.hh:748
compressed_block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:1052
B block_type
export the type representing the components
Definition: bvector.hh:322
void resize(size_type size, bool copyOldValues=true)
Resize the vector.
Definition: bvector.hh:499
base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:64
A::size_type size_type
The type for the index access.
Definition: bvector.hh:328
block_vector_unmanaged & operator+=(const block_vector_unmanaged &y)
vector space addition
Definition: bvector.hh:90
B::field_type field_type
export the type representing the field
Definition: bvector.hh:52
base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:67
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:193
size_type getsize() const
get size
Definition: bvector.hh:1153
size_type dim() const
dimension of the vector space
Definition: bvector.hh:283
void setptr(B *_p)
set pointer only
Definition: bvector.hh:1118
Definition: basearray.hh:19
void setptr(B *_p)
set pointer only
Definition: bvector.hh:739
size_type * getindexptr()
get pointer
Definition: bvector.hh:1136
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:897
BlockVectorWindow(const BlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:693
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:889
B * p
Definition: basearray.hh:257
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:398
iterator find(size_type i)
random access returning iterator (end if not contained)
Definition: basearray.hh:198
FieldTraits< ft >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:907
B::field_type field_type
export the type representing the field
Definition: bvector.hh:1031
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:163
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:337
Definition: bvector.hh:770
B * getptr()
get pointer
Definition: bvector.hh:1130
void setsize(size_type _n)
set size only
Definition: bvector.hh:733
B::field_type field_type
export the type representing the field
Definition: bvector.hh:656
An unmanaged vector of blocks.
Definition: bvector.hh:45
compressed_block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:1049
BlockVector()
makes empty vector
Definition: bvector.hh:345
A allocator_type
export the allocator type
Definition: bvector.hh:58
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:340
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:142
block_vector_unmanaged & operator/=(const field_type &k)
vector space division by scalar
Definition: bvector.hh:117
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:350
const B & const_reference
Type used for const references.
Definition: bvector.hh:76
void reserve(size_type capacity, bool copyOldValues=true)
Reserve space.
Definition: bvector.hh:437
B block_type
export the type representing the components
Definition: bvector.hh:780
Implements several basic array containers.
size_type dim() const
dimension of the vector space
Definition: bvector.hh:979
B block_type
export the type representing the components
Definition: bvector.hh:55
A simple array container for objects of type B.
Definition: basearray.hh:46
B block_type
export the type representing the components
Definition: bvector.hh:659
B::field_type field_type
export the type representing the field
Definition: bvector.hh:319
A::size_type size_type
The type for the index access.
Definition: bvector.hh:792
size_type n
Definition: basearray.hh:746
CompressedBlockVectorWindow(B *_p, size_type *_j, size_type _n)
make array from given pointers and size
Definition: bvector.hh:1061
B & reference
Type used for references.
Definition: bvector.hh:73
size_type size() const
number of blocks in the array (are of size 1 here)
Definition: basearray.hh:242
A::size_type size_type
The type for the index access.
Definition: bvector.hh:1040
block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:293
size_type capacity_
Definition: bvector.hh:593
compressed_base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:789
const size_type * getindexptr() const
get pointer
Definition: bvector.hh:1148
iterator class for sequential access
Definition: basearray.hh:563
derive error class from the base class in common
Definition: istlexception.hh:16
B value_type
for STL compatibility
Definition: bvector.hh:70
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:480
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:185
compressed_base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:786
FieldTraits< B >::real_type real_type
Definition: bvector.hh:608
~BlockVector()
free dynamic memory
Definition: bvector.hh:532
compressed_block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:989
FieldTraits< ft >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:211
CompressedBlockVectorWindow()
makes empty array
Definition: bvector.hh:1057
BlockVector(std::initializer_list< B > const &l)
Construct from a std::initializer_list.
Definition: bvector.hh:367
Definition: bvector.hh:29