3 #ifndef DUNE_DIAGONAL_MATRIX_HH 4 #define DUNE_DIAGONAL_MATRIX_HH 15 #include <initializer_list> 50 template<
class K,
int n>
122 std::copy_n(l.begin(), std::min(static_cast<std::size_t>(
rows),
137 return (
this==&other);
153 return Iterator(WrapperType(
this),0);
159 return Iterator(WrapperType(
this),n);
166 return Iterator(WrapperType(
this),n-1);
173 return Iterator(WrapperType(
this),-1);
193 ConstIterator
end ()
const 276 template<
class X,
class Y>
277 void mv (
const X& x, Y& y)
const 279 #ifdef DUNE_FMatrix_WITH_CHECKING 283 for (size_type i=0; i<n; ++i)
284 y[i] = diag_[i] * x[i];
288 template<
class X,
class Y>
289 void mtv (
const X& x, Y& y)
const 295 template<
class X,
class Y>
296 void umv (
const X& x, Y& y)
const 298 #ifdef DUNE_FMatrix_WITH_CHECKING 302 for (size_type i=0; i<n; ++i)
303 y[i] += diag_[i] * x[i];
307 template<
class X,
class Y>
308 void umtv (
const X& x, Y& y)
const 310 #ifdef DUNE_FMatrix_WITH_CHECKING 314 for (size_type i=0; i<n; ++i)
315 y[i] += diag_[i] * x[i];
319 template<
class X,
class Y>
320 void umhv (
const X& x, Y& y)
const 322 #ifdef DUNE_FMatrix_WITH_CHECKING 326 for (size_type i=0; i<n; i++)
331 template<
class X,
class Y>
332 void mmv (
const X& x, Y& y)
const 334 #ifdef DUNE_FMatrix_WITH_CHECKING 338 for (size_type i=0; i<n; ++i)
339 y[i] -= diag_[i] * x[i];
343 template<
class X,
class Y>
344 void mmtv (
const X& x, Y& y)
const 346 #ifdef DUNE_FMatrix_WITH_CHECKING 350 for (size_type i=0; i<n; ++i)
351 y[i] -= diag_[i] * x[i];
355 template<
class X,
class Y>
356 void mmhv (
const X& x, Y& y)
const 358 #ifdef DUNE_FMatrix_WITH_CHECKING 362 for (size_type i=0; i<n; i++)
367 template<
class X,
class Y>
369 const X& x, Y& y)
const 371 #ifdef DUNE_FMatrix_WITH_CHECKING 375 for (size_type i=0; i<n; i++)
376 y[i] += alpha * diag_[i] * x[i];
380 template<
class X,
class Y>
382 const X& x, Y& y)
const 384 #ifdef DUNE_FMatrix_WITH_CHECKING 388 for (size_type i=0; i<n; i++)
389 y[i] += alpha * diag_[i] * x[i];
393 template<
class X,
class Y>
395 const X& x, Y& y)
const 397 #ifdef DUNE_FMatrix_WITH_CHECKING 401 for (size_type i=0; i<n; i++)
439 for (
int i=0; i<n; i++)
440 x[i] = b[i]/diag_[i];
446 for (
int i=0; i<n; i++)
447 diag_[i] = 1/diag_[i];
454 for (
int i=1; i<n; i++)
480 bool exists (size_type i, size_type j)
const 490 friend std::ostream& operator<< (std::ostream& s, const DiagonalMatrix<K,n>& a)
492 for (size_type i=0; i<n; i++) {
493 for (size_type j=0; j<n; j++)
494 s << ((i==j) ? a.diag_[i] : 0) <<
" ";
503 return reference(const_cast<K*>(&diag_[i]), i);
542 #ifndef DOXYGEN // hide specialization 551 typedef typename Base::size_type
size_type;
560 typedef typename Base::row_type
row_type;
583 (*this)[0][0] = scalar;
589 return (*
this)[0][0];
595 return (*
this)[0][0];
614 template<
class DiagonalMatrixType>
617 typedef typename DiagonalMatrixType::reference
reference;
619 typedef typename DiagonalMatrixType::field_type K;
634 mat_(const_cast<DiagonalMatrixType*>(mat))
644 row_ =
row_type(&(mat_->diagonal(i)), i);
650 return mat_==other.mat_;
655 mutable DiagonalMatrixType* mat_;
656 mutable row_type row_;
662 template<
class K,
int n >
665 template<
class DiagonalMatrixType>
671 enum { dimension = n };
724 return ((p_ == other.
p_)and (row_ == other.
row_));
739 ConstIterator
end ()
const 761 return ((p_==y.
p_)and (row_==y.
row_));
799 return const_cast<K*
>(p_);
812 template<
class K,
int n >
815 template<
class DiagonalMatrixType>
922 template<
class K,
int n>
928 template<
class K,
int n>
934 template<
class K,
int n>
940 template<
class K,
int n>
970 template<
class CW,
class T,
class R>
973 typedef typename std::remove_const<CW>::type NonConstCW;
990 containerWrapper_(containerWrapper),
994 template<
class OtherContainerWrapperIteratorType>
996 containerWrapper_(other.containerWrapper_),
997 position_(other.position_)
1001 containerWrapper_(other.containerWrapper_),
1002 position_(other.position_)
1006 containerWrapper_(other.containerWrapper_),
1007 position_(other.position_)
1010 template<
class OtherContainerWrapperIteratorType>
1013 containerWrapper_ = other.containerWrapper_;
1014 position_ = other.position_;
1022 return containerWrapper_.pointer(position_);
1028 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1033 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1038 return *containerWrapper_.pointer(position_);
1055 return *containerWrapper_.pointer(position_+i);
1060 position_=position_+n;
1063 template<
class OtherContainerWrapperIteratorType>
1064 std::ptrdiff_t
distanceTo(OtherContainerWrapperIteratorType& other)
const 1066 assert(containerWrapper_.identical(other));
1067 return other.position_ - position_;
1072 return containerWrapper_.realIndex(position_);
1076 NonConstCW containerWrapper_;
1080 template <
class DenseMatrix,
class field,
int N>
1086 denseMatrix = field(0);
1087 for (
int i = 0; i <
N; ++i)
1088 denseMatrix[i][i] = rhs.
diagonal()[i];
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:144
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:831
DiagonalRowVectorConst< K, n > const_row_type
Definition: diagonalmatrix.hh:78
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:753
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: diagonalmatrix.hh:420
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition: diagonalmatrix.hh:261
Implements a vector constructed from a given type representing a field and a compile-time given size...
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:590
R dereference() const
Definition: diagonalmatrix.hh:1036
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:746
size_type dim() const
dimension of the vector space
Definition: diagonalmatrix.hh:773
DiagonalRowVector()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:834
reference operator[](size_type i)
Return reference object as row replacement.
Definition: diagonalmatrix.hh:501
void usmhv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: diagonalmatrix.hh:394
The number of columns.
Definition: diagonalmatrix.hh:87
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:151
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:684
void mmv(const X &x, Y &y) const
y -= A x
Definition: diagonalmatrix.hh:332
static void apply(DenseMatrix &denseMatrix, DiagonalMatrix< field, N > const &rhs)
Definition: diagonalmatrix.hh:1082
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:626
The number of block levels we contain. This is 1.
Definition: diagonalmatrix.hh:71
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:180
void decrement()
Definition: diagonalmatrix.hh:1047
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:51
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition: diagonalmatrix.hh:519
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
size_type M() const
number of blocks in column direction
Definition: diagonalmatrix.hh:470
size_type row_
Definition: diagonalmatrix.hh:809
Definition: diagonalmatrix.hh:32
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:269
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition: diagonalmatrix.hh:252
Iterator begin()
begin iterator
Definition: densevector.hh:308
Iterator beforeEnd()
Definition: diagonalmatrix.hh:878
ConstIterator begin() const
begin iterator
Definition: diagonalmatrix.hh:187
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:838
ContainerWrapperIterator & operator=(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:1011
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:925
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition: diagonalmatrix.hh:531
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:178
std::ptrdiff_t index() const
Definition: diagonalmatrix.hh:1070
void umtv(const X &x, Y &y) const
y += A^T x
Definition: diagonalmatrix.hh:308
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition: diagonalmatrix.hh:525
void mv(const X &x, Y &y) const
y = A x
Definition: diagonalmatrix.hh:277
bool operator!=(const DiagonalMatrix &other) const
incomparison operator
Definition: diagonalmatrix.hh:267
Get the 'const' version of a reference to a mutable object.
Definition: genericiterator.hh:84
Iterator end()
end iterator
Definition: diagonalmatrix.hh:157
R elementAt(int i) const
Definition: diagonalmatrix.hh:1053
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:893
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:182
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:730
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:637
void umhv(const X &x, Y &y) const
y += A^H x
Definition: diagonalmatrix.hh:320
A dense n x m matrix.
Definition: densematrix.hh:38
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition: diagonalmatrix.hh:75
ContainerWrapperIterator< DiagonalRowVector< K, n >, K, K & > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:860
size_type size() const
Definition: diagonalmatrix.hh:92
Dune namespace.
Definition: alignment.hh:10
const K & diagonal() const
the diagonal value
Definition: diagonalmatrix.hh:785
bool equals(const MyType &other) const
Definition: diagonalmatrix.hh:1026
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:140
Traits for type conversions and type information.
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:699
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:678
DiagonalMatrix(std::initializer_list< K > const &l)
Construct diagonal matrix from an initializer list.
Definition: diagonalmatrix.hh:120
Iterator beforeEnd()
Definition: diagonalmatrix.hh:164
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:200
Iterator class for sparse vector-like containers.
Definition: diagonalmatrix.hh:34
K * p_
Definition: diagonalmatrix.hh:808
Definition: diagonalmatrix.hh:31
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition: diagonalmatrix.hh:245
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:825
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:184
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:63
void increment()
Definition: diagonalmatrix.hh:1041
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:681
T * operator->() const
Definition: diagonalmatrix.hh:1020
value_type field_type
Definition: diagonalmatrix.hh:60
A few common exception classes.
void invert()
Compute inverse.
Definition: diagonalmatrix.hh:444
std::size_t size_type
The type used for the index access and size operations.
Definition: diagonalmatrix.hh:66
Macro for wrapping boundary checks.
std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType &other) const
Definition: diagonalmatrix.hh:1064
DiagonalMatrix()
Default constructor.
Definition: diagonalmatrix.hh:100
Iterator RowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:146
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:792
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:891
Iterator beforeBegin()
Definition: diagonalmatrix.hh:171
DiagonalMatrixWrapper()
Definition: diagonalmatrix.hh:629
K determinant() const
calculates the determinant of this matrix
Definition: diagonalmatrix.hh:451
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:943
void usmv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A x
Definition: diagonalmatrix.hh:368
void advance(int n)
Definition: diagonalmatrix.hh:1058
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
K value_type
export the type representing the field
Definition: diagonalmatrix.hh:59
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
bool equals(const MyConstType &other) const
Definition: diagonalmatrix.hh:1031
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: diagonalmatrix.hh:344
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:103
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:862
const_row_type const_row_reference
Definition: diagonalmatrix.hh:80
size_type N() const
number of blocks in row direction
Definition: diagonalmatrix.hh:464
ContainerWrapperIterator(CW containerWrapper, int position)
Definition: diagonalmatrix.hh:989
Definition: diagonalmatrix.hh:33
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:142
ContainerWrapperIterator(const MyConstType &other)
Definition: diagonalmatrix.hh:1005
ConstIterator begin() const
begin ConstIterator
Definition: diagonalmatrix.hh:733
K * pointer(size_type i) const
Definition: diagonalmatrix.hh:797
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: diagonalmatrix.hh:408
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition: diagonalmatrix.hh:224
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
row_type reference
Definition: diagonalmatrix.hh:76
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition: diagonalmatrix.hh:217
const_row_type const_reference
Definition: diagonalmatrix.hh:79
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:437
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition: diagonalmatrix.hh:128
void usmtv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: diagonalmatrix.hh:381
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:828
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: diagonalmatrix.hh:426
DiagonalMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition: diagonalmatrix.hh:103
ConstIterator end() const
end ConstIterator
Definition: diagonalmatrix.hh:739
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:705
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:937
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition: diagonalmatrix.hh:480
Iterator beforeBegin()
Definition: diagonalmatrix.hh:885
size_type M() const
number of columns
Definition: densematrix.hh:677
you have to specialize this structure for any type that should be assignable to a DenseMatrix ...
Definition: densematrix.hh:74
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:728
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: diagonalmatrix.hh:767
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:207
row_type::Iterator ColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:148
A dense n x m matrix.
Definition: densematrix.hh:25
bool identical(const DiagonalMatrixWrapper &other) const
Definition: diagonalmatrix.hh:648
DiagonalMatrix(const FieldVector< K, n > &diag)
Constructor initializing the diagonal with a vector.
Definition: diagonalmatrix.hh:108
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:513
bool identical(const DiagonalRowVectorConst< K, n > &other) const
Definition: diagonalmatrix.hh:722
ConstIterator end() const
end iterator
Definition: diagonalmatrix.hh:193
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition: diagonalmatrix.hh:135
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:18
void mtv(const X &x, Y &y) const
y = A^T x
Definition: diagonalmatrix.hh:289
DiagonalMatrixWrapper(const DiagonalMatrixType *mat)
Definition: diagonalmatrix.hh:633
size_type rowIndex() const
index of this row in surrounding matrix
Definition: diagonalmatrix.hh:779
ContainerWrapperIterator(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:995
Implements a matrix constructed from a given type representing a field and compile-time given number ...
row_type * pointer(int i) const
Definition: diagonalmatrix.hh:642
Iterator end()
end iterator
Definition: diagonalmatrix.hh:871
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:865
size_type N() const
number of rows
Definition: densematrix.hh:671
Implements a generic iterator class for writing stl conformant iterators.
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:931
The number of rows.
Definition: diagonalmatrix.hh:85
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
void umv(const X &x, Y &y) const
y += A x
Definition: diagonalmatrix.hh:296
ContainerWrapperIterator(const MyType &other)
Definition: diagonalmatrix.hh:1000
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition: diagonalmatrix.hh:507
DiagonalRowVector * operator &()
Definition: diagonalmatrix.hh:909
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: diagonalmatrix.hh:356
row_type row_reference
Definition: diagonalmatrix.hh:77
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: diagonalmatrix.hh:414