Dune Core Modules (2.3.1)

diagonalmatrix.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_DIAGONAL_MATRIX_HH
4#define DUNE_DIAGONAL_MATRIX_HH
5
10#include <cassert>
11#include <cmath>
12#include <complex>
13#include <cstddef>
14#include <iostream>
15#include <memory>
16
23#include <dune/common/unused.hh>
24
25
26namespace Dune {
27
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;
32
47 template<class K, int n>
49 {
50 typedef DiagonalMatrixWrapper< DiagonalMatrix<K,n> > WrapperType;
51
52 public:
53 //===== type definitions and constants
54
56 typedef K value_type;
57 typedef value_type field_type;
58
60 typedef K block_type;
61
63 typedef std::size_t size_type;
64
66 enum {
68 blocklevel = 1
69 };
70
72 typedef DiagonalRowVector<K,n> row_type;
73 typedef row_type reference;
74 typedef row_type row_reference;
75 typedef DiagonalRowVectorConst<K,n> const_row_type;
76 typedef const_row_type const_reference;
77 typedef const_row_type const_row_reference;
78
80 enum {
82 rows = n,
84 cols = n
85 };
86
87 //==== size
88
89 size_type size () const
90 {
91 return rows;
92 }
93
94 //===== constructors
95
98
100 DiagonalMatrix (const K& k)
101 : diag_(k)
102 {}
103
106 : diag_(diag)
107 {}
108
109
112 {
113 diag_ = k;
114 return *this;
115 }
116
118 bool identical(const DiagonalMatrix<K,n>& other) const
119 {
120 return (this==&other);
121 }
122
123 //===== iterator interface to rows of the matrix
132
135 {
136 return Iterator(WrapperType(this),0);
137 }
138
141 {
142 return Iterator(WrapperType(this),n);
143 }
144
148 {
149 return Iterator(WrapperType(this),n-1);
150 }
151
155 {
156 return Iterator(WrapperType(this),-1);
157 }
158
159
168
171 {
172 return ConstIterator(WrapperType(this),0);
173 }
174
177 {
178 return ConstIterator(WrapperType(this),n);
179 }
180
184 {
185 return ConstIterator(WrapperType(this),n-1);
186 }
187
191 {
192 return ConstIterator(WrapperType(this),-1);
193 }
194
195
196
197 //===== vector space arithmetic
198
201 {
202 diag_ += y.diag_;
203 return *this;
204 }
205
208 {
209 diag_ -= y.diag_;
210 return *this;
211 }
212
215 {
216 diag_ += k;
217 return *this;
218 }
219
222 {
223 diag_ -= k;
224 return *this;
225 }
226
229 {
230 diag_ *= k;
231 return *this;
232 }
233
236 {
237 diag_ /= k;
238 return *this;
239 }
240
241 //===== comparison ops
242
244 bool operator==(const DiagonalMatrix& other) const
245 {
246 return diag_==other.diagonal();
247 }
248
250 bool operator!=(const DiagonalMatrix& other) const
251 {
252 return diag_!=other.diagonal();
253 }
254
255
256 //===== linear maps
257
259 template<class X, class Y>
260 void mv (const X& x, Y& y) const
261 {
262#ifdef DUNE_FMatrix_WITH_CHECKING
263 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
264 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
265#endif
266 for (size_type i=0; i<n; ++i)
267 y[i] = diag_[i] * x[i];
268 }
269
271 template<class X, class Y>
272 void mtv (const X& x, Y& y) const
273 {
274 mv(x, y);
275 }
276
278 template<class X, class Y>
279 void umv (const X& x, Y& y) const
280 {
281#ifdef DUNE_FMatrix_WITH_CHECKING
282 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
283 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
284#endif
285 for (size_type i=0; i<n; ++i)
286 y[i] += diag_[i] * x[i];
287 }
288
290 template<class X, class Y>
291 void umtv (const X& x, Y& y) const
292 {
293#ifdef DUNE_FMatrix_WITH_CHECKING
294 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
295 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
296#endif
297 for (size_type i=0; i<n; ++i)
298 y[i] += diag_[i] * x[i];
299 }
300
302 template<class X, class Y>
303 void umhv (const X& x, Y& y) const
304 {
305#ifdef DUNE_FMatrix_WITH_CHECKING
306 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
307 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
308#endif
309 for (size_type i=0; i<n; i++)
310 y[i] += conjugateComplex(diag_[i])*x[i];
311 }
312
314 template<class X, class Y>
315 void mmv (const X& x, Y& y) const
316 {
317#ifdef DUNE_FMatrix_WITH_CHECKING
318 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
319 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
320#endif
321 for (size_type i=0; i<n; ++i)
322 y[i] -= diag_[i] * x[i];
323 }
324
326 template<class X, class Y>
327 void mmtv (const X& x, Y& y) const
328 {
329#ifdef DUNE_FMatrix_WITH_CHECKING
330 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
331 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
332#endif
333 for (size_type i=0; i<n; ++i)
334 y[i] -= diag_[i] * x[i];
335 }
336
338 template<class X, class Y>
339 void mmhv (const X& x, Y& y) const
340 {
341#ifdef DUNE_FMatrix_WITH_CHECKING
342 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
343 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
344#endif
345 for (size_type i=0; i<n; i++)
346 y[i] -= conjugateComplex(diag_[i])*x[i];
347 }
348
350 template<class X, class Y>
351 void usmv (const K& alpha, const X& x, Y& y) const
352 {
353#ifdef DUNE_FMatrix_WITH_CHECKING
354 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
355 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
356#endif
357 for (size_type i=0; i<n; i++)
358 y[i] += alpha * diag_[i] * x[i];
359 }
360
362 template<class X, class Y>
363 void usmtv (const K& alpha, const X& x, Y& y) const
364 {
365#ifdef DUNE_FMatrix_WITH_CHECKING
366 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
367 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
368#endif
369 for (size_type i=0; i<n; i++)
370 y[i] += alpha * diag_[i] * x[i];
371 }
372
374 template<class X, class Y>
375 void usmhv (const K& alpha, const X& x, Y& y) const
376 {
377#ifdef DUNE_FMatrix_WITH_CHECKING
378 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
379 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
380#endif
381 for (size_type i=0; i<n; i++)
382 y[i] += alpha * conjugateComplex(diag_[i]) * x[i];
383 }
384
385 //===== norms
386
388 double frobenius_norm () const
389 {
390 return diag_.two_norm();
391 }
392
394 double frobenius_norm2 () const
395 {
396 return diag_.two_norm2();
397 }
398
400 double infinity_norm () const
401 {
402 return diag_.infinity_norm();
403 }
404
406 double infinity_norm_real () const
407 {
408 return diag_.infinity_norm_real();
409 }
410
411
412
413 //===== solve
414
416 template<class V>
417 void solve (V& x, const V& b) const
418 {
419 for (int i=0; i<n; i++)
420 x[i] = b[i]/diag_[i];
421 }
422
424 void invert()
425 {
426 for (int i=0; i<n; i++)
427 diag_[i] = 1/diag_[i];
428 }
429
431 K determinant () const
432 {
433 K det = diag_[0];
434 for (int i=1; i<n; i++)
435 det *= diag_[i];
436 return det;
437 }
438
439
440
441 //===== sizes
442
444 size_type N () const
445 {
446 return n;
447 }
448
450 size_type M () const
451 {
452 return n;
453 }
454
455
456
457 //===== query
458
460 bool exists (size_type i, size_type j) const
461 {
462#ifdef DUNE_FMatrix_WITH_CHECKING
463 if (i<0 || i>=n) DUNE_THROW(FMatrixError,"row index out of range");
464 if (j<0 || j>=n) DUNE_THROW(FMatrixError,"column index out of range");
465#endif
466 return i==j;
467 }
468
469
470
472 friend std::ostream& operator<< (std::ostream& s, const DiagonalMatrix<K,n>& a)
473 {
474 for (size_type i=0; i<n; i++) {
475 for (size_type j=0; j<n; j++)
476 s << ((i==j) ? a.diag_[i] : 0) << " ";
477 s << std::endl;
478 }
479 return s;
480 }
481
484 {
485 return reference(const_cast<K*>(&diag_[i]), i);
486 }
487
489 const_reference operator[](size_type i) const
490 {
491 return const_reference(const_cast<K*>(&diag_[i]), i);
492 }
493
495 const K& diagonal(size_type i) const
496 {
497 return diag_[i];
498 }
499
502 {
503 return diag_[i];
504 }
505
508 {
509 return diag_;
510 }
511
514 {
515 return diag_;
516 }
517
518 private:
519
520 // the data, a FieldVector storing the diagonal
521 FieldVector<K,n> diag_;
522 };
523
524#ifndef DOXYGEN // hide specialization
527 template< class K >
528 class DiagonalMatrix<K, 1> : public FieldMatrix<K, 1, 1>
529 {
530 typedef FieldMatrix<K,1,1> Base;
531 public:
533 typedef typename Base::size_type size_type;
534
536 enum {
539 blocklevel = 1
540 };
541
542 typedef typename Base::row_type row_type;
543
544 typedef typename Base::row_reference row_reference;
545 typedef typename Base::const_row_reference const_row_reference;
546
548 enum {
551 rows = 1,
554 cols = 1
555 };
556
557
560 {}
561
563 DiagonalMatrix(const K& scalar)
564 {
565 (*this)[0][0] = scalar;
566 }
567
569 const K& diagonal(size_type) const
570 {
571 return (*this)[0][0];
572 }
573
576 {
577 return (*this)[0][0];
578 }
579
581 const FieldVector<K,1>& diagonal() const
582 {
583 return (*this)[0];
584 }
585
587 FieldVector<K,1>& diagonal()
588 {
589 return (*this)[0];
590 }
591
592 };
593#endif
594
595
596 template<class DiagonalMatrixType>
597 class DiagonalMatrixWrapper
598 {
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;
605
606 friend class ContainerWrapperIterator<const MyType, reference, reference>;
607 friend class ContainerWrapperIterator<const MyType, const_reference, const_reference>;
608
609 public:
610
611 DiagonalMatrixWrapper() :
612 mat_(0)
613 {}
614
615 DiagonalMatrixWrapper(const DiagonalMatrixType* mat) :
616 mat_(const_cast<DiagonalMatrixType*>(mat))
617 {}
618
619 size_type realIndex(int i) const
620 {
621 return i;
622 }
623
624 row_type* pointer(int i) const
625 {
626 row_ = row_type(&(mat_->diagonal(i)), i);
627 return &row_;
628 }
629
630 bool identical(const DiagonalMatrixWrapper& other) const
631 {
632 return mat_==other.mat_;
633 }
634
635 private:
636
637 mutable DiagonalMatrixType* mat_;
638 mutable row_type row_;
639 };
640
644 template< class K, int n >
645 class DiagonalRowVectorConst
646 {
647 template<class DiagonalMatrixType>
648 friend class DiagonalMatrixWrapper;
649 friend class ContainerWrapperIterator<DiagonalRowVectorConst<K,n>, const K, const K&>;
650
651 public:
652 // remember size of vector
653 enum { dimension = n };
654
655 // standard constructor and everything is sufficient ...
656
657 //===== type definitions and constants
658
660 typedef K field_type;
661
663 typedef K block_type;
664
666 typedef std::size_t size_type;
667
669 enum {
671 blocklevel = 1
672 };
673
675 enum {
677 size = n
678 };
679
682 p_(0),
683 row_(0)
684 {}
685
687 explicit DiagonalRowVectorConst (K* p, int col) :
688 p_(p),
689 row_(col)
690 {}
691
692 //===== access to components
693
695 const K& operator[] (size_type i) const
696 {
697#ifdef DUNE_FMatrix_WITH_CHECKING
698 if (i!=row_)
699 DUNE_THROW(FMatrixError,"index is not contained in pattern");
700#else
702#endif
703 return *p_;
704 }
705
706 // check if row is identical to other row (not only identical values)
707 // since this is a proxy class we need to check equality of the stored pointer
708 bool identical(const DiagonalRowVectorConst<K,n>& other) const
709 {
710 return ((p_ == other.p_)and (row_ == other.row_));
711 }
712
717
720 {
721 return ConstIterator(*this,0);
722 }
723
726 {
727 return ConstIterator(*this,1);
728 }
729
733 {
734 return ConstIterator(*this,0);
735 }
736
740 {
741 return ConstIterator(*this,-1);
742 }
743
745 bool operator== (const DiagonalRowVectorConst& y) const
746 {
747 return ((p_==y.p_)and (row_==y.row_));
748 }
749
750 //===== sizes
751
753 size_type N () const
754 {
755 return n;
756 }
757
759 size_type dim () const
760 {
761 return n;
762 }
763
766 {
767 return row_;
768 }
769
771 const K& diagonal() const
772 {
773 return *p_;
774 }
775
776 protected:
777
778 size_type realIndex(int i) const
779 {
780 return rowIndex();
781 }
782
783 K* pointer(size_type i) const
784 {
785 return const_cast<K*>(p_);
786 }
787
788 DiagonalRowVectorConst* operator&()
789 {
790 return this;
791 }
792
793 // the data, very simply a pointer to the diagonal value and the row number
794 K* p_;
795 size_type row_;
796 };
797
798 template< class K, int n >
799 class DiagonalRowVector : public DiagonalRowVectorConst<K,n>
800 {
801 template<class DiagonalMatrixType>
802 friend class DiagonalMatrixWrapper;
803 friend class ContainerWrapperIterator<DiagonalRowVector<K,n>, K, K&>;
804
805 public:
806 // standard constructor and everything is sufficient ...
807
808 //===== type definitions and constants
809
811 typedef K field_type;
812
814 typedef K block_type;
815
817 typedef std::size_t size_type;
818
820 DiagonalRowVector() : DiagonalRowVectorConst<K,n>()
821 {}
822
824 explicit DiagonalRowVector (K* p, int col) : DiagonalRowVectorConst<K,n>(p, col)
825 {}
826
827 //===== assignment from scalar
829 DiagonalRowVector& operator= (const K& k)
830 {
831 *p_ = k;
832 return *this;
833 }
834
835 //===== access to components
836
838 K& operator[] (size_type i)
839 {
840#ifdef DUNE_FMatrix_WITH_CHECKING
841 if (i!=row_)
842 DUNE_THROW(FMatrixError,"index is contained in pattern");
843#endif
844 return *p_;
845 }
846
851
854 {
855 return Iterator(*this, 0);
856 }
857
860 {
861 return Iterator(*this, 1);
862 }
863
867 {
868 return Iterator(*this, 0);
869 }
870
874 {
875 return Iterator(*this, -1);
876 }
877
882
883 using DiagonalRowVectorConst<K,n>::identical;
884 using DiagonalRowVectorConst<K,n>::operator[];
885 using DiagonalRowVectorConst<K,n>::operator==;
886 using DiagonalRowVectorConst<K,n>::begin;
887 using DiagonalRowVectorConst<K,n>::end;
888 using DiagonalRowVectorConst<K,n>::beforeEnd;
889 using DiagonalRowVectorConst<K,n>::beforeBegin;
890 using DiagonalRowVectorConst<K,n>::N;
891 using DiagonalRowVectorConst<K,n>::dim;
892 using DiagonalRowVectorConst<K,n>::rowIndex;
893 using DiagonalRowVectorConst<K,n>::diagonal;
894
895 protected:
896
897 DiagonalRowVector* operator&()
898 {
899 return this;
900 }
901
902 private:
903
904 using DiagonalRowVectorConst<K,n>::p_;
905 using DiagonalRowVectorConst<K,n>::row_;
906 };
907
908
909 // implement type traits
910 template<class K, int n>
911 struct const_reference< DiagonalRowVector<K,n> >
912 {
913 typedef DiagonalRowVectorConst<K,n> type;
914 };
915
916 template<class K, int n>
917 struct const_reference< DiagonalRowVectorConst<K,n> >
918 {
919 typedef DiagonalRowVectorConst<K,n> type;
920 };
921
922 template<class K, int n>
923 struct mutable_reference< DiagonalRowVector<K,n> >
924 {
925 typedef DiagonalRowVector<K,n> type;
926 };
927
928 template<class K, int n>
929 struct mutable_reference< DiagonalRowVectorConst<K,n> >
930 {
931 typedef DiagonalRowVector<K,n> type;
932 };
933
934
935
958 template<class CW, class T, class R>
959 class ContainerWrapperIterator : public BidirectionalIteratorFacade<ContainerWrapperIterator<CW,T,R>,T, R, int>
960 {
961 typedef typename remove_const<CW>::type NonConstCW;
962
963 friend class ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type>;
964 friend class ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type>;
965
966 typedef ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type> MyType;
967 typedef ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type> MyConstType;
968
969 public:
970
971 // Constructors needed by the facade iterators.
973 containerWrapper_(),
974 position_(0)
975 {}
976
977 ContainerWrapperIterator(CW containerWrapper, int position) :
978 containerWrapper_(containerWrapper),
979 position_(position)
980 {}
981
982 template<class OtherContainerWrapperIteratorType>
983 ContainerWrapperIterator(OtherContainerWrapperIteratorType& other) :
984 containerWrapper_(other.containerWrapper_),
985 position_(other.position_)
986 {}
987
988 ContainerWrapperIterator(const MyType& other) :
989 containerWrapper_(other.containerWrapper_),
990 position_(other.position_)
991 {}
992
994 containerWrapper_(other.containerWrapper_),
995 position_(other.position_)
996 {}
997
998 template<class OtherContainerWrapperIteratorType>
999 ContainerWrapperIterator& operator=(OtherContainerWrapperIteratorType& other)
1000 {
1001 containerWrapper_ = other.containerWrapper_;
1002 position_ = other.position_;
1003 }
1004
1005 // This operator is needed since we can not get the address of the
1006 // temporary object returned by dereference
1007 T* operator->() const
1008 {
1009 return containerWrapper_.pointer(position_);
1010 }
1011
1012 // Methods needed by the forward iterator
1013 bool equals(const MyType& other) const
1014 {
1015 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1016 }
1017
1018 bool equals(const MyConstType& other) const
1019 {
1020 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1021 }
1022
1023 R dereference() const
1024 {
1025 return *containerWrapper_.pointer(position_);
1026 }
1027
1028 void increment()
1029 {
1030 ++position_;
1031 }
1032
1033 // Additional function needed by BidirectionalIterator
1034 void decrement()
1035 {
1036 --position_;
1037 }
1038
1039 // Additional function needed by RandomAccessIterator
1040 R elementAt(int i) const
1041 {
1042 return *containerWrapper_.pointer(position_+i);
1043 }
1044
1045 void advance(int n)
1046 {
1047 position_=position_+n;
1048 }
1049
1050 template<class OtherContainerWrapperIteratorType>
1051 std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType& other) const
1052 {
1053 assert(containerWrapper_.identical(other));
1054 return other.position_ - position_;
1055 }
1056
1057 std::ptrdiff_t index() const
1058 {
1059 return containerWrapper_.realIndex(position_);
1060 }
1061
1062 private:
1063 NonConstCW containerWrapper_;
1064 size_t position_;
1065 };
1066
1067
1068
1069 template<class M, class K, int n>
1070 void istl_assign_to_fmatrix(DenseMatrix<M>& fm, const DiagonalMatrix<K,n>& s)
1071 {
1072 assert( fm.rows() == n );
1073 assert( fm.cols() == n );
1074 fm = K();
1075 for(int i=0; i<n; ++i)
1076 fm[i][i] = s.diagonal()[i];
1077 }
1078 /* @} */
1079} // end namespace
1080#endif
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:273
Iterator class for sparse vector-like containers.
Definition: diagonalmatrix.hh:960
A dense n x m matrix.
Definition: densematrix.hh:192
size_type cols() const
number of columns
Definition: densematrix.hh:710
size_type rows() const
number of rows
Definition: densematrix.hh:704
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
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 infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:553
FieldTraits< value_type >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:539
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:49
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:178
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
A few common exception classes.
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Implements a generic iterator class for writing stl conformant iterators.
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:190
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: diagonalmatrix.hh:339
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition: diagonalmatrix.hh:228
std::size_t size_type
The type used for the index access and size operations.
Definition: diagonalmatrix.hh:63
size_type dim() const
dimension of the vector space
Definition: diagonalmatrix.hh:759
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:165
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition: diagonalmatrix.hh:513
DiagonalMatrix()
Default constructor.
Definition: diagonalmatrix.hh:97
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:850
void usmhv(const K &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: diagonalmatrix.hh:375
void usmv(const K &alpha, const X &x, Y &y) const
y += alpha A x
Definition: diagonalmatrix.hh:351
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:660
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:732
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:167
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition: diagonalmatrix.hh:460
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:161
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:824
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition: diagonalmatrix.hh:501
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:417
Iterator beforeBegin()
Definition: diagonalmatrix.hh:873
size_type M() const
number of blocks in column direction
Definition: diagonalmatrix.hh:450
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition: diagonalmatrix.hh:489
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:127
ConstIterator begin() const
begin ConstIterator
Definition: diagonalmatrix.hh:719
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:881
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition: diagonalmatrix.hh:207
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:687
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: diagonalmatrix.hh:327
DiagonalMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition: diagonalmatrix.hh:100
ContainerWrapperIterator< DiagonalRowVector< K, n >, K, K & > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:848
Iterator beforeEnd()
Definition: diagonalmatrix.hh:866
void umtv(const X &x, Y &y) const
y += A^T x
Definition: diagonalmatrix.hh:291
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:716
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: diagonalmatrix.hh:406
void umv(const X &x, Y &y) const
y += A x
Definition: diagonalmatrix.hh:279
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:125
void mv(const X &x, Y &y) const
y = A x
Definition: diagonalmatrix.hh:260
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: diagonalmatrix.hh:388
ConstIterator end() const
end iterator
Definition: diagonalmatrix.hh:176
size_type rowIndex() const
index of this row in surrounding matrix
Definition: diagonalmatrix.hh:765
bool operator!=(const DiagonalMatrix &other) const
incomparison operator
Definition: diagonalmatrix.hh:250
ConstIterator begin() const
begin iterator
Definition: diagonalmatrix.hh:170
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:853
void mmv(const X &x, Y &y) const
y -= A x
Definition: diagonalmatrix.hh:315
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition: diagonalmatrix.hh:235
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:163
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition: diagonalmatrix.hh:118
Iterator end()
end iterator
Definition: diagonalmatrix.hh:140
void usmtv(const K &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: diagonalmatrix.hh:363
DiagonalRowVector()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:820
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: diagonalmatrix.hh:394
void mtv(const X &x, Y &y) const
y = A^T x
Definition: diagonalmatrix.hh:272
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:879
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition: diagonalmatrix.hh:507
void invert()
Compute inverse.
Definition: diagonalmatrix.hh:424
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:495
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: diagonalmatrix.hh:753
row_type::Iterator ColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:131
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:811
reference operator[](size_type i)
Return reference object as row replacement.
Definition: diagonalmatrix.hh:483
size_type N() const
number of blocks in row direction
Definition: diagonalmatrix.hh:444
Iterator end()
end iterator
Definition: diagonalmatrix.hh:859
DiagonalMatrix(const FieldVector< K, n > &diag)
Constructor initializing the diagonal with a vector.
Definition: diagonalmatrix.hh:105
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:817
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: diagonalmatrix.hh:400
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition: diagonalmatrix.hh:200
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:60
void umhv(const X &x, Y &y) const
y += A^H x
Definition: diagonalmatrix.hh:303
Iterator beforeBegin()
Definition: diagonalmatrix.hh:154
ConstIterator end() const
end ConstIterator
Definition: diagonalmatrix.hh:725
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:666
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition: diagonalmatrix.hh:111
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:681
Iterator beforeEnd()
Definition: diagonalmatrix.hh:147
friend std::ostream & operator<<(std::ostream &s, const DiagonalMatrix< K, n > &a)
Sends the matrix to an output stream.
Definition: diagonalmatrix.hh:472
K value_type
export the type representing the field
Definition: diagonalmatrix.hh:56
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:663
K determinant() const
calculates the determinant of this matrix
Definition: diagonalmatrix.hh:431
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:739
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:714
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:134
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition: diagonalmatrix.hh:244
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition: diagonalmatrix.hh:72
Iterator RowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:129
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:814
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:183
const K & diagonal() const
the diagonal value
Definition: diagonalmatrix.hh:771
@ blocklevel
The number of block levels we contain. This is 1.
Definition: diagonalmatrix.hh:68
@ cols
The number of columns.
Definition: diagonalmatrix.hh:84
@ rows
The number of rows.
Definition: diagonalmatrix.hh:82
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:231
Dune namespace.
Definition: alignment.hh:14
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:103
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:115
Removes a const qualifier while preserving others.
Definition: typetraits.hh:176
Traits for type conversions and type information.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)