dune-fem  2.4.1-rc
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 
9 
10 namespace Dune
11 {
12 
13  namespace Fem
14  {
15 
16  template< class DofVector, class Dof >
17  class SubDofVector
18  {
19  typedef DofVector DofVectorType;
20  typedef Dof DofType;
21 
22  public:
23  typedef DofType value_type;
24 
25  SubDofVector( DofVectorType &dofs, int size, int offset ) :
26  dofs_( dofs ),
27  offset_ ( offset ),
28  size_( size )
29  {}
30 
31  const DofType &operator[] ( const int i ) const
32  {
33  assert( (i < size_ )&& (i >= 0 ) );
34  return dofs_[ i + offset_ ];
35  }
36 
37  DofType &operator[] ( const int i )
38  {
39  assert( (i < size_ )&& (i >= 0 ) );
40  return dofs_[ i + offset_ ];
41  }
42 
43  int size() const
44  {
45  return size_;
46  }
47 
48 
49  private:
50  DofVectorType &dofs_;
51  const int offset_;
52  const int size_;
53  };
54 
55 
56  template< class T >
57  struct RowType;
58 
59  template< class T >
60  struct RowType< const T>
61  {
62  typedef const typename RowType<T> :: Type Type;
63  static const int size = RowType<T> :: size;
64  };
65 
66  template< class K, int SIZE >
67  struct RowType< FieldVector< K, SIZE > >
68  {
69  typedef K Type;
70  static const int size = SIZE;
71  };
72 
73  template< class K, int ROWS, int COLS >
74  struct RowType< FieldMatrix< K, ROWS, COLS > >
75  {
76  typedef FieldVector<K, COLS> Type;
77  static const int size = ROWS;
78  };
79 
80 
81 
82  template <class DomainObject, class RangeObject, int offset >
83  class SubObject
84  {
85  typedef DomainObject DomainObjectType;
86  typedef RangeObject RangeObjectType;
87 
88  typedef typename RowType< RangeObject > :: Type RowType;
89 
90  public:
91  SubObject( DomainObjectType &host )
92  : host_( host )
93  {}
94 
95  const RowType &operator[] ( const int i ) const
96  {
97  assert( (i >=0 ) && (i < size()) );
98  return host_[ i + offset ];
99  }
100 
101  RowType& operator[] ( const int i )
102  {
103  assert( (i >=0 ) && (i < size()) );
104  return host_[ i + offset ];
105  }
106 
107  int size () const
108  {
110  }
111 
112  operator typename std::remove_const< RangeObjectType >::type () const
113  {
114  typename std::remove_const< RangeObjectType >::type y;
115  for( int i = 0; i < size(); ++i )
116  y[ i ] = (*this)[ i ];
117  return y;
118  }
119 
120  private:
121  DomainObjectType &host_;
122  };
123 
124  } // namespace Fem
125 
126 
127  // cast into fieldMatrix
128  template<class DomainObj, class RangeObj, int offset>
129  void istl_assign_to_fmatrix( DenseMatrix< typename std::remove_const< RangeObj > :: type >& fm,
131  {
132  for( int i = 0; i < s.size(); ++i )
133  fm[ i ] = s[ i ];
134  }
135 
136 } // namespace Dune
137 
138 #endif // #ifndef DUNE_FEM_SUBOBJECTS_HH
SubObject(DomainObjectType &host)
Definition: subobjects.hh:91
Definition: subobjects.hh:57
int size() const
Definition: subobjects.hh:107
Definition: subobjects.hh:83
DofType value_type
Definition: subobjects.hh:23
SubDofVector(DofVectorType &dofs, int size, int offset)
Definition: subobjects.hh:25
Definition: coordinate.hh:4
void istl_assign_to_fmatrix(FieldMatrix< K, n, m > &A, const Fem::FieldMatrixConverter< FieldVector< K, n *m >, FieldMatrix< K, n, m > > &B)
Definition: fmatrixconverter.hh:241
K Type
Definition: subobjects.hh:69
const RowType< T >::Type Type
Definition: subobjects.hh:62
const DofType & operator[](const int i) const
Definition: subobjects.hh:31
int size() const
Definition: subobjects.hh:43
FieldVector< K, COLS > Type
Definition: subobjects.hh:76