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 template<
class K,
int n >
550 #ifndef DOXYGEN // hide specialization 559 typedef typename Base::size_type
size_type;
568 typedef typename Base::row_type
row_type;
591 (*this)[0][0] = scalar;
597 return (*
this)[0][0];
603 return (*
this)[0][0];
622 template<
class DiagonalMatrixType>
625 typedef typename DiagonalMatrixType::reference
reference;
627 typedef typename DiagonalMatrixType::field_type K;
642 mat_(const_cast<DiagonalMatrixType*>(mat))
652 row_ =
row_type(&(mat_->diagonal(i)), i);
658 return mat_==other.mat_;
663 mutable DiagonalMatrixType* mat_;
664 mutable row_type row_;
670 template<
class K,
int n >
673 template<
class DiagonalMatrixType>
679 enum { dimension = n };
732 return ((p_ == other.
p_)and (row_ == other.
row_));
747 ConstIterator
end ()
const 769 return ((p_==y.
p_)and (row_==y.
row_));
809 return const_cast<K*
>(p_);
822 template<
class K,
int n >
825 template<
class DiagonalMatrixType>
932 template<
class K,
int n>
938 template<
class K,
int n>
944 template<
class K,
int n>
950 template<
class K,
int n>
980 template<
class CW,
class T,
class R>
983 typedef typename std::remove_const<CW>::type NonConstCW;
1000 containerWrapper_(containerWrapper),
1004 template<
class OtherContainerWrapperIteratorType>
1006 containerWrapper_(other.containerWrapper_),
1007 position_(other.position_)
1011 containerWrapper_(other.containerWrapper_),
1012 position_(other.position_)
1016 containerWrapper_(other.containerWrapper_),
1017 position_(other.position_)
1020 template<
class OtherContainerWrapperIteratorType>
1023 containerWrapper_ = other.containerWrapper_;
1024 position_ = other.position_;
1032 return containerWrapper_.pointer(position_);
1038 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1043 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1048 return *containerWrapper_.pointer(position_);
1065 return *containerWrapper_.pointer(position_+i);
1070 position_=position_+n;
1073 template<
class OtherContainerWrapperIteratorType>
1074 std::ptrdiff_t
distanceTo(OtherContainerWrapperIteratorType& other)
const 1076 assert(containerWrapper_.identical(other));
1077 return other.position_ - position_;
1082 return containerWrapper_.realIndex(position_);
1086 NonConstCW containerWrapper_;
1090 template <
class DenseMatrix,
class field,
int N>
1096 denseMatrix = field(0);
1097 for (
int i = 0; i <
N; ++i)
1098 denseMatrix[i][i] = rhs.
diagonal()[i];
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: diagonalmatrix.hh:344
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:872
size_type size() const
Definition: diagonalmatrix.hh:92
ContainerWrapperIterator & operator=(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:1021
ConstIterator end() const
end iterator
Definition: diagonalmatrix.hh:193
bool equals(const MyType &other) const
Definition: diagonalmatrix.hh:1036
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
DiagonalMatrix(std::initializer_list< K > const &l)
Construct diagonal matrix from an initializer list.
Definition: diagonalmatrix.hh:120
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition: diagonalmatrix.hh:525
row_type * pointer(int i) const
Definition: diagonalmatrix.hh:650
A dense n x m matrix.
Definition: densematrix.hh:39
static void apply(DenseMatrix &denseMatrix, DiagonalMatrix< field, N > const &rhs)
Definition: diagonalmatrix.hh:1092
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:437
value_type field_type
Definition: diagonalmatrix.hh:60
std::size_t size_type
The type used for the index access and size operations.
Definition: diagonalmatrix.hh:66
void usmtv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: diagonalmatrix.hh:381
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:182
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:626
The number of columns.
Definition: diagonalmatrix.hh:87
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:738
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:645
void umv(const X &x, Y &y) const
y += A x
Definition: diagonalmatrix.hh:296
The number of block levels we contain. This is 1.
Definition: diagonalmatrix.hh:71
K determinant() const
calculates the determinant of this matrix
Definition: diagonalmatrix.hh:451
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:947
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition: diagonalmatrix.hh:507
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:146
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
bool equals(const MyConstType &other) const
Definition: diagonalmatrix.hh:1041
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition: diagonalmatrix.hh:75
const_row_type const_row_reference
Definition: diagonalmatrix.hh:80
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:935
bool identical(const DiagonalMatrixWrapper &other) const
Definition: diagonalmatrix.hh:656
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:142
Macro for wrapping boundary checks.
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition: diagonalmatrix.hh:224
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:761
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:513
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition: diagonalmatrix.hh:135
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition: diagonalmatrix.hh:217
const_row_type const_reference
Definition: diagonalmatrix.hh:79
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:707
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:686
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:105
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:200
ContainerWrapperIterator(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:1005
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition: diagonalmatrix.hh:128
R dereference() const
Definition: diagonalmatrix.hh:1046
size_type dim() const
dimension of the vector space
Definition: diagonalmatrix.hh:781
reference operator[](size_type i)
Return reference object as row replacement.
Definition: diagonalmatrix.hh:501
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:953
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition: diagonalmatrix.hh:245
void increment()
Definition: diagonalmatrix.hh:1051
T * operator->() const
Definition: diagonalmatrix.hh:1030
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:692
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition: diagonalmatrix.hh:480
void mmv(const X &x, Y &y) const
y -= A x
Definition: diagonalmatrix.hh:332
std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType &other) const
Definition: diagonalmatrix.hh:1074
DiagonalMatrixWrapper()
Definition: diagonalmatrix.hh:637
row_type::Iterator ColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:148
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:51
void usmv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A x
Definition: diagonalmatrix.hh:368
Definition: diagonalmatrix.hh:32
size_type row_
Definition: diagonalmatrix.hh:819
K value_type
export the type representing the field
Definition: diagonalmatrix.hh:59
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition: diagonalmatrix.hh:252
ContainerWrapperIterator(CW containerWrapper, int position)
Definition: diagonalmatrix.hh:999
ConstIterator begin() const
begin iterator
Definition: diagonalmatrix.hh:187
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:144
ContainerWrapperIterator(const MyConstType &other)
Definition: diagonalmatrix.hh:1015
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition: diagonalmatrix.hh:531
ConstIterator begin() const
begin ConstIterator
Definition: diagonalmatrix.hh:741
K * pointer(size_type i) const
Definition: diagonalmatrix.hh:806
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:178
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: diagonalmatrix.hh:408
void mtv(const X &x, Y &y) const
y = A^T x
Definition: diagonalmatrix.hh:289
std::ptrdiff_t index() const
Definition: diagonalmatrix.hh:1080
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
you have to specialize this structure for any type that should be assignable to a DenseMatrix ...
Definition: densematrix.hh:79
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition: diagonalmatrix.hh:261
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:875
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
R elementAt(int i) const
Definition: diagonalmatrix.hh:1063
A few common exception classes.
DiagonalRowVector()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:844
Dune namespace.
Definition: alignedallocator.hh:9
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:838
Iterator beforeBegin()
Definition: diagonalmatrix.hh:895
DiagonalRowVector * operator &()
Definition: diagonalmatrix.hh:919
Definition: ftraits.hh:23
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: diagonalmatrix.hh:775
void decrement()
Definition: diagonalmatrix.hh:1057
FieldTraits< K >::real_type real_type
Definition: diagonalmatrix.hh:546
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: diagonalmatrix.hh:414
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
DiagonalMatrix(const FieldVector< K, n > &diag)
Constructor initializing the diagonal with a vector.
Definition: diagonalmatrix.hh:108
Iterator beforeEnd()
Definition: diagonalmatrix.hh:888
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: diagonalmatrix.hh:420
FieldTraits< K >::field_type field_type
Definition: diagonalmatrix.hh:545
bool identical(const DiagonalRowVectorConst< K, n > &other) const
Definition: diagonalmatrix.hh:730
const K & diagonal() const
the diagonal value
Definition: diagonalmatrix.hh:793
Iterator beforeEnd()
Definition: diagonalmatrix.hh:164
DiagonalMatrixWrapper(const DiagonalMatrixType *mat)
Definition: diagonalmatrix.hh:641
size_type rowIndex() const
index of this row in surrounding matrix
Definition: diagonalmatrix.hh:787
Iterator class for sparse vector-like containers.
Definition: diagonalmatrix.hh:34
Implements a vector constructed from a given type representing a field and a compile-time given size...
void umtv(const X &x, Y &y) const
y += A^T x
Definition: diagonalmatrix.hh:308
K * p_
Definition: diagonalmatrix.hh:818
void usmhv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: diagonalmatrix.hh:394
Definition: diagonalmatrix.hh:31
Iterator end()
end iterator
Definition: diagonalmatrix.hh:881
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
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:63
size_type N() const
number of rows
Definition: densematrix.hh:686
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:689
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:903
T field_type
export the type representing the field
Definition: ftraits.hh:26
DiagonalMatrix()
Default constructor.
Definition: diagonalmatrix.hh:100
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:800
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:901
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:610
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:180
ContainerWrapperIterator(const MyType &other)
Definition: diagonalmatrix.hh:1010
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:269
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition: diagonalmatrix.hh:519
size_type M() const
number of blocks in column direction
Definition: diagonalmatrix.hh:470
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: diagonalmatrix.hh:356
row_type row_reference
Definition: diagonalmatrix.hh:77
size_type N() const
number of blocks in row direction
Definition: diagonalmatrix.hh:464
Definition: diagonalmatrix.hh:33
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:848
Implements a generic iterator class for writing stl conformant iterators.
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:841
DiagonalRowVectorConst< K, n > const_row_type
Definition: diagonalmatrix.hh:78
Get the 'const' version of a reference to a mutable object.
Definition: genericiterator.hh:84
Iterator begin()
begin iterator
Definition: densevector.hh:308
Traits for type conversions and type information.
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:590
Iterator end()
end iterator
Definition: diagonalmatrix.hh:157
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:754
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: diagonalmatrix.hh:426
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:835
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:184
DiagonalMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition: diagonalmatrix.hh:103
ConstIterator end() const
end ConstIterator
Definition: diagonalmatrix.hh:747
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:941
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:713
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:151
void invert()
Compute inverse.
Definition: diagonalmatrix.hh:444
The number of rows.
Definition: diagonalmatrix.hh:85
void umhv(const X &x, Y &y) const
y += A^H x
Definition: diagonalmatrix.hh:320
size_type M() const
number of columns
Definition: densematrix.hh:692
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:736
Iterator RowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:146
Iterator beforeBegin()
Definition: diagonalmatrix.hh:171
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:207
ContainerWrapperIterator< DiagonalRowVector< K, n >, K, K & > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:870
A dense n x m matrix.
Definition: densematrix.hh:26
void advance(int n)
Definition: diagonalmatrix.hh:1068
Implements a matrix constructed from a given type representing a field and compile-time given number ...