Dune Core Modules (2.8.0)

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 <algorithm>
11#include <cassert>
12#include <cmath>
13#include <complex>
14#include <cstddef>
15#include <initializer_list>
16#include <iostream>
17#include <memory>
18
26
27
28namespace Dune {
29
30 template< class K, int n > class DiagonalRowVectorConst;
31 template< class K, int n > class DiagonalRowVector;
32 template< class DiagonalMatrixType > class DiagonalMatrixWrapper;
33 template< class C, class T, class R> class ContainerWrapperIterator;
34
49 template<class K, int n>
51 {
52 typedef DiagonalMatrixWrapper< DiagonalMatrix<K,n> > WrapperType;
53
54 public:
55 //===== type definitions and constants
56
58 typedef K value_type;
59 typedef value_type field_type;
60
62 typedef K block_type;
63
65 typedef std::size_t size_type;
66
68 enum {
70 blocklevel = 1
71 };
72
74 typedef DiagonalRowVector<K,n> row_type;
75 typedef row_type reference;
76 typedef row_type row_reference;
77 typedef DiagonalRowVectorConst<K,n> const_row_type;
78 typedef const_row_type const_reference;
79 typedef const_row_type const_row_reference;
80
82 enum {
84 rows = n,
86 cols = n
87 };
88
89 //==== size
90
91 static constexpr size_type size ()
92 {
93 return rows;
94 }
95
96 //===== constructors
97
99 constexpr DiagonalMatrix() = default;
100
102 DiagonalMatrix (const K& k)
103 : diag_(k)
104 {}
105
108 : diag_(diag)
109 {}
110
119 DiagonalMatrix (std::initializer_list<K> const &l)
120 {
121 std::copy_n(l.begin(), std::min(static_cast<std::size_t>(rows),
122 l.size()),
123 diag_.begin());
124 }
125
128 {
129 diag_ = k;
130 return *this;
131 }
132
134 bool identical(const DiagonalMatrix<K,n>& other) const
135 {
136 return (this==&other);
137 }
138
139 //===== iterator interface to rows of the matrix
148
151 {
152 return Iterator(WrapperType(this),0);
153 }
154
157 {
158 return Iterator(WrapperType(this),n);
159 }
160
164 {
165 return Iterator(WrapperType(this),n-1);
166 }
167
171 {
172 return Iterator(WrapperType(this),-1);
173 }
174
175
184
187 {
188 return ConstIterator(WrapperType(this),0);
189 }
190
193 {
194 return ConstIterator(WrapperType(this),n);
195 }
196
200 {
201 return ConstIterator(WrapperType(this),n-1);
202 }
203
207 {
208 return ConstIterator(WrapperType(this),-1);
209 }
210
211
212
213 //===== vector space arithmetic
214
217 {
218 diag_ += y.diag_;
219 return *this;
220 }
221
224 {
225 diag_ -= y.diag_;
226 return *this;
227 }
228
231 {
232 diag_ += k;
233 return *this;
234 }
235
238 {
239 diag_ -= k;
240 return *this;
241 }
242
245 {
246 diag_ *= k;
247 return *this;
248 }
249
252 {
253 diag_ /= k;
254 return *this;
255 }
256
257 //===== comparison ops
258
260 bool operator==(const DiagonalMatrix& other) const
261 {
262 return diag_==other.diagonal();
263 }
264
266 bool operator!=(const DiagonalMatrix& other) const
267 {
268 return diag_!=other.diagonal();
269 }
270
271
272 //===== linear maps
273
275 template<class X, class Y>
276 void mv (const X& x, Y& y) const
277 {
278#ifdef DUNE_FMatrix_WITH_CHECKING
279 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
280 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
281#endif
282 for (size_type i=0; i<n; ++i)
283 y[i] = diag_[i] * x[i];
284 }
285
287 template<class X, class Y>
288 void mtv (const X& x, Y& y) const
289 {
290 mv(x, y);
291 }
292
294 template<class X, class Y>
295 void umv (const X& x, Y& y) const
296 {
297#ifdef DUNE_FMatrix_WITH_CHECKING
298 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
299 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
300#endif
301 for (size_type i=0; i<n; ++i)
302 y[i] += diag_[i] * x[i];
303 }
304
306 template<class X, class Y>
307 void umtv (const X& x, Y& y) const
308 {
309#ifdef DUNE_FMatrix_WITH_CHECKING
310 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
311 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
312#endif
313 for (size_type i=0; i<n; ++i)
314 y[i] += diag_[i] * x[i];
315 }
316
318 template<class X, class Y>
319 void umhv (const X& x, Y& y) const
320 {
321#ifdef DUNE_FMatrix_WITH_CHECKING
322 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
323 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
324#endif
325 for (size_type i=0; i<n; i++)
326 y[i] += conjugateComplex(diag_[i])*x[i];
327 }
328
330 template<class X, class Y>
331 void mmv (const X& x, Y& y) const
332 {
333#ifdef DUNE_FMatrix_WITH_CHECKING
334 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
335 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
336#endif
337 for (size_type i=0; i<n; ++i)
338 y[i] -= diag_[i] * x[i];
339 }
340
342 template<class X, class Y>
343 void mmtv (const X& x, Y& y) const
344 {
345#ifdef DUNE_FMatrix_WITH_CHECKING
346 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
347 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
348#endif
349 for (size_type i=0; i<n; ++i)
350 y[i] -= diag_[i] * x[i];
351 }
352
354 template<class X, class Y>
355 void mmhv (const X& x, Y& y) const
356 {
357#ifdef DUNE_FMatrix_WITH_CHECKING
358 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
359 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
360#endif
361 for (size_type i=0; i<n; i++)
362 y[i] -= conjugateComplex(diag_[i])*x[i];
363 }
364
366 template<class X, class Y>
367 void usmv (const typename FieldTraits<Y>::field_type & alpha,
368 const X& x, Y& y) const
369 {
370#ifdef DUNE_FMatrix_WITH_CHECKING
371 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
372 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
373#endif
374 for (size_type i=0; i<n; i++)
375 y[i] += alpha * diag_[i] * x[i];
376 }
377
379 template<class X, class Y>
380 void usmtv (const typename FieldTraits<Y>::field_type & alpha,
381 const X& x, Y& y) const
382 {
383#ifdef DUNE_FMatrix_WITH_CHECKING
384 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
385 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
386#endif
387 for (size_type i=0; i<n; i++)
388 y[i] += alpha * diag_[i] * x[i];
389 }
390
392 template<class X, class Y>
393 void usmhv (const typename FieldTraits<Y>::field_type & alpha,
394 const X& x, Y& y) const
395 {
396#ifdef DUNE_FMatrix_WITH_CHECKING
397 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
398 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
399#endif
400 for (size_type i=0; i<n; i++)
401 y[i] += alpha * conjugateComplex(diag_[i]) * x[i];
402 }
403
404 //===== norms
405
407 double frobenius_norm () const
408 {
409 return diag_.two_norm();
410 }
411
413 double frobenius_norm2 () const
414 {
415 return diag_.two_norm2();
416 }
417
419 double infinity_norm () const
420 {
421 return diag_.infinity_norm();
422 }
423
425 double infinity_norm_real () const
426 {
427 return diag_.infinity_norm_real();
428 }
429
430
431
432 //===== solve
433
435 template<class V>
436 void solve (V& x, const V& b) const
437 {
438 for (int i=0; i<n; i++)
439 x[i] = b[i]/diag_[i];
440 }
441
443 void invert()
444 {
445 using real_type = typename FieldTraits<K>::real_type;
446 for (int i=0; i<n; i++)
447 diag_[i] = real_type(1.0)/diag_[i];
448 }
449
451 K determinant () const
452 {
453 K det = diag_[0];
454 for (int i=1; i<n; i++)
455 det *= diag_[i];
456 return det;
457 }
458
459
460
461 //===== sizes
462
464 static constexpr size_type N ()
465 {
466 return n;
467 }
468
470 static constexpr size_type M ()
471 {
472 return n;
473 }
474
475
476
477 //===== query
478
480 bool exists (size_type i, size_type j) const
481 {
482 DUNE_ASSERT_BOUNDS(i >= 0 && i < n);
483 DUNE_ASSERT_BOUNDS(j >= 0 && j < n);
484 return i==j;
485 }
486
487
488
490 friend std::ostream& operator<< (std::ostream& s, const DiagonalMatrix<K,n>& a)
491 {
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) << " ";
495 s << std::endl;
496 }
497 return s;
498 }
499
502 {
503 return reference(const_cast<K*>(&diag_[i]), i);
504 }
505
507 const_reference operator[](size_type i) const
508 {
509 return const_reference(const_cast<K*>(&diag_[i]), i);
510 }
511
513 const K& diagonal(size_type i) const
514 {
515 return diag_[i];
516 }
517
520 {
521 return diag_[i];
522 }
523
526 {
527 return diag_;
528 }
529
532 {
533 return diag_;
534 }
535
536 private:
537
538 // the data, a FieldVector storing the diagonal
539 FieldVector<K,n> diag_;
540 };
541
542 template< class K, int n >
543 struct FieldTraits< DiagonalMatrix<K,n> >
544 {
545 typedef typename FieldTraits<K>::field_type field_type;
546 typedef typename FieldTraits<K>::real_type real_type;
547 };
548
549
550#ifndef DOXYGEN // hide specialization
553 template< class K >
554 class DiagonalMatrix<K, 1> : public FieldMatrix<K, 1, 1>
555 {
556 typedef FieldMatrix<K,1,1> Base;
557 public:
559 typedef typename Base::size_type size_type;
560
562 enum {
565 blocklevel = 1
566 };
567
568 typedef typename Base::row_type row_type;
569
570 typedef typename Base::row_reference row_reference;
571 typedef typename Base::const_row_reference const_row_reference;
572
574 enum {
577 rows = 1,
580 cols = 1
581 };
582
583
585 constexpr DiagonalMatrix() = default;
586
588 DiagonalMatrix(const K& scalar)
589 {
590 (*this)[0][0] = scalar;
591 }
592
594 const K& diagonal(size_type) const
595 {
596 return (*this)[0][0];
597 }
598
601 {
602 return (*this)[0][0];
603 }
604
606 const FieldVector<K,1>& diagonal() const
607 {
608 return (*this)[0];
609 }
610
612 FieldVector<K,1>& diagonal()
613 {
614 return (*this)[0];
615 }
616
617 };
618#endif
619
620
621 template<class DiagonalMatrixType>
622 class DiagonalMatrixWrapper
623 {
624 typedef typename DiagonalMatrixType::reference reference;
625 typedef typename DiagonalMatrixType::const_reference const_reference;
626 typedef typename DiagonalMatrixType::field_type K;
627 typedef DiagonalRowVector<K, DiagonalMatrixType::rows> row_type;
628 typedef std::size_t size_type;
629 typedef DiagonalMatrixWrapper< DiagonalMatrixType> MyType;
630
631 friend class ContainerWrapperIterator<const MyType, reference, reference>;
632 friend class ContainerWrapperIterator<const MyType, const_reference, const_reference>;
633
634 public:
635
636 DiagonalMatrixWrapper() :
637 mat_(0)
638 {}
639
640 DiagonalMatrixWrapper(const DiagonalMatrixType* mat) :
641 mat_(const_cast<DiagonalMatrixType*>(mat))
642 {}
643
644 size_type realIndex(int i) const
645 {
646 return i;
647 }
648
649 row_type* pointer(int i) const
650 {
651 row_ = row_type(&(mat_->diagonal(i)), i);
652 return &row_;
653 }
654
655 bool identical(const DiagonalMatrixWrapper& other) const
656 {
657 return mat_==other.mat_;
658 }
659
660 private:
661
662 mutable DiagonalMatrixType* mat_;
663 mutable row_type row_;
664 };
665
669 template< class K, int n >
670 class DiagonalRowVectorConst
671 {
672 template<class DiagonalMatrixType>
673 friend class DiagonalMatrixWrapper;
674 friend class ContainerWrapperIterator<DiagonalRowVectorConst<K,n>, const K, const K&>;
675
676 public:
677 // remember size of vector
678 enum { dimension = n };
679
680 // standard constructor and everything is sufficient ...
681
682 //===== type definitions and constants
683
685 typedef K field_type;
686
688 typedef K block_type;
689
691 typedef std::size_t size_type;
692
694 enum {
696 blocklevel = 1
697 };
698
700 enum {
702 size = n
703 };
704
707 p_(0),
708 row_(0)
709 {}
710
712 explicit DiagonalRowVectorConst (K* p, int col) :
713 p_(p),
714 row_(col)
715 {}
716
717 //===== access to components
718
720 const K& operator[] ([[maybe_unused]] size_type i) const
721 {
722 DUNE_ASSERT_BOUNDS(i == row_);
723 return *p_;
724 }
725
726 // check if row is identical to other row (not only identical values)
727 // since this is a proxy class we need to check equality of the stored pointer
728 bool identical(const DiagonalRowVectorConst<K,n>& other) const
729 {
730 return ((p_ == other.p_)and (row_ == other.row_));
731 }
732
737
740 {
741 return ConstIterator(*this,0);
742 }
743
746 {
747 return ConstIterator(*this,1);
748 }
749
753 {
754 return ConstIterator(*this,0);
755 }
756
760 {
761 return ConstIterator(*this,-1);
762 }
763
765 bool operator== (const DiagonalRowVectorConst& y) const
766 {
767 return ((p_==y.p_)and (row_==y.row_));
768 }
769
770 //===== sizes
771
773 size_type N () const
774 {
775 return n;
776 }
777
779 size_type dim () const
780 {
781 return n;
782 }
783
786 {
787 return row_;
788 }
789
791 const K& diagonal() const
792 {
793 return *p_;
794 }
795
796 protected:
797
798 size_type realIndex([[maybe_unused]] int i) const
799 {
800 return rowIndex();
801 }
802
803 K* pointer([[maybe_unused]] size_type i) const
804 {
805 return const_cast<K*>(p_);
806 }
807
808 DiagonalRowVectorConst* operator&()
809 {
810 return this;
811 }
812
813 // the data, very simply a pointer to the diagonal value and the row number
814 K* p_;
815 size_type row_;
816 };
817
818 template< class K, int n >
819 class DiagonalRowVector : public DiagonalRowVectorConst<K,n>
820 {
821 template<class DiagonalMatrixType>
822 friend class DiagonalMatrixWrapper;
823 friend class ContainerWrapperIterator<DiagonalRowVector<K,n>, K, K&>;
824
825 public:
826 // standard constructor and everything is sufficient ...
827
828 //===== type definitions and constants
829
831 typedef K field_type;
832
834 typedef K block_type;
835
837 typedef std::size_t size_type;
838
840 DiagonalRowVector() : DiagonalRowVectorConst<K,n>()
841 {}
842
844 explicit DiagonalRowVector (K* p, int col) : DiagonalRowVectorConst<K,n>(p, col)
845 {}
846
847 //===== assignment from scalar
849 DiagonalRowVector& operator= (const K& k)
850 {
851 *p_ = k;
852 return *this;
853 }
854
855 //===== access to components
856
858 K& operator[] ([[maybe_unused]] size_type i)
859 {
860 DUNE_ASSERT_BOUNDS(i == row_);
861 return *p_;
862 }
863
868
871 {
872 return Iterator(*this, 0);
873 }
874
877 {
878 return Iterator(*this, 1);
879 }
880
884 {
885 return Iterator(*this, 0);
886 }
887
891 {
892 return Iterator(*this, -1);
893 }
894
899
900 using DiagonalRowVectorConst<K,n>::identical;
901 using DiagonalRowVectorConst<K,n>::operator[];
902 using DiagonalRowVectorConst<K,n>::operator==;
903 using DiagonalRowVectorConst<K,n>::begin;
904 using DiagonalRowVectorConst<K,n>::end;
905 using DiagonalRowVectorConst<K,n>::beforeEnd;
906 using DiagonalRowVectorConst<K,n>::beforeBegin;
907 using DiagonalRowVectorConst<K,n>::N;
908 using DiagonalRowVectorConst<K,n>::dim;
909 using DiagonalRowVectorConst<K,n>::rowIndex;
910 using DiagonalRowVectorConst<K,n>::diagonal;
911
912 protected:
913
914 DiagonalRowVector* operator&()
915 {
916 return this;
917 }
918
919 private:
920
921 using DiagonalRowVectorConst<K,n>::p_;
922 using DiagonalRowVectorConst<K,n>::row_;
923 };
924
925
926 // implement type traits
927 template<class K, int n>
928 struct const_reference< DiagonalRowVector<K,n> >
929 {
930 typedef DiagonalRowVectorConst<K,n> type;
931 };
932
933 template<class K, int n>
934 struct const_reference< DiagonalRowVectorConst<K,n> >
935 {
936 typedef DiagonalRowVectorConst<K,n> type;
937 };
938
939 template<class K, int n>
940 struct mutable_reference< DiagonalRowVector<K,n> >
941 {
942 typedef DiagonalRowVector<K,n> type;
943 };
944
945 template<class K, int n>
946 struct mutable_reference< DiagonalRowVectorConst<K,n> >
947 {
948 typedef DiagonalRowVector<K,n> type;
949 };
950
951
952
975 template<class CW, class T, class R>
976 class ContainerWrapperIterator : public BidirectionalIteratorFacade<ContainerWrapperIterator<CW,T,R>,T, R, int>
977 {
978 typedef typename std::remove_const<CW>::type NonConstCW;
979
980 friend class ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type>;
981 friend class ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type>;
982
983 typedef ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type> MyType;
984 typedef ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type> MyConstType;
985
986 public:
987
988 // Constructors needed by the facade iterators.
990 containerWrapper_(),
991 position_(0)
992 {}
993
994 ContainerWrapperIterator(CW containerWrapper, int position) :
995 containerWrapper_(containerWrapper),
996 position_(position)
997 {}
998
999 template<class OtherContainerWrapperIteratorType>
1000 ContainerWrapperIterator(OtherContainerWrapperIteratorType& other) :
1001 containerWrapper_(other.containerWrapper_),
1002 position_(other.position_)
1003 {}
1004
1005 ContainerWrapperIterator(const MyType& other) :
1006 containerWrapper_(other.containerWrapper_),
1007 position_(other.position_)
1008 {}
1009
1011 containerWrapper_(other.containerWrapper_),
1012 position_(other.position_)
1013 {}
1014
1015 template<class OtherContainerWrapperIteratorType>
1016 ContainerWrapperIterator& operator=(OtherContainerWrapperIteratorType& other)
1017 {
1018 containerWrapper_ = other.containerWrapper_;
1019 position_ = other.position_;
1020 return *this;
1021 }
1022
1023 // This operator is needed since we can not get the address of the
1024 // temporary object returned by dereference
1025 T* operator->() const
1026 {
1027 return containerWrapper_.pointer(position_);
1028 }
1029
1030 // Methods needed by the forward iterator
1031 bool equals(const MyType& other) const
1032 {
1033 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1034 }
1035
1036 bool equals(const MyConstType& other) const
1037 {
1038 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1039 }
1040
1041 R dereference() const
1042 {
1043 return *containerWrapper_.pointer(position_);
1044 }
1045
1046 void increment()
1047 {
1048 ++position_;
1049 }
1050
1051 // Additional function needed by BidirectionalIterator
1052 void decrement()
1053 {
1054 --position_;
1055 }
1056
1057 // Additional function needed by RandomAccessIterator
1058 R elementAt(int i) const
1059 {
1060 return *containerWrapper_.pointer(position_+i);
1061 }
1062
1063 void advance(int n)
1064 {
1065 position_=position_+n;
1066 }
1067
1068 template<class OtherContainerWrapperIteratorType>
1069 std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType& other) const
1070 {
1071 assert(containerWrapper_.identical(other));
1072 return other.position_ - position_;
1073 }
1074
1075 std::ptrdiff_t index() const
1076 {
1077 return containerWrapper_.realIndex(position_);
1078 }
1079
1080 private:
1081 NonConstCW containerWrapper_;
1082 size_t position_;
1083 };
1084
1085 template <class DenseMatrix, class field, int N>
1087 static void apply(DenseMatrix& denseMatrix,
1088 DiagonalMatrix<field, N> const& rhs) {
1089 DUNE_ASSERT_BOUNDS(denseMatrix.M() == N);
1090 DUNE_ASSERT_BOUNDS(denseMatrix.N() == N);
1091 denseMatrix = field(0);
1092 for (int i = 0; i < N; ++i)
1093 denseMatrix[i][i] = rhs.diagonal()[i];
1094 }
1095 };
1096 /* @} */
1097} // end namespace
1098#endif
Macro for wrapping boundary checks.
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:272
Iterator class for sparse vector-like containers.
Definition: diagonalmatrix.hh:977
A dense n x m matrix.
Definition: densematrix.hh:165
constexpr size_type M() const
number of columns
Definition: densematrix.hh:731
constexpr size_type N() const
number of rows
Definition: densematrix.hh:725
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:651
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:642
Iterator begin()
begin iterator
Definition: densevector.hh:348
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:662
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:678
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:51
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:151
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
A few common exception classes.
Traits for type conversions and type information.
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.
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:206
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: diagonalmatrix.hh:355
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition: diagonalmatrix.hh:244
std::size_t size_type
The type used for the index access and size operations.
Definition: diagonalmatrix.hh:65
size_type dim() const
dimension of the vector space
Definition: diagonalmatrix.hh:779
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:181
static constexpr size_type M()
number of blocks in column direction
Definition: diagonalmatrix.hh:470
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition: diagonalmatrix.hh:531
void usmhv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: diagonalmatrix.hh:393
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:867
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:685
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:752
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:183
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition: diagonalmatrix.hh:480
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:177
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:844
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition: diagonalmatrix.hh:519
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:436
static constexpr size_type N()
number of blocks in row direction
Definition: diagonalmatrix.hh:464
Iterator beforeBegin()
Definition: diagonalmatrix.hh:890
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition: diagonalmatrix.hh:507
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:143
ConstIterator begin() const
begin ConstIterator
Definition: diagonalmatrix.hh:739
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:898
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition: diagonalmatrix.hh:223
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:712
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: diagonalmatrix.hh:343
DiagonalMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition: diagonalmatrix.hh:102
ContainerWrapperIterator< DiagonalRowVector< K, n >, K, K & > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:865
Iterator beforeEnd()
Definition: diagonalmatrix.hh:883
void umtv(const X &x, Y &y) const
y += A^T x
Definition: diagonalmatrix.hh:307
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:736
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: diagonalmatrix.hh:425
void umv(const X &x, Y &y) const
y += A x
Definition: diagonalmatrix.hh:295
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:141
void mv(const X &x, Y &y) const
y = A x
Definition: diagonalmatrix.hh:276
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: diagonalmatrix.hh:407
ConstIterator end() const
end iterator
Definition: diagonalmatrix.hh:192
size_type rowIndex() const
index of this row in surrounding matrix
Definition: diagonalmatrix.hh:785
bool operator!=(const DiagonalMatrix &other) const
incomparison operator
Definition: diagonalmatrix.hh:266
ConstIterator begin() const
begin iterator
Definition: diagonalmatrix.hh:186
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:870
void mmv(const X &x, Y &y) const
y -= A x
Definition: diagonalmatrix.hh:331
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition: diagonalmatrix.hh:251
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:179
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition: diagonalmatrix.hh:134
Iterator end()
end iterator
Definition: diagonalmatrix.hh:156
DiagonalRowVector()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:840
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: diagonalmatrix.hh:413
constexpr DiagonalMatrix()=default
Default constructor.
void mtv(const X &x, Y &y) const
y = A^T x
Definition: diagonalmatrix.hh:288
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:896
void usmtv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: diagonalmatrix.hh:380
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition: diagonalmatrix.hh:525
void invert()
Compute inverse.
Definition: diagonalmatrix.hh:443
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:513
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: diagonalmatrix.hh:773
DiagonalMatrix(std::initializer_list< K > const &l)
Construct diagonal matrix from an initializer list.
Definition: diagonalmatrix.hh:119
row_type::Iterator ColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:147
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:831
reference operator[](size_type i)
Return reference object as row replacement.
Definition: diagonalmatrix.hh:501
Iterator end()
end iterator
Definition: diagonalmatrix.hh:876
DiagonalMatrix(const FieldVector< K, n > &diag)
Constructor initializing the diagonal with a vector.
Definition: diagonalmatrix.hh:107
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:837
void usmv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A x
Definition: diagonalmatrix.hh:367
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: diagonalmatrix.hh:419
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition: diagonalmatrix.hh:216
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:62
void umhv(const X &x, Y &y) const
y += A^H x
Definition: diagonalmatrix.hh:319
Iterator beforeBegin()
Definition: diagonalmatrix.hh:170
ConstIterator end() const
end ConstIterator
Definition: diagonalmatrix.hh:745
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:691
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition: diagonalmatrix.hh:127
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:706
Iterator beforeEnd()
Definition: diagonalmatrix.hh:163
friend std::ostream & operator<<(std::ostream &s, const DiagonalMatrix< K, n > &a)
Sends the matrix to an output stream.
Definition: diagonalmatrix.hh:490
K value_type
export the type representing the field
Definition: diagonalmatrix.hh:58
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:688
K determinant() const
calculates the determinant of this matrix
Definition: diagonalmatrix.hh:451
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:759
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:734
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:150
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition: diagonalmatrix.hh:260
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition: diagonalmatrix.hh:74
Iterator RowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:145
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:834
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:199
const K & diagonal() const
the diagonal value
Definition: diagonalmatrix.hh:791
@ blocklevel
The number of block levels we contain. This is 1.
Definition: diagonalmatrix.hh:70
@ cols
The number of columns.
Definition: diagonalmatrix.hh:86
@ rows
The number of rows.
Definition: diagonalmatrix.hh:84
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
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:235
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:87
Dune namespace.
Definition: alignedallocator.hh:11
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:161
you have to specialize this structure for any type that should be assignable to a DenseMatrix
Definition: densematrix.hh:84
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:114
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)