dune-fem  2.8-git
subobjects.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_SUBOBJECTS_HH
2 #define DUNE_FEM_SUBOBJECTS_HH
3 
4 #include <type_traits>
5 
6 #include <dune/common/fvector.hh>
7 #include <dune/common/fmatrix.hh>
8 
10 
11 
12 namespace Dune
13 {
14 
15  namespace Fem
16  {
17 
18  template< class T >
19  struct RowType;
20 
21  template< class T >
22  struct RowType< const T>
23  {
24  typedef const typename RowType<T> :: Type Type;
25  static const int size = RowType<T> :: size;
26  };
27 
28  template< class K, int SIZE >
29  struct RowType< FieldVector< K, SIZE > >
30  {
31  typedef K Type;
32  static const int size = SIZE;
33  };
34 
35  template< class K, int SIZE >
36  struct RowType< ExplicitFieldVector< K, SIZE > >
37  {
38  typedef K Type;
39  static const int size = SIZE;
40  };
41 
42  template< class K, int ROWS, int COLS >
43  struct RowType< FieldMatrix< K, ROWS, COLS > >
44  {
45  typedef FieldVector<K, COLS> Type;
46  static const int size = ROWS;
47  };
48 
49 
50 
51  template <class DomainObject, class RangeObject, int offset >
52  class SubObject
53  {
54  typedef DomainObject DomainObjectType;
55  typedef RangeObject RangeObjectType;
56 
57  typedef typename RowType< RangeObject > :: Type RowType;
58 
59  public:
60  SubObject( DomainObjectType &host )
61  : host_( host )
62  {}
63 
64  const RowType &operator[] ( const int i ) const
65  {
66  assert( (i >=0 ) && (i < size()) );
67  return host_[ i + offset ];
68  }
69 
70  RowType& operator[] ( const int i )
71  {
72  assert( (i >=0 ) && (i < size()) );
73  return host_[ i + offset ];
74  }
75 
76  int size () const
77  {
79  }
80 
81  operator typename std::remove_const< RangeObjectType >::type () const
82  {
83  typename std::remove_const< RangeObjectType >::type y;
84  for( int i = 0; i < size(); ++i )
85  y[ i ] = (*this)[ i ];
86  return y;
87  }
88 
89  private:
90  DomainObjectType &host_;
91  };
92 
93  } // namespace Fem
94 
95 
96  // cast into fieldMatrix
97  template< class DomianObj, class RangeObj, int offset >
98  struct DenseMatrixAssigner< typename std::remove_const< RangeObj >::type, Fem::SubObject< DomianObj, RangeObj, offset > >
99  {
100  static void apply ( typename std::remove_const< RangeObj >::type &fm, const Fem::SubObject< DomianObj, RangeObj, offset > &s )
101  {
102  for( int i = 0; i < s.size(); ++i )
103  fm[ i ] = s[ i ];
104  }
105  };
106 
107 } // namespace Dune
108 
109 #endif // #ifndef DUNE_FEM_SUBOBJECTS_HH
Definition: bindguard.hh:11
Definition: explicitfieldvector.hh:75
Definition: subobjects.hh:19
const RowType< T >::Type Type
Definition: subobjects.hh:24
K Type
Definition: subobjects.hh:31
FieldVector< K, COLS > Type
Definition: subobjects.hh:45
Definition: subobjects.hh:53
const RowType & operator[](const int i) const
Definition: subobjects.hh:64
int size() const
Definition: subobjects.hh:76
SubObject(DomainObjectType &host)
Definition: subobjects.hh:60
static void apply(typename std::remove_const< RangeObj >::type &fm, const Fem::SubObject< DomianObj, RangeObj, offset > &s)
Definition: subobjects.hh:100