dune-pdelab  2.5-dev
uncachedvectorview.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_UNCACHEDVECTORVIEW_HH
4 #define DUNE_PDELAB_BACKEND_COMMON_UNCACHEDVECTORVIEW_HH
5 
6 #include <dune/common/typetraits.hh>
7 #include <dune/common/deprecated.hh>
9 
10 namespace Dune {
11  namespace PDELab {
12 
13 
14  template<typename V, typename LFSC>
16  {
17 
18  typedef typename std::remove_const<V>::type Container;
19  typedef LFSC LFSCache;
20 
21  typedef typename Container::E ElementType;
22  typedef typename Container::size_type size_type;
23  typedef typename LFSCache::DOFIndex DOFIndex;
24  typedef typename LFSCache::ContainerIndex ContainerIndex;
25 
26 
28  : _container(nullptr)
29  , _lfs_cache(nullptr)
30  {}
31 
33  : _container(&container)
34  , _lfs_cache(nullptr)
35  {}
36 
37  void attach(V& container)
38  {
40  }
41 
42  void detach()
43  {
44  _container = nullptr;
45  }
46 
47  void bind(const LFSCache& lfs_cache)
48  {
49  _lfs_cache = &lfs_cache;
50  }
51 
52  void unbind()
53  {
54  }
55 
56  size_type size() const
57  {
58  return cache().size();
59  }
60 
61  template<typename LC>
62  void read(LC& local_container) const
63  {
64  for (size_type i = 0; i < size(); ++i)
65  {
66  accessBaseContainer(local_container)[i] = container()[cache().containerIndex(i)];
67  }
68  }
69 
70  template<typename ChildLFS, typename LC>
71  void read(const ChildLFS& child_lfs, LC& local_container) const
72  {
73  for (size_type i = 0; i < child_lfs.size(); ++i)
74  {
75  const size_type local_index = child_lfs.localIndex(i);
76  accessBaseContainer(local_container)[local_index] = container()[cache().containerIndex(local_index)];
77  }
78  }
79 
80  template<typename ChildLFS, typename LC>
81  void read_sub_container(const ChildLFS& child_lfs, LC& local_container) const
82  {
83  for (size_type i = 0; i < child_lfs.size(); ++i)
84  {
85  const size_type local_index = child_lfs.localIndex(i);
86  accessBaseContainer(local_container)[i] = container()[cache().containerIndex(local_index)];
87  }
88  }
89 
90 
91  const ElementType& operator[](size_type i) const
92  {
93  return container()[cache().containerIndex(i)];
94  }
95 
96 
97  const ElementType& operator[](const DOFIndex& di) const
98  {
99  return container()[cache().containerIndex(di)];
100  }
101 
102 
103  const ElementType& operator[](const ContainerIndex& ci) const
104  {
105  return container()[ci];
106  }
107 
108 
109  const Container& container() const
110  {
111  return *_container;
112  }
113 
114  const LFSCache& cache() const
115  {
116  return *_lfs_cache;
117  }
118 
119  protected:
120 
122  const LFSCache* _lfs_cache;
123 
124  };
125 
126 
127  template<typename V, typename LFSC>
129  : public ConstUncachedVectorView<V,LFSC>
130  {
131 
132  typedef V Container;
133  typedef typename Container::ElementType ElementType;
134  typedef typename Container::size_type size_type;
135 
136  typedef LFSC LFSCache;
137  typedef typename LFSCache::DOFIndex DOFIndex;
138  typedef typename LFSCache::ContainerIndex ContainerIndex;
139 
142 
143  // Explicitly pull in operator[] from the base class to work around a problem
144  // with clang not finding the const overloads of the operator from the base class.
146 
148  {}
149 
151  : ConstUncachedVectorView<V,LFSC>(container)
152  {}
153 
154  template<typename LC>
155  void write(const LC& local_container)
156  {
157  for (size_type i = 0; i < size(); ++i)
158  {
159  container()[cache().containerIndex(i)] = accessBaseContainer(local_container)[i];
160  }
161  }
162 
163  template<typename LC>
164  void add(const LC& local_container)
165  {
166  for (size_type i = 0; i < size(); ++i)
167  {
168  container()[cache().containerIndex(i)] += accessBaseContainer(local_container)[i];
169  }
170  }
171 
172 
173 
174  template<typename ChildLFS, typename LC>
175  void write(const ChildLFS& child_lfs, const LC& local_container)
176  {
177  for (size_type i = 0; i < child_lfs.size(); ++i)
178  {
179  const size_type local_index = child_lfs.localIndex(i);
180  container()[cache().containerIndex(local_index)] = accessBaseContainer(local_container)[local_index];
181  }
182  }
183 
184  template<typename ChildLFS, typename LC>
185  void add(const ChildLFS& child_lfs, const LC& local_container)
186  {
187  for (size_type i = 0; i < child_lfs.size(); ++i)
188  {
189  const size_type local_index = child_lfs.localIndex(i);
190  container()[cache().containerIndex(local_index)] += accessBaseContainer(local_container)[local_index];
191  }
192  }
193 
194 
195 
196 
197  template<typename ChildLFS, typename LC>
198  void write_sub_container(const ChildLFS& child_lfs, const LC& local_container)
199  {
200  for (size_type i = 0; i < child_lfs.size(); ++i)
201  {
202  const size_type local_index = child_lfs.localIndex(i);
203  container()[cache().containerIndex(local_index)] = accessBaseContainer(local_container)[i];
204  }
205  }
206 
207  template<typename ChildLFS, typename LC>
208  void add_sub_container(const ChildLFS& child_lfs, const LC& local_container)
209  {
210  for (size_type i = 0; i < child_lfs.size(); ++i)
211  {
212  const size_type local_index = child_lfs.localIndex(i);
213  container()[cache().containerIndex(local_index)] += accessBaseContainer(local_container)[i];
214  }
215  }
216 
217  void commit()
218  {
219  }
220 
221 
222  ElementType& operator[](size_type i)
223  {
224  return container()[cache().containerIndex(i)];
225  }
226 
227 
228  ElementType& operator[](const DOFIndex& di)
229  {
230  return container()[cache().containerIndex(di)];
231  }
232 
233 
234  ElementType& operator[](const ContainerIndex& ci)
235  {
236  return container()[ci];
237  }
238 
239 
240  Container& container()
241  {
242  return *(this->_container);
243  }
244 
245 
246  };
247 
248  } // namespace PDELab
249 } // namespace Dune
250 
251 #endif // DUNE_PDELAB_BACKEND_COMMON_UNCACHEDVECTORVIEW_HH
V Container
Definition: uncachedvectorview.hh:132
void write(const ChildLFS &child_lfs, const LC &local_container)
Definition: uncachedvectorview.hh:175
std::remove_const< V >::type Container
Definition: uncachedvectorview.hh:18
void write_sub_container(const ChildLFS &child_lfs, const LC &local_container)
Definition: uncachedvectorview.hh:198
ElementType & operator[](const DOFIndex &di)
Definition: uncachedvectorview.hh:228
Container::size_type size_type
Definition: uncachedvectorview.hh:134
void read(const ChildLFS &child_lfs, LC &local_container) const
Definition: uncachedvectorview.hh:71
Definition: uncachedvectorview.hh:128
const LFSCache * _lfs_cache
Definition: uncachedvectorview.hh:122
void add(const ChildLFS &child_lfs, const LC &local_container)
Definition: uncachedvectorview.hh:185
const Container & container() const
Definition: uncachedvectorview.hh:109
const ElementType & operator[](size_type i) const
Definition: uncachedvectorview.hh:91
LFSCache::DOFIndex DOFIndex
Definition: uncachedvectorview.hh:137
Container::ElementType ElementType
Definition: uncachedvectorview.hh:133
void detach()
Definition: uncachedvectorview.hh:42
LFSCache::ContainerIndex ContainerIndex
Definition: uncachedvectorview.hh:24
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
LFSCache::ContainerIndex ContainerIndex
Definition: uncachedvectorview.hh:138
UncachedVectorView(Container &container)
Definition: uncachedvectorview.hh:150
LFSCache::DOFIndex DOFIndex
Definition: uncachedvectorview.hh:23
void read(LC &local_container) const
Definition: uncachedvectorview.hh:62
ConstUncachedVectorView(V &container)
Definition: uncachedvectorview.hh:32
void write(const LC &local_container)
Definition: uncachedvectorview.hh:155
ElementType & operator[](size_type i)
Definition: uncachedvectorview.hh:222
void add_sub_container(const ChildLFS &child_lfs, const LC &local_container)
Definition: uncachedvectorview.hh:208
ElementType & operator[](const ContainerIndex &ci)
Definition: uncachedvectorview.hh:234
void bind(const LFSCache &lfs_cache)
Definition: uncachedvectorview.hh:47
Container::size_type size_type
Definition: uncachedvectorview.hh:22
Definition: uncachedvectorview.hh:15
const ElementType & operator[](const ContainerIndex &ci) const
Definition: uncachedvectorview.hh:103
UncachedVectorView()
Definition: uncachedvectorview.hh:147
const ElementType & operator[](const DOFIndex &di) const
Definition: uncachedvectorview.hh:97
void attach(V &container)
Definition: uncachedvectorview.hh:37
V * _container
Definition: uncachedvectorview.hh:121
void commit()
Definition: uncachedvectorview.hh:217
void unbind()
Definition: uncachedvectorview.hh:52
LFSC LFSCache
Definition: uncachedvectorview.hh:136
const LFSCache & cache() const
Definition: uncachedvectorview.hh:114
void add(const LC &local_container)
Definition: uncachedvectorview.hh:164
Container & container()
Definition: uncachedvectorview.hh:240
void read_sub_container(const ChildLFS &child_lfs, LC &local_container) const
Definition: uncachedvectorview.hh:81
C & accessBaseContainer(C &c)
Definition: localvector.hh:296
ConstUncachedVectorView()
Definition: uncachedvectorview.hh:27
size_type size() const
Definition: uncachedvectorview.hh:56
Container::E ElementType
Definition: uncachedvectorview.hh:21
LFSC LFSCache
Definition: uncachedvectorview.hh:19