Dune Core Modules (2.5.2)

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 #ifndef DOXYGEN // hide specialization
545  template< class K >
546  class DiagonalMatrix<K, 1> : public FieldMatrix<K, 1, 1>
547  {
548  typedef FieldMatrix<K,1,1> Base;
549  public:
551  typedef typename Base::size_type size_type;
552 
554  enum {
557  blocklevel = 1
558  };
559 
560  typedef typename Base::row_type row_type;
561 
562  typedef typename Base::row_reference row_reference;
563  typedef typename Base::const_row_reference const_row_reference;
564 
566  enum {
569  rows = 1,
572  cols = 1
573  };
574 
575 
578  {}
579 
581  DiagonalMatrix(const K& scalar)
582  {
583  (*this)[0][0] = scalar;
584  }
585 
587  const K& diagonal(size_type) const
588  {
589  return (*this)[0][0];
590  }
591 
593  K& diagonal(size_type)
594  {
595  return (*this)[0][0];
596  }
597 
599  const FieldVector<K,1>& diagonal() const
600  {
601  return (*this)[0];
602  }
603 
605  FieldVector<K,1>& diagonal()
606  {
607  return (*this)[0];
608  }
609 
610  };
611 #endif
612 
613 
614  template<class DiagonalMatrixType>
615  class DiagonalMatrixWrapper
616  {
617  typedef typename DiagonalMatrixType::reference reference;
618  typedef typename DiagonalMatrixType::const_reference const_reference;
619  typedef typename DiagonalMatrixType::field_type K;
620  typedef DiagonalRowVector<K, DiagonalMatrixType::rows> row_type;
621  typedef std::size_t size_type;
622  typedef DiagonalMatrixWrapper< DiagonalMatrixType> MyType;
623 
624  friend class ContainerWrapperIterator<const MyType, reference, reference>;
625  friend class ContainerWrapperIterator<const MyType, const_reference, const_reference>;
626 
627  public:
628 
629  DiagonalMatrixWrapper() :
630  mat_(0)
631  {}
632 
633  DiagonalMatrixWrapper(const DiagonalMatrixType* mat) :
634  mat_(const_cast<DiagonalMatrixType*>(mat))
635  {}
636 
637  size_type realIndex(int i) const
638  {
639  return i;
640  }
641 
642  row_type* pointer(int i) const
643  {
644  row_ = row_type(&(mat_->diagonal(i)), i);
645  return &row_;
646  }
647 
648  bool identical(const DiagonalMatrixWrapper& other) const
649  {
650  return mat_==other.mat_;
651  }
652 
653  private:
654 
655  mutable DiagonalMatrixType* mat_;
656  mutable row_type row_;
657  };
658 
662  template< class K, int n >
663  class DiagonalRowVectorConst
664  {
665  template<class DiagonalMatrixType>
666  friend class DiagonalMatrixWrapper;
667  friend class ContainerWrapperIterator<DiagonalRowVectorConst<K,n>, const K, const K&>;
668 
669  public:
670  // remember size of vector
671  enum { dimension = n };
672 
673  // standard constructor and everything is sufficient ...
674 
675  //===== type definitions and constants
676 
678  typedef K field_type;
679 
681  typedef K block_type;
682 
684  typedef std::size_t size_type;
685 
687  enum {
689  blocklevel = 1
690  };
691 
693  enum {
695  size = n
696  };
697 
700  p_(0),
701  row_(0)
702  {}
703 
705  explicit DiagonalRowVectorConst (K* p, int col) :
706  p_(p),
707  row_(col)
708  {}
709 
710  //===== access to components
711 
713  const K& operator[] (size_type i) const
714  {
716  DUNE_ASSERT_BOUNDS(i == row_);
717  return *p_;
718  }
719 
720  // check if row is identical to other row (not only identical values)
721  // since this is a proxy class we need to check equality of the stored pointer
722  bool identical(const DiagonalRowVectorConst<K,n>& other) const
723  {
724  return ((p_ == other.p_)and (row_ == other.row_));
725  }
726 
731 
734  {
735  return ConstIterator(*this,0);
736  }
737 
740  {
741  return ConstIterator(*this,1);
742  }
743 
747  {
748  return ConstIterator(*this,0);
749  }
750 
754  {
755  return ConstIterator(*this,-1);
756  }
757 
759  bool operator== (const DiagonalRowVectorConst& y) const
760  {
761  return ((p_==y.p_)and (row_==y.row_));
762  }
763 
764  //===== sizes
765 
767  size_type N () const
768  {
769  return n;
770  }
771 
773  size_type dim () const
774  {
775  return n;
776  }
777 
780  {
781  return row_;
782  }
783 
785  const K& diagonal() const
786  {
787  return *p_;
788  }
789 
790  protected:
791 
792  size_type realIndex(int i) const
793  {
794  return rowIndex();
795  }
796 
797  K* pointer(size_type i) const
798  {
799  return const_cast<K*>(p_);
800  }
801 
802  DiagonalRowVectorConst* operator&()
803  {
804  return this;
805  }
806 
807  // the data, very simply a pointer to the diagonal value and the row number
808  K* p_;
809  size_type row_;
810  };
811 
812  template< class K, int n >
813  class DiagonalRowVector : public DiagonalRowVectorConst<K,n>
814  {
815  template<class DiagonalMatrixType>
816  friend class DiagonalMatrixWrapper;
817  friend class ContainerWrapperIterator<DiagonalRowVector<K,n>, K, K&>;
818 
819  public:
820  // standard constructor and everything is sufficient ...
821 
822  //===== type definitions and constants
823 
825  typedef K field_type;
826 
828  typedef K block_type;
829 
831  typedef std::size_t size_type;
832 
834  DiagonalRowVector() : DiagonalRowVectorConst<K,n>()
835  {}
836 
838  explicit DiagonalRowVector (K* p, int col) : DiagonalRowVectorConst<K,n>(p, col)
839  {}
840 
841  //===== assignment from scalar
843  DiagonalRowVector& operator= (const K& k)
844  {
845  *p_ = k;
846  return *this;
847  }
848 
849  //===== access to components
850 
852  K& operator[] (size_type i)
853  {
855  DUNE_ASSERT_BOUNDS(i == row_);
856  return *p_;
857  }
858 
863 
866  {
867  return Iterator(*this, 0);
868  }
869 
872  {
873  return Iterator(*this, 1);
874  }
875 
879  {
880  return Iterator(*this, 0);
881  }
882 
886  {
887  return Iterator(*this, -1);
888  }
889 
894 
895  using DiagonalRowVectorConst<K,n>::identical;
896  using DiagonalRowVectorConst<K,n>::operator[];
897  using DiagonalRowVectorConst<K,n>::operator==;
898  using DiagonalRowVectorConst<K,n>::begin;
899  using DiagonalRowVectorConst<K,n>::end;
900  using DiagonalRowVectorConst<K,n>::beforeEnd;
901  using DiagonalRowVectorConst<K,n>::beforeBegin;
902  using DiagonalRowVectorConst<K,n>::N;
903  using DiagonalRowVectorConst<K,n>::dim;
904  using DiagonalRowVectorConst<K,n>::rowIndex;
905  using DiagonalRowVectorConst<K,n>::diagonal;
906 
907  protected:
908 
909  DiagonalRowVector* operator&()
910  {
911  return this;
912  }
913 
914  private:
915 
916  using DiagonalRowVectorConst<K,n>::p_;
917  using DiagonalRowVectorConst<K,n>::row_;
918  };
919 
920 
921  // implement type traits
922  template<class K, int n>
923  struct const_reference< DiagonalRowVector<K,n> >
924  {
925  typedef DiagonalRowVectorConst<K,n> type;
926  };
927 
928  template<class K, int n>
929  struct const_reference< DiagonalRowVectorConst<K,n> >
930  {
931  typedef DiagonalRowVectorConst<K,n> type;
932  };
933 
934  template<class K, int n>
935  struct mutable_reference< DiagonalRowVector<K,n> >
936  {
937  typedef DiagonalRowVector<K,n> type;
938  };
939 
940  template<class K, int n>
941  struct mutable_reference< DiagonalRowVectorConst<K,n> >
942  {
943  typedef DiagonalRowVector<K,n> type;
944  };
945 
946 
947 
970  template<class CW, class T, class R>
971  class ContainerWrapperIterator : public BidirectionalIteratorFacade<ContainerWrapperIterator<CW,T,R>,T, R, int>
972  {
973  typedef typename std::remove_const<CW>::type NonConstCW;
974 
975  friend class ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type>;
976  friend class ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type>;
977 
978  typedef ContainerWrapperIterator<CW, typename mutable_reference<T>::type, typename mutable_reference<R>::type> MyType;
979  typedef ContainerWrapperIterator<CW, typename const_reference<T>::type, typename const_reference<R>::type> MyConstType;
980 
981  public:
982 
983  // Constructors needed by the facade iterators.
985  containerWrapper_(),
986  position_(0)
987  {}
988 
989  ContainerWrapperIterator(CW containerWrapper, int position) :
990  containerWrapper_(containerWrapper),
991  position_(position)
992  {}
993 
994  template<class OtherContainerWrapperIteratorType>
995  ContainerWrapperIterator(OtherContainerWrapperIteratorType& other) :
996  containerWrapper_(other.containerWrapper_),
997  position_(other.position_)
998  {}
999 
1000  ContainerWrapperIterator(const MyType& other) :
1001  containerWrapper_(other.containerWrapper_),
1002  position_(other.position_)
1003  {}
1004 
1005  ContainerWrapperIterator(const MyConstType& other) :
1006  containerWrapper_(other.containerWrapper_),
1007  position_(other.position_)
1008  {}
1009 
1010  template<class OtherContainerWrapperIteratorType>
1011  ContainerWrapperIterator& operator=(OtherContainerWrapperIteratorType& other)
1012  {
1013  containerWrapper_ = other.containerWrapper_;
1014  position_ = other.position_;
1015  return *this;
1016  }
1017 
1018  // This operator is needed since we can not get the address of the
1019  // temporary object returned by dereference
1020  T* operator->() const
1021  {
1022  return containerWrapper_.pointer(position_);
1023  }
1024 
1025  // Methods needed by the forward iterator
1026  bool equals(const MyType& other) const
1027  {
1028  return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1029  }
1030 
1031  bool equals(const MyConstType& other) const
1032  {
1033  return position_ == other.position_ && containerWrapper_.identical(other.containerWrapper_);
1034  }
1035 
1036  R dereference() const
1037  {
1038  return *containerWrapper_.pointer(position_);
1039  }
1040 
1041  void increment()
1042  {
1043  ++position_;
1044  }
1045 
1046  // Additional function needed by BidirectionalIterator
1047  void decrement()
1048  {
1049  --position_;
1050  }
1051 
1052  // Additional function needed by RandomAccessIterator
1053  R elementAt(int i) const
1054  {
1055  return *containerWrapper_.pointer(position_+i);
1056  }
1057 
1058  void advance(int n)
1059  {
1060  position_=position_+n;
1061  }
1062 
1063  template<class OtherContainerWrapperIteratorType>
1064  std::ptrdiff_t distanceTo(OtherContainerWrapperIteratorType& other) const
1065  {
1066  assert(containerWrapper_.identical(other));
1067  return other.position_ - position_;
1068  }
1069 
1070  std::ptrdiff_t index() const
1071  {
1072  return containerWrapper_.realIndex(position_);
1073  }
1074 
1075  private:
1076  NonConstCW containerWrapper_;
1077  size_t position_;
1078  };
1079 
1080  template <class DenseMatrix, class field, int N>
1081  struct DenseMatrixAssigner<DenseMatrix, DiagonalMatrix<field, N>> {
1082  static void apply(DenseMatrix& denseMatrix,
1083  DiagonalMatrix<field, N> const& rhs) {
1084  DUNE_ASSERT_BOUNDS(denseMatrix.M() == N);
1085  DUNE_ASSERT_BOUNDS(denseMatrix.N() == N);
1086  denseMatrix = field(0);
1087  for (int i = 0; i < N; ++i)
1088  denseMatrix[i][i] = rhs.diagonal()[i];
1089  }
1090  };
1091  /* @} */
1092 } // end namespace
1093 #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:972
A dense n x m matrix.
Definition: densematrix.hh:154
size_type M() const
number of columns
Definition: densematrix.hh:677
size_type N() const
number of rows
Definition: densematrix.hh:671
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:140
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
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:773
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:862
K field_type
export the type representing the field
Definition: diagonalmatrix.hh:678
ConstIterator beforeEnd() const
Definition: diagonalmatrix.hh:746
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:838
void solve(V &x, const V &b) const
Solve system A x = b.
Definition: diagonalmatrix.hh:437
Iterator beforeBegin()
Definition: diagonalmatrix.hh:885
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:733
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:893
DiagonalRowVectorConst(K *p, int col)
Constructor making vector with identical coordinates.
Definition: diagonalmatrix.hh:705
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:860
Iterator beforeEnd()
Definition: diagonalmatrix.hh:878
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:730
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:779
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:865
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:834
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:891
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:767
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:825
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:785
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:871
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:831
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:739
std::size_t size_type
The type used for the index access and size operation.
Definition: diagonalmatrix.hh:684
DiagonalRowVectorConst()
Constructor making uninitialized vector.
Definition: diagonalmatrix.hh:699
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:681
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:753
ContainerWrapperIterator< DiagonalRowVectorConst< K, n >, const K, const K & > ConstIterator
ConstIterator class for sequential access.
Definition: diagonalmatrix.hh:728
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:828
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: alignment.hh:11
K conjugateComplex(const K &x)
compute conjugate complex of x
Definition: math.hh:103
you have to specialize this structure for any type that should be assignable to a DenseMatrix
Definition: densematrix.hh:74
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.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 13, 22:30, 2024)