dune-common  2.5.1
identitymatrix.hh
Go to the documentation of this file.
1 #ifndef DUNE_COMMON_IDENTITYMATRIX_HH
2 #define DUNE_COMMON_IDENTITYMATRIX_HH
3 
4 #warning Deprecated since dune-common 2.5: If you really do need an identity matrix, use DiagonalMatrix or ScalarIdentityMatrix (from dune-istl) instead!
5 
7 #include <dune/common/fmatrix.hh>
8 #include <dune/common/ftraits.hh>
9 #include <dune/common/math.hh>
10 
19 namespace Dune
20 {
21 
22  // IdentityMatrix
23  // --------------
24 
36  template< class K, int N >
38  {
40  typedef K field_type;
42  typedef std::size_t size_type;
43 
45  constexpr size_type rows () const { return N; }
47  constexpr size_type cols () const { return N; }
48 
50  template< class X, class Y >
51  void mv ( const X &x, Y &y ) const
52  {
53  y = x;
54  }
55 
57  template< class X, class Y >
58  void mtv ( const X &x, Y &y ) const
59  {
60  y = x;
61  }
62 
64  template< class X, class Y >
65  void umv ( const X &x, Y &y ) const
66  {
67  y += x;
68  }
69 
71  template< class X, class Y >
72  void umtv ( const X &x, Y &y ) const
73  {
74  y += x;
75  }
76 
78  template< class X, class Y >
79  void umhv ( const X &x, Y &y ) const
80  {
81  y += x;
82  }
83 
85  template< class X, class Y >
86  void mmv ( const X &x, Y &y ) const
87  {
88  y -= x;
89  }
90 
92  template< class X, class Y >
93  void mmtv ( const X &x, Y &y ) const
94  {
95  y -= x;
96  }
97 
99  template< class X, class Y >
100  void mmhv ( const X &x, Y &y ) const
101  {
102  y -= x;
103  }
104 
106  template< class X, class Y >
107  void usmv (const typename FieldTraits<Y>::field_type & alpha,
108  const X& x, Y& y) const
109  {
110  y.axpy( alpha, x );
111  }
112 
114  template< class X, class Y >
115  void usmtv (const typename FieldTraits<Y>::field_type & alpha,
116  const X& x, Y& y) const
117  {
118  y.axpy( alpha, x );
119  }
120 
122  template< class X, class Y >
123  void usmhv (const typename FieldTraits<Y>::field_type & alpha,
124  const X& x, Y& y) const
125  {
126  y.axpy( alpha, x );
127  }
128 
131  {
132  return std::sqrt( frobenius_norm2() );
133  }
134 
137  {
139  }
140 
143  {
145  }
146 
149  {
151  }
152  };
153 
154  template <class DenseMatrix, class field, int N>
156  static void apply(DenseMatrix &denseMatrix, IdentityMatrix<field, N> const &rhs) {
157  DUNE_ASSERT_BOUNDS(denseMatrix.M() == N);
158  DUNE_ASSERT_BOUNDS(denseMatrix.N() == N);
159  denseMatrix = field(0);
160  for (int i = 0; i < N; ++i)
161  denseMatrix[i][i] = field(1);
162  }
163  };
164 } // namespace Dune
165 
166 #endif // #ifndef DUNE_COMMON_IDENTITYMATRIX_HH
std::size_t size_type
size type
Definition: identitymatrix.hh:42
constexpr size_type cols() const
return number of columns
Definition: identitymatrix.hh:47
void usmv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A x
Definition: identitymatrix.hh:107
FieldTraits< field_type >::real_type frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition: identitymatrix.hh:130
FieldTraits< field_type >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition: identitymatrix.hh:148
static void apply(DenseMatrix &denseMatrix, IdentityMatrix< field, N > const &rhs)
Definition: identitymatrix.hh:156
void usmhv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition: identitymatrix.hh:123
void usmtv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition: identitymatrix.hh:115
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition: identitymatrix.hh:100
void umv(const X &x, Y &y) const
y += A x
Definition: identitymatrix.hh:65
void umhv(const X &x, Y &y) const
y += A^H x
Definition: identitymatrix.hh:79
FieldTraits< field_type >::real_type frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition: identitymatrix.hh:136
Dune namespace.
Definition: alignment.hh:10
Some useful basic math stuff.
K field_type
field type
Definition: identitymatrix.hh:40
Macro for wrapping boundary checks.
FieldTraits< field_type >::real_type infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition: identitymatrix.hh:142
void mmv(const X &x, Y &y) const
y -= A x
Definition: identitymatrix.hh:86
void mtv(const X &x, Y &y) const
y = A^T x
Definition: identitymatrix.hh:58
T real_type
export the type representing the real type of the field
Definition: ftraits.hh:28
constexpr size_type rows() const
return number of rows
Definition: identitymatrix.hh:45
size_type M() const
number of columns
Definition: densematrix.hh:677
you have to specialize this structure for any type that should be assignable to a DenseMatrix ...
Definition: densematrix.hh:74
A dense n x m matrix.
Definition: densematrix.hh:25
void umtv(const X &x, Y &y) const
y += A^T x
Definition: identitymatrix.hh:72
void mv(const X &x, Y &y) const
y = A x
Definition: identitymatrix.hh:51
Read-only identity matrix.
Definition: identitymatrix.hh:37
Implements a matrix constructed from a given type representing a field and compile-time given number ...
size_type N() const
number of rows
Definition: densematrix.hh:671
Type traits to determine the type of reals (when working with complex numbers)
T field_type
export the type representing the field
Definition: ftraits.hh:26
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition: identitymatrix.hh:93
#define DUNE_ASSERT_BOUNDS(cond)
If DUNE_CHECK_BOUNDS is defined: check if condition cond holds; otherwise, do nothing.
Definition: boundschecking.hh:28