3 #ifndef DUNE_DENSEVECTOR_HH
4 #define DUNE_DENSEVECTOR_HH
57 return abs(c.real()) + abs(c.imag());
77 return c.real()*c.real() + c.imag()*c.imag();
84 template<class K, bool isInteger = std::numeric_limits<K>::is_integer>
115 return Sqrt<K>::sqrt(k);
124 template<
class C,
class T,
class R =T&>
129 friend class
DenseIterator<const typename remove_const<C>::type, const typename remove_const<T>::type, typename const_reference<R>::type >;
131 typedef
DenseIterator<typename remove_const<C>::type, typename remove_const<T>::type, typename mutable_reference<R>::type >
MutableIterator;
132 typedef
DenseIterator<const typename remove_const<C>::type, const typename remove_const<T>::type, typename const_reference<R>::type >
ConstIterator;
151 : container_(&cont), position_(pos)
155 : container_(other.container_), position_(other.position_)
159 : container_(other.container_), position_(other.position_)
165 return position_ == other.position_ && container_ == other.container_;
171 return position_ == other.position_ && container_ == other.container_;
175 return container_->operator[](position_);
189 return container_->operator[](position_+i);
193 position_=position_+n;
198 assert(other.container_==container_);
199 return other.position_ - position_;
204 assert(other.container_==container_);
205 return other.position_ - position_;
211 return this->position_;
235 typedef DenseMatVecTraits<V> Traits;
239 V & asImp() {
return static_cast<V&
>(*this); }
240 const V & asImp()
const {
return static_cast<const V&
>(*this); }
277 for (size_type i=0; i<
size(); i++)
287 return asImp().vec_access(i);
292 return asImp().vec_access(i);
298 return asImp().vec_size();
350 ConstIterator
end ()
const
370 ConstIterator
find (size_type i)
const
378 template <
class Other>
381 assert(y.size() ==
size());
382 for (size_type i=0; i<
size(); i++)
388 template <
class Other>
391 assert(y.size() ==
size());
392 for (size_type i=0; i<
size(); i++)
398 template <
class Other>
401 derived_type z = asImp();
406 template <
class Other>
409 derived_type z = asImp();
422 template <
typename ValueType>
423 typename std::enable_if<
424 std::is_convertible<ValueType, value_type>::value,
429 const value_type& k = kk;
430 for (size_type i=0; i<
size(); i++)
444 template <
typename ValueType>
445 typename std::enable_if<
446 std::is_convertible<ValueType, value_type>::value,
451 const value_type& k = kk;
452 for (size_type i=0; i<
size(); i++)
466 template <
typename ValueType>
467 typename std::enable_if<
468 std::is_convertible<ValueType, value_type>::value,
473 const value_type& k = kk;
474 for (size_type i=0; i<
size(); i++)
488 template <
typename ValueType>
489 typename std::enable_if<
490 std::is_convertible<ValueType, value_type>::value,
495 const value_type& k = kk;
496 for (size_type i=0; i<
size(); i++)
502 template <
class Other>
505 assert(y.size() ==
size());
506 for (size_type i=0; i<
size(); i++)
507 if ((*
this)[i]!=y[i])
514 template <
class Other>
522 template <
class Other>
525 assert(y.size() ==
size());
526 for (size_type i=0; i<
size(); i++)
527 (*
this)[i] += a*y[i];
538 template<
class Other>
540 typedef typename PromotionTraits<field_type, typename DenseVector<Other>::field_type>::PromotedType PromotedType;
541 PromotedType result(0);
542 assert(y.size() ==
size());
543 for (size_type i=0; i<
size(); i++) {
544 result += PromotedType((*
this)[i]*y[i]);
556 template<
class Other>
557 typename PromotionTraits<field_type,typename DenseVector<Other>::field_type>::PromotedType
dot(
const DenseVector<Other>& y)
const {
558 typedef typename PromotionTraits<field_type, typename DenseVector<Other>::field_type>::PromotedType PromotedType;
559 PromotedType result(0);
560 assert(y.size() ==
size());
561 for (size_type i=0; i<
size(); i++) {
573 for (size_type i=0; i<
size(); i++)
574 result += abs((*
this)[i]);
583 for (size_type i=0; i<
size(); i++)
584 result += fvmeta::absreal((*
this)[i]);
592 for (size_type i=0; i<
size(); i++)
593 result += fvmeta::abs2((*
this)[i]);
594 return fvmeta::sqrt(result);
601 for (size_type i=0; i<
size(); i++)
602 result += fvmeta::abs2((*
this)[i]);
616 ConstIterator it =
begin();
617 real_type max_val = abs(*it);
618 for (it = it + 1; it !=
end(); ++it)
619 max_val = max(max_val, real_type(abs(*it)));
632 ConstIterator it =
begin();
634 for (it = it + 1; it !=
end(); ++it)
635 max_val = max(max_val, fvmeta::absreal(*it));
665 std::ostream& operator<< (std::ostream& s, const DenseVector<V>& v)
668 s << ((i>0) ?
" " :
"") << v[i];
676 #endif // DUNE_DENSEVECTOR_HH
DifferenceType distanceTo(DenseIterator< typename remove_const< C >::type, typename remove_const< T >::type > other) const
Definition: densevector.hh:202
enable_if<!IsVector< A >::value &&!is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type >::value, typename PromotionTraits< A, B >::PromotedType >::type dot(const A &a, const B &b)
computes the dot product for fundamental data types according to Petsc's VectDot function: dot(a...
Definition: dotproduct.hh:44
size_type size() const
size method
Definition: densevector.hh:296
Definition: ftraits.hh:22
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:424
ConstIterator beforeEnd() const
Definition: densevector.hh:357
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:570
C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:143
Traits::value_type field_type
export the type representing the field
Definition: densevector.hh:259
derived_type & operator+=(const DenseVector< Other > &y)
vector space addition
Definition: densevector.hh:379
char c
Definition: alignment.hh:33
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:253
FieldTraits< value_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:625
DifferenceType distanceTo(DenseIterator< const typename remove_const< C >::type, const typename remove_const< T >::type > other) const
Definition: densevector.hh:196
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:341
std::enable_if< std::is_convertible< ValueType, value_type >::value, derived_type >::type & operator/=(const ValueType &kk)
vector space division by scalar
Definition: densevector.hh:493
FieldTraits< typename DenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:23
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:643
void advance(DifferenceType n)
Definition: densevector.hh:192
bool equals(const ConstIterator &other) const
Definition: densevector.hh:169
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:125
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:27
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
void increment()
Definition: densevector.hh:178
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:304
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:589
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:598
derived_type operator-(const DenseVector< Other > &b) const
Binary vector subtraction.
Definition: densevector.hh:407
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:18
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:339
Provides some promotion traits.
Iterator beforeBegin()
Definition: densevector.hh:327
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
derived_type & operator-=(const DenseVector< Other > &y)
vector space subtraction
Definition: densevector.hh:389
DenseIterator(const ConstIterator &other)
Definition: densevector.hh:158
ConstIterator find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:370
Dune namespace.
Definition: alignment.hh:9
value_type & operator[](size_type i)
random access
Definition: densevector.hh:285
ConstIterator end() const
end ConstIterator
Definition: densevector.hh:350
Type traits to determine the type of reals (when working with complex numbers)
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:333
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:539
FieldTraits< typename DenseMatVecTraits< V >::value_type >::real_type real_type
Definition: densevector.hh:24
bool equals(const MutableIterator &other) const
Definition: densevector.hh:163
void decrement()
Definition: densevector.hh:183
bool operator==(const DenseVector< Other > &y) const
Binary vector comparison.
Definition: densevector.hh:503
Iterator end()
end iterator
Definition: densevector.hh:313
derived_type & axpy(const value_type &a, const DenseVector< Other > &y)
vector space axpy operation ( *this += a y )
Definition: densevector.hh:523
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:138
size_type dim() const
dimension of the vector space
Definition: densevector.hh:649
derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition: densevector.hh:275
R dereference() const
Definition: densevector.hh:174
The number of block levels we contain.
Definition: densevector.hh:270
DenseIterator(const MutableIterator &other)
Definition: densevector.hh:154
std::size_t position_
The current position in the buffer.
Definition: variablesizecommunicator.hh:136
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:302
Iterator beforeEnd()
Definition: densevector.hh:320
SizeType index() const
return index
Definition: densevector.hh:209
Iterator begin()
begin iterator
Definition: densevector.hh:307
R elementAt(DifferenceType i) const
Definition: densevector.hh:188
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:557
FieldTraits< value_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:607
ConstIterator begin() const
begin ConstIterator
Definition: densevector.hh:344
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:265
std::enable_if< std::is_convertible< ValueType, value_type >::value, derived_type >::type & operator*=(const ValueType &kk)
vector space multiplication with scalar
Definition: densevector.hh:471
Traits::value_type block_type
export the type representing the components
Definition: densevector.hh:262
Provides the functions dot(a,b) := and dotT(a,b) := .
DenseVector()
Definition: densevector.hh:247
DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:150
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:580
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:256
bool operator!=(const DenseVector< Other > &y) const
Binary vector incomparison.
Definition: densevector.hh:515
derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition: densevector.hh:399
Implements a generic iterator class for writing stl conformant iterators.
ConstIterator beforeBegin() const
Definition: densevector.hh:364