dune-pdelab  2.7-git
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 
12 namespace 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 
43  ConstAliasedVectorView(std::shared_ptr<V> container)
44  : _container(container.get())
45  , _lfs_cache(nullptr)
46  , _data(nullptr)
47  {}
48 
49  void attach(V& container)
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 
81  size_type size() const
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<
118  const ElementType*,
119  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 
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.
147 
148  // pull in const version of data access
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
const ElementType * data() const
Definition: aliasedvectorview.hh:70
V * _container
Definition: aliasedvectorview.hh:114
const ElementType & operator[](const ContainerIndex &ci) const
Definition: aliasedvectorview.hh:91
std::remove_const< V >::type Container
Definition: aliasedvectorview.hh:20
const LFSCache * _lfs_cache
Definition: aliasedvectorview.hh:115
const ElementType & operator[](size_type i) const
Definition: aliasedvectorview.hh:86
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 Container & container() const
Definition: aliasedvectorview.hh:102
const ElementType & operator()(const LFS &lfs, size_type i) const
Definition: aliasedvectorview.hh:97
void attach(std::shared_ptr< V > container)
Definition: aliasedvectorview.hh:54
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
const LFSCache & cache() const
Definition: aliasedvectorview.hh:107
ConstAliasedVectorView(std::shared_ptr< V > container)
Definition: aliasedvectorview.hh:43
Container::E ElementType
Definition: aliasedvectorview.hh:23
std::conditional< std::is_const< V >::value, const ElementType *, ElementType * >::type _data
Definition: aliasedvectorview.hh:120
void detach()
Definition: aliasedvectorview.hh:59
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
V Container
Definition: aliasedvectorview.hh:130
ElementType & operator[](const ContainerIndex &ci)
Definition: aliasedvectorview.hh:185
AliasedVectorView(std::shared_ptr< Container > container)
Definition: aliasedvectorview.hh:160
AliasedVectorView(Container &container)
Definition: aliasedvectorview.hh:155
const ElementType * data() const
Definition: aliasedvectorview.hh:195
weight_type weight()
Definition: aliasedvectorview.hh:210
LFSCache::ContainerIndex ContainerIndex
Definition: aliasedvectorview.hh:136
ElementType & operator[](size_type i)
Definition: aliasedvectorview.hh:180
ElementType * data()
Definition: aliasedvectorview.hh:190
Container & container()
Definition: aliasedvectorview.hh:200
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
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139