dune-fem  2.8-git
fmatrixcol.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_COMMON_FMATRIXCOL_HH
2 #define DUNE_FEM_COMMON_FMATRIXCOL_HH
3 
4 #include <type_traits>
5 
6 #include <dune/common/densevector.hh>
7 #include <dune/common/fmatrix.hh>
8 
9 namespace Dune
10 {
11 
12  // Internal Forward Declarations
13  // -----------------------------
14 
15  template< class FieldMatrix >
17 
18 
19 
20  // DenseMatVecTraits for FieldMatrixColumn
21  // ---------------------------------------
22 
23  template< class FieldMatrix >
24  struct DenseMatVecTraits< FieldMatrixColumn< FieldMatrix > >
25  {
27 
28  typedef typename DenseMatVecTraits< typename std::remove_const< FieldMatrix >::type >::value_type value_type;
29  typedef typename DenseMatVecTraits< typename std::remove_const< FieldMatrix >::type >::size_type size_type;
30  };
31 
32 
33  // FieldTraits for FieldMatrixColumn
34  // ---------------------------------
35 
36  template< class FieldMatrix >
37  struct FieldTraits< FieldMatrixColumn< FieldMatrix > >
38  {
39  typedef typename FieldTraits< typename std::remove_const< FieldMatrix >::type >::field_type field_type;
40  typedef typename FieldTraits< typename std::remove_const< FieldMatrix >::type >::real_type real_type;
41  };
42 
43 
44 
45  // FieldMatrixColumn
46  // -----------------
47 
48  template< class K, int m, int n >
49  class FieldMatrixColumn< FieldMatrix< K, m, n > >
50  : public DenseVector< FieldMatrixColumn< FieldMatrix< K, m, n > > >
51  {
52  typedef DenseVector< FieldMatrixColumn< FieldMatrix< K, m, n > > > Base;
53 
54  public:
55  static const int dimension = m;
56 
57  typedef typename Base::size_type size_type;
58  typedef typename Base::value_type value_type;
59 
60  FieldMatrixColumn ( FieldMatrix< K, m, n > &fieldMatrix, int column )
61  : fieldMatrix_( fieldMatrix ),
62  column_( column )
63  {}
64 
65  using Base::operator=;
66 
67  constexpr size_type size () const { return dimension; }
68 
69  const value_type &operator[] ( size_type i ) const { return fieldMatrix_[ i ][ column_ ]; }
70  value_type &operator[] ( size_type i ) { return fieldMatrix_[ i ][ column_ ]; }
71 
72  private:
73  FieldMatrix< K, m, n > &fieldMatrix_;
74  int column_;
75  };
76 
77  template< class K, int m, int n >
78  class FieldMatrixColumn< const FieldMatrix< K, m, n > >
79  : public DenseVector< FieldMatrixColumn< const FieldMatrix< K, m, n > > >
80  {
81  typedef DenseVector< FieldMatrixColumn< const FieldMatrix< K, m, n > > > Base;
82 
83  public:
84  static const int dimension = m;
85 
86  typedef typename Base::size_type size_type;
87  typedef typename Base::value_type value_type;
88 
89  FieldMatrixColumn ( const FieldMatrix< K, m, n > &fieldMatrix, int column )
90  : fieldMatrix_( fieldMatrix ),
91  column_( column )
92  {}
93 
94  using Base::operator=;
95 
96  constexpr size_type size () const { return dimension; }
97  const value_type &operator[] ( size_type i ) const { return fieldMatrix_[ i ][ column_ ]; }
98 
99  private:
100  const FieldMatrix< K, m, n > &fieldMatrix_;
101  int column_;
102  };
103 
104 } // namespace Dune
105 
106 #endif // #ifndef DUNE_FEM_COMMON_FMATRIXCOL_HH
Definition: bindguard.hh:11
Definition: fmatrixcol.hh:16
DenseMatVecTraits< typename std::remove_const< FieldMatrix >::type >::value_type value_type
Definition: fmatrixcol.hh:28
FieldMatrixColumn< FieldMatrix > derived_type
Definition: fmatrixcol.hh:26
DenseMatVecTraits< typename std::remove_const< FieldMatrix >::type >::size_type size_type
Definition: fmatrixcol.hh:29
FieldTraits< typename std::remove_const< FieldMatrix >::type >::field_type field_type
Definition: fmatrixcol.hh:39
FieldTraits< typename std::remove_const< FieldMatrix >::type >::real_type real_type
Definition: fmatrixcol.hh:40
FieldMatrixColumn(FieldMatrix< K, m, n > &fieldMatrix, int column)
Definition: fmatrixcol.hh:60
constexpr size_type size() const
Definition: fmatrixcol.hh:67
Base::size_type size_type
Definition: fmatrixcol.hh:57
Base::value_type value_type
Definition: fmatrixcol.hh:58
Base::size_type size_type
Definition: fmatrixcol.hh:86
Base::value_type value_type
Definition: fmatrixcol.hh:87
FieldMatrixColumn(const FieldMatrix< K, m, n > &fieldMatrix, int column)
Definition: fmatrixcol.hh:89
constexpr size_type size() const
Definition: fmatrixcol.hh:96