dune-pdelab  2.5-dev
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 namespace Dune {
10  namespace PDELab {
11 
12 
13  template<typename V, typename LFSC>
15  {
16 
17  typedef typename std::remove_const<V>::type Container;
18  typedef LFSC LFSCache;
19 
20  typedef typename Container::E ElementType;
21  typedef typename Container::size_type size_type;
22  typedef typename LFSCache::DOFIndex DOFIndex;
23  typedef typename LFSCache::ContainerIndex ContainerIndex;
24 
26 
27 
29  : _container(nullptr)
30  , _lfs_cache(nullptr)
31  , _data(nullptr)
32  {}
33 
35  : _container(&container)
36  , _lfs_cache(nullptr)
37  , _data(nullptr)
38  {}
39 
40  void attach(V& container)
41  {
43  }
44 
45  void detach()
46  {
47  _container = nullptr;
48  }
49 
50  void bind(const LFSCache& lfs_cache)
51  {
52  _lfs_cache = &lfs_cache;
53  _data = _container->data(lfs_cache);
54  }
55 
56  const ElementType* data() const
57  {
58  return _data;
59  }
60 
61  void unbind()
62  {
63  _lfs_cache = nullptr;
64  _data = nullptr;
65  }
66 
67  size_type size() const
68  {
69  return cache().size();
70  }
71 
72  const ElementType& operator[](size_type i) const
73  {
74  return _data[i];
75  }
76 
77  const ElementType& operator[](const ContainerIndex& ci) const
78  {
79  return container()[ci];
80  }
81 
82  template<typename LFS>
83  const ElementType& operator()(const LFS& lfs, size_type i) const
84  {
85  return this->_data[lfs.localIndex(i)];
86  }
87 
88  const Container& container() const
89  {
90  return *_container;
91  }
92 
93  const LFSCache& cache() const
94  {
95  return *_lfs_cache;
96  }
97 
98  protected:
99 
101  const LFSCache* _lfs_cache;
102  typename std::conditional<
104  const ElementType*,
105  ElementType*
106  >::type _data;
107 
108  };
109 
110 
111  template<typename V, typename LFSC>
113  : public ConstAliasedVectorView<V,LFSC>
114  {
115 
116  typedef V Container;
117  typedef typename Container::ElementType ElementType;
118  typedef typename Container::size_type size_type;
119 
120  typedef LFSC LFSCache;
121  typedef typename LFSCache::DOFIndex DOFIndex;
122  typedef typename LFSCache::ContainerIndex ContainerIndex;
123 
126 
129 
130  // Explicitly pull in operator[] from the base class to work around a problem
131  // with clang not finding the const overloads of the operator from the base class.
133 
134  // pull in const version of data access
136 
138  : weight_(1.0)
139  {}
140 
142  : ConstAliasedVectorView<V,LFSC>(container)
143  , weight_(1.0)
144  {}
145 
146  void commit()
147  {}
148 
149  template<typename LFS>
150  void accumulate(const LFS& lfs, size_type n, value_type v)
151  {
152  this->_data[lfs.localIndex(n)] += v;
153  }
154 
155  template<typename LFS>
156  void rawAccumulate(const LFS& lfs, size_type n, value_type v)
157  {
158  accumulate(lfs,n,v);
159  }
160 
161  ElementType& operator[](size_type i)
162  {
163  return this->_data[i];
164  }
165 
166  ElementType& operator[](const ContainerIndex& ci)
167  {
168  return container()[ci];
169  }
170 
171  ElementType* data()
172  {
173  return this->_data;
174  }
175 
176  const ElementType* data() const
177  {
178  return this->_data;
179  }
180 
181  Container& container()
182  {
183  return *(this->_container);
184  }
185 
186  void setWeight(weight_type weight)
187  {
188  weight_ = weight;
189  }
190 
192  {
193  return weight_;
194  }
195 
196  private :
197  weight_type weight_;
198  };
199 
200  } // namespace PDELab
201 } // namespace Dune
202 
203 #endif // DUNE_PDELAB_BACKEND_COMMON_ALIASEDVECTORVIEW_HH
ElementType value_type
Definition: aliasedvectorview.hh:25
void unbind()
Definition: aliasedvectorview.hh:61
LFSCache::ContainerIndex ContainerIndex
Definition: aliasedvectorview.hh:23
Container::ElementType ElementType
Definition: aliasedvectorview.hh:117
AliasedVectorView(Container &container)
Definition: aliasedvectorview.hh:141
void rawAccumulate(const LFS &lfs, size_type n, value_type v)
Definition: aliasedvectorview.hh:156
std::remove_const< V >::type Container
Definition: aliasedvectorview.hh:17
weight_type weight()
Definition: aliasedvectorview.hh:191
Definition: aliasedvectorview.hh:112
std::conditional< std::is_const< V >::value, const ElementType *, ElementType *>::type _data
Definition: aliasedvectorview.hh:106
LFSCache::DOFIndex DOFIndex
Definition: aliasedvectorview.hh:121
V Container
Definition: aliasedvectorview.hh:116
V * _container
Definition: aliasedvectorview.hh:100
ElementType * data()
Definition: aliasedvectorview.hh:171
const ElementType & operator[](const ContainerIndex &ci) const
Definition: aliasedvectorview.hh:77
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
void accumulate(const LFS &lfs, size_type n, value_type v)
Definition: aliasedvectorview.hh:150
Definition: aliasedvectorview.hh:14
const Container & container() const
Definition: aliasedvectorview.hh:88
const ElementType * data() const
Definition: aliasedvectorview.hh:176
Container::E ElementType
Definition: aliasedvectorview.hh:20
ElementType & operator[](size_type i)
Definition: aliasedvectorview.hh:161
LFSCache::DOFIndex DOFIndex
Definition: aliasedvectorview.hh:22
ElementType weight_type
Definition: aliasedvectorview.hh:125
void setWeight(weight_type weight)
Definition: aliasedvectorview.hh:186
const ElementType & operator[](size_type i) const
Definition: aliasedvectorview.hh:72
AliasedVectorView()
Definition: aliasedvectorview.hh:137
void attach(V &container)
Definition: aliasedvectorview.hh:40
const LFSCache & cache() const
Definition: aliasedvectorview.hh:93
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Container::size_type size_type
Definition: aliasedvectorview.hh:21
LFSC LFSCache
Definition: aliasedvectorview.hh:120
const ElementType * data() const
Definition: aliasedvectorview.hh:56
LFSCache::ContainerIndex ContainerIndex
Definition: aliasedvectorview.hh:122
void commit()
Definition: aliasedvectorview.hh:146
void bind(const LFSCache &lfs_cache)
Definition: aliasedvectorview.hh:50
ElementType & operator[](const ContainerIndex &ci)
Definition: aliasedvectorview.hh:166
size_type size() const
Definition: aliasedvectorview.hh:67
const ElementType & operator()(const LFS &lfs, size_type i) const
Definition: aliasedvectorview.hh:83
Container & container()
Definition: aliasedvectorview.hh:181
ConstAliasedVectorView(V &container)
Definition: aliasedvectorview.hh:34
Container::size_type size_type
Definition: aliasedvectorview.hh:118
ConstAliasedVectorView()
Definition: aliasedvectorview.hh:28
const LFSCache * _lfs_cache
Definition: aliasedvectorview.hh:101
void detach()
Definition: aliasedvectorview.hh:45
LFSC LFSCache
Definition: aliasedvectorview.hh:18