00001 #ifndef DUNE_COMMON_IDENTITYMATRIX_HH
00002 #define DUNE_COMMON_IDENTITYMATRIX_HH
00003
00004 #warning Deprecated since dune-common 2.5: If you really do need an identity matrix, use DiagonalMatrix or ScalarIdentityMatrix (from dune-istl) instead!
00005
00006 #include <dune/common/boundschecking.hh>
00007 #include <dune/common/fmatrix.hh>
00008 #include <dune/common/ftraits.hh>
00009 #include <dune/common/math.hh>
00010
00019 namespace Dune
00020 {
00021
00022
00023
00024
00036 template< class K, int N >
00037 struct IdentityMatrix
00038 {
00040 typedef K field_type;
00042 typedef std::size_t size_type;
00043
00045 constexpr size_type rows () const { return N; }
00047 constexpr size_type cols () const { return N; }
00048
00050 template< class X, class Y >
00051 void mv ( const X &x, Y &y ) const
00052 {
00053 y = x;
00054 }
00055
00057 template< class X, class Y >
00058 void mtv ( const X &x, Y &y ) const
00059 {
00060 y = x;
00061 }
00062
00064 template< class X, class Y >
00065 void umv ( const X &x, Y &y ) const
00066 {
00067 y += x;
00068 }
00069
00071 template< class X, class Y >
00072 void umtv ( const X &x, Y &y ) const
00073 {
00074 y += x;
00075 }
00076
00078 template< class X, class Y >
00079 void umhv ( const X &x, Y &y ) const
00080 {
00081 y += x;
00082 }
00083
00085 template< class X, class Y >
00086 void mmv ( const X &x, Y &y ) const
00087 {
00088 y -= x;
00089 }
00090
00092 template< class X, class Y >
00093 void mmtv ( const X &x, Y &y ) const
00094 {
00095 y -= x;
00096 }
00097
00099 template< class X, class Y >
00100 void mmhv ( const X &x, Y &y ) const
00101 {
00102 y -= x;
00103 }
00104
00106 template< class X, class Y >
00107 void usmv (const typename FieldTraits<Y>::field_type & alpha,
00108 const X& x, Y& y) const
00109 {
00110 y.axpy( alpha, x );
00111 }
00112
00114 template< class X, class Y >
00115 void usmtv (const typename FieldTraits<Y>::field_type & alpha,
00116 const X& x, Y& y) const
00117 {
00118 y.axpy( alpha, x );
00119 }
00120
00122 template< class X, class Y >
00123 void usmhv (const typename FieldTraits<Y>::field_type & alpha,
00124 const X& x, Y& y) const
00125 {
00126 y.axpy( alpha, x );
00127 }
00128
00130 typename FieldTraits< field_type >::real_type frobenius_norm () const
00131 {
00132 return std::sqrt( frobenius_norm2() );
00133 }
00134
00136 typename FieldTraits< field_type >::real_type frobenius_norm2 () const
00137 {
00138 return FieldTraits< field_type >::real_type( N );
00139 }
00140
00142 typename FieldTraits< field_type >::real_type infinity_norm () const
00143 {
00144 return FieldTraits< field_type >::real_type( 1 );
00145 }
00146
00148 typename FieldTraits< field_type >::real_type infinity_norm_real () const
00149 {
00150 return FieldTraits< field_type >::real_type( 1 );
00151 }
00152 };
00153
00154 template <class DenseMatrix, class field, int N>
00155 struct DenseMatrixAssigner<DenseMatrix, IdentityMatrix<field, N>> {
00156 static void apply(DenseMatrix &denseMatrix, IdentityMatrix<field, N> const &rhs) {
00157 DUNE_ASSERT_BOUNDS(denseMatrix.M() == N);
00158 DUNE_ASSERT_BOUNDS(denseMatrix.N() == N);
00159 denseMatrix = field(0);
00160 for (int i = 0; i < N; ++i)
00161 denseMatrix[i][i] = field(1);
00162 }
00163 };
00164 }
00165
00166 #endif // #ifndef DUNE_COMMON_IDENTITYMATRIX_HH