dune-pdelab  2.0.0
uncachedmatrixview.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil -*-
2 #ifndef DUNE_PDELAB_BACKEND_COMMON_UNCACHEDMATRIXVIEW_HH
3 #define DUNE_PDELAB_BACKEND_COMMON_UNCACHEDMATRIXVIEW_HH
4 
5 #include <dune/common/typetraits.hh>
6 #include <dune/common/static_assert.hh>
7 #include <dune/common/nullptr.hh>
8 
9 namespace Dune {
10  namespace PDELab {
11 
12 
13  template<typename M_, typename RowCache, typename ColCache>
15  {
16 
17  public:
18 
19  typedef typename remove_const<M_>::type Container;
20 
22  (is_same<
23  typename RowCache::LocalFunctionSpace::Traits::GridFunctionSpace,
24  typename Container::TestGridFunctionSpace
25  >::value),
26  "The RowCache passed to LocalView must belong to the underlying GFSV"
27  );
28 
30  (is_same<
31  typename ColCache::LocalFunctionSpace::Traits::GridFunctionSpace,
32  typename Container::TrialGridFunctionSpace
33  >::value),
34  "The ColCache passed to LocalView must belong to the underlying GFSU"
35  );
36 
37  public:
38 
39  typedef typename Container::field_type E;
40  typedef typename Container::size_type size_type;
41 
42  typedef E ElementType;
43 
44  typedef RowCache RowIndexCache;
45  typedef ColCache ColIndexCache;
46 
47  typedef typename RowCache::LocalFunctionSpace LFSV;
48  typedef typename ColCache::LocalFunctionSpace LFSU;
49 
50  typedef typename LFSV::Traits::DOFIndex RowDOFIndex;
51  typedef typename LFSV::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex RowContainerIndex;
52 
53  typedef typename LFSU::Traits::DOFIndex ColDOFIndex;
54  typedef typename LFSU::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex ColContainerIndex;
55 
57  : _container(nullptr)
58  , _row_cache(nullptr)
59  , _col_cache(nullptr)
60  {}
61 
63  : _container(&container)
64  , _row_cache(nullptr)
65  , _col_cache(nullptr)
66  {}
67 
69  {
70  assert(_row_cache);
71  return *_row_cache;
72  }
73 
75  {
76  assert(_col_cache);
77  return *_col_cache;
78  }
79 
80  void attach(M_& container)
81  {
83  }
84 
85  void detach()
86  {
87  _container = nullptr;
88  }
89 
90  void bind(const RowCache& row_cache, const ColCache& col_cache)
91  {
92  _row_cache = &row_cache;
93  _col_cache = &col_cache;
94  }
95 
96  void unbind()
97  {}
98 
99  size_type N() const
100  {
101  return rowIndexCache().size();
102  }
103 
104  size_type M() const
105  {
106  return colIndexCache().size();
107  }
108 
109  template<typename LC>
110  void read(LC& local_container) const
111  {
112  for (size_type i = 0; i < N(); ++i)
113  for (size_type j = 0; j < M(); ++j)
114  local_container.getEntry(i,j) = container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
115  }
116 
117 
118 
120  {
121  return container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
122  }
123 
124  const ElementType& operator()(const RowDOFIndex& i, const ColDOFIndex& j) const
125  {
126  return container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
127  }
128 
130  {
131  return container()(i,j);
132  }
133 
135  {
136  return container()(i,colIndexCache().containerIndex(j));
137  }
138 
140  {
141  return container()(rowIndexCache().containerIndex(i),j);
142  }
143 
144  const Container& container() const
145  {
146  return *_container;
147  }
148 
149  protected:
150 
152  const RowCache* _row_cache;
153  const ColCache* _col_cache;
154 
155  };
156 
157 
158  template<typename M_, typename RowCache, typename ColCache>
160  : public ConstUncachedMatrixView<M_,RowCache,ColCache>
161  {
162 
164 
165  public:
166 
167  typedef M_ Container;
168  typedef typename Container::ElementType ElementType;
169  typedef typename Container::size_type size_type;
170 
171  typedef RowCache RowIndexCache;
172  typedef ColCache ColIndexCache;
173 
174  typedef typename RowCache::LocalFunctionSpace LFSV;
175  typedef typename ColCache::LocalFunctionSpace LFSU;
176 
177  typedef typename LFSV::Traits::DOFIndex RowDOFIndex;
178  typedef typename LFSV::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex RowContainerIndex;
179 
180  typedef typename LFSU::Traits::DOFIndex ColDOFIndex;
181  typedef typename LFSU::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex ColContainerIndex;
182 
183  using BaseT::rowIndexCache;
184  using BaseT::colIndexCache;
185  using BaseT::N;
186  using BaseT::M;
187 
188  // Explicitly pull in operator() from the base class to work around a problem
189  // with clang not finding the const overloads of the operator from the base class.
190  using BaseT::operator();
191 
193  {}
194 
196  : BaseT(container)
197  {}
198 
199  void commit()
200  {}
201 
202  template<typename LC>
203  void write(const LC& local_container)
204  {
205  for (size_type i = 0; i < N(); ++i)
206  for (size_type j = 0; j < M(); ++j)
207  container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j)) = local_container.getEntry(i,j);
208  }
209 
210  template<typename LC>
211  void add(const LC& local_container)
212  {
213  for (size_type i = 0; i < N(); ++i)
214  for (size_type j = 0; j < M(); ++j)
215  container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j)) += local_container.getEntry(i,j);
216  }
217 
218 
219 
221  {
222  return container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
223  }
224 
226  {
227  return container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j));
228  }
229 
231  {
232  return container()(i,j);
233  }
234 
236  {
237  return container()(i,colIndexCache().containerIndex(j));
238  }
239 
241  {
242  return container()(rowIndexCache().containerIndex(i),j);
243  }
244 
245  void add(size_type i, size_type j, const ElementType& v)
246  {
247  container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j)) += v;
248  }
249 
250  void add(const RowDOFIndex& i, const ColDOFIndex& j, const ElementType& v)
251  {
252  container()(rowIndexCache().containerIndex(i),colIndexCache().containerIndex(j)) += v;
253  }
254 
255  void add(const RowContainerIndex& i, const ColContainerIndex& j, const ElementType& v)
256  {
257  container()(i,j) += v;
258  }
259 
260  void add(const RowContainerIndex& i, size_type j, const ElementType& v)
261  {
262  container()(i,colIndexCache().containerIndex(j)) += v;
263  }
264 
265  void add(size_type i, const ColContainerIndex& j, const ElementType& v)
266  {
267  container()(rowIndexCache().containerIndex(i),j) += v;
268  }
269 
271  {
272  return *(this->_container);
273  }
274 
275  };
276 
277 
278  } // namespace PDELab
279 } // namespace Dune
280 
281 #endif // DUNE_PDELAB_BACKEND_COMMON_UNCACHEDMATRIXVIEW_HH
const RowCache * _row_cache
Definition: uncachedmatrixview.hh:152
const ColIndexCache & colIndexCache() const
Definition: uncachedmatrixview.hh:74
Container & container()
Definition: uncachedmatrixview.hh:270
void commit()
Definition: uncachedmatrixview.hh:199
Definition: uncachedmatrixview.hh:14
UncachedMatrixView()
Definition: uncachedmatrixview.hh:192
ElementType & operator()(const RowDOFIndex &i, const ColDOFIndex &j)
Definition: uncachedmatrixview.hh:225
Definition: uncachedmatrixview.hh:159
const Container & container() const
Definition: uncachedmatrixview.hh:144
void detach()
Definition: uncachedmatrixview.hh:85
ColCache ColIndexCache
Definition: uncachedmatrixview.hh:45
Container::size_type size_type
Definition: uncachedmatrixview.hh:40
RowCache::LocalFunctionSpace LFSV
Definition: uncachedmatrixview.hh:47
const ElementType & operator()(const RowContainerIndex &i, const ColContainerIndex &j) const
Definition: uncachedmatrixview.hh:129
ConstUncachedMatrixView()
Definition: uncachedmatrixview.hh:56
LFSU::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex ColContainerIndex
Definition: uncachedmatrixview.hh:181
const ElementType & operator()(const RowDOFIndex &i, const ColDOFIndex &j) const
Definition: uncachedmatrixview.hh:124
LFSV::Traits::DOFIndex RowDOFIndex
Definition: uncachedmatrixview.hh:177
RowCache::LocalFunctionSpace LFSV
Definition: uncachedmatrixview.hh:174
void add(const RowContainerIndex &i, const ColContainerIndex &j, const ElementType &v)
Definition: uncachedmatrixview.hh:255
size_type M() const
Definition: uncachedmatrixview.hh:104
Container::size_type size_type
Definition: uncachedmatrixview.hh:169
void read(LC &local_container) const
Definition: uncachedmatrixview.hh:110
LFSU::Traits::DOFIndex ColDOFIndex
Definition: uncachedmatrixview.hh:53
ElementType & operator()(const RowContainerIndex &i, const ColContainerIndex &j)
Definition: uncachedmatrixview.hh:230
ConstUncachedMatrixView(M_ &container)
Definition: uncachedmatrixview.hh:62
void unbind()
Definition: uncachedmatrixview.hh:96
const ColCache * _col_cache
Definition: uncachedmatrixview.hh:153
size_type N() const
Definition: uncachedmatrixview.hh:99
Container::field_type E
Definition: uncachedmatrixview.hh:39
void write(const LC &local_container)
Definition: uncachedmatrixview.hh:203
LFSU::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex ColContainerIndex
Definition: uncachedmatrixview.hh:54
dune_static_assert((is_same< typename RowCache::LocalFunctionSpace::Traits::GridFunctionSpace, typename Container::TestGridFunctionSpace >::value),"The RowCache passed to LocalView must belong to the underlying GFSV")
void attach(M_ &container)
Definition: uncachedmatrixview.hh:80
const RowIndexCache & rowIndexCache() const
Definition: uncachedmatrixview.hh:68
const ElementType & operator()(const RowContainerIndex &i, size_type j) const
Definition: uncachedmatrixview.hh:134
ColCache::LocalFunctionSpace LFSU
Definition: uncachedmatrixview.hh:48
M_ Container
Definition: uncachedmatrixview.hh:167
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
const ElementType & operator()(size_type i, const ColContainerIndex &j) const
Definition: uncachedmatrixview.hh:139
LFSV::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex RowContainerIndex
Definition: uncachedmatrixview.hh:51
void add(size_type i, size_type j, const ElementType &v)
Definition: uncachedmatrixview.hh:245
LFSU::Traits::DOFIndex ColDOFIndex
Definition: uncachedmatrixview.hh:180
ColCache::LocalFunctionSpace LFSU
Definition: uncachedmatrixview.hh:175
void bind(const RowCache &row_cache, const ColCache &col_cache)
Definition: uncachedmatrixview.hh:90
void add(const LC &local_container)
Definition: uncachedmatrixview.hh:211
void add(const RowDOFIndex &i, const ColDOFIndex &j, const ElementType &v)
Definition: uncachedmatrixview.hh:250
M_ * _container
Definition: uncachedmatrixview.hh:151
ElementType & operator()(const RowContainerIndex &i, size_type j)
Definition: uncachedmatrixview.hh:235
RowCache RowIndexCache
Definition: uncachedmatrixview.hh:171
RowCache RowIndexCache
Definition: uncachedmatrixview.hh:44
remove_const< M_ >::type Container
Definition: uncachedmatrixview.hh:19
ElementType & operator()(size_type i, const ColContainerIndex &j)
Definition: uncachedmatrixview.hh:240
LFSV::Traits::DOFIndex RowDOFIndex
Definition: uncachedmatrixview.hh:50
ColCache ColIndexCache
Definition: uncachedmatrixview.hh:172
E ElementType
Definition: uncachedmatrixview.hh:42
UncachedMatrixView(Container &container)
Definition: uncachedmatrixview.hh:195
void add(const RowContainerIndex &i, size_type j, const ElementType &v)
Definition: uncachedmatrixview.hh:260
LFSV::Traits::GridFunctionSpace::Ordering::Traits::ContainerIndex RowContainerIndex
Definition: uncachedmatrixview.hh:178
ElementType & operator()(size_type i, size_type j)
Definition: uncachedmatrixview.hh:220
const ElementType & operator()(size_type i, size_type j) const
Definition: uncachedmatrixview.hh:119
Container::ElementType ElementType
Definition: uncachedmatrixview.hh:168
void add(size_type i, const ColContainerIndex &j, const ElementType &v)
Definition: uncachedmatrixview.hh:265