3 #ifndef DUNE_DIAGONAL_MATRIX_HH
4 #define DUNE_DIAGONAL_MATRIX_HH
28 template<
class K,
int n >
class DiagonalRowVectorConst;
29 template<
class K,
int n >
class DiagonalRowVector;
30 template<
class DiagonalMatrixType >
class DiagonalMatrixWrapper;
31 template<
class C,
class T,
class R>
class ContainerWrapperIterator;
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>
599 typedef typename DiagonalMatrixType::reference reference;
600 typedef typename DiagonalMatrixType::const_reference const_reference;
601 typedef typename DiagonalMatrixType::field_type K;
603 typedef std::size_t size_type;
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 >
647 template<
class DiagonalMatrixType>
697 #ifdef DUNE_FMatrix_WITH_CHECKING
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];