3#ifndef DUNE_PDELAB_BACKEND_COMMON_ALIASEDVECTORVIEW_HH
4#define DUNE_PDELAB_BACKEND_COMMON_ALIASEDVECTORVIEW_HH
16 template<
typename V,
typename LFSC>
17 struct ConstAliasedVectorView
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;
28 using value_type = ElementType;
31 ConstAliasedVectorView()
37 ConstAliasedVectorView(V& container)
38 : _container(&container)
43 ConstAliasedVectorView(std::shared_ptr<V> container)
44 : _container(container.get())
49 void attach(V& container)
51 _container = &container;
54 void attach(std::shared_ptr<V> container)
56 _container = container.get();
64 void bind(
const LFSCache& lfs_cache)
66 _lfs_cache = &lfs_cache;
67 _data = _container->data(lfs_cache);
70 const ElementType* data()
const
81 size_type size()
const
83 return cache().size();
86 const ElementType& operator[](size_type i)
const
91 const ElementType& operator[](
const ContainerIndex& ci)
const
93 return container()[ci];
96 template<
typename LFS>
97 const ElementType& operator()(
const LFS& lfs, size_type i)
const
99 return this->_data[lfs.localIndex(i)];
102 const Container& container()
const
107 const LFSCache& cache()
const
115 const LFSCache* _lfs_cache;
116 typename std::conditional<
117 std::is_const<V>::value,
125 template<
typename V,
typename LFSC>
126 struct AliasedVectorView
127 :
public ConstAliasedVectorView<V,LFSC>
131 typedef typename Container::ElementType ElementType;
132 typedef typename Container::size_type size_type;
134 typedef LFSC LFSCache;
135 typedef typename LFSCache::DOFIndex DOFIndex;
136 typedef typename LFSCache::ContainerIndex ContainerIndex;
138 using value_type = ElementType;
139 using weight_type = ElementType;
141 using ConstAliasedVectorView<V,LFSC>::cache;
142 using ConstAliasedVectorView<V,LFSC>::size;
146 using ConstAliasedVectorView<V,LFSC>::operator[];
149 using ConstAliasedVectorView<V,LFSC>::data;
155 AliasedVectorView(Container& container)
156 : ConstAliasedVectorView<V,LFSC>(container)
160 AliasedVectorView(std::shared_ptr<Container> container)
161 : ConstAliasedVectorView<V,LFSC>(container)
168 template<
typename LFS>
169 void accumulate(
const LFS& lfs, size_type n, value_type v)
171 this->_data[lfs.localIndex(n)] += weight_ * v;
174 template<
typename LFS>
175 void rawAccumulate(
const LFS& lfs, size_type n, value_type v)
180 ElementType& operator[](size_type i)
182 return this->_data[i];
185 ElementType& operator[](
const ContainerIndex& ci)
187 return container()[ci];
195 const ElementType* data()
const
200 Container& container()
202 return *(this->_container);
205 void setWeight(weight_type weight)
Traits for type conversions and type information.
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:289
Dune namespace.
Definition: alignedallocator.hh:11