DUNE-FEM (unstable)

referencevector.hh
1#ifndef DUNE_FEM_REFERENCEVECTOR_HH
2#define DUNE_FEM_REFERENCEVECTOR_HH
3
4#include <algorithm>
5#include <cassert>
6#include <memory>
7#include <utility>
8#include <vector>
9
12
13#include <dune/fem/misc/bartonnackmaninterface.hh>
14
15namespace Dune
16{
17
18 namespace Fem
19 {
20 // forward declaration
21 template< class K, class A = std::allocator< K* > >
22 class DynamicReferenceVector;
23 }
24
25 // specialization of DenseMatVecTraits for DynamicReferenceVector
26 template< class K, class A >
27 struct DenseMatVecTraits< Fem::DynamicReferenceVector< K, A > >
28 {
29 typedef Fem::DynamicReferenceVector< K, A > derived_type;
30 typedef std::vector< K*, typename A::template rebind< K* >::other > container_type;
31
32 typedef K value_type;
33 typedef typename container_type::size_type size_type;
34 };
35
36 template< class K, class A >
37 struct FieldTraits< Fem::DynamicReferenceVector< K, A > >
38 {
39 typedef typename FieldTraits< K >::field_type field_type;
40 typedef typename FieldTraits< K >::real_type real_type;
41 };
42
43 namespace Fem
44 {
45
51 template< class K, class A >
52 class DynamicReferenceVector : public DenseVector< DynamicReferenceVector< K, A > >
53 {
56
57 public:
58 typedef typename BaseType::size_type size_type;
59 typedef typename BaseType::value_type value_type;
60 typedef value_type FieldType;
61 typedef typename DenseMatVecTraits< ThisType >::container_type DofStorageType;
62
64 explicit DynamicReferenceVector ( const A &a = A() )
65 : data_( a )
66 {}
67
69 explicit DynamicReferenceVector ( size_type n, const A &a = A() )
70 : data_( n, nullptr, a )
71 {}
72
75 : BaseType(), // DenseVector stores no data anyway
76 data_( other.data_ )
77 {}
78
81 : data_( std::move( other.data_ ) )
82 {}
83
84 // issue with gcc 5.5 and ambiguity of
85 // operator= ( const DenseVector< V > &other )
86 // using BaseType::operator=;
87 // to avoid this adding to missing operator= overload:
88 ThisType& operator= (const value_type& k)
89 {
90 for (size_type i=0; i<size(); i++)
91 data_[i] = k;
92 return *this;
93 }
94
95 template< class V >
96 ThisType & operator= ( const DenseVector< V > &other )
97 {
98 assert( data_.size() == other.size() );
99 std::copy( other.begin(), other.end(), BaseType::begin() );
100 return *this;
101 }
102
103 ThisType & operator= ( const ThisType &other )
104 {
105 assert( data_.size() == other.size() );
106 std::copy( other.begin(), other.end(), BaseType::begin() );
107 return *this;
108 }
109
110 ThisType & operator= ( ThisType &&other )
111 {
112 data_ = std::move( other.data_ );
113 return *this;
114 }
115
116 size_type capacity () const
117 {
118 return data_.capacity();
119 }
120
121 void resize ( size_type n )
122 {
123 data_.resize( n, nullptr );
124 }
125
126 void reserve ( size_type n )
127 {
128 data_.reserve( n );
129 }
130
132 void bind ( size_type i, K& u )
133 {
134 assert( i < data_.size() );
135 data_[ i ] = &u;
136 }
137
139 void unbind ( size_type i )
140 {
141 asssert( i < data_.size() );
142 data_[ i ] = nullptr;
143 }
144
145 size_type size () const
146 {
147 return data_.size();
148 }
149
150 value_type &operator[] ( size_type i )
151 {
152 return *data_[ i ];
153 }
154
155 const value_type &operator[] ( size_type i ) const
156 {
157 return *data_[ i ];
158 }
159
160 void clear()
161 {
162 for (std::size_t i=0;i<size();++i)
163 (*this)[i] = 0;
164 }
165
166 private:
167 DofStorageType data_;
168 };
169
170 } // namespace Fem
171
172
173} // namespace Dune
174
175#endif //#ifndef DUNE_FEM_REFERENCEVECTOR_HH
Interface for a class of dense vectors over a given field.
Definition: densevector.hh:229
Traits::value_type value_type
export the type representing the field
Definition: densevector.hh:250
Iterator begin()
begin iterator
Definition: densevector.hh:347
size_type size() const
size method
Definition: densevector.hh:336
Iterator end()
end iterator
Definition: densevector.hh:353
Traits::size_type size_type
The type used for the index access and size operation.
Definition: densevector.hh:259
An implementation of DenseVector which uses a std::vector of references as storage.
Definition: referencevector.hh:53
DynamicReferenceVector(ThisType &&other)
Move constructor.
Definition: referencevector.hh:80
void unbind(size_type i)
Unbind i-th entry.
Definition: referencevector.hh:139
DynamicReferenceVector(const ThisType &other)
Copy constructor.
Definition: referencevector.hh:74
DynamicReferenceVector(const A &a=A())
Constructor with uninitialized vector.
Definition: referencevector.hh:64
DynamicReferenceVector(size_type n, const A &a=A())
Constructor with uninitialized vector of size n.
Definition: referencevector.hh:69
void bind(size_type i, K &u)
Bind i-th entry to a reference.
Definition: referencevector.hh:132
Implements the dense vector interface, with an exchangeable storage class.
Type traits to determine the type of reals (when working with complex numbers)
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)