3 #ifndef DUNE_DIAGONAL_MATRIX_HH
4 #define DUNE_DIAGONAL_MATRIX_HH
47 template<
class K,
int n>
120 return (
this==&other);
259 template<
class X,
class Y>
260 void mv (
const X& x, Y& y)
const
262 #ifdef DUNE_FMatrix_WITH_CHECKING
267 y[i] = diag_[i] * x[i];
271 template<
class X,
class Y>
272 void mtv (
const X& x, Y& y)
const
278 template<
class X,
class Y>
279 void umv (
const X& x, Y& y)
const
281 #ifdef DUNE_FMatrix_WITH_CHECKING
286 y[i] += diag_[i] * x[i];
290 template<
class X,
class Y>
291 void umtv (
const X& x, Y& y)
const
293 #ifdef DUNE_FMatrix_WITH_CHECKING
298 y[i] += diag_[i] * x[i];
302 template<
class X,
class Y>
303 void umhv (
const X& x, Y& y)
const
305 #ifdef DUNE_FMatrix_WITH_CHECKING
314 template<
class X,
class Y>
315 void mmv (
const X& x, Y& y)
const
317 #ifdef DUNE_FMatrix_WITH_CHECKING
322 y[i] -= diag_[i] * x[i];
326 template<
class X,
class Y>
327 void mmtv (
const X& x, Y& y)
const
329 #ifdef DUNE_FMatrix_WITH_CHECKING
334 y[i] -= diag_[i] * x[i];
338 template<
class X,
class Y>
339 void mmhv (
const X& x, Y& y)
const
341 #ifdef DUNE_FMatrix_WITH_CHECKING
350 template<
class X,
class Y>
351 void usmv (
const K& alpha,
const X& x, Y& y)
const
353 #ifdef DUNE_FMatrix_WITH_CHECKING
358 y[i] += alpha * diag_[i] * x[i];
362 template<
class X,
class Y>
363 void usmtv (
const K& alpha,
const X& x, Y& y)
const
365 #ifdef DUNE_FMatrix_WITH_CHECKING
370 y[i] += alpha * diag_[i] * x[i];
374 template<
class X,
class Y>
375 void usmhv (
const K& alpha,
const X& x, Y& y)
const
377 #ifdef DUNE_FMatrix_WITH_CHECKING
419 for (
int i=0; i<n; i++)
420 x[i] = b[i]/diag_[i];
426 for (
int i=0; i<n; i++)
427 diag_[i] = 1/diag_[i];
434 for (
int i=1; i<n; i++)
462 #ifdef DUNE_FMatrix_WITH_CHECKING
472 friend std::ostream& operator<< (std::ostream& s, const DiagonalMatrix<K,n>& a)
476 s << ((i==j) ? a.diag_[i] : 0) <<
" ";
485 return reference(const_cast<K*>(&diag_[i]), i);
524 #ifndef DOXYGEN // hide specialization
528 class DiagonalMatrix<K, 1> :
public FieldMatrix<K, 1, 1>
530 typedef FieldMatrix<K,1,1> Base;
533 typedef typename Base::size_type
size_type;
542 typedef typename Base::row_type
row_type;
565 (*this)[0][0] = scalar;
571 return (*
this)[0][0];
577 return (*
this)[0][0];
581 const FieldVector<K,1>&
diagonal()
const
596 template<
class DiagonalMatrixType>
597 class DiagonalMatrixWrapper
599 typedef typename DiagonalMatrixType::reference reference;
600 typedef typename DiagonalMatrixType::const_reference const_reference;
601 typedef typename DiagonalMatrixType::field_type K;
602 typedef DiagonalRowVector<K, DiagonalMatrixType::rows> row_type;
603 typedef std::size_t size_type;
604 typedef DiagonalMatrixWrapper< DiagonalMatrixType> MyType;
616 mat_(const_cast<DiagonalMatrixType*>(mat))
626 row_ =
row_type(&(mat_->diagonal(i)), i);
632 return mat_==other.mat_;
637 mutable DiagonalMatrixType* mat_;
638 mutable row_type row_;
644 template<
class K,
int n >
645 class DiagonalRowVectorConst
647 template<
class DiagonalMatrixType>
697 #ifdef DUNE_FMatrix_WITH_CHECKING
710 return ((
p_ == other.p_)and (
row_ == other.row_));
747 return ((
p_==y.p_)and (
row_==y.row_));
785 return const_cast<K*
>(
p_);
798 template<
class K,
int n >
801 template<
class DiagonalMatrixType>
840 #ifdef DUNE_FMatrix_WITH_CHECKING
910 template<
class K,
int n>
916 template<
class K,
int n>
922 template<
class K,
int n>
928 template<
class K,
int n>
958 template<
class CW,
class T,
class R>
978 containerWrapper_(containerWrapper),
982 template<
class OtherContainerWrapperIteratorType>
984 containerWrapper_(other.containerWrapper_),
985 position_(other.position_)
989 containerWrapper_(other.containerWrapper_),
990 position_(other.position_)
994 containerWrapper_(other.containerWrapper_),
995 position_(other.position_)
998 template<
class OtherContainerWrapperIteratorType>
1001 containerWrapper_ = other.containerWrapper_;
1002 position_ = other.position_;
1009 return containerWrapper_.pointer(position_);
1015 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1020 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1025 return *containerWrapper_.pointer(position_);
1042 return *containerWrapper_.pointer(position_+i);
1047 position_=position_+n;
1050 template<
class OtherContainerWrapperIteratorType>
1051 std::ptrdiff_t
distanceTo(OtherContainerWrapperIteratorType& other)
const
1053 assert(containerWrapper_.identical(other));
1054 return other.position_ - position_;
1059 return containerWrapper_.realIndex(position_);
1063 NonConstCW containerWrapper_;
1069 template<
class M,
class K,
int n>
1072 assert( fm.
rows() == n );
1073 assert( fm.
cols() == n );
1075 for(
int i=0; i<n; ++i)
1076 fm[i][i] = s.diagonal()[i];
void usmtv(const K &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: diagonalmatrix.hh:363
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:814
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: diagonalmatrix.hh:339
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:183
DiagonalMatrix(const FieldVector< K, n > &diag)
Constructor initializing the diagonal with a vector.
Definition: diagonalmatrix.hh:105
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition: diagonalmatrix.hh:513
The number of block levels we contain. This is 1.
Definition: diagonalmatrix.hh:68
ConstIterator end() const
end iterator
Definition: diagonalmatrix.hh:176
row_type row_reference
Definition: diagonalmatrix.hh:74
ConstIterator begin() const
begin iterator
Definition: diagonalmatrix.hh:170
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition: diagonalmatrix.hh:507
Implements a generic iterator class for writing stl conformant iterators.
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:931
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: diagonalmatrix.hh:406
A few common exception classes.
ContainerWrapperIterator & operator=(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:999
void umhv(const X &x, Y &y) const
y += A^H x
Definition: diagonalmatrix.hh:303
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:850
void usmv(const K &alpha, const X &x, Y &y) const
y += alpha A x
Definition: diagonalmatrix.hh:351
Iterator beforeBegin()
Definition: diagonalmatrix.hh:154
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: diagonalmatrix.hh:394
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:60
void advance(int n)
Definition: diagonalmatrix.hh:1045
row_type::Iterator ColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:131
The number of rows.
Definition: diagonalmatrix.hh:82
size_type M() const
number of blocks in column direction
Definition: diagonalmatrix.hh:450
void mmv(const X &x, Y &y) const
y -= A x
Definition: diagonalmatrix.hh:315
void invert()
Compute inverse.
Definition: diagonalmatrix.hh:424
void usmhv(const K &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: diagonalmatrix.hh:375
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:267
K * pointer(size_type i) const
Definition: diagonalmatrix.hh:783
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:913
R dereference() const
Definition: diagonalmatrix.hh:1023
void mtv(const X &x, Y &y) const
y = A^T x
Definition: diagonalmatrix.hh:272
DiagonalRowVectorConst< K, n > const_row_type
Definition: diagonalmatrix.hh:75
K value_type
export the type representing the field
Definition: diagonalmatrix.hh:56
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:48
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:660
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:919
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:666
std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType &other) const
Definition: diagonalmatrix.hh:1051
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:495
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:687
DiagonalMatrixWrapper()
Definition: diagonalmatrix.hh:611
void mv(const X &x, Y &y) const
y = A x
Definition: diagonalmatrix.hh:260
void umv(const X &x, Y &y) const
y += A x
Definition: diagonalmatrix.hh:279
Definition: diagonalmatrix.hh:28
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: diagonalmatrix.hh:753
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition: diagonalmatrix.hh:460
DiagonalMatrixWrapper(const DiagonalMatrixType *mat)
Definition: diagonalmatrix.hh:615
size_type cols() const
number of columns
Definition: densematrix.hh:710
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:619
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:681
bool equals(const MyConstType &other) const
Definition: diagonalmatrix.hh:1018
const_row_type const_row_reference
Definition: diagonalmatrix.hh:77
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:879
size_type rows() const
number of rows
Definition: densematrix.hh:704
DiagonalRowVectorConst * operator&()
Definition: diagonalmatrix.hh:788
The number of block levels we contain.
Definition: diagonalmatrix.hh:671
void decrement()
Definition: diagonalmatrix.hh:1034
T * operator->() const
Definition: diagonalmatrix.hh:1007
K & operator[](size_type i)
random access
Definition: diagonalmatrix.hh:838
std::ptrdiff_t index() const
Definition: diagonalmatrix.hh:1057
R elementAt(int i) const
Definition: diagonalmatrix.hh:1040
FieldTraits< value_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:539
std::size_t position_
The current position in the buffer.
Definition: variablesizecommunicator.hh:136
ConstIterator end() const
end ConstIterator
Definition: diagonalmatrix.hh:725
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:161
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:178
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition: diagonalmatrix.hh:111
void umtv(const X &x, Y &y) const
y += A^T x
Definition: diagonalmatrix.hh:291
Definition: diagonalmatrix.hh:653
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:811
size_type rowIndex() const
index of this row in surrounding matrix
Definition: diagonalmatrix.hh:765
ConstIterator begin() const
begin ConstIterator
Definition: diagonalmatrix.hh:719
Traits for type conversions and type information.
DiagonalMatrix()
Default constructor.
Definition: diagonalmatrix.hh:97
reference operator[](size_type i)
Return reference object as row replacement.
Definition: diagonalmatrix.hh:483
void istl_assign_to_fmatrix(DenseMatrix &denseMatrix, const K(&values)[M][N])
Definition: densematrix.hh:78
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:714
size_type dim() const
dimension of the vector space
Definition: diagonalmatrix.hh:759
ContainerWrapperIterator(const MyConstType &other)
Definition: diagonalmatrix.hh:993
Definition: diagonalmatrix.hh:29
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:163
row_type * pointer(int i) const
Definition: diagonalmatrix.hh:624
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:167
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:165
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:716
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: diagonalmatrix.hh:400
DiagonalRowVector & operator=(const K &k)
Assignment operator for scalar.
Definition: diagonalmatrix.hh:829
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
const_row_type const_reference
Definition: diagonalmatrix.hh:76
K determinant() const
calculates the determinant of this matrix
Definition: diagonalmatrix.hh:431
ContainerWrapperIterator(CW containerWrapper, int position)
Definition: diagonalmatrix.hh:977
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:190
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:127
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition: diagonalmatrix.hh:228
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:925
DiagonalMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition: diagonalmatrix.hh:100
Iterator class for sparse vector-like containers.
Definition: diagonalmatrix.hh:31
Implements a vector constructed from a given type representing a field and a compile-time given size...
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition: diagonalmatrix.hh:207
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:778
const K & operator[](size_type i) const
same for read only access
Definition: diagonalmatrix.hh:695
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Get the 'const' version of a reference to a mutable object.
Definition: genericiterator.hh:85
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition: diagonalmatrix.hh:489
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:739
bool identical(const DiagonalRowVectorConst< K, n > &other) const
Definition: diagonalmatrix.hh:708
ContainerWrapperIterator(const MyType &other)
Definition: diagonalmatrix.hh:988
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:817
row_type reference
Definition: diagonalmatrix.hh:73
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:881
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:663
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition: diagonalmatrix.hh:501
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:103
ContainerWrapperIterator< DiagonalRowVector< K, n >, K, K & > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:848
bool identical(const DiagonalMatrixWrapper &other) const
Definition: diagonalmatrix.hh:630
Iterator beforeEnd()
Definition: diagonalmatrix.hh:147
Iterator end()
end iterator
Definition: diagonalmatrix.hh:140
DiagonalRowVector()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:820
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition: diagonalmatrix.hh:118
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition: diagonalmatrix.hh:200
std::size_t size_type
The type used for the index access and size operations.
Definition: diagonalmatrix.hh:63
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition: diagonalmatrix.hh:72
bool operator==(const DiagonalRowVectorConst &y) const
Binary vector comparison.
Definition: diagonalmatrix.hh:745
bool operator!=(const DiagonalMatrix &other) const
incomparison operator
Definition: diagonalmatrix.hh:250
The size of this vector.
Definition: diagonalmatrix.hh:677
FieldTraits< value_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:553
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: diagonalmatrix.hh:388
Iterator RowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:129
K * p_
Definition: diagonalmatrix.hh:794
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:114
Iterator beforeEnd()
Definition: diagonalmatrix.hh:866
The number of columns.
Definition: diagonalmatrix.hh:84
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: diagonalmatrix.hh:327
Iterator end()
end iterator
Definition: diagonalmatrix.hh:859
Iterator beforeBegin()
Definition: diagonalmatrix.hh:873
Definition: diagonalmatrix.hh:30
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:134
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:824
size_type row_
Definition: diagonalmatrix.hh:795
Removes a const qualifier while preserving others.
Definition: typetraits.hh:175
value_type field_type
Definition: diagonalmatrix.hh:57
bool equals(const MyType &other) const
Definition: diagonalmatrix.hh:1013
DiagonalRowVector * operator&()
Definition: diagonalmatrix.hh:897
size_type size() const
Definition: diagonalmatrix.hh:89
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:732
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 two_norm2() const
square of two norm (sum over squared values of entries), need for block recursion ...
Definition: densevector.hh:530
size_type N() const
number of blocks in row direction
Definition: diagonalmatrix.hh:444
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:853
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition: diagonalmatrix.hh:235
const K & diagonal() const
the diagonal value
Definition: diagonalmatrix.hh:771
void increment()
Definition: diagonalmatrix.hh:1028
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:417
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition: diagonalmatrix.hh:244
Implements a matrix constructed from a given type representing a field and compile-time given number ...
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:125
A dense n x m matrix.
Definition: densematrix.hh:24
ContainerWrapperIterator(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:983