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