DUNE-FEM (unstable)

subobjects.hh
1#ifndef DUNE_FEM_SUBOBJECTS_HH
2#define DUNE_FEM_SUBOBJECTS_HH
3
4#include <type_traits>
5
8
9#include <dune/fem/common/explicitfieldvector.hh>
10
11
12namespace 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 {
78 return Dune::Fem::RowType< RangeObject > :: size;
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
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)