dune-common 2.12-git
Loading...
Searching...
No Matches
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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_DIAGONAL_MATRIX_HH
6#define DUNE_DIAGONAL_MATRIX_HH
7
12#include <algorithm>
13#include <cassert>
14#include <cmath>
15#include <complex>
16#include <cstddef>
17#include <initializer_list>
18#include <iostream>
19#include <memory>
20
32
33
34namespace Dune {
35
36 template< class K, int n > class DiagonalRowVectorConst;
37 template< class K, int n > class DiagonalRowVector;
38 template< class DiagonalMatrixType > class DiagonalMatrixWrapper;
39 template< class C, class T, class R> class ContainerWrapperIterator;
40
55 template<class K, int n>
57 {
58 template<class, int> friend class DiagonalMatrix;
60
61 public:
62 //===== type definitions and constants
63
65 typedef K value_type;
67
69 typedef K block_type;
70
73
75 constexpr static int blocklevel = 1;
76
84
86 constexpr static int rows = n;
88 constexpr static int cols = n;
89
90 //==== size
91
92 static constexpr size_type size ()
93 {
94 return rows;
95 }
96
97 //===== constructors
98
100 constexpr DiagonalMatrix() = default;
101
103 DiagonalMatrix (const K& k)
104 : diag_(k)
105 {}
106
109 : diag_(diag)
110 {}
111
121 {
122 std::copy_n(l.begin(), std::min<std::size_t>(rows, l.size()),
123 diag_.begin());
124 }
125
127 template <class OtherK>
129 : diag_(other.diag_)
130 {}
131
134 {
135 diag_ = k;
136 return *this;
137 }
138
140 template <class OtherK>
142 {
143 diag_ = other.diag_;
144 return *this;
145 }
146
148 bool identical(const DiagonalMatrix<K,n>& other) const
149 {
150 return (this==&other);
151 }
152
155 {
156 return *this;
157 }
158
159 //===== iterator interface to rows of the matrix
168
171 {
172 return Iterator(WrapperType(this),0);
173 }
174
177 {
178 return Iterator(WrapperType(this),n);
179 }
180
184 {
185 return Iterator(WrapperType(this),n-1);
186 }
187
191 {
192 return Iterator(WrapperType(this),-1);
193 }
194
195
204
207 {
208 return ConstIterator(WrapperType(this),0);
209 }
210
213 {
214 return ConstIterator(WrapperType(this),n);
215 }
216
220 {
221 return ConstIterator(WrapperType(this),n-1);
222 }
223
227 {
228 return ConstIterator(WrapperType(this),-1);
229 }
230
231
232
233 //===== vector space arithmetic
234
237 {
238 diag_ += y.diag_;
239 return *this;
240 }
241
244 {
245 diag_ -= y.diag_;
246 return *this;
247 }
248
251 {
252 diag_ += k;
253 return *this;
254 }
255
258 {
259 diag_ -= k;
260 return *this;
261 }
262
265 {
266 diag_ *= k;
267 return *this;
268 }
269
272 {
273 diag_ /= k;
274 return *this;
275 }
276
277 //===== comparison ops
278
280 bool operator==(const DiagonalMatrix& other) const
281 {
282 return diag_==other.diagonal();
283 }
284
286 bool operator!=(const DiagonalMatrix& other) const
287 {
288 return diag_!=other.diagonal();
289 }
290
291
292 //===== linear maps
293
295 template<class X, class Y>
296 void mv (const X& x, Y& y) const
297 {
298#ifdef DUNE_FMatrix_WITH_CHECKING
299 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
300 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
301#endif
302 for (size_type i=0; i<n; ++i)
303 y[i] = diag_[i] * x[i];
304 }
305
307 template<class X, class Y>
308 void mtv (const X& x, Y& y) const
309 {
310 mv(x, y);
311 }
312
314 template<class X, class Y>
315 void umv (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 umtv (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 umhv (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 mmv (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] -= diag_[i] * x[i];
359 }
360
362 template<class X, class Y>
363 void mmtv (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] -= diag_[i] * x[i];
371 }
372
374 template<class X, class Y>
375 void mmhv (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] -= conjugateComplex(diag_[i])*x[i];
383 }
384
386 template<class X, class Y>
387 void usmv (const typename FieldTraits<Y>::field_type & alpha,
388 const X& x, Y& y) const
389 {
390#ifdef DUNE_FMatrix_WITH_CHECKING
391 if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
392 if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
393#endif
394 for (size_type i=0; i<n; i++)
395 y[i] += alpha * diag_[i] * x[i];
396 }
397
399 template<class X, class Y>
400 void usmtv (const typename FieldTraits<Y>::field_type & alpha,
401 const X& x, Y& y) const
402 {
403#ifdef DUNE_FMatrix_WITH_CHECKING
404 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
405 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
406#endif
407 for (size_type i=0; i<n; i++)
408 y[i] += alpha * diag_[i] * x[i];
409 }
410
412 template<class X, class Y>
413 void usmhv (const typename FieldTraits<Y>::field_type & alpha,
414 const X& x, Y& y) const
415 {
416#ifdef DUNE_FMatrix_WITH_CHECKING
417 if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
418 if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
419#endif
420 for (size_type i=0; i<n; i++)
421 y[i] += alpha * conjugateComplex(diag_[i]) * x[i];
422 }
423
424 //===== norms
425
427 double frobenius_norm () const
428 {
429 return diag_.two_norm();
430 }
431
433 double frobenius_norm2 () const
434 {
435 return diag_.two_norm2();
436 }
437
439 double infinity_norm () const
440 {
441 return diag_.infinity_norm();
442 }
443
445 double infinity_norm_real () const
446 {
447 return diag_.infinity_norm_real();
448 }
449
450
451
452 //===== solve
453
455 template<class V>
456 void solve (V& x, const V& b) const
457 {
458 for (int i=0; i<n; i++)
459 x[i] = b[i]/diag_[i];
460 }
461
463 void invert()
464 {
465 using real_type = typename FieldTraits<K>::real_type;
466 for (int i=0; i<n; i++)
467 diag_[i] = real_type(1.0)/diag_[i];
468 }
469
471 K determinant () const
472 {
473 K det = diag_[0];
474 for (int i=1; i<n; i++)
475 det *= diag_[i];
476 return det;
477 }
478
479
480
481 //===== matrix-matrix multiplication
482
485 template <class OtherScalar>
486 friend auto operator* ( const DiagonalMatrix& matrixA,
487 const DiagonalMatrix<OtherScalar, n>& matrixB)
488 {
490 for(int i=0; i<n; ++i)
491 result.diagonal(i) = matrixA.diagonal(i)*matrixB.diagonal(i);
492 return result;
493 }
494
504 template <class OtherMatrix,
505 std::enable_if_t<(Impl::IsDenseMatrix<OtherMatrix>::value), int> = 0,
506 std::enable_if_t<(not Impl::IsFieldMatrix<OtherMatrix>::value), int> = 0>
507 friend auto operator* ( const DiagonalMatrix& matrixA,
508 const OtherMatrix& matrixB)
509 {
510 using OtherField = typename FieldTraits<OtherMatrix>::field_type;
512
513 auto result = [&]{
514 if constexpr (Impl::IsStaticSizeMatrix_v<OtherMatrix>) {
515 static_assert(n == OtherMatrix::rows);
517 } else {
518 assert(n == matrixB.N());
519 return DynamicMatrix<F>{n,matrixB.M()};
520 }
521 }();
522
523 for (auto i : Dune::range(result.N()))
524 for (auto j : Dune::range(result.M()))
525 result[i][j] = matrixA.diagonal(i) * matrixB[i][j];
526 return result;
527 }
528
529 //===== sizes
530
532 static constexpr size_type N ()
533 {
534 return n;
535 }
536
538 static constexpr size_type M ()
539 {
540 return n;
541 }
542
543
544
545 //===== query
546
548 bool exists (size_type i, size_type j) const
549 {
550 DUNE_ASSERT_BOUNDS(i >= 0 && i < n);
551 DUNE_ASSERT_BOUNDS(j >= 0 && j < n);
552 return i==j;
553 }
554
555
556
559 {
560 for (size_type i=0; i<n; i++) {
561 for (size_type j=0; j<n; j++)
562 s << ((i==j) ? a.diag_[i] : 0) << " ";
563 s << std::endl;
564 }
565 return s;
566 }
567
570 {
571 return reference(const_cast<K*>(&diag_[i]), i);
572 }
573
576 {
577 return const_reference(const_cast<K*>(&diag_[i]), i);
578 }
579
581 const K& diagonal(size_type i) const
582 {
583 return diag_[i];
584 }
585
588 {
589 return diag_[i];
590 }
591
594 {
595 return diag_;
596 }
597
600 {
601 return diag_;
602 }
603
604 private:
605
606 // the data, a FieldVector storing the diagonal
607 FieldVector<K,n> diag_;
608 };
609
610 template< class K, int n >
616
617
618#ifndef DOXYGEN // hide specialization
621 template< class K >
622 class DiagonalMatrix<K, 1> : public FieldMatrix<K, 1, 1>
623 {
624 typedef FieldMatrix<K,1,1> Base;
625 public:
627 typedef typename Base::size_type size_type;
628
631 constexpr static int blocklevel = 1;
632
633 typedef typename Base::row_type row_type;
634
635 typedef typename Base::row_reference row_reference;
636 typedef typename Base::const_row_reference const_row_reference;
637
640 constexpr static int rows = 1;
643 constexpr static int cols = 1;
644
645
647 constexpr DiagonalMatrix() = default;
648
650 DiagonalMatrix(const K& scalar)
651 {
652 (*this)[0][0] = scalar;
653 }
654
656 template <class OtherK>
657 DiagonalMatrix(const DiagonalMatrix<OtherK,1>& other)
658 : Base(FieldMatrix<OtherK,1,1>(other))
659 {}
660
662 const K& diagonal(size_type) const
663 {
664 return (*this)[0][0];
665 }
666
669 {
670 return (*this)[0][0];
671 }
672
674 const FieldVector<K,1>& diagonal() const
675 {
676 return (*this)[0];
677 }
678
680 FieldVector<K,1>& diagonal()
681 {
682 return (*this)[0];
683 }
684
686 DiagonalMatrix<K, 1> transposed() const
687 {
688 return *this;
689 }
690
693 template <class OtherScalar>
694 friend auto operator* ( const DiagonalMatrix& matrixA,
695 const DiagonalMatrix<OtherScalar, 1>& matrixB)
696 {
697 return DiagonalMatrix<typename PromotionTraits<K,OtherScalar>::PromotedType, 1>{matrixA.diagonal(0)*matrixB.diagonal(0)};
698 }
699
700 template <class OtherMatrix,
701 std::enable_if_t<(Impl::IsDenseMatrix<OtherMatrix>::value), int> = 0,
702 std::enable_if_t<(not Impl::IsFieldMatrix<OtherMatrix>::value), int> = 0>
703 friend auto operator* ( const DiagonalMatrix& matrixA,
704 const OtherMatrix& matrixB)
705 {
706 using OtherField = typename FieldTraits<OtherMatrix>::field_type;
708
709 auto result = [&]{
710 if constexpr (Impl::IsStaticSizeMatrix_v<OtherMatrix>) {
711 static_assert(1 == OtherMatrix::rows);
712 return FieldMatrix<F, 1, OtherMatrix::cols>{};
713 } else {
714 assert(1 == matrixB.N());
715 return DynamicMatrix<F>{1,matrixB.M()};
716 }
717 }();
718
719 for (auto i : Dune::range(result.N()))
720 for (auto j : Dune::range(result.M()))
721 result[i][j] = matrixA.diagonal(i) * matrixB[i][j];
722 return result;
723 }
724
725 };
726#endif
727
728
729 template<class DiagonalMatrixType>
731 {
732 typedef typename DiagonalMatrixType::reference reference;
733 typedef typename DiagonalMatrixType::const_reference const_reference;
734 typedef typename DiagonalMatrixType::field_type K;
736 typedef std::size_t size_type;
738
739 friend class ContainerWrapperIterator<const MyType, reference, reference>;
740 friend class ContainerWrapperIterator<const MyType, const_reference, const_reference>;
741
742 public:
743
745 mat_(0)
746 {}
747
748 DiagonalMatrixWrapper(const DiagonalMatrixType* mat) :
749 mat_(const_cast<DiagonalMatrixType*>(mat))
750 {}
751
752 size_type realIndex(int i) const
753 {
754 return i;
755 }
756
757 row_type* pointer(int i) const
758 {
759 row_ = row_type(&(mat_->diagonal(i)), i);
760 return &row_;
761 }
762
763 bool identical(const DiagonalMatrixWrapper& other) const
764 {
765 return mat_==other.mat_;
766 }
767
768 private:
769
770 mutable DiagonalMatrixType* mat_;
771 mutable row_type row_;
772 };
773
777 template< class K, int n >
779 {
780 template<class DiagonalMatrixType>
782 friend class ContainerWrapperIterator<DiagonalRowVectorConst<K,n>, const K, const K&>;
783
784 public:
785 // remember size of vector
786 constexpr static int dimension = n;
787
788 // standard constructor and everything is sufficient ...
789
790 //===== type definitions and constants
791
793 typedef K field_type;
794
796 typedef K block_type;
797
800
802 constexpr static int blocklevel = 1;
803
805 constexpr static int size = n;
806
809 p_(0),
810 row_(0)
811 {}
812
814 explicit DiagonalRowVectorConst (K* p, int col) :
815 p_(p),
816 row_(col)
817 {}
818
819 //===== access to components
820
822 const K& operator[] ([[maybe_unused]] size_type i) const
823 {
825 return *p_;
826 }
827
828 // check if row is identical to other row (not only identical values)
829 // since this is a proxy class we need to check equality of the stored pointer
830 bool identical(const DiagonalRowVectorConst<K,n>& other) const
831 {
832 return ((p_ == other.p_)and (row_ == other.row_));
833 }
834
839
842 {
843 return ConstIterator(*this,0);
844 }
845
848 {
849 return ConstIterator(*this,1);
850 }
851
855 {
856 return ConstIterator(*this,0);
857 }
858
862 {
863 return ConstIterator(*this,-1);
864 }
865
868 {
869 return ((p_==y.p_)and (row_==y.row_));
870 }
871
872 //===== sizes
873
875 size_type N () const
876 {
877 return n;
878 }
879
881 size_type dim () const
882 {
883 return n;
884 }
885
888 {
889 return row_;
890 }
891
893 const K& diagonal() const
894 {
895 return *p_;
896 }
897
898 protected:
899
900 size_type realIndex([[maybe_unused]] int i) const
901 {
902 return rowIndex();
903 }
904
905 K* pointer([[maybe_unused]] size_type i) const
906 {
907 return const_cast<K*>(p_);
908 }
909
911 {
912 return this;
913 }
914
915 // the data, very simply a pointer to the diagonal value and the row number
916 K* p_;
918 };
919
920 template< class K, int n >
922 {
923 template<class DiagonalMatrixType>
925 friend class ContainerWrapperIterator<DiagonalRowVector<K,n>, K, K&>;
926
927 public:
928 // standard constructor and everything is sufficient ...
929
930 //===== type definitions and constants
931
933 typedef K field_type;
934
936 typedef K block_type;
937
940
944
946 explicit DiagonalRowVector (K* p, int col) : DiagonalRowVectorConst<K,n>(p, col)
947 {}
948
949 //===== assignment from scalar
952 {
953 *p_ = k;
954 return *this;
955 }
956
957 //===== access to components
958
960 K& operator[] ([[maybe_unused]] size_type i)
961 {
963 return *p_;
964 }
965
970
973 {
974 return Iterator(*this, 0);
975 }
976
979 {
980 return Iterator(*this, 1);
981 }
982
986 {
987 return Iterator(*this, 0);
988 }
989
993 {
994 return Iterator(*this, -1);
995 }
996
1001
1003 using DiagonalRowVectorConst<K,n>::operator[];
1004 using DiagonalRowVectorConst<K,n>::operator==;
1006 using DiagonalRowVectorConst<K,n>::end;
1009 using DiagonalRowVectorConst<K,n>::N;
1010 using DiagonalRowVectorConst<K,n>::dim;
1013
1014 protected:
1015
1017 {
1018 return this;
1019 }
1020
1021 private:
1022
1023 using DiagonalRowVectorConst<K,n>::p_;
1025 };
1026
1027
1028 // implement type traits
1029 template<class K, int n>
1034
1035 template<class K, int n>
1040
1041 template<class K, int n>
1046
1047 template<class K, int n>
1052
1053
1054
1077 template<class CW, class T, class R>
1078 class ContainerWrapperIterator : public BidirectionalIteratorFacade<ContainerWrapperIterator<CW,T,R>,T, R, int>
1079 {
1080 typedef typename std::remove_const<CW>::type NonConstCW;
1081
1082 friend class ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type>;
1083 friend class ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type>;
1084
1085 typedef ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type> MyType;
1086 typedef ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type> MyConstType;
1087
1088 public:
1089
1090 // Constructors needed by the facade iterators.
1092 containerWrapper_(),
1093 position_(0)
1094 {}
1095
1096 ContainerWrapperIterator(CW containerWrapper, int position) :
1097 containerWrapper_(containerWrapper),
1098 position_(position)
1099 {}
1100
1101 template<class OtherContainerWrapperIteratorType>
1102 ContainerWrapperIterator(OtherContainerWrapperIteratorType& other) :
1103 containerWrapper_(other.containerWrapper_),
1104 position_(other.position_)
1105 {}
1106
1108 containerWrapper_(other.containerWrapper_),
1109 position_(other.position_)
1110 {}
1111
1113 containerWrapper_(other.containerWrapper_),
1114 position_(other.position_)
1115 {}
1116
1117 template<class OtherContainerWrapperIteratorType>
1118 ContainerWrapperIterator& operator=(OtherContainerWrapperIteratorType& other)
1119 {
1120 containerWrapper_ = other.containerWrapper_;
1121 position_ = other.position_;
1122 return *this;
1123 }
1124
1125 // This operator is needed since we can not get the address of the
1126 // temporary object returned by dereference
1127 T* operator->() const
1128 {
1129 return containerWrapper_.pointer(position_);
1130 }
1131
1132 // Methods needed by the forward iterator
1133 bool equals(const MyType& other) const
1134 {
1135 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1136 }
1137
1138 bool equals(const MyConstType& other) const
1139 {
1140 return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1141 }
1142
1143 R dereference() const
1144 {
1145 return *containerWrapper_.pointer(position_);
1146 }
1147
1149 {
1150 ++position_;
1151 }
1152
1153 // Additional function needed by BidirectionalIterator
1155 {
1156 --position_;
1157 }
1158
1159 // Additional function needed by RandomAccessIterator
1160 R elementAt(int i) const
1161 {
1162 return *containerWrapper_.pointer(position_+i);
1163 }
1164
1165 void advance(int n)
1166 {
1167 position_=position_+n;
1168 }
1169
1170 template<class OtherContainerWrapperIteratorType>
1171 std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType& other) const
1172 {
1173 assert(containerWrapper_.identical(other));
1174 return other.position_ - position_;
1175 }
1176
1178 {
1179 return containerWrapper_.realIndex(position_);
1180 }
1181
1182 private:
1183 NonConstCW containerWrapper_;
1184 size_t position_;
1185 };
1186
1187 template <class DenseMatrix, class field, int N>
1189 static void apply(DenseMatrix& denseMatrix,
1190 DiagonalMatrix<field, N> const& rhs)
1192 {
1193#ifdef DUNE_CHECK_BOUNDS
1194 if (denseMatrix.M() != N || denseMatrix.N() != N)
1195 DUNE_THROW(Dune::RangeError, "Incompatible matrix dimensions in assignment.");
1196#endif // DUNE_CHECK_BOUNDS
1197
1198 denseMatrix = field(0);
1199 for (int i = 0; i < N; ++i)
1200 denseMatrix[i][i] = rhs.diagonal()[i];
1201 }
1202 };
1203 /* @} */
1204} // end namespace
1205#endif
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Macro for wrapping boundary checks.
Utilities for reduction like operations on ranges.
Type traits to determine the type of reals (when working with complex numbers)
Implements a generic iterator class for writing stl conformant iterators.
A few common exception classes.
This file implements a dense matrix with dynamic numbers of rows and columns.
Traits for type conversions and type information.
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition boundschecking.hh:30
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
free standing function for setting up a range based for loop over an integer range for (auto i: range...
Definition rangeutilities.hh:293
friend class DiagonalMatrix
Definition diagonalmatrix.hh:58
ConstIterator beforeBegin() const
Definition diagonalmatrix.hh:226
DiagonalMatrix< K, n > transposed() const
Return transposed of the matrix as DiagonalMatrix.
Definition diagonalmatrix.hh:154
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition diagonalmatrix.hh:375
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition diagonalmatrix.hh:264
FieldTraits< K >::field_type field_type
Definition diagonalmatrix.hh:613
std::size_t size_type
The type used for the index access and size operations.
Definition diagonalmatrix.hh:72
size_type dim() const
dimension of the vector space
Definition diagonalmatrix.hh:881
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition diagonalmatrix.hh:201
row_type row_reference
Definition diagonalmatrix.hh:80
K & operator[](size_type i)
random access
Definition diagonalmatrix.hh:960
ContainerWrapperIterator & operator=(OtherContainerWrapperIteratorType &other)
Definition diagonalmatrix.hh:1118
static constexpr int rows
The number of rows.
Definition diagonalmatrix.hh:86
static constexpr size_type M()
number of blocks in column direction
Definition diagonalmatrix.hh:538
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition diagonalmatrix.hh:599
void usmhv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition diagonalmatrix.hh:413
Iterator iterator
typedef for stl compliant access
Definition diagonalmatrix.hh:969
void increment()
Definition diagonalmatrix.hh:1148
static constexpr int blocklevel
The number of block levels we contain. This is the leaf, that is, 1.
Definition diagonalmatrix.hh:75
DiagonalRowVectorConst< K, n > type
Definition diagonalmatrix.hh:1038
T * operator->() const
Definition diagonalmatrix.hh:1127
static constexpr int size
The size of this vector.
Definition diagonalmatrix.hh:805
K * pointer(size_type i) const
Definition diagonalmatrix.hh:905
K field_type
export the type representing the field
Definition diagonalmatrix.hh:793
DiagonalRowVector< K, n > type
Definition diagonalmatrix.hh:1044
ConstIterator beforeEnd() const
Definition diagonalmatrix.hh:854
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition diagonalmatrix.hh:203
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition diagonalmatrix.hh:548
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition diagonalmatrix.hh:197
const_row_type const_row_reference
Definition diagonalmatrix.hh:83
static constexpr size_type size()
Definition diagonalmatrix.hh:92
size_type row_
Definition diagonalmatrix.hh:917
ContainerWrapperIterator(CW containerWrapper, int position)
Definition diagonalmatrix.hh:1096
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition diagonalmatrix.hh:946
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition diagonalmatrix.hh:587
void solve(V &x, const V &b) const
Solve system A x = b.
Definition diagonalmatrix.hh:456
static constexpr size_type N()
number of blocks in row direction
Definition diagonalmatrix.hh:532
Iterator beforeBegin()
Definition diagonalmatrix.hh:992
ContainerWrapperIterator(OtherContainerWrapperIteratorType &other)
Definition diagonalmatrix.hh:1102
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition diagonalmatrix.hh:575
Iterator iterator
typedef for stl compliant access
Definition diagonalmatrix.hh:163
ConstIterator begin() const
begin ConstIterator
Definition diagonalmatrix.hh:841
ConstIterator const_iterator
typedef for stl compliant access
Definition diagonalmatrix.hh:1000
bool identical(const DiagonalRowVectorConst< K, n > &other) const
Definition diagonalmatrix.hh:830
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition diagonalmatrix.hh:243
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition diagonalmatrix.hh:814
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition diagonalmatrix.hh:363
static constexpr int blocklevel
The number of block levels we contain.
Definition diagonalmatrix.hh:802
row_type * pointer(int i) const
Definition diagonalmatrix.hh:757
DiagonalMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition diagonalmatrix.hh:103
ContainerWrapperIterator< DiagonalRowVector< K, n >, K, K & > Iterator
Iterator class for sequential access.
Definition diagonalmatrix.hh:967
R elementAt(int i) const
Definition diagonalmatrix.hh:1160
std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType &other) const
Definition diagonalmatrix.hh:1171
Iterator beforeEnd()
Definition diagonalmatrix.hh:985
void umtv(const X &x, Y &y) const
y += A^T x
Definition diagonalmatrix.hh:327
ConstIterator const_iterator
typedef for stl compliant access
Definition diagonalmatrix.hh:838
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition diagonalmatrix.hh:445
DiagonalMatrixWrapper(const DiagonalMatrixType *mat)
Definition diagonalmatrix.hh:748
void umv(const X &x, Y &y) const
y += A x
Definition diagonalmatrix.hh:315
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition diagonalmatrix.hh:161
DiagonalRowVector< K, n > type
Definition diagonalmatrix.hh:1050
void mv(const X &x, Y &y) const
y = A x
Definition diagonalmatrix.hh:296
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition diagonalmatrix.hh:427
ConstIterator end() const
end iterator
Definition diagonalmatrix.hh:212
static void apply(DenseMatrix &denseMatrix, DiagonalMatrix< field, N > const &rhs)
Definition diagonalmatrix.hh:1189
static constexpr int cols
The number of columns.
Definition diagonalmatrix.hh:88
static constexpr int dimension
Definition diagonalmatrix.hh:786
K * p_
Definition diagonalmatrix.hh:916
size_type rowIndex() const
index of this row in surrounding matrix
Definition diagonalmatrix.hh:887
R dereference() const
Definition diagonalmatrix.hh:1143
DiagonalRowVector & operator=(const K &k)
Assignment operator for scalar.
Definition diagonalmatrix.hh:951
bool operator!=(const DiagonalMatrix &other) const
incomparison operator
Definition diagonalmatrix.hh:286
value_type field_type
Definition diagonalmatrix.hh:66
void advance(int n)
Definition diagonalmatrix.hh:1165
ConstIterator begin() const
begin iterator
Definition diagonalmatrix.hh:206
Iterator begin()
begin iterator
Definition diagonalmatrix.hh:972
void mmv(const X &x, Y &y) const
y -= A x
Definition diagonalmatrix.hh:351
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition diagonalmatrix.hh:271
ConstIterator const_iterator
typedef for stl compliant access
Definition diagonalmatrix.hh:199
const_row_type const_reference
Definition diagonalmatrix.hh:82
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition diagonalmatrix.hh:148
friend auto operator*(const DiagonalMatrix &matrixA, const DiagonalMatrix< OtherScalar, n > &matrixB)
Matrix-matrix multiplication.
Definition diagonalmatrix.hh:486
size_type realIndex(int i) const
Definition diagonalmatrix.hh:752
Iterator end()
end iterator
Definition diagonalmatrix.hh:176
const K & operator[](size_type i) const
same for read only access
Definition diagonalmatrix.hh:822
DiagonalRowVector()
Constructor making uninitialized vector.
Definition diagonalmatrix.hh:942
row_type reference
Definition diagonalmatrix.hh:79
DiagonalRowVectorConst * operator&()
Definition diagonalmatrix.hh:910
bool operator==(const DiagonalRowVectorConst &y) const
Binary vector comparison.
Definition diagonalmatrix.hh:867
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition diagonalmatrix.hh:433
constexpr DiagonalMatrix()=default
Default constructor.
void mtv(const X &x, Y &y) const
y = A^T x
Definition diagonalmatrix.hh:308
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition diagonalmatrix.hh:998
bool identical(const DiagonalMatrixWrapper &other) const
Definition diagonalmatrix.hh:763
void usmtv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition diagonalmatrix.hh:400
void decrement()
Definition diagonalmatrix.hh:1154
std::ptrdiff_t index() const
Definition diagonalmatrix.hh:1177
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition diagonalmatrix.hh:593
void invert()
Compute inverse.
Definition diagonalmatrix.hh:463
DiagonalRowVector * operator&()
Definition diagonalmatrix.hh:1016
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition diagonalmatrix.hh:581
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition diagonalmatrix.hh:875
DiagonalMatrix(std::initializer_list< K > const &l)
Construct diagonal matrix from an initializer list.
Definition diagonalmatrix.hh:120
row_type::Iterator ColIterator
rename the iterators for easier access
Definition diagonalmatrix.hh:167
K field_type
export the type representing the field
Definition diagonalmatrix.hh:933
reference operator[](size_type i)
Return reference object as row replacement.
Definition diagonalmatrix.hh:569
DiagonalRowVectorConst< K, n > type
Definition diagonalmatrix.hh:1032
Iterator end()
end iterator
Definition diagonalmatrix.hh:978
DiagonalMatrix(const FieldVector< K, n > &diag)
Constructor initializing the diagonal with a vector.
Definition diagonalmatrix.hh:108
std::size_t size_type
The type used for the index access and size operation.
Definition diagonalmatrix.hh:939
void usmv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A x
Definition diagonalmatrix.hh:387
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition diagonalmatrix.hh:439
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition diagonalmatrix.hh:236
K block_type
export the type representing the components
Definition diagonalmatrix.hh:69
void umhv(const X &x, Y &y) const
y += A^H x
Definition diagonalmatrix.hh:339
Iterator beforeBegin()
Definition diagonalmatrix.hh:190
ContainerWrapperIterator(const MyType &other)
Definition diagonalmatrix.hh:1107
ConstIterator end() const
end ConstIterator
Definition diagonalmatrix.hh:847
std::size_t size_type
The type used for the index access and size operation.
Definition diagonalmatrix.hh:799
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition diagonalmatrix.hh:133
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition diagonalmatrix.hh:808
Iterator beforeEnd()
Definition diagonalmatrix.hh:183
size_type realIndex(int i) const
Definition diagonalmatrix.hh:900
friend std::ostream & operator<<(std::ostream &s, const DiagonalMatrix< K, n > &a)
Sends the matrix to an output stream.
Definition diagonalmatrix.hh:558
K value_type
export the type representing the field
Definition diagonalmatrix.hh:65
K block_type
export the type representing the components
Definition diagonalmatrix.hh:796
K determinant() const
calculates the determinant of this matrix
Definition diagonalmatrix.hh:471
FieldTraits< K >::real_type real_type
Definition diagonalmatrix.hh:614
ConstIterator beforeBegin() const
Definition diagonalmatrix.hh:861
DiagonalMatrixWrapper()
Definition diagonalmatrix.hh:744
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition diagonalmatrix.hh:836
Iterator begin()
begin iterator
Definition diagonalmatrix.hh:170
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition diagonalmatrix.hh:280
DiagonalRowVectorConst< K, n > const_row_type
Definition diagonalmatrix.hh:81
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition diagonalmatrix.hh:78
bool equals(const MyType &other) const
Definition diagonalmatrix.hh:1133
Iterator RowIterator
rename the iterators for easier access
Definition diagonalmatrix.hh:165
K block_type
export the type representing the components
Definition diagonalmatrix.hh:936
ConstIterator beforeEnd() const
Definition diagonalmatrix.hh:219
DiagonalMatrix(const DiagonalMatrix< OtherK, n > &other)
Converting constructor.
Definition diagonalmatrix.hh:128
const K & diagonal() const
the diagonal value
Definition diagonalmatrix.hh:893
#define DUNE_THROW(E,...)
Definition exceptions.hh:314
Dune namespace
Definition alignedallocator.hh:13
constexpr K conjugateComplex(const K &x)
compute conjugate complex of x
Definition math.hh:146
A dense n x m matrix.
Definition densematrix.hh:145
constexpr size_type M() const
number of columns
Definition densematrix.hh:708
A dense n x m matrix.
Definition fmatrix.hh:142
vector space out of a tensor product of fields.
Definition fvector.hh:97
you have to specialize this structure for any type that should be assignable to a DenseMatrix
Definition densematrix.hh:61
Error thrown if operations of a FieldMatrix fail.
Definition densematrix.hh:131
constexpr FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition densevector.hh:656
constexpr 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:665
constexpr FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition densevector.hh:676
constexpr FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition densevector.hh:692
constexpr Iterator begin()
begin iterator
Definition densevector.hh:362
Definition diagonalmatrix.hh:779
Definition diagonalmatrix.hh:922
Definition diagonalmatrix.hh:731
Iterator class for sparse vector-like containers.
Definition diagonalmatrix.hh:1079
ContainerWrapperIterator(const MyConstType &other)
Definition diagonalmatrix.hh:1112
bool equals(const MyConstType &other) const
Definition diagonalmatrix.hh:1138
A diagonal matrix of static size.
Definition diagonalmatrix.hh:57
Construct a matrix with a dynamic size.
Definition dynmatrix.hh:61
Default exception class for range errors.
Definition exceptions.hh:348
TMP to check the shape of a DenseMatrix statically, if possible.
Definition fmatrix.hh:121
Definition ftraits.hh:26
T field_type
export the type representing the field
Definition ftraits.hh:28
T real_type
export the type representing the real type of the field
Definition ftraits.hh:30
Get the 'const' version of a reference to a mutable object.
Definition genericiterator.hh:87
get the 'mutable' version of a reference to a const object
Definition genericiterator.hh:116
Facade class for stl conformant bidirectional iterators.
Definition iteratorfacades.hh:275
decltype(std::declval< T1 >()+std::declval< T2 >()) PromotedType
Definition promotiontraits.hh:28
T copy_n(T... args)
T endl(T... args)