3 #ifndef DUNE_DENSEVECTOR_HH
4 #define DUNE_DENSEVECTOR_HH
54 return std::abs(c.real()) + std::abs(c.imag());
74 return c.real()*c.real() + c.imag()*c.imag();
81 template<class K, bool isInteger = std::numeric_limits<K>::is_integer>
110 return Sqrt<K>::sqrt(k);
119 template<
class C,
class T>
124 friend class
DenseIterator<const typename remove_const<C>::type, const typename remove_const<T>::type >;
144 : container_(&cont), position_(pos)
148 : container_(other.container_), position_(other.position_)
154 return position_ == other.position_ && container_ == other.container_;
160 return position_ == other.position_ && container_ == other.container_;
164 return container_->operator[](position_);
178 return container_->operator[](position_+i);
182 position_=position_+n;
187 assert(other.container_==container_);
188 return other.position_ - position_;
193 assert(other.container_==container_);
194 return other.position_ - position_;
200 return this->position_;
224 typedef DenseMatVecTraits<V> Traits;
228 V & asImp() {
return static_cast<V&
>(*this); }
229 const V & asImp()
const {
return static_cast<const V&
>(*this); }
266 for (size_type i=0; i<
size(); i++)
276 return asImp().vec_access(i);
281 return asImp().vec_access(i);
287 return asImp().vec_size();
339 ConstIterator
end ()
const
359 ConstIterator
find (size_type i)
const
367 template <
class Other>
370 assert(y.size() ==
size());
371 for (size_type i=0; i<
size(); i++)
377 template <
class Other>
380 assert(y.size() ==
size());
381 for (size_type i=0; i<
size(); i++)
387 template <
class Other>
390 derived_type z = asImp();
395 template <
class Other>
398 derived_type z = asImp();
405 for (size_type i=0; i<
size(); i++)
413 for (size_type i=0; i<
size(); i++)
421 for (size_type i=0; i<
size(); i++)
429 for (size_type i=0; i<
size(); i++)
435 template <
class Other>
438 assert(y.size() ==
size());
439 for (size_type i=0; i<
size(); i++)
440 if ((*
this)[i]!=y[i])
447 template <
class Other>
455 template <
class Other>
458 assert(y.size() ==
size());
459 for (size_type i=0; i<
size(); i++)
460 (*
this)[i] += a*y[i];
471 template<
class Other>
473 typedef typename PromotionTraits<field_type, typename DenseVector<Other>::field_type>::PromotedType PromotedType;
474 PromotedType result(0);
475 assert(y.size() ==
size());
476 for (size_type i=0; i<
size(); i++) {
477 result += PromotedType((*
this)[i]*y[i]);
489 template<
class Other>
490 typename PromotionTraits<field_type,typename DenseVector<Other>::field_type>::PromotedType
dot(
const DenseVector<Other>& y)
const {
491 typedef typename PromotionTraits<field_type, typename DenseVector<Other>::field_type>::PromotedType PromotedType;
492 PromotedType result(0);
493 assert(y.size() ==
size());
494 for (size_type i=0; i<
size(); i++) {
505 for (size_type i=0; i<
size(); i++)
506 result += std::abs((*
this)[i]);
515 for (size_type i=0; i<
size(); i++)
516 result += fvmeta::absreal((*
this)[i]);
524 for (size_type i=0; i<
size(); i++)
525 result += fvmeta::abs2((*
this)[i]);
526 return fvmeta::sqrt(result);
533 for (size_type i=0; i<
size(); i++)
534 result += fvmeta::abs2((*
this)[i]);
544 ConstIterator it =
begin();
546 for (it = it + 1; it !=
end(); ++it)
547 max = std::max(max, std::abs(*it));
558 ConstIterator it =
begin();
560 for (it = it + 1; it !=
end(); ++it)
561 max = std::max(max, fvmeta::absreal(*it));
591 std::ostream& operator<< (std::ostream& s, const DenseVector<V>& v)
594 s << ((i>0) ?
" " :
"") << v[i];
602 #endif // DUNE_DENSEVECTOR_HH
DenseIterator(C &cont, SizeType pos)
Definition: densevector.hh:143
derived_type & operator-=(const DenseVector< Other > &y)
vector space subtraction
Definition: densevector.hh:378
bool equals(const DenseIterator< const typename remove_const< C >::type, const typename remove_const< T >::type > &other) const
Definition: densevector.hh:158
Generic iterator class for dense vector and matrix implementations.
Definition: densevector.hh:120
FieldTraits< typename DenseMatVecTraits< V >::value_type >::real_type real_type
Definition: densevector.hh:23
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:254
size_type dim() const
dimension of the vector space
Definition: densevector.hh:575
Dune namespace.
Definition: alignment.hh:13
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:530
FieldTraits< typename DenseMatVecTraits< V >::value_type >::field_type field_type
Definition: densevector.hh:22
DenseVector()
Definition: densevector.hh:236
derived_type & operator*=(const value_type &k)
vector space multiplication with scalar
Definition: densevector.hh:419
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:17
Iterator begin()
begin iterator
Definition: densevector.hh:296
char c
Definition: alignment.hh:37
Provides the functions dot(a,b) := and dotT(a,b) := .
std::ptrdiff_t DifferenceType
The type of the difference between two positions.
Definition: densevector.hh:131
bool operator==(const DenseVector< Other > &y) const
Binary vector comparison.
Definition: densevector.hh:436
Iterator end()
end iterator
Definition: densevector.hh:302
Type traits to determine the type of reals (when working with complex numbers)
FieldTraits< value_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:539
DifferenceType distanceTo(DenseIterator< const typename remove_const< C >::type, const typename remove_const< T >::type > other) const
Definition: densevector.hh:185
std::size_t position_
The current position in the buffer.
Definition: variablesizecommunicator.hh:136
ConstIterator begin() const
begin ConstIterator
Definition: densevector.hh:333
Traits::value_type block_type
export the type representing the components
Definition: densevector.hh:251
bool equals(const DenseIterator< typename remove_const< C >::type, typename remove_const< T >::type > &other) const
Definition: densevector.hh:152
ConstIterator end() const
end ConstIterator
Definition: densevector.hh:339
DenseIterator< DenseVector, value_type > Iterator
Iterator class for sequential access.
Definition: densevector.hh:291
Iterator beforeEnd()
Definition: densevector.hh:309
ConstIterator beforeEnd() const
Definition: densevector.hh:346
void advance(DifferenceType n)
Definition: densevector.hh:181
derived_type operator+(const DenseVector< Other > &b) const
Binary vector addition.
Definition: densevector.hh:388
C::size_type SizeType
The type to index the underlying container.
Definition: densevector.hh:136
derived_type & operator+=(const DenseVector< Other > &y)
vector space addition
Definition: densevector.hh:368
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:490
derived_type & axpy(const value_type &a, const DenseVector< Other > &y)
vector space axpy operation ( *this += a y )
Definition: densevector.hh:456
void decrement()
Definition: densevector.hh:172
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: densevector.hh:569
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
Provides some promotion traits.
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:245
bool operator!=(const DenseVector< Other > &y) const
Binary vector incomparison.
Definition: densevector.hh:448
ConstIterator beforeBegin() const
Definition: densevector.hh:353
derived_type operator-(const DenseVector< Other > &b) const
Binary vector subtraction.
Definition: densevector.hh:396
Removes a const qualifier while preserving others.
Definition: typetraits.hh:175
Traits::derived_type derived_type
type of derived vector class
Definition: densevector.hh:242
size_type size() const
size method
Definition: densevector.hh:285
Implements a generic iterator class for writing stl conformant iterators.
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
ConstIterator find(size_type i) const
return iterator to given element or end()
Definition: densevector.hh:359
FieldTraits< value_type >::real_type one_norm_real() const
simplified one norm (uses Manhattan norm for complex values)
Definition: densevector.hh:512
RemoveConstHelper< T, IsVolatile< T >::value >::Type type
Definition: typetraits.hh:177
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:521
FieldTraits< value_type >::real_type one_norm() const
one norm (sum over absolute values of entries)
Definition: densevector.hh:503
Documentation of the traits classes you need to write for each implementation of DenseVector or Dense...
derived_type & operator/=(const value_type &k)
vector space division by scalar
Definition: densevector.hh:427
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:425
Definition: ftraits.hh:23
ConstIterator const_iterator
typedef for stl compliant access
Definition: densevector.hh:330
Iterator find(size_type i)
return iterator to given element or end()
Definition: densevector.hh:322
Iterator beforeBegin()
Definition: densevector.hh:316
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:472
DifferenceType distanceTo(DenseIterator< typename remove_const< C >::type, typename remove_const< T >::type > other) const
Definition: densevector.hh:191
T & elementAt(DifferenceType i) const
Definition: densevector.hh:177
value_type & operator[](size_type i)
random access
Definition: densevector.hh:274
Iterator iterator
typedef for stl compliant access
Definition: densevector.hh:293
T & dereference() const
Definition: densevector.hh:163
derived_type & operator=(const value_type &k)
Assignment operator for scalar.
Definition: densevector.hh:264
The number of block levels we contain.
Definition: densevector.hh:259
DenseIterator(const DenseIterator< typename remove_const< C >::type, typename remove_const< T >::type > &other)
Definition: densevector.hh:147
SizeType index() const
return index
Definition: densevector.hh:198
Traits::value_type field_type
export the type representing the field
Definition: densevector.hh:248
void increment()
Definition: densevector.hh:167
DenseIterator< const DenseVector, const value_type > ConstIterator
ConstIterator class for sequential access.
Definition: densevector.hh:328
FieldTraits< value_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:553