Dune Core Modules (2.6.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 
22 #include <dune/common/fmatrix.hh>
23 #include <dune/common/fvector.hh>
26 #include <dune/common/unused.hh>
27 
28 
29 namespace Dune {
30 
31  template< class K, int n > class DiagonalRowVectorConst;
32  template< class K, int n > class DiagonalRowVector;
33  template< class DiagonalMatrixType > class DiagonalMatrixWrapper;
34  template< class C, class T, class R> class ContainerWrapperIterator;
35 
50  template<class K, int n>
52  {
53  typedef DiagonalMatrixWrapper< DiagonalMatrix<K,n> > WrapperType;
54 
55  public:
56  //===== type definitions and constants
57 
59  typedef K value_type;
60  typedef value_type field_type;
61 
63  typedef K block_type;
64 
66  typedef std::size_t size_type;
67 
69  enum {
71  blocklevel = 1
72  };
73 
75  typedef DiagonalRowVector<K,n> row_type;
76  typedef row_type reference;
77  typedef row_type row_reference;
78  typedef DiagonalRowVectorConst<K,n> const_row_type;
79  typedef const_row_type const_reference;
80  typedef const_row_type const_row_reference;
81 
83  enum {
85  rows = n,
87  cols = n
88  };
89 
90  //==== size
91 
92  size_type size () const
93  {
94  return rows;
95  }
96 
97  //===== constructors
98 
101 
103  DiagonalMatrix (const K& k)
104  : diag_(k)
105  {}
106 
109  : diag_(diag)
110  {}
111 
120  DiagonalMatrix (std::initializer_list<K> const &l)
121  {
122  std::copy_n(l.begin(), std::min(static_cast<std::size_t>(rows),
123  l.size()),
124  diag_.begin());
125  }
126 
129  {
130  diag_ = k;
131  return *this;
132  }
133 
135  bool identical(const DiagonalMatrix<K,n>& other) const
136  {
137  return (this==&other);
138  }
139 
140  //===== iterator interface to rows of the matrix
148  typedef typename row_type::Iterator ColIterator;
149 
152  {
153  return Iterator(WrapperType(this),0);
154  }
155 
158  {
159  return Iterator(WrapperType(this),n);
160  }
161 
165  {
166  return Iterator(WrapperType(this),n-1);
167  }
168 
172  {
173  return Iterator(WrapperType(this),-1);
174  }
175 
176 
185 
188  {
189  return ConstIterator(WrapperType(this),0);
190  }
191 
194  {
195  return ConstIterator(WrapperType(this),n);
196  }
197 
201  {
202  return ConstIterator(WrapperType(this),n-1);
203  }
204 
208  {
209  return ConstIterator(WrapperType(this),-1);
210  }
211 
212 
213 
214  //===== vector space arithmetic
215 
218  {
219  diag_ += y.diag_;
220  return *this;
221  }
222 
225  {
226  diag_ -= y.diag_;
227  return *this;
228  }
229 
232  {
233  diag_ += k;
234  return *this;
235  }
236 
239  {
240  diag_ -= k;
241  return *this;
242  }
243 
246  {
247  diag_ *= k;
248  return *this;
249  }
250 
253  {
254  diag_ /= k;
255  return *this;
256  }
257 
258  //===== comparison ops
259 
261  bool operator==(const DiagonalMatrix& other) const
262  {
263  return diag_==other.diagonal();
264  }
265 
267  bool operator!=(const DiagonalMatrix& other) const
268  {
269  return diag_!=other.diagonal();
270  }
271 
272 
273  //===== linear maps
274 
276  template<class X, class Y>
277  void mv (const X& x, Y& y) const
278  {
279 #ifdef DUNE_FMatrix_WITH_CHECKING
280  if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
281  if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
282 #endif
283  for (size_type i=0; i<n; ++i)
284  y[i] = diag_[i] * x[i];
285  }
286 
288  template<class X, class Y>
289  void mtv (const X& x, Y& y) const
290  {
291  mv(x, y);
292  }
293 
295  template<class X, class Y>
296  void umv (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 umtv (const X& x, Y& y) const
309  {
310 #ifdef DUNE_FMatrix_WITH_CHECKING
311  if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
312  if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
313 #endif
314  for (size_type i=0; i<n; ++i)
315  y[i] += diag_[i] * x[i];
316  }
317 
319  template<class X, class Y>
320  void umhv (const X& x, Y& y) const
321  {
322 #ifdef DUNE_FMatrix_WITH_CHECKING
323  if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
324  if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
325 #endif
326  for (size_type i=0; i<n; i++)
327  y[i] += conjugateComplex(diag_[i])*x[i];
328  }
329 
331  template<class X, class Y>
332  void mmv (const X& x, Y& y) const
333  {
334 #ifdef DUNE_FMatrix_WITH_CHECKING
335  if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
336  if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
337 #endif
338  for (size_type i=0; i<n; ++i)
339  y[i] -= diag_[i] * x[i];
340  }
341 
343  template<class X, class Y>
344  void mmtv (const X& x, Y& y) const
345  {
346 #ifdef DUNE_FMatrix_WITH_CHECKING
347  if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
348  if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
349 #endif
350  for (size_type i=0; i<n; ++i)
351  y[i] -= diag_[i] * x[i];
352  }
353 
355  template<class X, class Y>
356  void mmhv (const X& x, Y& y) const
357  {
358 #ifdef DUNE_FMatrix_WITH_CHECKING
359  if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
360  if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
361 #endif
362  for (size_type i=0; i<n; i++)
363  y[i] -= conjugateComplex(diag_[i])*x[i];
364  }
365 
367  template<class X, class Y>
368  void usmv (const typename FieldTraits<Y>::field_type & alpha,
369  const X& x, Y& y) const
370  {
371 #ifdef DUNE_FMatrix_WITH_CHECKING
372  if (x.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
373  if (y.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
374 #endif
375  for (size_type i=0; i<n; i++)
376  y[i] += alpha * diag_[i] * x[i];
377  }
378 
380  template<class X, class Y>
381  void usmtv (const typename FieldTraits<Y>::field_type & alpha,
382  const X& x, Y& y) const
383  {
384 #ifdef DUNE_FMatrix_WITH_CHECKING
385  if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
386  if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
387 #endif
388  for (size_type i=0; i<n; i++)
389  y[i] += alpha * diag_[i] * x[i];
390  }
391 
393  template<class X, class Y>
394  void usmhv (const typename FieldTraits<Y>::field_type & alpha,
395  const X& x, Y& y) const
396  {
397 #ifdef DUNE_FMatrix_WITH_CHECKING
398  if (x.N()!=N()) DUNE_THROW(FMatrixError,"index out of range");
399  if (y.N()!=M()) DUNE_THROW(FMatrixError,"index out of range");
400 #endif
401  for (size_type i=0; i<n; i++)
402  y[i] += alpha * conjugateComplex(diag_[i]) * x[i];
403  }
404 
405  //===== norms
406 
408  double frobenius_norm () const
409  {
410  return diag_.two_norm();
411  }
412 
414  double frobenius_norm2 () const
415  {
416  return diag_.two_norm2();
417  }
418 
420  double infinity_norm () const
421  {
422  return diag_.infinity_norm();
423  }
424 
426  double infinity_norm_real () const
427  {
428  return diag_.infinity_norm_real();
429  }
430 
431 
432 
433  //===== solve
434 
436  template<class V>
437  void solve (V& x, const V& b) const
438  {
439  for (int i=0; i<n; i++)
440  x[i] = b[i]/diag_[i];
441  }
442 
444  void invert()
445  {
446  for (int i=0; i<n; i++)
447  diag_[i] = 1/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  size_type N () const
465  {
466  return n;
467  }
468 
470  size_type M () const
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 
501  reference operator[](size_type i)
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 
525  const FieldVector<K,n>& diagonal() const
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 
586  {}
587 
589  DiagonalMatrix(const K& scalar)
590  {
591  (*this)[0][0] = scalar;
592  }
593 
595  const K& diagonal(size_type) const
596  {
597  return (*this)[0][0];
598  }
599 
601  K& diagonal(size_type)
602  {
603  return (*this)[0][0];
604  }
605 
607  const FieldVector<K,1>& diagonal() const
608  {
609  return (*this)[0];
610  }
611 
613  FieldVector<K,1>& diagonal()
614  {
615  return (*this)[0];
616  }
617 
618  };
619 #endif
620 
621 
622  template<class DiagonalMatrixType>
623  class DiagonalMatrixWrapper
624  {
625  typedef typename DiagonalMatrixType::reference reference;
626  typedef typename DiagonalMatrixType::const_reference const_reference;
627  typedef typename DiagonalMatrixType::field_type K;
628  typedef DiagonalRowVector<K, DiagonalMatrixType::rows> row_type;
629  typedef std::size_t size_type;
630  typedef DiagonalMatrixWrapper< DiagonalMatrixType> MyType;
631 
632  friend class ContainerWrapperIterator<const MyType, reference, reference>;
633  friend class ContainerWrapperIterator<const MyType, const_reference, const_reference>;
634 
635  public:
636 
637  DiagonalMatrixWrapper() :
638  mat_(0)
639  {}
640 
641  DiagonalMatrixWrapper(const DiagonalMatrixType* mat) :
642  mat_(const_cast<DiagonalMatrixType*>(mat))
643  {}
644 
645  size_type realIndex(int i) const
646  {
647  return i;
648  }
649 
650  row_type* pointer(int i) const
651  {
652  row_ = row_type(&(mat_->diagonal(i)), i);
653  return &row_;
654  }
655 
656  bool identical(const DiagonalMatrixWrapper& other) const
657  {
658  return mat_==other.mat_;
659  }
660 
661  private:
662 
663  mutable DiagonalMatrixType* mat_;
664  mutable row_type row_;
665  };
666 
670  template< class K, int n >
671  class DiagonalRowVectorConst
672  {
673  template<class DiagonalMatrixType>
674  friend class DiagonalMatrixWrapper;
675  friend class ContainerWrapperIterator<DiagonalRowVectorConst<K,n>, const K, const K&>;
676 
677  public:
678  // remember size of vector
679  enum { dimension = n };
680 
681  // standard constructor and everything is sufficient ...
682 
683  //===== type definitions and constants
684 
686  typedef K field_type;
687 
689  typedef K block_type;
690 
692  typedef std::size_t size_type;
693 
695  enum {
697  blocklevel = 1
698  };
699 
701  enum {
703  size = n
704  };
705 
708  p_(0),
709  row_(0)
710  {}
711 
713  explicit DiagonalRowVectorConst (K* p, int col) :
714  p_(p),
715  row_(col)
716  {}
717 
718  //===== access to components
719 
721  const K& operator[] (size_type i) const
722  {
724  DUNE_ASSERT_BOUNDS(i == row_);
725  return *p_;
726  }
727 
728  // check if row is identical to other row (not only identical values)
729  // since this is a proxy class we need to check equality of the stored pointer
730  bool identical(const DiagonalRowVectorConst<K,n>& other) const
731  {
732  return ((p_ == other.p_)and (row_ == other.row_));
733  }
734 
739 
742  {
743  return ConstIterator(*this,0);
744  }
745 
748  {
749  return ConstIterator(*this,1);
750  }
751 
755  {
756  return ConstIterator(*this,0);
757  }
758 
762  {
763  return ConstIterator(*this,-1);
764  }
765 
767  bool operator== (const DiagonalRowVectorConst& y) const
768  {
769  return ((p_==y.p_)and (row_==y.row_));
770  }
771 
772  //===== sizes
773 
775  size_type N () const
776  {
777  return n;
778  }
779 
781  size_type dim () const
782  {
783  return n;
784  }
785 
788  {
789  return row_;
790  }
791 
793  const K& diagonal() const
794  {
795  return *p_;
796  }
797 
798  protected:
799 
800  size_type realIndex(int i) const
801  {
803  return rowIndex();
804  }
805 
806  K* pointer(size_type i) const
807  {
809  return const_cast<K*>(p_);
810  }
811 
812  DiagonalRowVectorConst* operator&()
813  {
814  return this;
815  }
816 
817  // the data, very simply a pointer to the diagonal value and the row number
818  K* p_;
819  size_type row_;
820  };
821 
822  template< class K, int n >
823  class DiagonalRowVector : public DiagonalRowVectorConst<K,n>
824  {
825  template<class DiagonalMatrixType>
826  friend class DiagonalMatrixWrapper;
827  friend class ContainerWrapperIterator<DiagonalRowVector<K,n>, K, K&>;
828 
829  public:
830  // standard constructor and everything is sufficient ...
831 
832  //===== type definitions and constants
833 
835  typedef K field_type;
836 
838  typedef K block_type;
839 
841  typedef std::size_t size_type;
842 
844  DiagonalRowVector() : DiagonalRowVectorConst<K,n>()
845  {}
846 
848  explicit DiagonalRowVector (K* p, int col) : DiagonalRowVectorConst<K,n>(p, col)
849  {}
850 
851  //===== assignment from scalar
853  DiagonalRowVector& operator= (const K& k)
854  {
855  *p_ = k;
856  return *this;
857  }
858 
859  //===== access to components
860 
862  K& operator[] (size_type i)
863  {
865  DUNE_ASSERT_BOUNDS(i == row_);
866  return *p_;
867  }
868 
873 
876  {
877  return Iterator(*this, 0);
878  }
879 
882  {
883  return Iterator(*this, 1);
884  }
885 
889  {
890  return Iterator(*this, 0);
891  }
892 
896  {
897  return Iterator(*this, -1);
898  }
899 
904 
905  using DiagonalRowVectorConst<K,n>::identical;
906  using DiagonalRowVectorConst<K,n>::operator[];
907  using DiagonalRowVectorConst<K,n>::operator==;
908  using DiagonalRowVectorConst<K,n>::begin;
909  using DiagonalRowVectorConst<K,n>::end;
910  using DiagonalRowVectorConst<K,n>::beforeEnd;
911  using DiagonalRowVectorConst<K,n>::beforeBegin;
912  using DiagonalRowVectorConst<K,n>::N;
913  using DiagonalRowVectorConst<K,n>::dim;
914  using DiagonalRowVectorConst<K,n>::rowIndex;
915  using DiagonalRowVectorConst<K,n>::diagonal;
916 
917  protected:
918 
919  DiagonalRowVector* operator&()
920  {
921  return this;
922  }
923 
924  private:
925 
926  using DiagonalRowVectorConst<K,n>::p_;
927  using DiagonalRowVectorConst<K,n>::row_;
928  };
929 
930 
931  // implement type traits
932  template<class K, int n>
933  struct const_reference< DiagonalRowVector<K,n> >
934  {
935  typedef DiagonalRowVectorConst<K,n> type;
936  };
937 
938  template<class K, int n>
939  struct const_reference< DiagonalRowVectorConst<K,n> >
940  {
941  typedef DiagonalRowVectorConst<K,n> type;
942  };
943 
944  template<class K, int n>
945  struct mutable_reference< DiagonalRowVector<K,n> >
946  {
947  typedef DiagonalRowVector<K,n> type;
948  };
949 
950  template<class K, int n>
951  struct mutable_reference< DiagonalRowVectorConst<K,n> >
952  {
953  typedef DiagonalRowVector<K,n> type;
954  };
955 
956 
957 
980  template<class CW, class T, class R>
981  class ContainerWrapperIterator : public BidirectionalIteratorFacade<ContainerWrapperIterator<CW,T,R>,T, R, int>
982  {
983  typedef typename std::remove_const<CW>::type NonConstCW;
984 
985  friend class ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type>;
986  friend class ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type>;
987 
988  typedef ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type> MyType;
989  typedef ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type> MyConstType;
990 
991  public:
992 
993  // Constructors needed by the facade iterators.
995  containerWrapper_(),
996  position_(0)
997  {}
998 
999  ContainerWrapperIterator(CW containerWrapper, int position) :
1000  containerWrapper_(containerWrapper),
1001  position_(position)
1002  {}
1003 
1004  template<class OtherContainerWrapperIteratorType>
1005  ContainerWrapperIterator(OtherContainerWrapperIteratorType& other) :
1006  containerWrapper_(other.containerWrapper_),
1007  position_(other.position_)
1008  {}
1009 
1010  ContainerWrapperIterator(const MyType& other) :
1011  containerWrapper_(other.containerWrapper_),
1012  position_(other.position_)
1013  {}
1014 
1015  ContainerWrapperIterator(const MyConstType& other) :
1016  containerWrapper_(other.containerWrapper_),
1017  position_(other.position_)
1018  {}
1019 
1020  template<class OtherContainerWrapperIteratorType>
1021  ContainerWrapperIterator& operator=(OtherContainerWrapperIteratorType& other)
1022  {
1023  containerWrapper_ = other.containerWrapper_;
1024  position_ = other.position_;
1025  return *this;
1026  }
1027 
1028  // This operator is needed since we can not get the address of the
1029  // temporary object returned by dereference
1030  T* operator->() const
1031  {
1032  return containerWrapper_.pointer(position_);
1033  }
1034 
1035  // Methods needed by the forward iterator
1036  bool equals(const MyType& other) const
1037  {
1038  return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1039  }
1040 
1041  bool equals(const MyConstType& other) const
1042  {
1043  return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1044  }
1045 
1046  R dereference() const
1047  {
1048  return *containerWrapper_.pointer(position_);
1049  }
1050 
1051  void increment()
1052  {
1053  ++position_;
1054  }
1055 
1056  // Additional function needed by BidirectionalIterator
1057  void decrement()
1058  {
1059  --position_;
1060  }
1061 
1062  // Additional function needed by RandomAccessIterator
1063  R elementAt(int i) const
1064  {
1065  return *containerWrapper_.pointer(position_+i);
1066  }
1067 
1068  void advance(int n)
1069  {
1070  position_=position_+n;
1071  }
1072 
1073  template<class OtherContainerWrapperIteratorType>
1074  std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType& other) const
1075  {
1076  assert(containerWrapper_.identical(other));
1077  return other.position_ - position_;
1078  }
1079 
1080  std::ptrdiff_t index() const
1081  {
1082  return containerWrapper_.realIndex(position_);
1083  }
1084 
1085  private:
1086  NonConstCW containerWrapper_;
1087  size_t position_;
1088  };
1089 
1090  template <class DenseMatrix, class field, int N>
1091  struct DenseMatrixAssigner<DenseMatrix, DiagonalMatrix<field, N>> {
1092  static void apply(DenseMatrix& denseMatrix,
1093  DiagonalMatrix<field, N> const& rhs) {
1094  DUNE_ASSERT_BOUNDS(denseMatrix.M() == N);
1095  DUNE_ASSERT_BOUNDS(denseMatrix.N() == N);
1096  denseMatrix = field(0);
1097  for (int i = 0; i < N; ++i)
1098  denseMatrix[i][i] = rhs.diagonal()[i];
1099  }
1100  };
1101  /* @} */
1102 } // end namespace
1103 #endif
Macro for wrapping boundary checks.
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:275
Iterator class for sparse vector-like containers.
Definition: diagonalmatrix.hh:982
A dense n x m matrix.
Definition: densematrix.hh:160
size_type M() const
number of columns
Definition: densematrix.hh:692
size_type N() const
number of rows
Definition: densematrix.hh:686
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:599
Iterator begin()
begin iterator
Definition: densevector.hh:308
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:590
FieldTraits< vt >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: densevector.hh:626
FieldTraits< vt >::real_type infinity_norm() const
infinity norm (maximum of absolute values of entries)
Definition: densevector.hh:610
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:52
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:146
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.
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:58
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:207
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: diagonalmatrix.hh:356
std::size_t size_type
The type used for the index access and size operations.
Definition: diagonalmatrix.hh:66
size_type dim() const
dimension of the vector space
Definition: diagonalmatrix.hh:781
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:182
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition: diagonalmatrix.hh:128
DiagonalMatrix()
Default constructor.
Definition: diagonalmatrix.hh:100
void usmhv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: diagonalmatrix.hh:394
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:872
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:686
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:754
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:184
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:178
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:848
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:437
Iterator beforeBegin()
Definition: diagonalmatrix.hh:895
size_type M() const
number of blocks in column direction
Definition: diagonalmatrix.hh:470
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:144
ConstIterator begin() const
begin ConstIterator
Definition: diagonalmatrix.hh:741
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition: diagonalmatrix.hh:519
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:903
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:713
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: diagonalmatrix.hh:344
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:870
Iterator beforeEnd()
Definition: diagonalmatrix.hh:888
void umtv(const X &x, Y &y) const
y += A^T x
Definition: diagonalmatrix.hh:308
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:738
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: diagonalmatrix.hh:426
void umv(const X &x, Y &y) const
y += A x
Definition: diagonalmatrix.hh:296
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:142
void mv(const X &x, Y &y) const
y = A x
Definition: diagonalmatrix.hh:277
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: diagonalmatrix.hh:408
ConstIterator end() const
end iterator
Definition: diagonalmatrix.hh:193
size_type rowIndex() const
index of this row in surrounding matrix
Definition: diagonalmatrix.hh:787
bool operator!=(const DiagonalMatrix &other) const
incomparison operator
Definition: diagonalmatrix.hh:267
ConstIterator begin() const
begin iterator
Definition: diagonalmatrix.hh:187
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:875
void mmv(const X &x, Y &y) const
y -= A x
Definition: diagonalmatrix.hh:332
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:180
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition: diagonalmatrix.hh:135
Iterator end()
end iterator
Definition: diagonalmatrix.hh:157
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:513
DiagonalRowVector()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:844
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: diagonalmatrix.hh:414
void mtv(const X &x, Y &y) const
y = A^T x
Definition: diagonalmatrix.hh:289
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:901
friend std::ostream & operator<<(std::ostream &s, const DiagonalMatrix< K, n > &a)
Sends the matrix to an output stream.
Definition: diagonalmatrix.hh:490
void usmtv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: diagonalmatrix.hh:381
void invert()
Compute inverse.
Definition: diagonalmatrix.hh:444
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: diagonalmatrix.hh:775
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:148
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:835
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition: diagonalmatrix.hh:525
reference operator[](size_type i)
Return reference object as row replacement.
Definition: diagonalmatrix.hh:501
const K & diagonal() const
the diagonal value
Definition: diagonalmatrix.hh:793
size_type N() const
number of blocks in row direction
Definition: diagonalmatrix.hh:464
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition: diagonalmatrix.hh:224
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition: diagonalmatrix.hh:252
Iterator end()
end iterator
Definition: diagonalmatrix.hh:881
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:841
void usmv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A x
Definition: diagonalmatrix.hh:368
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: diagonalmatrix.hh:420
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:63
void umhv(const X &x, Y &y) const
y += A^H x
Definition: diagonalmatrix.hh:320
Iterator beforeBegin()
Definition: diagonalmatrix.hh:171
ConstIterator end() const
end ConstIterator
Definition: diagonalmatrix.hh:747
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:692
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:707
Iterator beforeEnd()
Definition: diagonalmatrix.hh:164
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition: diagonalmatrix.hh:217
K value_type
export the type representing the field
Definition: diagonalmatrix.hh:59
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:689
K determinant() const
calculates the determinant of this matrix
Definition: diagonalmatrix.hh:451
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition: diagonalmatrix.hh:531
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:761
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:736
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:151
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition: diagonalmatrix.hh:261
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition: diagonalmatrix.hh:75
Iterator RowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:146
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:838
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition: diagonalmatrix.hh:245
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:200
@ cols
The number of columns.
Definition: diagonalmatrix.hh:87
@ rows
The number of rows.
Definition: diagonalmatrix.hh:85
@ blocklevel
The number of block levels we contain. This is 1.
Definition: diagonalmatrix.hh:71
#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:233
Dune namespace.
Definition: alignedallocator.hh:10
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:105
you have to specialize this structure for any type that should be assignable to a DenseMatrix
Definition: densematrix.hh:79
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:114
Traits for type conversions and type information.
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 23, 22:30, 2024)