Go to the documentation of this file.
3 #ifndef DUNE_DENSEVECTOR_HH
4 #define DUNE_DENSEVECTOR_HH
59 return abs(c.real()) + abs(c.imag());
79 return c.real()*c.real() + c.imag()*c.imag();
86 template<class K, bool isInteger = std::numeric_limits<K>::is_integer>
117 return Sqrt<K>::sqrt(k);
126 template<
class C,
class T,
class R =T&>
131 friend class
DenseIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type >;
133 typedef
DenseIterator<typename std::remove_const<C>::type, typename std::remove_const<T>::type, typename mutable_reference<R>::type >
MutableIterator;
134 typedef
DenseIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type >
ConstIterator;
149 : container_(0), position_()
153 : container_(&cont), position_(pos)
157 : container_(other.container_), position_(other.position_)
161 : container_(other.container_), position_(other.position_)
167 return position_ == other.position_ && container_ == other.container_;
173 return position_ == other.position_ && container_ == other.container_;
177 return container_->operator[](position_);
191 return container_->operator[](position_+i);
195 position_=position_+n;
200 assert(other.container_==container_);
206 assert(other.container_==container_);
213 return this->position_;
228 typedef DenseMatVecTraits<V> Traits;
232 V & asImp() {
return static_cast<V&
>(*this); }
233 const V & asImp()
const {
return static_cast<const V&
>(*this); }
282 template <
typename W,
284 std::is_assignable<value_type&, typename DenseVector<W>::value_type>::value,
int> = 0>
287 assert(other.size() ==
size());
289 asImp()[i] = other[i];
321 return asImp()[
size()-1];
327 return asImp()[
size()-1];
339 return asImp().size();
419 template <
class Other>
429 template <
class Other>
439 template <
class Other>
447 template <
class Other>
461 result[i] = -asImp()[i];
475 template <
typename ValueType>
476 typename std::enable_if<
477 std::is_convertible<ValueType, value_type>::value,
497 template <
typename ValueType>
498 typename std::enable_if<
499 std::is_convertible<ValueType, value_type>::value,
519 template <
typename FieldType>
520 typename std::enable_if<
521 std::is_convertible<FieldType, field_type>::value,
541 template <
typename FieldType>
542 typename std::enable_if<
543 std::is_convertible<FieldType, field_type>::value,
555 template <
class Other>
560 if ((*
this)[i]!=x[i])
567 template <
class Other>
575 template <
class Other>
580 (*
this)[i] += a*x[i];
591 template<
class Other>
594 PromotedType result(0);
595 assert(x.size() ==
size());
597 result += PromotedType((*
this)[i]*x[i]);
609 template<
class Other>
612 PromotedType result(0);
613 assert(x.size() ==
size());
627 result += abs((*
this)[i]);
637 result += fvmeta::absreal((*
this)[i]);
646 result += fvmeta::abs2((*
this)[i]);
647 return fvmeta::sqrt(result);
655 result += fvmeta::abs2((*
this)[i]);
661 typename std::enable_if<!HasNaN<vt>::value,
int>::type = 0>
668 for (
auto const &x : *
this) {
669 real_type
const a = abs(x);
677 typename std::enable_if<!HasNaN<vt>::value,
int>::type = 0>
683 for (
auto const &x : *
this) {
684 real_type
const a = fvmeta::absreal(x);
692 typename std::enable_if<HasNaN<vt>::value,
int>::type = 0>
700 for (
auto const &x : *
this) {
701 real_type
const a = abs(x);
710 typename std::enable_if<HasNaN<vt>::value,
int>::type = 0>
717 for (
auto const &x : *
this) {
718 real_type
const a = fvmeta::absreal(x);
753 s << ((i>0) ?
" " :
"") << v[i];
761 #endif // DUNE_DENSEVECTOR_HH
R dereference() const
Definition: densevector.hh:176
derived_type & operator+=(const DenseVector< Other > &x)
vector space addition
Definition: densevector.hh:420
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:245
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:374
void decrement()
Definition: densevector.hh:185
DenseIterator(const ConstIterator &other)
Definition: densevector.hh:160
auto max(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:412
Base::size_type size_type
Definition: dynvector.hh:62
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:642
ConstIterator beforeBegin() const
Definition: densevector.hh:405
Compute type of the result of an arithmetic operation involving two different number types.
auto min(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:434
const value_type & front() const
return reference to first element
Definition: densevector.hh:313
derived_type & operator-=(const DenseVector< Other > &x)
vector space subtraction
Definition: densevector.hh:430
derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition: densevector.hh:440
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:127
size_type size() const
size method
Definition: densevector.hh:337
DifferenceType distanceTo(DenseIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type > other) const
Definition: densevector.hh:198
Macro for wrapping boundary checks.
bool empty() const
checks whether the container is empty
Definition: densevector.hh:331
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:343
constexpr DenseVector()=default
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:728
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:431
FieldTraits< typename DenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:25
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:257
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
const value_type & back() const
return reference to last element
Definition: densevector.hh:325
void advance(DifferenceType n)
Definition: densevector.hh:194
T field_type
export the type representing the field
Definition: ftraits.hh:26
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:623
R elementAt(DifferenceType i) const
Definition: densevector.hh:190
auto dot(const A &a, const B &b) -> typename std::enable_if<!IsVector< A >::value &&!std::is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type > ::value, decltype(conj(a) *b)>::type
computes the dot product for fundamental data types according to Petsc's VectDot function: dot(a,...
Definition: dotproduct.hh:40
DenseIterator(const MutableIterator &other)
Definition: densevector.hh:156
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:633
FieldTraits< value_type >::field_type field_type
export the type representing the field
Definition: densevector.hh:251
derived_type operator-() const
Vector negation.
Definition: densevector.hh:455
C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:145
Iterator beforeBegin()
Definition: densevector.hh:368
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:273
value_type & front()
return reference to first element
Definition: densevector.hh:307
@ blocklevel
The number of block levels we contain.
Definition: densevector.hh:262
FieldTraits< value_type >::real_type two_norm2() const
square of two norm (sum over squared values of entries), need for block recursion
Definition: densevector.hh:651
Iterator begin()
begin iterator
Definition: densevector.hh:348
std::enable_if< std::is_convertible< FieldType, field_type >::value, derived_type >::type & operator/=(const FieldType &kk)
vector space division by scalar
Definition: densevector.hh:546
std::enable_if< std::is_convertible< FieldType, field_type >::value, derived_type >::type & operator*=(const FieldType &kk)
vector space multiplication with scalar
Definition: densevector.hh:524
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:613
Provides the functions dot(a,b) := and dotT(a,b) := .
size_type dim() const
dimension of the vector space
Definition: densevector.hh:734
ConstIterator beforeEnd() const
Definition: densevector.hh:398
bool equals(const ConstIterator &other) const
Definition: densevector.hh:171
Iterator beforeEnd()
Definition: densevector.hh:361
SizeType index() const
return index
Definition: densevector.hh:211
Definition: ftraits.hh:23
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:140
Traits::value_type block_type
export the type representing the components
Definition: densevector.hh:254
value_type & operator[](size_type i)
random access
Definition: densevector.hh:296
FieldTraits< typename DenseMatVecTraits< V >::value_type >::real_type real_type
Definition: densevector.hh:26
Implements a generic iterator class for writing stl conformant iterators.
derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition: densevector.hh:267
bool operator!=(const DenseVector< Other > &x) const
Binary vector incomparison.
Definition: densevector.hh:568
bool operator==(const DenseVector< Other > &x) const
Binary vector comparison.
Definition: densevector.hh:556
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:20
DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:152
Iterator end()
end iterator
Definition: densevector.hh:354
ConstIterator begin() const
begin ConstIterator
Definition: densevector.hh:385
Base::value_type value_type
Definition: dynvector.hh:63
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:248
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
ConstIterator find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:411
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:678
PromotionTraits< field_type, typename DenseVector< Other >::field_type >::PromotedType dot(const DenseVector< Other > &x) const
vector dot product which corresponds to Petsc's VecDot
Definition: densevector.hh:610
PromotionTraits< field_type, typename DenseVector< Other >::field_type >::PromotedType operator*(const DenseVector< Other > &x) const
indefinite vector dot product which corresponds to Petsc's VecTDot
Definition: densevector.hh:592
ConstIterator end() const
end ConstIterator
Definition: densevector.hh:391
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:380
bool equals(const MutableIterator &other) const
Definition: densevector.hh:165
derived_type & axpy(const field_type &a, const DenseVector< Other > &x)
vector space axpy operation ( *this += a x )
Definition: densevector.hh:576
Type traits to determine the type of reals (when working with complex numbers)
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:345
void increment()
Definition: densevector.hh:180
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:662
Compute type of the result of an arithmetic operation involving two different number types.
Definition: promotiontraits.hh:24
DifferenceType distanceTo(DenseIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type > other) const
Definition: densevector.hh:204
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:382
value_type & back()
return reference to last element
Definition: densevector.hh:319
Dune namespace.
Definition: alignedallocator.hh:13