5#ifndef DUNE_DENSEVECTOR_HH
6#define DUNE_DENSEVECTOR_HH
22 template<
typename V>
class DenseVector;
61 return abs(c.real()) + abs(c.imag());
81 return c.real()*c.real() + c.imag()*c.imag();
88 template<class K, bool isInteger = std::numeric_limits<K>::is_integer>
119 return Sqrt<K>::sqrt(k);
128 template<
class C,
class T,
class R =T&>
133 friend class
DenseIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type >;
135 typedef
DenseIterator<typename std::remove_const<C>::type, typename std::remove_const<T>::type, typename mutable_reference<R>::type >
MutableIterator;
136 typedef
DenseIterator<const typename std::remove_const<C>::type, const typename std::remove_const<T>::type, typename const_reference<R>::type >
ConstIterator;
151 : container_(0), position_()
155 : container_(&cont), position_(pos)
159 : container_(other.container_), position_(other.position_)
163 : container_(other.container_), position_(other.position_)
169 return position_ == other.position_ && container_ == other.container_;
175 return position_ == other.position_ && container_ == other.container_;
179 return container_->operator[](position_);
193 return container_->operator[](position_+i);
197 position_=position_+n;
202 assert(other.container_==container_);
208 assert(other.container_==container_);
215 return this->position_;
234 V & asImp() {
return static_cast<V&
>(*this); }
235 const V & asImp()
const {
return static_cast<const V&
>(*this); }
281 template <
typename W,
283 std::is_assignable<value_type&, typename DenseVector<W>::value_type>::value,
int> = 0>
288 asImp()[i] = other[i];
320 return asImp()[
size()-1];
326 return asImp()[
size()-1];
338 return asImp().size();
418 template <
class Other>
428 template <
class Other>
438 template <
class Other>
446 template <
class Other>
457 using idx_type =
typename decltype(result)
::size_type;
459 for (idx_type i = 0; i <
size(); ++i)
460 result[i] = -asImp()[i];
474 template <
typename ValueType>
475 typename std::enable_if<
476 std::is_convertible<ValueType, value_type>::value,
496 template <
typename ValueType>
497 typename std::enable_if<
498 std::is_convertible<ValueType, value_type>::value,
518 template <
typename FieldType>
519 typename std::enable_if<
520 std::is_convertible<FieldType, field_type>::value,
540 template <
typename FieldType>
541 typename std::enable_if<
542 std::is_convertible<FieldType, field_type>::value,
554 template <
class Other>
559 if ((*
this)[i]!=x[i])
566 template <
class Other>
574 template <
class Other>
579 (*
this)[i] += a*x[i];
590 template<
class Other>
593 PromotedType result(0);
596 result += PromotedType((*
this)[i]*x[i]);
608 template<
class Other>
611 PromotedType result(0);
626 result += abs((*
this)[i]);
636 result += fvmeta::absreal((*
this)[i]);
645 result += fvmeta::abs2((*
this)[i]);
646 return fvmeta::sqrt(result);
654 result += fvmeta::abs2((*
this)[i]);
660 typename std::enable_if<!HasNaN<vt>::value,
int>::type = 0>
667 for (
auto const &x : *
this) {
668 real_type
const a = abs(x);
676 typename std::enable_if<!HasNaN<vt>::value,
int>::type = 0>
682 for (
auto const &x : *
this) {
683 real_type
const a = fvmeta::absreal(x);
691 typename std::enable_if<HasNaN<vt>::value,
int>::type = 0>
699 for (
auto const &x : *
this) {
700 real_type
const a = abs(x);
709 typename std::enable_if<HasNaN<vt>::value,
int>::type = 0>
716 for (
auto const &x : *
this) {
717 real_type
const a = fvmeta::absreal(x);
752 s << ((i>0) ?
" " :
"") << v[i];
Implements a generic iterator class for writing stl conformant iterators.
Type traits to determine the type of reals (when working with complex numbers)
Macro for wrapping boundary checks.
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...
Compute type of the result of an arithmetic operation involving two different number types.
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:30
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:42
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:278
Dune namespace.
Definition: alignedallocator.hh:13
auto min(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:447
auto max(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:425
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:604
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:229
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:250
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:650
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:381
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:344
ConstIterator find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:410
ConstIterator end() const
end ConstIterator
Definition: densevector.hh:390
value_type & front()
return reference to first element
Definition: densevector.hh:306
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:641
ConstIterator beforeBegin() const
Definition: densevector.hh:404
bool operator==(const DenseVector< Other > &x) const
Binary vector comparison.
Definition: densevector.hh:555
Iterator begin()
begin iterator
Definition: densevector.hh:347
Iterator beforeBegin()
Definition: densevector.hh:367
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:379
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:247
const value_type & front() const
return reference to first element
Definition: densevector.hh:312
derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition: densevector.hh:439
size_type size() const
size method
Definition: densevector.hh:336
size_type dim() const
dimension of the vector space
Definition: densevector.hh:733
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:661
ConstIterator beforeEnd() const
Definition: densevector.hh:397
derived_type & axpy(const field_type &a, const DenseVector< Other > &x)
vector space axpy operation ( *this += a x )
Definition: densevector.hh:575
derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition: densevector.hh:266
static constexpr int blocklevel
The number of block levels we contain. This is the leaf, that is, 1.
Definition: densevector.hh:262
Iterator end()
end iterator
Definition: densevector.hh:353
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:259
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:342
derived_type & operator-=(const DenseVector< Other > &x)
vector space subtraction
Definition: densevector.hh:429
DenseVector(const DenseVector &)=default
Iterator beforeEnd()
Definition: densevector.hh:360
derived_type & operator+=(const DenseVector< Other > &x)
vector space addition
Definition: densevector.hh:419
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:523
bool operator!=(const DenseVector< Other > &x) const
Binary vector incomparison.
Definition: densevector.hh:567
const value_type & back() const
return reference to last element
Definition: densevector.hh:324
ConstIterator begin() const
begin ConstIterator
Definition: densevector.hh:384
PromotionTraits< field_type, typenameDenseVector< Other >::field_type >::PromotedType operator*(const DenseVector< Other > &x) const
indefinite vector dot product which corresponds to Petsc's VecTDot
Definition: densevector.hh:591
constexpr DenseVector()=default
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:677
DenseVector & operator=(const DenseVector &)=default
Assignment operator for other DenseVector of same type.
Traits::value_type block_type
export the type representing the components
Definition: densevector.hh:256
value_type & operator[](size_type i)
random access
Definition: densevector.hh:295
FieldTraits< value_type >::field_type field_type
export the type representing the field
Definition: densevector.hh:253
value_type & back()
return reference to last element
Definition: densevector.hh:318
derived_type operator-() const
Vector negation.
Definition: densevector.hh:454
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:545
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:632
PromotionTraits< field_type, typenameDenseVector< Other >::field_type >::PromotedType dot(const DenseVector< Other > &x) const
vector dot product which corresponds to Petsc's VecDot
Definition: densevector.hh:609
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:373
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:622
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:727
bool empty() const
checks whether the container is empty
Definition: densevector.hh:330
FieldTraits< typenameDenseMatVecTraits< V >::value_type >::real_type real_type
Definition: densevector.hh:28
FieldTraits< typenameDenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:27
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:131
void increment()
Definition: densevector.hh:182
SizeType index() const
return index
Definition: densevector.hh:213
bool equals(const MutableIterator &other) const
Definition: densevector.hh:167
DenseIterator(const MutableIterator &other)
Definition: densevector.hh:158
bool equals(const ConstIterator &other) const
Definition: densevector.hh:173
R elementAt(DifferenceType i) const
Definition: densevector.hh:192
DifferenceType distanceTo(DenseIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type > other) const
Definition: densevector.hh:200
void decrement()
Definition: densevector.hh:187
DenseIterator(const ConstIterator &other)
Definition: densevector.hh:162
DifferenceType distanceTo(DenseIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type > other) const
Definition: densevector.hh:206
DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:154
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:142
R dereference() const
Definition: densevector.hh:178
void advance(DifferenceType n)
Definition: densevector.hh:196
C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:147
Definition: ftraits.hh:26
T field_type
export the type representing the field
Definition: ftraits.hh:28
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:30
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:116
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:434
Definition: matvectraits.hh:31
Compute type of the result of an arithmetic operation involving two different number types.
Definition: promotiontraits.hh:27