3#ifndef DUNE_PDELAB_BACKEND_COMMON_UNCACHEDVECTORVIEW_HH
4#define DUNE_PDELAB_BACKEND_COMMON_UNCACHEDVECTORVIEW_HH
16 template<
typename V,
typename LFSC>
17 struct ConstUncachedVectorView
20 typedef typename std::remove_const<V>::type Container;
21 typedef LFSC LFSCache;
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;
29 ConstUncachedVectorView()
34 ConstUncachedVectorView(V& container)
35 : _container(&container)
39 ConstUncachedVectorView(std::shared_ptr<V> container)
40 : _container(container.get())
44 void attach(V& container)
46 _container = &container;
49 void attach(std::shared_ptr<V> container)
51 _container = container.get();
59 void bind(
const LFSCache& lfs_cache)
61 _lfs_cache = &lfs_cache;
68 size_type size()
const
70 return cache().size();
74 void read(LC& local_container)
const
76 for (size_type i = 0; i < size(); ++i)
78 accessBaseContainer(local_container)[i] = container()[cache().containerIndex(i)];
82 template<
typename ChildLFS,
typename LC>
83 void read(
const ChildLFS& child_lfs, LC& local_container)
const
85 for (size_type i = 0; i < child_lfs.size(); ++i)
87 const size_type local_index = child_lfs.localIndex(i);
88 accessBaseContainer(local_container)[local_index] = container()[cache().containerIndex(local_index)];
92 template<
typename ChildLFS,
typename LC>
93 void read_sub_container(
const ChildLFS& child_lfs, LC& local_container)
const
95 for (size_type i = 0; i < child_lfs.size(); ++i)
97 const size_type local_index = child_lfs.localIndex(i);
98 accessBaseContainer(local_container)[i] = container()[cache().containerIndex(local_index)];
103 const ElementType& operator[](size_type i)
const
105 return container()[cache().containerIndex(i)];
111 template<
typename DI>
113 (std::is_same<DI,DOFIndex>{} and not std::is_same<DI,ContainerIndex>{}),
116 operator[](
const DI& di)
const
118 return container()[cache().containerIndex(di)];
122 const ElementType& operator[](
const ContainerIndex& ci)
const
124 return container()[ci];
128 const Container& container()
const
133 const LFSCache& cache()
const
141 const LFSCache* _lfs_cache;
146 template<
typename V,
typename LFSC>
147 struct UncachedVectorView
148 :
public ConstUncachedVectorView<V,LFSC>
152 typedef typename Container::ElementType ElementType;
153 typedef typename Container::size_type size_type;
155 typedef LFSC LFSCache;
156 typedef typename LFSCache::DOFIndex DOFIndex;
157 typedef typename LFSCache::ContainerIndex ContainerIndex;
159 using ConstUncachedVectorView<V,LFSC>::cache;
160 using ConstUncachedVectorView<V,LFSC>::size;
164 using ConstUncachedVectorView<V,LFSC>::operator[];
169 UncachedVectorView(Container& container)
170 : ConstUncachedVectorView<V,LFSC>(container)
173 UncachedVectorView(std::shared_ptr<Container> container)
174 : ConstUncachedVectorView<V,LFSC>(container)
177 template<
typename LC>
178 void write(
const LC& local_container)
180 for (size_type i = 0; i < size(); ++i)
182 container()[cache().containerIndex(i)] = accessBaseContainer(local_container)[i];
186 template<
typename LC>
187 void add(
const LC& local_container)
189 for (size_type i = 0; i < size(); ++i)
191 container()[cache().containerIndex(i)] += accessBaseContainer(local_container)[i];
197 template<
typename ChildLFS,
typename LC>
198 void write(
const ChildLFS& child_lfs,
const LC& local_container)
200 for (size_type i = 0; i < child_lfs.size(); ++i)
202 const size_type local_index = child_lfs.localIndex(i);
203 container()[cache().containerIndex(local_index)] = accessBaseContainer(local_container)[local_index];
207 template<
typename ChildLFS,
typename LC>
208 void add(
const ChildLFS& child_lfs,
const LC& local_container)
210 for (size_type i = 0; i < child_lfs.size(); ++i)
212 const size_type local_index = child_lfs.localIndex(i);
213 container()[cache().containerIndex(local_index)] += accessBaseContainer(local_container)[local_index];
220 template<
typename ChildLFS,
typename LC>
221 void write_sub_container(
const ChildLFS& child_lfs,
const LC& local_container)
223 for (size_type i = 0; i < child_lfs.size(); ++i)
225 const size_type local_index = child_lfs.localIndex(i);
226 container()[cache().containerIndex(local_index)] = accessBaseContainer(local_container)[i];
230 template<
typename ChildLFS,
typename LC>
231 void add_sub_container(
const ChildLFS& child_lfs,
const LC& local_container)
233 for (size_type i = 0; i < child_lfs.size(); ++i)
235 const size_type local_index = child_lfs.localIndex(i);
236 container()[cache().containerIndex(local_index)] += accessBaseContainer(local_container)[i];
245 ElementType& operator[](size_type i)
247 return container()[cache().containerIndex(i)];
252 template<
typename DI>
254 (std::is_same<DI,DOFIndex>{} and not std::is_same<DI,ContainerIndex>{}),
257 operator[](
const DOFIndex& di)
259 return container()[cache().containerIndex(di)];
263 ElementType& operator[](
const ContainerIndex& ci)
265 return container()[ci];
269 Container& container()
271 return *(this->_container);
Traits for type conversions and type information.
Dune namespace.
Definition: alignedallocator.hh:11