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;
147 : container_(0), position_()
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_;
239 V & asImp() {
return static_cast<V&
>(*this); }
240 const V & asImp()
const {
return static_cast<const V&
>(*this); }
275 inline derived_type& operator= (
const value_type& k)
277 for (size_type i=0; i<size(); i++)
285 value_type & operator[] (size_type i)
287 return asImp().vec_access(i);
290 const value_type & operator[] (size_type i)
const 292 return asImp().vec_access(i);
298 return asImp().vec_size();
309 return Iterator(*
this,0);
315 return Iterator(*
this,size());
322 return Iterator(*
this,size()-1);
329 return Iterator(*
this,-1);
335 return Iterator(*
this,std::min(i,size()));
346 return ConstIterator(*
this,0);
350 ConstIterator
end ()
const 352 return ConstIterator(*
this,size());
359 return ConstIterator(*
this,size()-1);
366 return ConstIterator(*
this,-1);
370 ConstIterator
find (size_type i)
const 372 return ConstIterator(*
this,std::min(i,size()));
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,
427 operator+= (
const ValueType& kk)
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,
449 operator-= (
const ValueType& kk)
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,
471 operator*= (
const ValueType& kk)
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,
493 operator/= (
const ValueType& kk)
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 C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:143
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::value_type block_type
export the type representing the components
Definition: densevector.hh:262
ConstIterator end() const
end ConstIterator
Definition: densevector.hh:350
bigunsignedint< k > operator-(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:520
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:27
void increment()
Definition: densevector.hh:178
size_type dim() const
dimension of the vector space
Definition: densevector.hh:649
DifferenceType distanceTo(DenseIterator< typename remove_const< C >::type, typename remove_const< T >::type > other) const
Definition: densevector.hh:202
derived_type & axpy(const value_type &a, const DenseVector< Other > &y)
vector space axpy operation ( *this += a y )
Definition: densevector.hh:523
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:527
DenseIterator(const ConstIterator &other)
Definition: densevector.hh:158
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:302
Provides the functions dot(a,b) := and dotT(a,b) := .
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:265
ConstIterator beforeEnd() const
Definition: densevector.hh:357
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:252
DenseVector()
Definition: densevector.hh:247
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
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:253
Implements a generic iterator class for writing stl conformant iterators.
DifferenceType distanceTo(DenseIterator< const typename remove_const< C >::type, const typename remove_const< T >::type > other) const
Definition: densevector.hh:196
FieldTraits< typename DenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:23
void advance(DifferenceType n)
Definition: densevector.hh:192
bool equals(const ConstIterator &other) const
Definition: densevector.hh:169
void decrement()
Definition: densevector.hh:183
Iterator end()
end iterator
Definition: densevector.hh:313
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:580
R dereference() const
Definition: densevector.hh:174
ConstIterator beforeBegin() const
Definition: densevector.hh:364
Type traits to determine the type of reals (when working with complex numbers)
Definition: ftraits.hh:22
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:424
Iterator beforeEnd()
Definition: densevector.hh:320
Iterator beforeBegin()
Definition: densevector.hh:327
char c
Definition: alignment.hh:33
bigunsignedint< k > operator+(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:513
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:125
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:643
Traits::value_type field_type
export the type representing the field
Definition: densevector.hh:259
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
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:230
DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:150
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:256
Definition: matvectraits.hh:29
FieldTraits< value_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:625
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:341
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:333
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:589
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
FieldTraits< typename DenseMatVecTraits< V >::value_type >::real_type real_type
Definition: densevector.hh:24
bool equals(const MutableIterator &other) const
Definition: densevector.hh:163
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:18
Provides some promotion traits.
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:138
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:304
size_type size() const
size method
Definition: densevector.hh:296
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
DenseIterator(const MutableIterator &other)
Definition: densevector.hh:154
Dune namespace.
Definition: alignment.hh:9
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:339
ConstIterator find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:370
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
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:570