3 #ifndef DUNE_DENSEVECTOR_HH
4 #define DUNE_DENSEVECTOR_HH
20 template<
typename V>
class DenseVector;
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_;
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>
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>
458 using idx_type =
typename decltype(result)::
size_type;
460 for (idx_type i = 0; i <
size(); ++i)
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);
597 result += PromotedType((*
this)[i]*x[i]);
609 template<
class Other>
612 PromotedType result(0);
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];
Macro for wrapping boundary checks.
Provides the functions dot(a,b) := and dotT(a,b) := .
Type traits to determine the type of reals (when working with complex numbers)
Implements a generic iterator class for writing stl conformant iterators.
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.
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
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:273
Dune namespace.
Definition: alignedallocator.hh:11
auto min(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:434
auto max(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:412
bool isNaN(const FieldVector< K, SIZE > &b, PriorityTag< 2 >, ADLTag)
Definition: fvector.hh:610
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:227
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:248
value_type & back()
return reference to last element
Definition: densevector.hh:319
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:382
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:345
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
ConstIterator find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:411
ConstIterator end() const
end ConstIterator
Definition: densevector.hh:391
ConstIterator beforeBegin() const
Definition: densevector.hh:405
bool operator==(const DenseVector< Other > &x) const
Binary vector comparison.
Definition: densevector.hh:556
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
Iterator beforeBegin()
Definition: densevector.hh:368
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:380
derived_type & axpy(const field_type &a, const DenseVector< Other > &x)
vector space axpy operation ( *this += a x )
Definition: densevector.hh:576
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:245
derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition: densevector.hh:440
size_type size() const
size method
Definition: densevector.hh:337
const value_type & front() const
return reference to first element
Definition: densevector.hh:313
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
size_type dim() const
dimension of the vector space
Definition: densevector.hh:734
ConstIterator beforeEnd() const
Definition: densevector.hh:398
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:623
Iterator end()
end iterator
Definition: densevector.hh:354
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
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:257
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:343
const value_type & back() const
return reference to last element
Definition: densevector.hh:325
DenseVector(const DenseVector &)=default
Iterator beforeEnd()
Definition: densevector.hh:361
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:642
derived_type & operator+=(const DenseVector< Other > &x)
vector space addition
Definition: densevector.hh:420
bool operator!=(const DenseVector< Other > &x) const
Binary vector incomparison.
Definition: densevector.hh:568
value_type & operator[](size_type i)
random access
Definition: densevector.hh:296
ConstIterator begin() const
begin ConstIterator
Definition: densevector.hh:385
derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition: densevector.hh:267
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:678
constexpr DenseVector()=default
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:662
FieldTraits< value_type >::field_type field_type
export the type representing the field
Definition: densevector.hh:251
Traits::value_type block_type
export the type representing the components
Definition: densevector.hh:254
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
@ blocklevel
The number of block levels we contain.
Definition: densevector.hh:262
DenseVector & operator=(const DenseVector &)=default
Assignment operator for other DenseVector of same type.
derived_type operator-() const
Vector negation.
Definition: densevector.hh:455
derived_type & operator-=(const DenseVector< Other > &x)
vector space subtraction
Definition: densevector.hh:430
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:374
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:728
bool empty() const
checks whether the container is empty
Definition: densevector.hh:331
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:633
value_type & front()
return reference to first element
Definition: densevector.hh:307
FieldTraits< typename DenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:25
FieldTraits< typename DenseMatVecTraits< V >::value_type >::real_type real_type
Definition: densevector.hh:26
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:129
void increment()
Definition: densevector.hh:180
SizeType index() const
return index
Definition: densevector.hh:211
bool equals(const MutableIterator &other) const
Definition: densevector.hh:165
DenseIterator(const MutableIterator &other)
Definition: densevector.hh:156
bool equals(const ConstIterator &other) const
Definition: densevector.hh:171
R elementAt(DifferenceType i) const
Definition: densevector.hh:190
DifferenceType distanceTo(DenseIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type > other) const
Definition: densevector.hh:198
void decrement()
Definition: densevector.hh:185
DenseIterator(const ConstIterator &other)
Definition: densevector.hh:160
DifferenceType distanceTo(DenseIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type > other) const
Definition: densevector.hh:204
DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:152
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:140
R dereference() const
Definition: densevector.hh:176
void advance(DifferenceType n)
Definition: densevector.hh:194
C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:145
Definition: ftraits.hh:24
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:432
Definition: matvectraits.hh:29
Compute type of the result of an arithmetic operation involving two different number types.
Definition: promotiontraits.hh:25