dune-pdelab 2.7-git
Loading...
Searching...
No Matches
aliasedvectorview.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_PDELAB_BACKEND_COMMON_ALIASEDVECTORVIEW_HH
4#define DUNE_PDELAB_BACKEND_COMMON_ALIASEDVECTORVIEW_HH
5
6#include <dune/common/typetraits.hh>
8
9#include <memory>
10
11
12namespace Dune {
13 namespace PDELab {
14
15
16 template<typename V, typename LFSC>
18 {
19
20 typedef typename std::remove_const<V>::type Container;
21 typedef LFSC LFSCache;
22
23 typedef typename Container::E ElementType;
24 typedef typename Container::size_type size_type;
25 typedef typename LFSCache::DOFIndex DOFIndex;
26 typedef typename LFSCache::ContainerIndex ContainerIndex;
27
29
30
32 : _container(nullptr)
33 , _lfs_cache(nullptr)
34 , _data(nullptr)
35 {}
36
39 , _lfs_cache(nullptr)
40 , _data(nullptr)
41 {}
42
44 : _container(container.get())
45 , _lfs_cache(nullptr)
46 , _data(nullptr)
47 {}
48
50 {
52 }
53
54 void attach(std::shared_ptr<V> container)
55 {
56 _container = container.get();
57 }
58
59 void detach()
60 {
61 _container = nullptr;
62 }
63
64 void bind(const LFSCache& lfs_cache)
65 {
66 _lfs_cache = &lfs_cache;
67 _data = _container->data(lfs_cache);
68 }
69
70 const ElementType* data() const
71 {
72 return _data;
73 }
74
75 void unbind()
76 {
77 _lfs_cache = nullptr;
78 _data = nullptr;
79 }
80
82 {
83 return cache().size();
84 }
85
87 {
88 return _data[i];
89 }
90
91 const ElementType& operator[](const ContainerIndex& ci) const
92 {
93 return container()[ci];
94 }
95
96 template<typename LFS>
97 const ElementType& operator()(const LFS& lfs, size_type i) const
98 {
99 return this->_data[lfs.localIndex(i)];
100 }
101
102 const Container& container() const
103 {
104 return *_container;
105 }
106
107 const LFSCache& cache() const
108 {
109 return *_lfs_cache;
110 }
111
112 protected:
113
116 typename std::conditional<
117 std::is_const<V>::value,
118 const ElementType*,
120 >::type _data;
121
122 };
123
124
125 template<typename V, typename LFSC>
127 : public ConstAliasedVectorView<V,LFSC>
128 {
129
130 typedef V Container;
131 typedef typename Container::ElementType ElementType;
132 typedef typename Container::size_type size_type;
133
134 typedef LFSC LFSCache;
135 typedef typename LFSCache::DOFIndex DOFIndex;
136 typedef typename LFSCache::ContainerIndex ContainerIndex;
137
140
141 using ConstAliasedVectorView<V,LFSC>::cache;
142 using ConstAliasedVectorView<V,LFSC>::size;
143
144 // Explicitly pull in operator[] from the base class to work around a problem
145 // with clang not finding the const overloads of the operator from the base class.
146 using ConstAliasedVectorView<V,LFSC>::operator[];
147
148 // pull in const version of data access
149 using ConstAliasedVectorView<V,LFSC>::data;
150
152 : weight_(1.0)
153 {}
154
157 , weight_(1.0)
158 {}
159
160 AliasedVectorView(std::shared_ptr<Container> container)
162 , weight_(1.0)
163 {}
164
165 void commit()
166 {}
167
168 template<typename LFS>
169 void accumulate(const LFS& lfs, size_type n, value_type v)
170 {
171 this->_data[lfs.localIndex(n)] += weight_ * v;
172 }
173
174 template<typename LFS>
175 void rawAccumulate(const LFS& lfs, size_type n, value_type v)
176 {
177 accumulate(lfs,n,v);
178 }
179
181 {
182 return this->_data[i];
183 }
184
186 {
187 return container()[ci];
188 }
189
191 {
192 return this->_data;
193 }
194
195 const ElementType* data() const
196 {
197 return this->_data;
198 }
199
200 Container& container()
201 {
202 return *(this->_container);
203 }
204
206 {
207 weight_ = weight;
208 }
209
211 {
212 return weight_;
213 }
214
215 private :
216 weight_type weight_;
217 };
218
219 } // namespace PDELab
220} // namespace Dune
221
222#endif // DUNE_PDELAB_BACKEND_COMMON_ALIASEDVECTORVIEW_HH
For backward compatibility – Do not use this!
Definition adaptivity.hh:28
Definition aliasedvectorview.hh:18
ConstAliasedVectorView(V &container)
Definition aliasedvectorview.hh:37
void attach(V &container)
Definition aliasedvectorview.hh:49
V * _container
Definition aliasedvectorview.hh:114
std::remove_const< V >::type Container
Definition aliasedvectorview.hh:20
const ElementType * data() const
Definition aliasedvectorview.hh:70
const LFSCache * _lfs_cache
Definition aliasedvectorview.hh:115
ElementType value_type
Definition aliasedvectorview.hh:28
LFSCache::DOFIndex DOFIndex
Definition aliasedvectorview.hh:25
size_type size() const
Definition aliasedvectorview.hh:81
LFSCache::ContainerIndex ContainerIndex
Definition aliasedvectorview.hh:26
const ElementType & operator()(const LFS &lfs, size_type i) const
Definition aliasedvectorview.hh:97
std::conditional< std::is_const< V >::value, constElementType *, ElementType * >::type _data
Definition aliasedvectorview.hh:120
void attach(std::shared_ptr< V > container)
Definition aliasedvectorview.hh:54
const ElementType & operator[](size_type i) const
Definition aliasedvectorview.hh:86
void unbind()
Definition aliasedvectorview.hh:75
ConstAliasedVectorView()
Definition aliasedvectorview.hh:31
LFSC LFSCache
Definition aliasedvectorview.hh:21
Container::size_type size_type
Definition aliasedvectorview.hh:24
void bind(const LFSCache &lfs_cache)
Definition aliasedvectorview.hh:64
ConstAliasedVectorView(std::shared_ptr< V > container)
Definition aliasedvectorview.hh:43
const ElementType & operator[](const ContainerIndex &ci) const
Definition aliasedvectorview.hh:91
const Container & container() const
Definition aliasedvectorview.hh:102
Container::E ElementType
Definition aliasedvectorview.hh:23
void detach()
Definition aliasedvectorview.hh:59
const LFSCache & cache() const
Definition aliasedvectorview.hh:107
Definition aliasedvectorview.hh:128
Container::ElementType ElementType
Definition aliasedvectorview.hh:131
LFSC LFSCache
Definition aliasedvectorview.hh:134
void setWeight(weight_type weight)
Definition aliasedvectorview.hh:205
void commit()
Definition aliasedvectorview.hh:165
ElementType & operator[](size_type i)
Definition aliasedvectorview.hh:180
V Container
Definition aliasedvectorview.hh:130
AliasedVectorView(std::shared_ptr< Container > container)
Definition aliasedvectorview.hh:160
AliasedVectorView(Container &container)
Definition aliasedvectorview.hh:155
weight_type weight()
Definition aliasedvectorview.hh:210
LFSCache::ContainerIndex ContainerIndex
Definition aliasedvectorview.hh:136
Container & container()
Definition aliasedvectorview.hh:200
ElementType * data()
Definition aliasedvectorview.hh:190
AliasedVectorView()
Definition aliasedvectorview.hh:151
ElementType weight_type
Definition aliasedvectorview.hh:139
Container::size_type size_type
Definition aliasedvectorview.hh:132
void rawAccumulate(const LFS &lfs, size_type n, value_type v)
Definition aliasedvectorview.hh:175
void accumulate(const LFS &lfs, size_type n, value_type v)
Definition aliasedvectorview.hh:169
LFSCache::DOFIndex DOFIndex
Definition aliasedvectorview.hh:135
const ElementType * data() const
Definition aliasedvectorview.hh:195
ElementType & operator[](const ContainerIndex &ci)
Definition aliasedvectorview.hh:185
ElementType value_type
Definition aliasedvectorview.hh:138