dune-common  2.7.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  {
54 
55  public:
56  //===== type definitions and constants
57 
59  typedef K value_type;
61 
63  typedef K block_type;
64 
66  typedef std::size_t size_type;
67 
69  enum {
72  };
73 
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 
100  constexpr DiagonalMatrix() = default;
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  using real_type = typename FieldTraits<K>::real_type;
447  for (int i=0; i<n; i++)
448  diag_[i] = real_type(1.0)/diag_[i];
449  }
450 
452  K determinant () const
453  {
454  K det = diag_[0];
455  for (int i=1; i<n; i++)
456  det *= diag_[i];
457  return det;
458  }
459 
460 
461 
462  //===== sizes
463 
465  size_type N () const
466  {
467  return n;
468  }
469 
471  size_type M () const
472  {
473  return n;
474  }
475 
476 
477 
478  //===== query
479 
481  bool exists (size_type i, size_type j) const
482  {
483  DUNE_ASSERT_BOUNDS(i >= 0 && i < n);
484  DUNE_ASSERT_BOUNDS(j >= 0 && j < n);
485  return i==j;
486  }
487 
488 
489 
491  friend std::ostream& operator<< (std::ostream& s, const DiagonalMatrix<K,n>& a)
492  {
493  for (size_type i=0; i<n; i++) {
494  for (size_type j=0; j<n; j++)
495  s << ((i==j) ? a.diag_[i] : 0) << " ";
496  s << std::endl;
497  }
498  return s;
499  }
500 
503  {
504  return reference(const_cast<K*>(&diag_[i]), i);
505  }
506 
509  {
510  return const_reference(const_cast<K*>(&diag_[i]), i);
511  }
512 
514  const K& diagonal(size_type i) const
515  {
516  return diag_[i];
517  }
518 
521  {
522  return diag_[i];
523  }
524 
526  const FieldVector<K,n>& diagonal() const
527  {
528  return diag_;
529  }
530 
533  {
534  return diag_;
535  }
536 
537  private:
538 
539  // the data, a FieldVector storing the diagonal
540  FieldVector<K,n> diag_;
541  };
542 
543  template< class K, int n >
545  {
548  };
549 
550 
551 #ifndef DOXYGEN // hide specialization
552 
554  template< class K >
555  class DiagonalMatrix<K, 1> : public FieldMatrix<K, 1, 1>
556  {
557  typedef FieldMatrix<K,1,1> Base;
558  public:
560  typedef typename Base::size_type size_type;
561 
563  enum {
566  blocklevel = 1
567  };
568 
569  typedef typename Base::row_type row_type;
570 
571  typedef typename Base::row_reference row_reference;
572  typedef typename Base::const_row_reference const_row_reference;
573 
575  enum {
578  rows = 1,
581  cols = 1
582  };
583 
584 
586  constexpr DiagonalMatrix() = default;
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 
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 {
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 
813  {
814  return this;
815  }
816 
817  // the data, very simply a pointer to the diagonal value and the row number
818  K* p_;
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 
845  {}
846 
848  explicit DiagonalRowVector (K* p, int col) : DiagonalRowVectorConst<K,n>(p, col)
849  {}
850 
851  //===== assignment from scalar
854  {
855  *p_ = k;
856  return *this;
857  }
858 
859  //===== access to components
860 
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 
916 
917  protected:
918 
920  {
921  return this;
922  }
923 
924  private:
925 
928  };
929 
930 
931  // implement type traits
932  template<class K, int n>
934  {
936  };
937 
938  template<class K, int n>
940  {
942  };
943 
944  template<class K, int n>
946  {
948  };
949 
950  template<class K, int n>
952  {
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 
1011  containerWrapper_(other.containerWrapper_),
1012  position_(other.position_)
1013  {}
1014 
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>
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
Dune::DiagonalMatrix::diagonal
FieldVector< K, n > & diagonal()
Get reference to diagonal vector.
Definition: diagonalmatrix.hh:532
Dune::ContainerWrapperIterator::distanceTo
std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType &other) const
Definition: diagonalmatrix.hh:1074
Dune::conjugateComplex
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:161
Dune::DenseMatrixAssigner< DenseMatrix, DiagonalMatrix< field, N > >::apply
static void apply(DenseMatrix &denseMatrix, DiagonalMatrix< field, N > const &rhs)
Definition: diagonalmatrix.hh:1092
Dune::DiagonalMatrix::mmv
void mmv(const X &x, Y &y) const
y -= A x
Definition: diagonalmatrix.hh:332
Dune::DiagonalMatrix::begin
ConstIterator begin() const
begin iterator
Definition: diagonalmatrix.hh:187
exceptions.hh
A few common exception classes.
Dune::DiagonalRowVector::DiagonalRowVector
DiagonalRowVector(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:848
Dune::DiagonalMatrixWrapper::identical
bool identical(const DiagonalMatrixWrapper &other) const
Definition: diagonalmatrix.hh:656
Dune::FieldTraits::real_type
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
Dune::ContainerWrapperIterator::dereference
R dereference() const
Definition: diagonalmatrix.hh:1046
Dune::DiagonalMatrix::beforeEnd
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:200
Dune::DiagonalMatrix::mmhv
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: diagonalmatrix.hh:356
Dune::const_reference
Get the 'const' version of a reference to a mutable object.
Definition: genericiterator.hh:84
Dune::DiagonalMatrix::reference
row_type reference
Definition: diagonalmatrix.hh:76
Dune::ContainerWrapperIterator::operator->
T * operator->() const
Definition: diagonalmatrix.hh:1030
Dune::DiagonalMatrix::row_reference
row_type row_reference
Definition: diagonalmatrix.hh:77
Dune::DiagonalMatrix::umhv
void umhv(const X &x, Y &y) const
y += A^H x
Definition: diagonalmatrix.hh:320
Dune::DiagonalMatrix::DiagonalMatrix
DiagonalMatrix(std::initializer_list< K > const &l)
Construct diagonal matrix from an initializer list.
Definition: diagonalmatrix.hh:120
Dune::AlignedNumberImpl::min
auto min(const AlignedNumber< T, align > &a, const AlignedNumber< T, align > &b)
Definition: debugalign.hh:434
Dune::ContainerWrapperIterator
Iterator class for sparse vector-like containers.
Definition: diagonalmatrix.hh:34
Dune::DiagonalMatrix::cols
@ cols
The number of columns.
Definition: diagonalmatrix.hh:87
Dune::FieldTraits< DiagonalMatrix< K, n > >::real_type
FieldTraits< K >::real_type real_type
Definition: diagonalmatrix.hh:547
Dune::const_reference< DiagonalRowVector< K, n > >::type
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:935
Dune::DiagonalMatrix::const_reference
const_row_type const_reference
Definition: diagonalmatrix.hh:79
Dune::DiagonalMatrix::operator-=
DiagonalMatrix & operator-=(const DiagonalMatrix &y)
vector space subtraction
Definition: diagonalmatrix.hh:224
Dune::DiagonalRowVectorConst::operator==
bool operator==(const DiagonalRowVectorConst &y) const
Binary vector comparison.
Definition: diagonalmatrix.hh:767
Dune::DiagonalMatrix::DiagonalMatrix
DiagonalMatrix(const K &k)
Constructor initializing the whole matrix with a scalar.
Definition: diagonalmatrix.hh:103
Dune::DiagonalMatrix::diagonal
const FieldVector< K, n > & diagonal() const
Get const reference to diagonal vector.
Definition: diagonalmatrix.hh:526
Dune::DiagonalMatrix::field_type
value_type field_type
Definition: diagonalmatrix.hh:60
boundschecking.hh
Macro for wrapping boundary checks.
Dune::ContainerWrapperIterator::ContainerWrapperIterator
ContainerWrapperIterator(const MyType &other)
Definition: diagonalmatrix.hh:1010
Dune::DiagonalRowVectorConst::dim
size_type dim() const
dimension of the vector space
Definition: diagonalmatrix.hh:781
Dune::DiagonalRowVector::iterator
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:872
Dune::DiagonalRowVector::ConstIterator
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:901
Dune::DiagonalRowVector::operator&
DiagonalRowVector * operator&()
Definition: diagonalmatrix.hh:919
DUNE_UNUSED_PARAMETER
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
Dune::DiagonalMatrix::end
Iterator end()
end iterator
Definition: diagonalmatrix.hh:157
Dune::DiagonalRowVector::block_type
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:838
Dune::DiagonalMatrix::operator<<
friend std::ostream & operator<<(std::ostream &s, const DiagonalMatrix< K, n > &a)
Sends the matrix to an output stream.
Definition: diagonalmatrix.hh:491
Dune::ContainerWrapperIterator::index
std::ptrdiff_t index() const
Definition: diagonalmatrix.hh:1080
Dune::DiagonalRowVectorConst::field_type
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:686
Dune::ContainerWrapperIterator::equals
bool equals(const MyType &other) const
Definition: diagonalmatrix.hh:1036
Dune::ContainerWrapperIterator::decrement
void decrement()
Definition: diagonalmatrix.hh:1057
Dune::FMatrixError
Error thrown if operations of a FieldMatrix fail.
Definition: densematrix.hh:150
Dune::DiagonalMatrixWrapper::realIndex
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:645
Dune::DiagonalRowVectorConst::end
ConstIterator end() const
end ConstIterator
Definition: diagonalmatrix.hh:747
Dune::DiagonalMatrixWrapper
Definition: diagonalmatrix.hh:33
Dune::DiagonalMatrix::beforeBegin
Iterator beforeBegin()
Definition: diagonalmatrix.hh:171
Dune::DiagonalRowVectorConst::rowIndex
size_type rowIndex() const
index of this row in surrounding matrix
Definition: diagonalmatrix.hh:787
Dune::DiagonalRowVector::DiagonalRowVector
DiagonalRowVector()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:844
Dune::DiagonalMatrixWrapper::DiagonalMatrixWrapper
DiagonalMatrixWrapper()
Definition: diagonalmatrix.hh:637
Dune::FieldMatrix
A dense n x m matrix.
Definition: densematrix.hh:41
Dune::DiagonalRowVectorConst::operator[]
const K & operator[](size_type i) const
same for read only access
Definition: diagonalmatrix.hh:721
Dune::DiagonalMatrix::umtv
void umtv(const X &x, Y &y) const
y += A^T x
Definition: diagonalmatrix.hh:308
Dune::mutable_reference
get the 'mutable' version of a reference to a const object
Definition: genericiterator.hh:113
Dune::DiagonalMatrix::diagonal
const K & diagonal(size_type i) const
Get const reference to diagonal entry.
Definition: diagonalmatrix.hh:514
Dune::DiagonalRowVectorConst::N
size_type N() const
number of blocks in the vector (are of size 1 here)
Definition: diagonalmatrix.hh:775
Dune::DiagonalMatrix::block_type
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:63
Dune::DiagonalRowVector::const_iterator
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:903
Dune::ContainerWrapperIterator::increment
void increment()
Definition: diagonalmatrix.hh:1051
Dune::FieldTraits::field_type
T field_type
export the type representing the field
Definition: ftraits.hh:26
Dune::DiagonalMatrix::begin
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:151
Dune::DiagonalRowVectorConst::realIndex
size_type realIndex(int i) const
Definition: diagonalmatrix.hh:800
Dune::DiagonalRowVector::operator=
DiagonalRowVector & operator=(const K &k)
Assignment operator for scalar.
Definition: diagonalmatrix.hh:853
fvector.hh
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune::DenseMatrix
A dense n x m matrix.
Definition: densematrix.hh:28
Dune::DiagonalRowVectorConst::beforeBegin
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:761
Dune::DiagonalMatrix::blocklevel
@ blocklevel
The number of block levels we contain. This is 1.
Definition: diagonalmatrix.hh:71
Dune::DiagonalMatrix::operator[]
reference operator[](size_type i)
Return reference object as row replacement.
Definition: diagonalmatrix.hh:502
Dune::DiagonalMatrix::row_type
DiagonalRowVector< K, n > row_type
Each row is implemented by a field vector.
Definition: diagonalmatrix.hh:75
Dune::DiagonalMatrix::solve
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:437
typetraits.hh
Traits for type conversions and type information.
Dune::DiagonalMatrix::exists
bool exists(size_type i, size_type j) const
return true when (i,j) is in pattern
Definition: diagonalmatrix.hh:481
Dune::DiagonalRowVector::operator[]
K & operator[](size_type i)
random access
Definition: diagonalmatrix.hh:862
Dune::DiagonalMatrix::ConstIterator
ContainerWrapperIterator< const WrapperType, const_reference, const_reference > ConstIterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:178
Dune::DiagonalMatrix::mv
void mv(const X &x, Y &y) const
y = A x
Definition: diagonalmatrix.hh:277
Dune::DiagonalMatrix::operator*=
DiagonalMatrix & operator*=(const K &k)
vector space multiplication with scalar
Definition: diagonalmatrix.hh:245
Dune::DiagonalMatrix::operator/=
DiagonalMatrix & operator/=(const K &k)
vector space division by scalar
Definition: diagonalmatrix.hh:252
Dune::ContainerWrapperIterator::ContainerWrapperIterator
ContainerWrapperIterator(const MyConstType &other)
Definition: diagonalmatrix.hh:1015
Dune::DiagonalMatrix::operator==
bool operator==(const DiagonalMatrix &other) const
comparison operator
Definition: diagonalmatrix.hh:261
Dune::DiagonalRowVector::end
Iterator end()
end iterator
Definition: diagonalmatrix.hh:881
Dune::DiagonalMatrix::beforeBegin
ConstIterator beforeBegin() const
Definition: diagonalmatrix.hh:207
Dune::DiagonalMatrix::invert
void invert()
Compute inverse.
Definition: diagonalmatrix.hh:444
Dune::DiagonalRowVector::begin
Iterator begin()
begin iterator
Definition: diagonalmatrix.hh:875
Dune::DiagonalMatrix::RowIterator
Iterator RowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:146
Dune::DiagonalMatrix::usmhv
void usmhv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: diagonalmatrix.hh:394
Dune::const_reference< DiagonalRowVectorConst< K, n > >::type
DiagonalRowVectorConst< K, n > type
Definition: diagonalmatrix.hh:941
Dune::DiagonalRowVector::Iterator
ContainerWrapperIterator< DiagonalRowVector< K, n >, K, K & > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:870
Dune::DiagonalMatrix::determinant
K determinant() const
calculates the determinant of this matrix
Definition: diagonalmatrix.hh:452
Dune::DiagonalMatrix::usmv
void usmv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A x
Definition: diagonalmatrix.hh:368
Dune::DiagonalMatrix::operator=
DiagonalMatrix & operator=(const K &k)
Assignment from a scalar.
Definition: diagonalmatrix.hh:128
Dune::DiagonalMatrix::ConstColIterator
const_row_type::ConstIterator ConstColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:184
Dune::DiagonalRowVectorConst::row_
size_type row_
Definition: diagonalmatrix.hh:819
Dune::DiagonalRowVector::beforeBegin
Iterator beforeBegin()
Definition: diagonalmatrix.hh:895
Dune::DiagonalMatrix::Iterator
ContainerWrapperIterator< const WrapperType, reference, reference > Iterator
Iterator class for sequential access.
Definition: diagonalmatrix.hh:142
Dune::ContainerWrapperIterator::ContainerWrapperIterator
ContainerWrapperIterator(CW containerWrapper, int position)
Definition: diagonalmatrix.hh:999
Dune::DiagonalRowVectorConst::size
@ size
The size of this vector.
Definition: diagonalmatrix.hh:703
Dune::DenseMatrix::N
size_type N() const
number of rows
Definition: densematrix.hh:724
Dune::DenseMatrixAssigner
you have to specialize this structure for any type that should be assignable to a DenseMatrix
Definition: densematrix.hh:83
Dune::DiagonalMatrix::infinity_norm_real
double infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: diagonalmatrix.hh:426
Dune::DiagonalRowVectorConst
Definition: diagonalmatrix.hh:31
Dune::DenseMatrix::M
size_type M() const
number of columns
Definition: densematrix.hh:730
Dune::DiagonalRowVectorConst::dimension
@ dimension
Definition: diagonalmatrix.hh:679
Dune::DiagonalMatrix::operator!=
bool operator!=(const DiagonalMatrix &other) const
incomparison operator
Definition: diagonalmatrix.hh:267
Dune::FieldTraits
Definition: ftraits.hh:23
Dune::ContainerWrapperIterator::elementAt
R elementAt(int i) const
Definition: diagonalmatrix.hh:1063
Dune::DiagonalMatrix::size
size_type size() const
Definition: diagonalmatrix.hh:92
Dune::DiagonalMatrix::ConstRowIterator
ConstIterator ConstRowIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:182
Dune::DiagonalRowVectorConst::DiagonalRowVectorConst
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:713
Dune::DiagonalMatrix::const_row_type
DiagonalRowVectorConst< K, n > const_row_type
Definition: diagonalmatrix.hh:78
genericiterator.hh
Implements a generic iterator class for writing stl conformant iterators.
Dune::ContainerWrapperIterator::advance
void advance(int n)
Definition: diagonalmatrix.hh:1068
Dune::DiagonalRowVectorConst::p_
K * p_
Definition: diagonalmatrix.hh:818
Dune::ContainerWrapperIterator::ContainerWrapperIterator
ContainerWrapperIterator(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:1005
Dune::DiagonalMatrix::ColIterator
row_type::Iterator ColIterator
rename the iterators for easier access
Definition: diagonalmatrix.hh:148
unused.hh
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Dune::DiagonalMatrix::end
ConstIterator end() const
end iterator
Definition: diagonalmatrix.hh:193
Dune::FieldVector< K, n >
Dune::DiagonalMatrix::DiagonalMatrix
DiagonalMatrix(const FieldVector< K, n > &diag)
Constructor initializing the diagonal with a vector.
Definition: diagonalmatrix.hh:108
Dune::DiagonalMatrix::mmtv
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: diagonalmatrix.hh:344
Dune::DiagonalMatrix::operator[]
const_reference operator[](size_type i) const
Return const_reference object as row replacement.
Definition: diagonalmatrix.hh:508
Dune::mutable_reference< DiagonalRowVector< K, n > >::type
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:947
Dune::DiagonalMatrix::frobenius_norm2
double frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: diagonalmatrix.hh:414
Dune::DiagonalRowVector::size_type
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:841
Dune::DiagonalMatrix::const_row_reference
const_row_type const_row_reference
Definition: diagonalmatrix.hh:80
Dune::mutable_reference< DiagonalRowVectorConst< K, n > >::type
DiagonalRowVector< K, n > type
Definition: diagonalmatrix.hh:953
DUNE_ASSERT_BOUNDS
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28
Dune::DiagonalRowVector::beforeEnd
Iterator beforeEnd()
Definition: diagonalmatrix.hh:888
Dune::DiagonalMatrix::beforeEnd
Iterator beforeEnd()
Definition: diagonalmatrix.hh:164
Dune::DiagonalMatrix::mtv
void mtv(const X &x, Y &y) const
y = A^T x
Definition: diagonalmatrix.hh:289
Dune::DiagonalMatrix::size_type
std::size_t size_type
The type used for the index access and size operations.
Definition: diagonalmatrix.hh:66
Dune::DiagonalRowVectorConst::begin
ConstIterator begin() const
begin ConstIterator
Definition: diagonalmatrix.hh:741
Dune::DiagonalMatrix::iterator
Iterator iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:144
Dune::DiagonalMatrix::value_type
K value_type
export the type representing the field
Definition: diagonalmatrix.hh:59
Dune::DiagonalRowVector::field_type
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:835
fmatrix.hh
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Dune::DiagonalRowVectorConst::block_type
K block_type
export the type representing the components
Definition: diagonalmatrix.hh:689
Dune::DiagonalMatrix::infinity_norm
double infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: diagonalmatrix.hh:420
Dune::DiagonalRowVectorConst::beforeEnd
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:754
Dune::DiagonalMatrixWrapper::DiagonalMatrixWrapper
DiagonalMatrixWrapper(const DiagonalMatrixType *mat)
Definition: diagonalmatrix.hh:641
Dune::DiagonalMatrix
A diagonal matrix of static size.
Definition: diagonalmatrix.hh:51
Dune::ContainerWrapperIterator::equals
bool equals(const MyConstType &other) const
Definition: diagonalmatrix.hh:1041
Dune::DiagonalMatrix::M
size_type M() const
number of blocks in column direction
Definition: diagonalmatrix.hh:471
Dune::DiagonalMatrix::operator+=
DiagonalMatrix & operator+=(const DiagonalMatrix &y)
vector space addition
Definition: diagonalmatrix.hh:217
Dune::BidirectionalIteratorFacade
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:271
Dune::DiagonalRowVectorConst::blocklevel
@ blocklevel
The number of block levels we contain.
Definition: diagonalmatrix.hh:697
Dune::DiagonalRowVector
Definition: diagonalmatrix.hh:32
Dune::DiagonalMatrixWrapper::pointer
row_type * pointer(int i) const
Definition: diagonalmatrix.hh:650
Dune::DiagonalMatrix::diagonal
K & diagonal(size_type i)
Get reference to diagonal entry.
Definition: diagonalmatrix.hh:520
Dune::DiagonalMatrix::usmtv
void usmtv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: diagonalmatrix.hh:381
Dune::DiagonalMatrix::DiagonalMatrix
constexpr DiagonalMatrix()=default
Default constructor.
Dune::DiagonalRowVectorConst::ConstIterator
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:736
Dune::DiagonalRowVectorConst::DiagonalRowVectorConst
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:707
Dune::ContainerWrapperIterator::operator=
ContainerWrapperIterator & operator=(OtherContainerWrapperIteratorType &other)
Definition: diagonalmatrix.hh:1021
Dune::DiagonalMatrix::const_iterator
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:180
DUNE_THROW
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Dune::DiagonalRowVectorConst::identical
bool identical(const DiagonalRowVectorConst< K, n > &other) const
Definition: diagonalmatrix.hh:730
Dune::DiagonalRowVectorConst::diagonal
const K & diagonal() const
the diagonal value
Definition: diagonalmatrix.hh:793
Dune::DiagonalMatrix::identical
bool identical(const DiagonalMatrix< K, n > &other) const
Check if matrix is the same object as the other matrix.
Definition: diagonalmatrix.hh:135
densematrix.hh
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
Dune::DiagonalRowVectorConst::pointer
K * pointer(size_type i) const
Definition: diagonalmatrix.hh:806
Dune::DiagonalMatrix::rows
@ rows
The number of rows.
Definition: diagonalmatrix.hh:85
Dune::FieldTraits< DiagonalMatrix< K, n > >::field_type
FieldTraits< K >::field_type field_type
Definition: diagonalmatrix.hh:546
Dune::DiagonalMatrix::frobenius_norm
double frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: diagonalmatrix.hh:408
Dune::DiagonalRowVectorConst::operator&
DiagonalRowVectorConst * operator&()
Definition: diagonalmatrix.hh:812
Dune::DiagonalMatrix::N
size_type N() const
number of blocks in row direction
Definition: diagonalmatrix.hh:465
Dune::DiagonalRowVectorConst::const_iterator
ConstIterator const_iterator
typedef for stl compliant access
Definition: diagonalmatrix.hh:738
Dune::DiagonalMatrix::umv
void umv(const X &x, Y &y) const
y += A x
Definition: diagonalmatrix.hh:296
Dune::DiagonalRowVectorConst::size_type
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:692
Dune
Dune namespace.
Definition: alignedallocator.hh:13