3#ifndef DUNE_DENSEVECTOR_HH
4#define DUNE_DENSEVECTOR_HH
19 template<
typename V>
class DenseVector;
58 return abs(c.real()) + abs(c.imag());
78 return c.real()*c.real() + c.imag()*c.imag();
85 template<class K, bool isInteger = std::numeric_limits<K>::is_integer>
116 return Sqrt<K>::sqrt(k);
125 template<
class C,
class T,
class R =T&>
130 friend class
DenseIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type >;
132 typedef
DenseIterator<typename std::remove_const<C>::type, typename std::remove_const<T>::type, typename mutable_reference<R>::type >
MutableIterator;
133 typedef
DenseIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type >
ConstIterator;
148 : container_(0), position_()
152 : container_(&cont), position_(pos)
156 : container_(other.container_), position_(other.position_)
160 : container_(other.container_), position_(other.position_)
166 return position_ == other.position_ && container_ == other.container_;
172 return position_ == other.position_ && container_ == other.container_;
176 return container_->operator[](position_);
190 return container_->operator[](position_+i);
194 position_=position_+n;
199 assert(other.container_==container_);
205 assert(other.container_==container_);
212 return this->position_;
240 V & asImp() {
return static_cast<V&
>(*this); }
241 const V & asImp()
const {
return static_cast<const V&
>(*this); }
299 return asImp().size();
379 template <
class Other>
389 template <
class Other>
399 template <
class Other>
407 template <
class Other>
423 template <
typename ValueType>
424 typename std::enable_if<
425 std::is_convertible<ValueType, value_type>::value,
445 template <
typename ValueType>
446 typename std::enable_if<
447 std::is_convertible<ValueType, value_type>::value,
467 template <
typename ValueType>
468 typename std::enable_if<
469 std::is_convertible<ValueType, value_type>::value,
489 template <
typename ValueType>
490 typename std::enable_if<
491 std::is_convertible<ValueType, value_type>::value,
503 template <
class Other>
508 if ((*
this)[i]!=y[i])
515 template <
class Other>
523 template <
class Other>
528 (*
this)[i] += a*y[i];
539 template<
class Other>
542 PromotedType result(0);
545 result += PromotedType((*
this)[i]*y[i]);
557 template<
class Other>
560 PromotedType result(0);
575 result += abs((*
this)[i]);
585 result += fvmeta::absreal((*
this)[i]);
594 result += fvmeta::abs2((*
this)[i]);
595 return fvmeta::sqrt(result);
603 result += fvmeta::abs2((*
this)[i]);
609 typename std::enable_if<!has_nan<vt>::value,
int>::type = 0>
616 for (
auto const &x : *
this) {
617 real_type
const a = abs(x);
625 typename std::enable_if<!has_nan<vt>::value,
int>::type = 0>
631 for (
auto const &x : *
this) {
632 real_type
const a = fvmeta::absreal(x);
640 typename std::enable_if<has_nan<vt>::value,
int>::type = 0>
648 for (
auto const &x : *
this) {
649 real_type
const a = abs(x);
659 typename std::enable_if<has_nan<vt>::value,
int>::type = 0>
666 for (
auto const &x : *
this) {
667 real_type
const a = fvmeta::absreal(x);
703 s << ((i>0) ?
" " :
"") << v[i];
Implements a generic iterator class for writing stl conformant iterators.
#define DUNE_ASSERT_BOUNDS(cond)
Definition boundschecking.hh:20
Compute type of the result of an arithmetic operation involving two different number types.
Provides the functions dot(a,b) := and dotT(a,b) := .
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
Type traits to determine the type of reals (when working with complex numbers)
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:43
std::ostream & operator<<(std::ostream &s, const std::array< T, N > &e)
Output operator for array.
Definition array.hh:28
Dune namespace.
Definition alignment.hh:11
Interface for a class of dense vectors over a given field.
Definition densevector.hh:235
Traits::value_type value_type
export the type representing the field
Definition densevector.hh:257
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:599
ConstIterator const_iterator
typedef for stl compliant access
Definition densevector.hh:342
Iterator iterator
typedef for stl compliant access
Definition densevector.hh:305
ConstIterator find(size_type i) const
return iterator to given element or end()
Definition densevector.hh:371
ConstIterator end() const
end ConstIterator
Definition densevector.hh:351
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition densevector.hh:590
ConstIterator beforeBegin() const
Definition densevector.hh:365
PromotionTraits< field_type, typenameDenseVector< Other >::field_type >::PromotedType dot(const DenseVector< Other > &y) const
vector dot product which corresponds to Petsc's VecDot
Definition densevector.hh:558
Iterator begin()
begin iterator
Definition densevector.hh:308
derived_type & axpy(const value_type &a, const DenseVector< Other > &y)
vector space axpy operation ( *this += a y )
Definition densevector.hh:524
Iterator beforeBegin()
Definition densevector.hh:328
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition densevector.hh:340
Traits::derived_type derived_type
type of derived vector class
Definition densevector.hh:254
derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition densevector.hh:400
@ blocklevel
The number of block levels we contain.
Definition densevector.hh:271
std::enable_if< std::is_convertible< ValueType, value_type >::value, derived_type >::type & operator/=(const ValueType &kk)
vector space division by scalar
Definition densevector.hh:494
size_type size() const
size method
Definition densevector.hh:297
derived_type & operator-=(const DenseVector< Other > &y)
vector space subtraction
Definition densevector.hh:390
size_type dim() const
dimension of the vector space
Definition densevector.hh:684
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition densevector.hh:610
ConstIterator beforeEnd() const
Definition densevector.hh:358
derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition densevector.hh:276
Iterator end()
end iterator
Definition densevector.hh:314
PromotionTraits< field_type, typenameDenseVector< Other >::field_type >::PromotedType operator*(const DenseVector< Other > &y) const
indefinite vector dot product which corresponds to Petsc's VecTDot
Definition densevector.hh:540
Traits::size_type size_type
The type used for the index access and size operation.
Definition densevector.hh:266
derived_type operator-(const DenseVector< Other > &b) const
Binary vector subtraction.
Definition densevector.hh:408
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition densevector.hh:303
bool operator==(const DenseVector< Other > &y) const
Binary vector comparison.
Definition densevector.hh:504
Iterator beforeEnd()
Definition densevector.hh:321
std::enable_if< std::is_convertible< ValueType, value_type >::value, derived_type >::type & operator*=(const ValueType &kk)
vector space multiplication with scalar
Definition densevector.hh:472
derived_type & operator+=(const DenseVector< Other > &y)
vector space addition
Definition densevector.hh:380
ConstIterator begin() const
begin ConstIterator
Definition densevector.hh:345
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition densevector.hh:626
Traits::value_type block_type
export the type representing the components
Definition densevector.hh:263
value_type & operator[](size_type i)
random access
Definition densevector.hh:286
Traits::value_type field_type
export the type representing the field
Definition densevector.hh:260
constexpr DenseVector()
Definition densevector.hh:248
bool operator!=(const DenseVector< Other > &y) const
Binary vector incomparison.
Definition densevector.hh:516
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition densevector.hh:581
Iterator find(size_type i)
return iterator to given element or end()
Definition densevector.hh:334
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition densevector.hh:571
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition densevector.hh:678
FieldTraits< typenameDenseMatVecTraits< V >::value_type >::real_type real_type
Definition densevector.hh:25
FieldTraits< typenameDenseMatVecTraits< V >::value_type >::field_type field_type
Definition densevector.hh:24
Generic iterator class for dense vector and matrix implementations.
Definition densevector.hh:128
void increment()
Definition densevector.hh:179
SizeType index() const
return index
Definition densevector.hh:210
bool equals(const MutableIterator &other) const
Definition densevector.hh:164
DenseIterator(const MutableIterator &other)
Definition densevector.hh:155
bool equals(const ConstIterator &other) const
Definition densevector.hh:170
R elementAt(DifferenceType i) const
Definition densevector.hh:189
DifferenceType distanceTo(DenseIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type > other) const
Definition densevector.hh:197
void decrement()
Definition densevector.hh:184
DenseIterator(const ConstIterator &other)
Definition densevector.hh:159
DifferenceType distanceTo(DenseIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type > other) const
Definition densevector.hh:203
DenseIterator(C &cont, SizeType pos)
Definition densevector.hh:151
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition densevector.hh:139
R dereference() const
Definition densevector.hh:175
void advance(DifferenceType n)
Definition densevector.hh:193
C::size_type SizeType
The type to index the underlying container.
Definition densevector.hh:144
T field_type
export the type representing the field
Definition ftraits.hh:26
T real_type
export the type representing the real type of the field
Definition ftraits.hh:28
get the 'mutable' version of a reference to a const object
Definition genericiterator.hh:114
Base class for stl conformant forward iterators.
Definition iteratorfacades.hh:433
Definition matvectraits.hh:29
Compute type of the result of an arithmetic operation involving two different number types.
Definition promotiontraits.hh:25
Definition typetraits.hh:74