3 #ifndef DUNE_DENSEVECTOR_HH
4 #define DUNE_DENSEVECTOR_HH
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;
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_);
200 return static_cast< DifferenceType >( other.position_ ) - static_cast< DifferenceType >( position_ );
205 assert(other.container_==container_);
206 return static_cast< DifferenceType >( other.position_ ) - static_cast< DifferenceType >( position_ );
212 return this->position_;
236 typedef DenseMatVecTraits<V> Traits;
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 FieldType>
468 typename std::enable_if<
469 std::is_convertible<FieldType, field_type>::value,
489 template <
typename FieldType>
490 typename std::enable_if<
491 std::is_convertible<FieldType, field_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);
543 assert(y.size() ==
size());
545 result += PromotedType((*
this)[i]*y[i]);
557 template<
class Other>
560 PromotedType result(0);
561 assert(y.size() ==
size());
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);
700 std::ostream& operator<< (std::ostream& s, const DenseVector<V>& v)
703 s << ((i>0) ?
" " :
"") << v[i];
711 #endif // DUNE_DENSEVECTOR_HH
void decrement()
Definition: densevector.hh:184
T field_type
export the type representing the field
Definition: ftraits.hh:26
DifferenceType distanceTo(DenseIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type > other) const
Definition: densevector.hh:203
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:254
The number of block levels we contain.
Definition: densevector.hh:271
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:427
FieldTraits< value_type >::field_type field_type
export the type representing the field
Definition: densevector.hh:260
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:305
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:139
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:334
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:590
DifferenceType distanceTo(DenseIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type > other) const
Definition: densevector.hh:197
R dereference() const
Definition: densevector.hh:175
constexpr DenseVector()
Definition: densevector.hh:248
bool equals(const MutableIterator &other) const
Definition: densevector.hh:164
derived_type operator-(const DenseVector< Other > &b) const
Binary vector subtraction.
Definition: densevector.hh:408
Iterator end()
end iterator
Definition: densevector.hh:314
Iterator begin()
begin iterator
Definition: densevector.hh:308
size_type size() const
size method
Definition: densevector.hh:297
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
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:19
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
ConstIterator beforeBegin() const
Definition: densevector.hh:365
Provides the functions dot(a,b) := and dotT(a,b) := .
ConstIterator begin() const
begin ConstIterator
Definition: densevector.hh:345
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:494
PromotionTraits< field_type, typename DenseVector< Other >::field_type >::PromotedType operator*(const DenseVector< Other > &y) const
indefinite vector dot product which corresponds to Petsc's VecTDot
Definition: densevector.hh:540
Type traits to determine the type of reals (when working with complex numbers)
R elementAt(DifferenceType i) const
Definition: densevector.hh:189
Macro for wrapping boundary checks.
Iterator beforeBegin()
Definition: densevector.hh:328
DenseIterator(const MutableIterator &other)
Definition: densevector.hh:155
derived_type & operator+=(const DenseVector< Other > &y)
vector space addition
Definition: densevector.hh:380
container_type::size_type size_type
Definition: dynvector.hh:39
derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition: densevector.hh:276
SizeType index() const
return index
Definition: densevector.hh:210
ConstIterator end() const
end ConstIterator
Definition: densevector.hh:351
FieldTraits< typename DenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:24
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:257
derived_type & operator-=(const DenseVector< Other > &y)
vector space subtraction
Definition: densevector.hh:390
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:342
Compute type of the result of an arithmetic operation involving two different number types...
Definition: promotiontraits.hh:24
Compute type of the result of an arithmetic operation involving two different number types...
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:303
DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:151
ConstIterator find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:371
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:266
ConstIterator beforeEnd() const
Definition: densevector.hh:358
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
value_type & operator[](size_type i)
random access
Definition: densevector.hh:286
PromotionTraits< field_type, typename DenseVector< Other >::field_type >::PromotedType dot(const DenseVector< Other > &y) const
vector dot product which corresponds to Petsc's VecDot
Definition: densevector.hh:558
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:571
std::size_t position_
The current position in the buffer.
Definition: variablesizecommunicator.hh:136
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:340
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:610
Definition: ftraits.hh:23
void advance(DifferenceType n)
Definition: densevector.hh:193
bool equals(const ConstIterator &other) const
Definition: densevector.hh:170
Traits::value_type block_type
export the type representing the components
Definition: densevector.hh:263
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:126
C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:144
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:581
Construct a vector with a dynamic size.
Definition: dynvector.hh:32
K value_type
Definition: dynvector.hh:38
bool operator!=(const DenseVector< Other > &y) const
Binary vector incomparison.
Definition: densevector.hh:516
Implements a generic iterator class for writing stl conformant iterators.
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:472
derived_type & axpy(const field_type &a, const DenseVector< Other > &y)
vector space axpy operation ( *this += a y )
Definition: densevector.hh:524
size_type dim() const
dimension of the vector space
Definition: densevector.hh:684
DenseIterator(const ConstIterator &other)
Definition: densevector.hh:159
Iterator beforeEnd()
Definition: densevector.hh:321
FieldTraits< typename DenseMatVecTraits< V >::value_type >::real_type real_type
Definition: densevector.hh:25
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition: densevector.hh:400
bool operator==(const DenseVector< Other > &y) const
Binary vector comparison.
Definition: densevector.hh:504
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:626
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:678
Definition: typetraits.hh:95
void increment()
Definition: densevector.hh:179