3 #ifndef DUNE_DIAGONAL_MATRIX_HH 4 #define DUNE_DIAGONAL_MATRIX_HH 15 #include <initializer_list> 49 template<
class K,
int n>
121 std::copy_n(l.begin(), std::min(static_cast<std::size_t>(
rows),
136 return (
this==&other);
152 return Iterator(WrapperType(
this),0);
158 return Iterator(WrapperType(
this),n);
165 return Iterator(WrapperType(
this),n-1);
172 return Iterator(WrapperType(
this),-1);
192 ConstIterator
end ()
const 275 template<
class X,
class Y>
276 void mv (
const X& x, Y& y)
const 278 #ifdef DUNE_FMatrix_WITH_CHECKING 282 for (size_type i=0; i<n; ++i)
283 y[i] = diag_[i] * x[i];
287 template<
class X,
class Y>
288 void mtv (
const X& x, Y& y)
const 294 template<
class X,
class Y>
295 void umv (
const X& x, Y& y)
const 297 #ifdef DUNE_FMatrix_WITH_CHECKING 301 for (size_type i=0; i<n; ++i)
302 y[i] += diag_[i] * x[i];
306 template<
class X,
class Y>
307 void umtv (
const X& x, Y& y)
const 309 #ifdef DUNE_FMatrix_WITH_CHECKING 313 for (size_type i=0; i<n; ++i)
314 y[i] += diag_[i] * x[i];
318 template<
class X,
class Y>
319 void umhv (
const X& x, Y& y)
const 321 #ifdef DUNE_FMatrix_WITH_CHECKING 325 for (size_type i=0; i<n; i++)
330 template<
class X,
class Y>
331 void mmv (
const X& x, Y& y)
const 333 #ifdef DUNE_FMatrix_WITH_CHECKING 337 for (size_type i=0; i<n; ++i)
338 y[i] -= diag_[i] * x[i];
342 template<
class X,
class Y>
343 void mmtv (
const X& x, Y& y)
const 345 #ifdef DUNE_FMatrix_WITH_CHECKING 349 for (size_type i=0; i<n; ++i)
350 y[i] -= diag_[i] * x[i];
354 template<
class X,
class Y>
355 void mmhv (
const X& x, Y& y)
const 357 #ifdef DUNE_FMatrix_WITH_CHECKING 361 for (size_type i=0; i<n; i++)
366 template<
class X,
class Y>
367 void usmv (
const K& alpha,
const X& x, Y& y)
const 369 #ifdef DUNE_FMatrix_WITH_CHECKING 373 for (size_type i=0; i<n; i++)
374 y[i] += alpha * diag_[i] * x[i];
378 template<
class X,
class Y>
379 void usmtv (
const K& alpha,
const X& x, Y& y)
const 381 #ifdef DUNE_FMatrix_WITH_CHECKING 385 for (size_type i=0; i<n; i++)
386 y[i] += alpha * diag_[i] * x[i];
390 template<
class X,
class Y>
391 void usmhv (
const K& alpha,
const X& x, Y& y)
const 393 #ifdef DUNE_FMatrix_WITH_CHECKING 397 for (size_type i=0; i<n; i++)
435 for (
int i=0; i<n; i++)
436 x[i] = b[i]/diag_[i];
442 for (
int i=0; i<n; i++)
443 diag_[i] = 1/diag_[i];
450 for (
int i=1; i<n; i++)
476 bool exists (size_type i, size_type j)
const 478 #ifdef DUNE_FMatrix_WITH_CHECKING 488 friend std::ostream& operator<< (std::ostream& s, const DiagonalMatrix<K,n>& a)
490 for (size_type i=0; i<n; i++) {
491 for (size_type j=0; j<n; j++)
492 s << ((i==j) ? a.diag_[i] : 0) <<
" ";
501 return reference(const_cast<K*>(&diag_[i]), i);
540 #ifndef DOXYGEN // hide specialization 549 typedef typename Base::size_type
size_type;
558 typedef typename Base::row_type
row_type;
581 (*this)[0][0] = scalar;
587 return (*
this)[0][0];
593 return (*
this)[0][0];
612 template<
class DiagonalMatrixType>
615 typedef typename DiagonalMatrixType::reference
reference;
617 typedef typename DiagonalMatrixType::field_type K;
632 mat_(const_cast<DiagonalMatrixType*>(mat))
642 row_ =
row_type(&(mat_->diagonal(i)), i);
648 return mat_==other.mat_;
653 mutable DiagonalMatrixType* mat_;
654 mutable row_type row_;
660 template<
class K,
int n >
663 template<
class DiagonalMatrixType>
669 enum { dimension = n };
713 #ifdef DUNE_FMatrix_WITH_CHECKING 726 return ((p_ == other.
p_)and (row_ == other.
row_));
741 ConstIterator
end ()
const 763 return ((p_==y.
p_)and (row_==y.
row_));
801 return const_cast<K*
>(p_);
814 template<
class K,
int n >
817 template<
class DiagonalMatrixType>
857 #ifdef DUNE_FMatrix_WITH_CHECKING 927 template<
class K,
int n>
933 template<
class K,
int n>
939 template<
class K,
int n>
945 template<
class K,
int n>
975 template<
class CW,
class T,
class R>
978 typedef typename remove_const<CW>::type NonConstCW;
995 containerWrapper_(containerWrapper),
999 template<
class OtherContainerWrapperIteratorType>
1001 containerWrapper_(other.containerWrapper_),
1002 position_(other.position_)
1006 containerWrapper_(other.containerWrapper_),
1007 position_(other.position_)
1011 containerWrapper_(other.containerWrapper_),
1012 position_(other.position_)
1015 template<
class OtherContainerWrapperIteratorType>
1018 containerWrapper_ = other.containerWrapper_;
1019 position_ = other.position_;
1026 return containerWrapper_.pointer(position_);
1032 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1037 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1042 return *containerWrapper_.pointer(position_);
1059 return *containerWrapper_.pointer(position_+i);
1064 position_=position_+n;
1067 template<
class OtherContainerWrapperIteratorType>
1068 std::ptrdiff_t
distanceTo(OtherContainerWrapperIteratorType& other)
const 1070 assert(containerWrapper_.identical(other));
1071 return other.position_ - position_;
1076 return containerWrapper_.realIndex(position_);
1080 NonConstCW containerWrapper_;
1086 template<
class M,
class K,
int n>
1089 assert( fm.
rows() == n );
1090 assert( fm.
cols() == n );
1092 for(
int i=0; i<n; ++i)
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:266
void mtv(const X &x, Y &y) const
y = A^T x
Definition: diagonalmatrix.hh:288
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:141
bool equals(const MyType &other) const
Definition: diagonalmatrix.hh:1030
FieldTraits< value_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:607
size_type rows() const
number of rows
Definition: densematrix.hh:695
ConstIterator end() const
end ConstIterator
Definition: diagonalmatrix.hh:741
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition: diagonalmatrix.hh:523
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:930
void decrement()
Definition: diagonalmatrix.hh:1051
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: diagonalmatrix.hh:404
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: diagonalmatrix.hh:422
void mv(const X &x, Y &y) const
y = A x
Definition: diagonalmatrix.hh:276
Get the 'const' version of a reference to a mutable object.
Definition: genericiterator.hh:84
void usmtv(const K &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: diagonalmatrix.hh:379
ConstIterator begin() const
begin ConstIterator
Definition: diagonalmatrix.hh:735
ContainerWrapperIterator(const MyConstType &other)
Definition: diagonalmatrix.hh:1010
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: diagonalmatrix.hh:355
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:948
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: diagonalmatrix.hh:343
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:635
size_type cols() const
number of columns
Definition: densematrix.hh:701
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:755
row_type row_reference
Definition: diagonalmatrix.hh:76
ConstIterator begin() const
begin iterator
Definition: diagonalmatrix.hh:186
value_type field_type
Definition: diagonalmatrix.hh:59
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:896
Implements a matrix constructed from a given type representing a field and compile-time given number ...
void invert()
Compute inverse.
Definition: diagonalmatrix.hh:440
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:748
void usmv(const K &alpha, const X &x, Y &y) const
y += alpha A x
Definition: diagonalmatrix.hh:367
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition: diagonalmatrix.hh:251
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:433
ContainerWrapperIterator(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:1000
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition: diagonalmatrix.hh:260
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: diagonalmatrix.hh:410
K value_type
export the type representing the field
Definition: diagonalmatrix.hh:58
row_type::Iterator ColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:147
The number of columns.
Definition: diagonalmatrix.hh:86
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
bool equals(const MyConstType &other) const
Definition: diagonalmatrix.hh:1035
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:171
Definition: diagonalmatrix.hh:32
void istl_assign_to_fmatrix(DenseMatrix &denseMatrix, const K(&values)[M][N])
Definition: densematrix.hh:76
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:199
DiagonalMatrix(const FieldVector< K, n > &diag)
Constructor initializing the diagonal with a vector.
Definition: diagonalmatrix.hh:107
Traits for type conversions and type information.
size_type dim() const
dimension of the vector space
Definition: diagonalmatrix.hh:775
ContainerWrapperIterator & operator=(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:1016
bool identical(const DiagonalRowVectorConst< K, n > &other) const
Definition: diagonalmatrix.hh:724
size_type row_
Definition: diagonalmatrix.hh:811
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:511
A dense n x m matrix.
Definition: densematrix.hh:22
void umv(const X &x, Y &y) const
y += A x
Definition: diagonalmatrix.hh:295
void umhv(const X &x, Y &y) const
y += A^H x
Definition: diagonalmatrix.hh:319
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:867
const K & diagonal() const
the diagonal value
Definition: diagonalmatrix.hh:787
const_row_type const_row_reference
Definition: diagonalmatrix.hh:79
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:177
size_type M() const
number of blocks in column direction
Definition: diagonalmatrix.hh:466
Implements a generic iterator class for writing stl conformant iterators.
The number of rows.
Definition: diagonalmatrix.hh:84
DiagonalMatrix(std::initializer_list< K > const &l)
Construct diagonal matrix from an initializer list.
Definition: diagonalmatrix.hh:119
void usmhv(const K &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: diagonalmatrix.hh:391
DiagonalMatrix()
Default constructor.
Definition: diagonalmatrix.hh:99
reference operator[](size_type i)
Return reference object as row replacement.
Definition: diagonalmatrix.hh:499
ContainerWrapperIterator(const MyType &other)
Definition: diagonalmatrix.hh:1005
DiagonalRowVectorConst< K, n > const_row_type
Definition: diagonalmatrix.hh:77
ContainerWrapperIterator(CW containerWrapper, int position)
Definition: diagonalmatrix.hh:994
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:179
T * operator->() const
Definition: diagonalmatrix.hh:1024
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:183
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:181
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition: diagonalmatrix.hh:127
std::ptrdiff_t index() const
Definition: diagonalmatrix.hh:1074
Definition: diagonalmatrix.hh:30
const_row_type const_reference
Definition: diagonalmatrix.hh:78
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition: diagonalmatrix.hh:476
K determinant() const
calculates the determinant of this matrix
Definition: diagonalmatrix.hh:447
R dereference() const
Definition: diagonalmatrix.hh:1040
std::size_t size_type
The type used for the index access and size operations.
Definition: diagonalmatrix.hh:65
void increment()
Definition: diagonalmatrix.hh:1045
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition: diagonalmatrix.hh:244
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: diagonalmatrix.hh:416
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:50
K * p_
Definition: diagonalmatrix.hh:810
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:942
std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType &other) const
Definition: diagonalmatrix.hh:1068
Iterator beforeEnd()
Definition: diagonalmatrix.hh:883
row_type * pointer(int i) const
Definition: diagonalmatrix.hh:640
A few common exception classes.
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:840
DiagonalMatrixWrapper()
Definition: diagonalmatrix.hh:627
row_type reference
Definition: diagonalmatrix.hh:75
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:898
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:676
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:703
DiagonalRowVector * operator&()
Definition: diagonalmatrix.hh:914
void umtv(const X &x, Y &y) const
y += A^T x
Definition: diagonalmatrix.hh:307
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:827
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:103
size_type size() const
Definition: diagonalmatrix.hh:91
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition: diagonalmatrix.hh:517
size_type rowIndex() const
index of this row in surrounding matrix
Definition: diagonalmatrix.hh:781
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:870
DiagonalRowVector()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:836
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition: diagonalmatrix.hh:134
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition: diagonalmatrix.hh:216
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition: diagonalmatrix.hh:74
bool operator!=(const DiagonalMatrix &other) const
incomparison operator
Definition: diagonalmatrix.hh:266
FieldTraits< value_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:625
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:589
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:830
The number of block levels we contain. This is 1.
Definition: diagonalmatrix.hh:70
ContainerWrapperIterator< DiagonalRowVector< K, n >, K, K & > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:865
K * pointer(size_type i) const
Definition: diagonalmatrix.hh:799
Iterator beforeEnd()
Definition: diagonalmatrix.hh:163
Iterator end()
end iterator
Definition: diagonalmatrix.hh:156
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:206
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition: diagonalmatrix.hh:529
Iterator end()
end iterator
Definition: diagonalmatrix.hh:876
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:143
Iterator beforeBegin()
Definition: diagonalmatrix.hh:890
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:150
ConstIterator end() const
end iterator
Definition: diagonalmatrix.hh:192
R elementAt(int i) const
Definition: diagonalmatrix.hh:1057
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:936
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:682
Iterator class for sparse vector-like containers.
Definition: diagonalmatrix.hh:33
DiagonalMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition: diagonalmatrix.hh:102
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
Iterator RowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:145
Definition: diagonalmatrix.hh:31
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
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition: diagonalmatrix.hh:223
bool identical(const DiagonalMatrixWrapper &other) const
Definition: diagonalmatrix.hh:646
DiagonalMatrixWrapper(const DiagonalMatrixType *mat)
Definition: diagonalmatrix.hh:631
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:794
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: diagonalmatrix.hh:769
Iterator beforeBegin()
Definition: diagonalmatrix.hh:170
A dense n x m matrix.
Definition: densematrix.hh:35
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition: diagonalmatrix.hh:505
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:730
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:62
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:697
Dune namespace.
Definition: alignment.hh:9
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:833
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:679
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:732
void mmv(const X &x, Y &y) const
y -= A x
Definition: diagonalmatrix.hh:331
Iterator begin()
begin iterator
Definition: densevector.hh:307
void advance(int n)
Definition: diagonalmatrix.hh:1062
DiagonalRowVectorConst * operator&()
Definition: diagonalmatrix.hh:804
Implements a vector constructed from a given type representing a field and a compile-time given size...
size_type N() const
number of blocks in row direction
Definition: diagonalmatrix.hh:460