2#ifndef DUNE_PDELAB_BACKEND_COMMON_ALIASEDMATRIXVIEW_HH
3#define DUNE_PDELAB_BACKEND_COMMON_ALIASEDMATRIXVIEW_HH
11 template<
typename M_,
typename RowCache,
typename ColCache>
12 class ConstAliasedMatrixView
17 typedef typename std::remove_const<M_>::type Container;
21 typename RowCache::LocalFunctionSpace::Traits::GridFunctionSpace,
22 typename Container::TestGridFunctionSpace
24 "The RowCache passed to LocalView must belong to the underlying GFSV"
29 typename ColCache::LocalFunctionSpace::Traits::GridFunctionSpace,
30 typename Container::TrialGridFunctionSpace
32 "The ColCache passed to LocalView must belong to the underlying GFSU"
37 typedef typename Container::field_type E;
38 typedef typename Container::size_type size_type;
40 typedef E ElementType;
42 typedef RowCache RowIndexCache;
43 typedef ColCache ColIndexCache;
45 typedef typename RowCache::LocalFunctionSpace LFSV;
46 typedef typename ColCache::LocalFunctionSpace LFSU;
48 typedef typename LFSV::Traits::DOFIndex RowDOFIndex;
49 typedef typename LFSV::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex RowContainerIndex;
51 typedef typename LFSU::Traits::DOFIndex ColDOFIndex;
52 typedef typename LFSU::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex ColContainerIndex;
54 using value_type = ElementType;
55 using weight_type = ElementType;
57 ConstAliasedMatrixView()
64 ConstAliasedMatrixView(M_& container)
65 : _container(&container)
71 const RowIndexCache& rowIndexCache()
const
77 const ColIndexCache& colIndexCache()
const
83 void attach(M_& container)
85 _container = &container;
93 void bind(
const RowCache& row_cache,
const ColCache& col_cache)
95 _row_cache = &row_cache;
96 _col_cache = &col_cache;
97 _data = _container->data(row_cache,col_cache);
102 _row_cache =
nullptr;
103 _col_cache =
nullptr;
109 return rowIndexCache().size();
114 return colIndexCache().size();
117 template<
typename LC>
118 void read(LC& local_container)
const
120 for (size_type i = 0; i < N(); ++i)
121 for (size_type j = 0; j < M(); ++j)
122 local_container.getEntry(i,j) = container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
125 const ElementType& operator()(size_type i, size_type j)
const
127 return _data[i * colIndexCache().size() + j];
130 const ElementType& operator()(
const RowDOFIndex& i,
const ColDOFIndex& j)
const
132 return container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
135 const ElementType& operator()(
const RowContainerIndex& i,
const ColContainerIndex& j)
const
137 return container()(i,j);
140 template<
typename LFSV,
typename LFSU>
141 const ElementType& operator()(
const LFSV& lfsv, size_type i,
const LFSU& lfsu, size_type j)
const
143 return _data[lfsv.localIndex(i) * colIndexCache().size() + lfsu.localIndex(j)];
146 const Container& container()
const
154 const RowCache* _row_cache;
155 const ColCache* _col_cache;
156 typename std::conditional<
157 std::is_const<M_>::value,
165 template<
typename M_,
typename RowCache,
typename ColCache>
166 class AliasedMatrixView
167 :
public ConstAliasedMatrixView<M_,RowCache,ColCache>
170 typedef ConstAliasedMatrixView<M_,RowCache,ColCache> BaseT;
174 typedef M_ Container;
175 typedef typename Container::ElementType ElementType;
176 typedef typename Container::size_type size_type;
178 typedef RowCache RowIndexCache;
179 typedef ColCache ColIndexCache;
181 typedef typename RowCache::LocalFunctionSpace LFSV;
182 typedef typename ColCache::LocalFunctionSpace LFSU;
184 typedef typename LFSV::Traits::DOFIndex RowDOFIndex;
185 typedef typename LFSV::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex RowContainerIndex;
187 typedef typename LFSU::Traits::DOFIndex ColDOFIndex;
188 typedef typename LFSU::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex ColContainerIndex;
190 using BaseT::rowIndexCache;
191 using BaseT::colIndexCache;
195 using typename BaseT::value_type;
196 using typename BaseT::weight_type;
200 using BaseT::operator();
206 AliasedMatrixView(Container& container)
214 template<
typename LC>
215 void write(
const LC& local_container)
217 for (size_type i = 0; i < N(); ++i)
218 for (size_type j = 0; j < M(); ++j)
219 container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j)) = local_container.getEntry(i,j);
222 template<
typename LC>
223 void add(
const LC& local_container)
225 for (size_type i = 0; i < N(); ++i)
226 for (size_type j = 0; j < M(); ++j)
227 container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j)) += local_container.getEntry(i,j);
232 ElementType& operator()(size_type i, size_type j)
234 return container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
237 ElementType& operator()(
const RowDOFIndex& i,
const ColDOFIndex& j)
239 return container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
242 ElementType& operator()(
const RowContainerIndex& i,
const ColContainerIndex& j)
244 return container()(i,j);
247 ElementType& operator()(
const RowContainerIndex& i, size_type j)
249 return container()(i,colIndexCache().containerIndex(j));
252 ElementType& operator()(size_type i,
const ColContainerIndex& j)
254 return container()(rowIndexCache().containerIndex(i),j);
257 template<
typename LFSV,
typename LFSU>
258 void accumulate(
const LFSV& lfsv, size_type i,
const LFSU& lfsu, size_type j, value_type value)
260 this->_data[lfsv.localIndex(i) * colIndexCache().size() + lfsu.localIndex(j)] += weight_ * value;
263 template<
typename LFSV,
typename LFSU>
264 void rawAccumulate(
const LFSV& lfsv, size_type i,
const LFSU& lfsu, size_type j, value_type value)
266 this->_data[lfsv.localIndex(i) * colIndexCache().size() + lfsu.localIndex(j)] += value;
275 Container& container()
277 return *(this->_container);
280 void setWeight(weight_type weight)
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:289
Dune namespace.
Definition: alignedallocator.hh:11