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> >
79 for (size_type i=0; i<this->
n; i++)
88 #ifdef DUNE_ISTL_WITH_CHECKING 89 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
91 for (size_type i=0; i<this->
n; ++i) (*
this)[i] += y[i];
98 #ifdef DUNE_ISTL_WITH_CHECKING 99 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
101 for (size_type i=0; i<this->
n; ++i) (*
this)[i] -= y[i];
108 for (size_type i=0; i<this->
n; ++i) (*
this)[i] *= k;
115 for (size_type i=0; i<this->
n; ++i) (*
this)[i] /= k;
122 #ifdef DUNE_ISTL_WITH_CHECKING 123 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
125 for (size_type i=0; i<this->
n; ++i) (*
this)[i].
axpy(a,y[i]);
137 template<
class OtherB,
class OtherA>
140 typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
142 #ifdef DUNE_ISTL_WITH_CHECKING 143 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
145 for (size_type i=0; i<this->
n; ++i) {
146 sum += PromotedType(((*
this)[i])*y[i]);
158 template<
class OtherB,
class OtherA>
161 typedef typename PromotionTraits<field_type,typename OtherB::field_type>::PromotedType PromotedType;
163 #ifdef DUNE_ISTL_WITH_CHECKING 164 if (this->
n!=y.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
166 for (size_type i=0; i<this->
n; ++i) sum += ((*
this)[i]).
dot(y[i]);
173 typename FieldTraits<field_type>::real_type
one_norm ()
const 175 typename FieldTraits<field_type>::real_type sum=0;
176 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].one_norm();
183 typename FieldTraits<field_type>::real_type sum=0;
184 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].one_norm_real();
189 typename FieldTraits<field_type>::real_type
two_norm ()
const 191 typename FieldTraits<field_type>::real_type sum=0;
192 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].two_norm2();
197 typename FieldTraits<field_type>::real_type
two_norm2 ()
const 199 typename FieldTraits<field_type>::real_type sum=0;
200 for (size_type i=0; i<this->
n; ++i) sum += (*
this)[i].two_norm2();
206 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
208 using real_type =
typename FieldTraits<ft>::real_type;
212 for (
auto const &x : *
this) {
213 real_type
const a = x.infinity_norm();
221 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
223 using real_type =
typename FieldTraits<ft>::real_type;
227 for (
auto const &x : *
this) {
228 real_type
const a = x.infinity_norm_real();
236 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
238 using real_type =
typename FieldTraits<ft>::real_type;
243 for (
auto const &x : *
this) {
244 real_type
const a = x.infinity_norm();
254 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
256 using real_type =
typename FieldTraits<ft>::real_type;
261 for (
auto const &x : *
this) {
262 real_type
const a = x.infinity_norm_real();
282 for (size_type i=0; i<this->
n; i++)
283 d += (*
this)[i].dim();
307 template<
class B,
class A=std::allocator<B> >
329 blocklevel = B::blocklevel+1
351 this->
p = this->allocator_.allocate(capacity_);
353 new(this->
p)B[capacity_];
366 capacity_ = l.size();
368 this->
p = this->allocator_.allocate(capacity_);
370 new(this->
p)B[capacity_];
372 std::copy_n(l.begin(), l.size(), this->
p);
396 static_assert(std::numeric_limits<S>::is_integer,
397 "capacity must be an unsigned integral type (be aware, that this constructor does not set the default value!)" );
398 size_type capacity = _capacity;
400 if(this->
n > capacity)
403 capacity_ = capacity;
406 this->
p = this->allocator_.allocate(capacity_);
407 new (this->
p)B[capacity_];
433 void reserve(size_type capacity,
bool copyOldValues=
true)
441 this->
p = this->allocator_.allocate(capacity);
442 new (this->
p)B[capacity];
449 for(size_type i=0; i < block_vector_unmanaged<B,A>::N(); ++i, ++from, ++to)
457 this->allocator_.deallocate(pold,capacity_);
466 capacity_ = capacity;
499 this->reserve(size, copyOldValues);
515 this->
p = this->allocator_.allocate(capacity_);
516 new (this->
p)B[capacity_];
524 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
538 this->
p = this->allocator_.allocate(capacity_);
539 new (this->
p)B[capacity_];
548 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
558 this->allocator_.deallocate(this->
p,capacity_);
574 this->allocator_.deallocate(this->
p,capacity_);
578 this->
p = this->allocator_.allocate(capacity_);
579 new (this->
p)B[capacity_];
588 for (size_type i=0; i<this->
n; i++)
598 return this->
operator=(static_cast<const BlockVector&>(a));
620 template<
class B,
class A>
630 template<
class K,
class A>
632 std::ostream& operator<< (std::ostream& s, const BlockVector<K, A>& v)
636 for (size_type i=0; i<v.size(); i++)
637 s << v[i] << std::endl;
658 template<
class B,
class A=std::allocator<B> >
680 blocklevel = B::blocklevel+1
725 #ifdef DUNE_ISTL_WITH_CHECKING 726 if (this->
n!=a.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
732 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
741 return this->
operator=(static_cast<const BlockVectorWindow&>(a));
755 void set (size_type _n, B* _p)
796 template<
class B,
class A=std::allocator<B> >
825 for (size_type i=0; i<this->
n; i++)
837 #ifdef DUNE_ISTL_WITH_CHECKING 838 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
840 for (size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) += y.p[i];
848 #ifdef DUNE_ISTL_WITH_CHECKING 849 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
851 for (size_type i=0; i<y.n; ++i) this->
operator[](y.j[i]) -= y.p[i];
859 #ifdef DUNE_ISTL_WITH_CHECKING 860 if (!includesindexset(y)) DUNE_THROW(
ISTLError,
"index set mismatch");
862 for (size_type i=0; i<y.n; ++i) (this->
operator[](y.j[i])).axpy(a,y.p[i]);
869 for (size_type i=0; i<this->
n; ++i) (this->
p)[i] *= k;
876 for (size_type i=0; i<this->
n; ++i) (this->
p)[i] /= k;
886 #ifdef DUNE_ISTL_WITH_CHECKING 888 DUNE_THROW(
ISTLError,
"index set mismatch");
891 for (size_type i=0; i<this->
n; ++i)
892 sum += (this->
p)[i] * y[(this->j)[i]];
900 typename FieldTraits<field_type>::real_type
one_norm ()
const 902 typename FieldTraits<field_type>::real_type sum=0;
903 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].one_norm();
910 typename FieldTraits<field_type>::real_type sum=0;
911 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].one_norm_real();
916 typename FieldTraits<field_type>::real_type
two_norm ()
const 918 typename FieldTraits<field_type>::real_type sum=0;
919 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].two_norm2();
924 typename FieldTraits<field_type>::real_type
two_norm2 ()
const 926 typename FieldTraits<field_type>::real_type sum=0;
927 for (size_type i=0; i<this->
n; ++i) sum += (this->
p)[i].two_norm2();
933 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
935 using real_type =
typename FieldTraits<ft>::real_type;
939 for (
auto const &x : *
this) {
940 real_type
const a = x.infinity_norm();
948 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
950 using real_type =
typename FieldTraits<ft>::real_type;
954 for (
auto const &x : *
this) {
955 real_type
const a = x.infinity_norm_real();
963 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
965 using real_type =
typename FieldTraits<ft>::real_type;
970 for (
auto const &x : *
this) {
971 real_type
const a = x.infinity_norm();
981 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
983 using real_type =
typename FieldTraits<ft>::real_type;
988 for (
auto const &x : *
this) {
989 real_type
const a = x.infinity_norm_real();
1000 size_type
N ()
const 1009 for (size_type i=0; i<this->
n; i++)
1010 d += (this->
p)[i].dim();
1023 typename V::ConstIterator e=this->
end();
1024 for (size_type i=0; i<y.n; i++)
1025 if (this->
find(y.j[i])==e)
1048 template<
class B,
class A=std::allocator<B> >
1070 blocklevel = B::blocklevel+1
1118 #ifdef DUNE_ISTL_WITH_CHECKING 1119 if (this->
n!=a.
N()) DUNE_THROW(
ISTLError,
"vector size mismatch");
1125 for (size_type i=0; i<this->
n; i++) this->
p[i]=a.
p[i];
1126 for (size_type i=0; i<this->
n; i++) this->j[i]=a.
j[i];
1135 return this->
operator=(static_cast<const CompressedBlockVectorWindow&>(a));
1149 void set (size_type _n, B* _p, size_type* _j)
B::field_type field_type
export the type representing the field
Definition: bvector.hh:315
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:684
block_vector_unmanaged & operator-=(const block_vector_unmanaged &y)
vector space subtraction
Definition: bvector.hh:96
block_vector_unmanaged & operator=(const field_type &k)
Assignment from a scalar.
Definition: bvector.hh:77
void reserve(size_type capacity, bool copyOldValues=true)
Reserve space.
Definition: bvector.hh:433
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:138
block_vector_unmanaged & operator/=(const field_type &k)
vector space division by scalar
Definition: bvector.hh:113
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:336
B block_type
export the type representing the components
Definition: bvector.hh:318
base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:60
BlockVector(size_type _n)
make vector with _n components
Definition: bvector.hh:346
const B & const_reference
Type used for const references.
Definition: bvector.hh:72
Definition: bvector.hh:1049
void setsize(size_type _n)
set size only
Definition: bvector.hh:1157
size_type n
Definition: basearray.hh:254
A simple array container with non-consecutive index set.
Definition: basearray.hh:547
iterator end()
end iterator
Definition: basearray.hh:176
A::size_type size_type
The type for the index access.
Definition: bvector.hh:324
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:900
FieldTraits< ft >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:207
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:181
BlockVectorWindow(B *_p, size_type _n)
make array from given pointer and size
Definition: bvector.hh:696
Iterator implementation class.
Definition: basearray.hh:82
FieldTraits< field_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: bvector.hh:173
A allocator_type
export the allocator type
Definition: bvector.hh:54
BlockVector()
makes empty vector
Definition: bvector.hh:341
BlockVector(const BlockVector &a)
copy constructor
Definition: bvector.hh:507
B * p
Definition: basearray.hh:768
void resize(size_type size, bool copyOldValues=true)
Resize the vector.
Definition: bvector.hh:495
compressed_block_vector_unmanaged & axpy(const field_type &a, const V &y)
vector space axpy operation
Definition: bvector.hh:857
CompressedBlockVectorWindow(const CompressedBlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:1094
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:1000
FieldTraits< ft >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:949
FieldTraits< field_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: bvector.hh:908
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: bvector.hh:273
size_type dim() const
dimension of the vector space
Definition: bvector.hh:279
size_type capacity() const
Get the capacity of the vector.
Definition: bvector.hh:476
FieldTraits< ft >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: bvector.hh:222
const B * getptr() const
get pointer
Definition: bvector.hh:1187
block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:289
base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:63
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:197
B block_type
export the type representing the components
Definition: bvector.hh:1059
B::field_type field_type
export the type representing the field
Definition: bvector.hh:804
bool includesindexset(const V &y)
return true if index sets coincide
Definition: bvector.hh:1021
~BlockVector()
free dynamic memory
Definition: bvector.hh:552
FieldTraits< B >::field_type field_type
Definition: bvector.hh:623
void setindexptr(size_type *_j)
set pointer only
Definition: bvector.hh:1169
size_type * j
Definition: basearray.hh:769
compressed_block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:1077
A::size_type size_type
The size type for the index access.
Definition: bvector.hh:57
B value_type
for STL compatibility
Definition: bvector.hh:66
size_type getsize() const
get size
Definition: bvector.hh:1198
size_type capacity_
Definition: bvector.hh:609
void setptr(B *_p)
set pointer only
Definition: bvector.hh:1163
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:159
block_vector_unmanaged< B, A >::ConstIterator ConstIterator
make iterators available as types
Definition: bvector.hh:687
Definition: basearray.hh:19
FieldTraits< B >::real_type real_type
Definition: bvector.hh:624
BlockVector(const block_vector_unmanaged< B, A > &_a)
construct from base class object
Definition: bvector.hh:528
size_type * getindexptr()
get pointer
Definition: bvector.hh:1181
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:189
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:924
FieldTraits< field_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: bvector.hh:916
B * p
Definition: basearray.hh:255
iterator find(size_type i)
random access returning iterator (end if not contained)
Definition: basearray.hh:196
FieldTraits< ft >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: bvector.hh:934
B::field_type field_type
export the type representing the field
Definition: bvector.hh:1056
Definition: bvector.hh:797
B * getptr()
get pointer
Definition: bvector.hh:1175
A vector of blocks with memory management.
Definition: bvector.hh:308
compressed_block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:1074
void setptr(B *_p)
set pointer only
Definition: bvector.hh:768
B block_type
export the type representing the components
Definition: bvector.hh:669
BlockVectorWindow(const BlockVectorWindow &a)
copy constructor, this has reference semantics!
Definition: bvector.hh:703
B block_type
export the type representing the components
Definition: bvector.hh:51
B block_type
export the type representing the components
Definition: bvector.hh:807
block_vector_unmanaged & operator*=(const field_type &k)
vector space multiplication with scalar
Definition: bvector.hh:106
block_vector_unmanaged & operator+=(const block_vector_unmanaged &y)
vector space addition
Definition: bvector.hh:86
Implements several basic array containers.
size_type dim() const
dimension of the vector space
Definition: bvector.hh:1006
A simple array container for objects of type B.
Definition: basearray.hh:44
size_type getsize()
get size
Definition: bvector.hh:780
A::size_type size_type
The type for the index access.
Definition: bvector.hh:819
size_type n
Definition: basearray.hh:767
CompressedBlockVectorWindow(B *_p, size_type *_j, size_type _n)
make array from given pointers and size
Definition: bvector.hh:1086
BlockVectorWindow(const block_vector_unmanaged< B, A > &_a)
construct from base class object with reference semantics!
Definition: bvector.hh:710
BlockVectorWindow()
makes empty array
Definition: bvector.hh:692
size_type size() const
number of blocks in the array (are of size 1 here)
Definition: basearray.hh:240
A::size_type size_type
The type for the index access.
Definition: bvector.hh:1065
block_vector_unmanaged & axpy(const field_type &a, const block_vector_unmanaged &y)
vector space axpy operation
Definition: bvector.hh:120
A::size_type size_type
The type for the index access.
Definition: bvector.hh:675
compressed_base_array_unmanaged< B, A >::const_iterator ConstIterator
make iterators available as types
Definition: bvector.hh:816
const size_type * getindexptr() const
get pointer
Definition: bvector.hh:1193
iterator class for sequential access
Definition: basearray.hh:584
derive error class from the base class in common
Definition: istlexception.hh:16
B & reference
Type used for references.
Definition: bvector.hh:69
compressed_base_array_unmanaged< B, A >::iterator Iterator
make iterators available as types
Definition: bvector.hh:813
block_vector_unmanaged< B, A >::Iterator Iterator
make iterators available as types
Definition: bvector.hh:333
compressed_block_vector_unmanaged()
make constructor protected, so only derived classes can be instantiated
Definition: bvector.hh:1016
B::field_type field_type
export the type representing the field
Definition: bvector.hh:666
BlockVector(size_type _n, S _capacity)
Make vector with _n components but preallocating capacity components.
Definition: bvector.hh:394
B * getptr()
get pointer
Definition: bvector.hh:774
void setsize(size_type _n)
set size only
Definition: bvector.hh:762
Definition: bvector.hh:659
CompressedBlockVectorWindow()
makes empty array
Definition: bvector.hh:1082
BlockVector(std::initializer_list< B > const &l)
Construct from a std::initializer_list.
Definition: bvector.hh:363
CompressedBlockVectorWindow(const compressed_block_vector_unmanaged< B, A > &_a)
construct from base class object with reference semantics!
Definition: bvector.hh:1102
An unmanaged vector of blocks.
Definition: bvector.hh:41