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;
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_);
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_;
240 V & asImp() {
return static_cast<V&
>(*this); }
241 const V & asImp()
const {
return static_cast<const V&
>(*this); }
276 inline derived_type& operator= (
const value_type& k)
278 for (size_type i=0; i<
size(); i++)
286 value_type & operator[] (size_type i)
291 const value_type & operator[] (size_type i)
const 299 return asImp().size();
310 return Iterator(*
this,0);
316 return Iterator(*
this,
size());
323 return Iterator(*
this,
size()-1);
330 return Iterator(*
this,-1);
336 return Iterator(*
this,std::min(i,
size()));
347 return ConstIterator(*
this,0);
351 ConstIterator
end ()
const 353 return ConstIterator(*
this,
size());
360 return ConstIterator(*
this,
size()-1);
367 return ConstIterator(*
this,-1);
371 ConstIterator
find (size_type i)
const 373 return ConstIterator(*
this,std::min(i,
size()));
379 template <
class Other>
383 for (size_type i=0; i<
size(); i++)
389 template <
class Other>
393 for (size_type i=0; i<
size(); i++)
399 template <
class Other>
402 derived_type z = asImp();
407 template <
class Other>
410 derived_type z = asImp();
423 template <
typename ValueType>
424 typename std::enable_if<
425 std::is_convertible<ValueType, value_type>::value,
428 operator+= (
const ValueType& kk)
430 const value_type& k = kk;
431 for (size_type i=0; i<
size(); i++)
445 template <
typename ValueType>
446 typename std::enable_if<
447 std::is_convertible<ValueType, value_type>::value,
450 operator-= (
const ValueType& kk)
452 const value_type& k = kk;
453 for (size_type i=0; i<
size(); i++)
467 template <
typename FieldType>
468 typename std::enable_if<
469 std::is_convertible<FieldType, field_type>::value,
472 operator*= (
const FieldType& kk)
474 const field_type& k = kk;
475 for (size_type i=0; i<
size(); i++)
489 template <
typename FieldType>
490 typename std::enable_if<
491 std::is_convertible<FieldType, field_type>::value,
494 operator/= (
const FieldType& kk)
496 const field_type& k = kk;
497 for (size_type i=0; i<
size(); i++)
503 template <
class Other>
507 for (size_type i=0; i<
size(); i++)
508 if ((*
this)[i]!=y[i])
515 template <
class Other>
523 template <
class Other>
527 for (size_type i=0; i<
size(); i++)
528 (*
this)[i] += a*y[i];
539 template<
class Other>
542 PromotedType result(0);
544 for (size_type i=0; i<
size(); i++) {
545 result += PromotedType((*
this)[i]*y[i]);
557 template<
class Other>
560 PromotedType result(0);
562 for (size_type i=0; i<
size(); i++) {
574 for (size_type i=0; i<
size(); i++)
575 result += abs((*
this)[i]);
584 for (size_type i=0; i<
size(); i++)
585 result += fvmeta::absreal((*
this)[i]);
593 for (size_type i=0; i<
size(); i++)
594 result += fvmeta::abs2((*
this)[i]);
595 return fvmeta::sqrt(result);
602 for (size_type i=0; i<
size(); i++)
603 result += fvmeta::abs2((*
this)[i]);
608 template <
typename vt = value_type,
609 typename std::enable_if<!has_nan<vt>::value,
int>::type = 0>
616 for (
auto const &x : *
this) {
624 template <
typename vt = value_type,
625 typename std::enable_if<!has_nan<vt>::value,
int>::type = 0>
631 for (
auto const &x : *
this) {
639 template <
typename vt = value_type,
640 typename std::enable_if<has_nan<vt>::value,
int>::type = 0>
648 for (
auto const &x : *
this) {
658 template <
typename vt = value_type,
659 typename std::enable_if<has_nan<vt>::value,
int>::type = 0>
666 for (
auto const &x : *
this) {
700 std::ostream& operator<< (std::ostream& s, const DenseVector<V>& v)
703 s << ((i>0) ?
" " :
"") << v[i];
711 #endif // DUNE_DENSEVECTOR_HH Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:266
DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:151
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:342
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:233
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:126
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:590
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:303
FieldTraits< value_type >::field_type field_type
export the type representing the field
Definition: densevector.hh:260
constexpr DenseVector()
Definition: densevector.hh:248
void increment()
Definition: densevector.hh:179
SizeType index() const
return index
Definition: densevector.hh:210
size_type size() const
size method
Definition: densevector.hh:297
Compute type of the result of an arithmetic operation involving two different number types...
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:626
Iterator beforeBegin()
Definition: densevector.hh:328
bigunsignedint< k > operator-(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:520
FieldTraits< typename DenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:24
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:581
Iterator begin()
begin iterator
Definition: densevector.hh:308
ConstIterator beforeBegin() const
Definition: densevector.hh:365
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
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:678
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
bool equals(const ConstIterator &other) const
Definition: densevector.hh:170
void decrement()
Definition: densevector.hh:184
Provides the functions dot(a,b) := and dotT(a,b) := .
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
ConstIterator beforeEnd() const
Definition: densevector.hh:358
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:139
bool equals(const MutableIterator &other) const
Definition: densevector.hh:164
Compute type of the result of an arithmetic operation involving two different number types...
Definition: promotiontraits.hh:24
DenseIterator(const ConstIterator &other)
Definition: densevector.hh:159
ConstIterator begin() const
begin ConstIterator
Definition: densevector.hh:345
Dune namespace.
Definition: alignment.hh:10
container_type::size_type size_type
Definition: dynvector.hh:39
Iterator beforeEnd()
Definition: densevector.hh:321
R dereference() const
Definition: densevector.hh:175
Macro for wrapping boundary checks.
ConstIterator end() const
end ConstIterator
Definition: densevector.hh:351
DenseIterator(const MutableIterator &other)
Definition: densevector.hh:155
void advance(DifferenceType n)
Definition: densevector.hh:193
derived_type & axpy(const field_type &a, const DenseVector< Other > &y)
vector space axpy operation ( *this += a y )
Definition: densevector.hh:524
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:427
K value_type
Definition: dynvector.hh:38
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
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 find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:371
Definition: matvectraits.hh:29
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
Definition: typetraits.hh:95
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:255
DifferenceType distanceTo(DenseIterator< const typename std::remove_const< C >::type, const typename std::remove_const< T >::type > other) const
Definition: densevector.hh:197
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:571
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:305
DifferenceType distanceTo(DenseIterator< typename std::remove_const< C >::type, typename std::remove_const< T >::type > other) const
Definition: densevector.hh:203
Traits::value_type block_type
export the type representing the components
Definition: densevector.hh:263
bigunsignedint< k > operator+(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:513
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:257
Iterator end()
end iterator
Definition: densevector.hh:314
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:334
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:19
size_type dim() const
dimension of the vector space
Definition: densevector.hh:684
Definition: ftraits.hh:23
R elementAt(DifferenceType i) const
Definition: densevector.hh:189
constexpr auto size(const Dune::FieldVector< T, i > *, const PriorityTag< 5 > &) -> decltype(std::integral_constant< std::size_t, i >())
Definition: hybridutilities.hh:22
Construct a vector with a dynamic size.
Definition: dynvector.hh:32
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:527
Implements a generic iterator class for writing stl conformant iterators.
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:254
Type traits to determine the type of reals (when working with complex numbers)
T field_type
export the type representing the field
Definition: ftraits.hh:26
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:610
C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:144
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:340