5 #ifndef DUNE_DENSEVECTOR_HH 6 #define DUNE_DENSEVECTOR_HH 10 #include <type_traits> 62 return abs(c.real()) +
abs(c.imag());
82 return c.real()*c.real() + c.imag()*c.imag();
89 template<class K, bool isInteger = std::numeric_limits<K>::is_integer>
129 template<
class C,
class T,
class R =T&>
134 friend class
DenseIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type >;
136 typedef
DenseIterator<typename std::remove_const<C>::type, typename std::remove_const<T>::type, typename mutable_reference<R>::type >
MutableIterator;
137 typedef
DenseIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type >
ConstIterator;
152 : container_(0), position_()
156 : container_(&cont), position_(pos)
170 container_ = other.container_;
171 position_ = other.position_;
176 container_ = other.container_;
177 position_ = other.position_;
184 return position_ == other.position_ && container_ == other.container_;
190 return position_ == other.position_ && container_ == other.container_;
194 return container_->operator[](position_);
208 return container_->operator[](position_+
i);
212 position_=position_+n;
217 assert(other.container_==container_);
218 return static_cast< DifferenceType >( other.position_ ) - static_cast< DifferenceType >( position_ );
223 assert(other.container_==container_);
224 return static_cast< DifferenceType >( other.position_ ) - static_cast< DifferenceType >( position_ );
230 return this->position_;
245 typedef DenseMatVecTraits<V> Traits;
249 constexpr V & asImp() {
return static_cast<V&
>(*this); }
250 constexpr
const V & asImp()
const {
return static_cast<const V&
>(*this); }
296 template <
typename W,
298 std::is_assignable<value_type&, typename DenseVector<W>::value_type>::value,
int> = 0>
301 assert(other.size() ==
size());
303 asImp()[
i] = other[
i];
335 return asImp()[
size()-1];
341 return asImp()[
size()-1];
353 return asImp().size();
433 template <
class Other>
443 template <
class Other>
453 template <
class Other>
461 template <
class Other>
472 using idx_type =
typename decltype(result)::
size_type;
474 for (idx_type
i = 0;
i <
size(); ++
i)
475 result[
i] = -asImp()[
i];
489 template <
typename ValueType>
490 constexpr
typename std::enable_if<
491 std::is_convertible<ValueType, value_type>::value,
511 template <
typename ValueType>
512 constexpr
typename std::enable_if<
513 std::is_convertible<ValueType, value_type>::value,
533 template <
typename FieldType>
534 constexpr
typename std::enable_if<
535 std::is_convertible<FieldType, field_type>::value,
555 template <
typename FieldType>
556 constexpr
typename std::enable_if<
557 std::is_convertible<FieldType, field_type>::value,
569 template <
class Other>
574 if ((*
this)[
i]!=x[
i])
581 template <
class Other>
589 template <
class Other>
594 (*
this)[
i] += a*x[
i];
605 template<
class Other>
608 PromotedType result(0);
609 assert(x.size() ==
size());
611 result += PromotedType((*
this)[
i]*x[
i]);
623 template<
class Other>
626 PromotedType result(0);
627 assert(x.size() ==
size());
641 result +=
abs((*
this)[
i]);
651 result += fvmeta::absreal((*
this)[
i]);
660 result += fvmeta::abs2((*
this)[
i]);
669 result += fvmeta::abs2((*
this)[
i]);
675 typename std::enable_if<!HasNaN<vt>::value,
int>::type = 0>
682 for (
auto const &x : *
this) {
683 real_type
const a =
abs(x);
691 typename std::enable_if<!HasNaN<vt>::value,
int>::type = 0>
697 for (
auto const &x : *
this) {
698 real_type
const a = fvmeta::absreal(x);
706 typename std::enable_if<HasNaN<vt>::value,
int>::type = 0>
714 for (
auto const &x : *
this) {
715 real_type
const a =
abs(x);
724 typename std::enable_if<HasNaN<vt>::value,
int>::type = 0>
731 for (
auto const &x : *
this) {
732 real_type
const a = fvmeta::absreal(x);
764 std::ostream& operator<< (std::ostream& s, const DenseVector<V>& v)
767 s << ((
i>0) ?
" " :
"") << v[
i];
775 #endif // DUNE_DENSEVECTOR_HH C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:148
constexpr bool operator==(const DenseVector< Other > &x) const
Binary vector comparison.
Definition: densevector.hh:570
Type traits to determine the type of reals (when working with complex numbers)
FieldTraits< typename DenseMatVecTraits< V >::value_type >::real_type real_type
Definition: densevector.hh:29
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:143
constexpr DifferenceType distanceTo(DenseIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type > other) const
Definition: densevector.hh:221
FieldTraits< typename DenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:28
constexpr DenseIterator(const ConstIterator &other)
Definition: densevector.hh:164
constexpr 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:538
static constexpr int blocklevel
The number of block levels we contain. This is the leaf, that is, 1.
Definition: densevector.hh:277
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Returns whether any entry is NaN.
Definition: fvector.hh:458
constexpr derived_type & axpy(const field_type &a, const DenseVector< Other > &x)
vector space axpy operation ( *this += a x )
Definition: densevector.hh:590
constexpr R dereference() const
Definition: densevector.hh:193
auto dot(const A &a, const B &b) -> typename std::enable_if< IsNumber< A >::value &&!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
constexpr derived_type & operator+=(const DenseVector< Other > &x)
vector space addition
Definition: densevector.hh:434
constexpr FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:676
Compute type of the result of an arithmetic operation involving two different number types...
Definition: promotiontraits.hh:26
constexpr ConstIterator end() const
end ConstIterator
Definition: densevector.hh:405
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:489
constexpr size_type dim() const
dimension of the vector space
Definition: densevector.hh:748
constexpr DifferenceType distanceTo(DenseIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type > other) const
Definition: densevector.hh:215
constexpr DenseVector()=default
constexpr 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:560
constexpr Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:388
constexpr value_type & back()
return reference to last element
Definition: densevector.hh:333
constexpr DenseIterator & operator=(const ConstIterator &other)
Definition: densevector.hh:169
constexpr derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition: densevector.hh:454
constexpr size_type size() const
size method
Definition: densevector.hh:351
constexpr SizeType index() const
return index
Definition: densevector.hh:228
constexpr DenseIterator(const MutableIterator &other)
Definition: densevector.hh:159
constexpr FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:656
constexpr bool empty() const
checks whether the container is empty
Definition: densevector.hh:345
FieldTraits< value_type >::field_type field_type
export the type representing the field
Definition: densevector.hh:268
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
constexpr void advance(DifferenceType n)
Definition: densevector.hh:211
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:30
constexpr Iterator beforeBegin()
Definition: densevector.hh:382
constexpr size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:742
constexpr Iterator beforeEnd()
Definition: densevector.hh:375
constexpr bool equals(const MutableIterator &other) const
Definition: densevector.hh:182
constexpr 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:606
constexpr bool operator!=(const DenseVector< Other > &x) const
Binary vector incomparison.
Definition: densevector.hh:582
I i
Definition: hybridmultiindex.hh:328
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:30
Macro for wrapping boundary checks.
constexpr FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:692
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:262
constexpr ConstIterator beforeBegin() const
Definition: densevector.hh:419
constexpr FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:637
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:434
constexpr void increment()
Definition: densevector.hh:197
Dune namespace
Definition: alignedallocator.hh:12
constexpr const value_type & front() const
return reference to first element
Definition: densevector.hh:327
K value_type
Definition: dynvector.hh:40
constexpr Iterator end()
end iterator
Definition: densevector.hh:368
constexpr 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:624
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:274
constexpr ConstIterator find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:425
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:23
Construct a vector with a dynamic size.
Definition: dynvector.hh:34
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:115
Compute type of the result of an arithmetic operation involving two different number types...
constexpr void decrement()
Definition: densevector.hh:202
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:511
constexpr 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:665
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:394
Definition: ftraits.hh:25
constexpr derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition: densevector.hh:281
constexpr const value_type & back() const
return reference to last element
Definition: densevector.hh:339
constexpr auto sqrt(T t) requires(std
Definition: cmath.hh:39
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:359
T field_type
export the type representing the field
Definition: ftraits.hh:28
constexpr FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:647
constexpr value_type & front()
return reference to first element
Definition: densevector.hh:321
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:396
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:130
constexpr ConstIterator begin() const
begin ConstIterator
Definition: densevector.hh:399
Traits::value_type block_type
export the type representing the components
Definition: densevector.hh:271
constexpr derived_type operator-() const
Vector negation.
Definition: densevector.hh:469
Implements a generic iterator class for writing stl conformant iterators.
Provides the functions dot(a,b) := and dotT(a,b) := .
constexpr bool equals(const ConstIterator &other) const
Definition: densevector.hh:188
constexpr T abs(T t)
Definition: cmath.hh:27
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:265
constexpr derived_type & operator-=(const DenseVector< Other > &x)
vector space subtraction
Definition: densevector.hh:444
container_type::size_type size_type
Definition: dynvector.hh:41
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:357
constexpr DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:155
constexpr value_type & operator[](size_type i)
random access
Definition: densevector.hh:310
constexpr ConstIterator beforeEnd() const
Definition: densevector.hh:412
constexpr Iterator begin()
begin iterator
Definition: densevector.hh:362
constexpr R elementAt(DifferenceType i) const
Definition: densevector.hh:207