dune-pdelab  2.5-dev
istl/vector.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_ISTL_VECTOR_HH
4 #define DUNE_PDELAB_BACKEND_ISTL_VECTOR_HH
5 
6 // this is here for backwards compatibility and deprecation warnings, remove after 2.5.0
7 #include "ensureistlinclude.hh"
8 
9 #include <dune/common/fvector.hh>
10 #include <dune/istl/bvector.hh>
11 #include <dune/typetree/typetree.hh>
12 
22 
23 namespace Dune {
24  namespace PDELab {
25  namespace ISTL {
26 
27  template<typename GFS, typename C>
29  : public Backend::impl::Wrapper<C>
30  {
31 
32  friend Backend::impl::Wrapper<C>;
33 
34  public:
35  typedef typename C::field_type ElementType;
36  typedef ElementType E;
37  typedef C Container;
38  typedef GFS GridFunctionSpace;
39  typedef typename Container::field_type field_type;
40  typedef typename Container::block_type block_type;
41  typedef typename Container::size_type size_type;
42 
43  typedef typename GFS::Ordering::Traits::ContainerIndex ContainerIndex;
44 
47 
48 
49  template<typename LFSCache>
51 
52  template<typename LFSCache>
54 
55 
57  : _gfs(rhs._gfs)
58  , _container(std::make_shared<Container>(_gfs.ordering().blockCount()))
59  {
60  ISTL::dispatch_vector_allocation(_gfs.ordering(),*_container,typename GFS::Ordering::ContainerAllocationTag());
61  (*_container) = rhs.native();
62  }
63 
65  : _gfs(gfs)
66  , _container(std::make_shared<Container>(gfs.ordering().blockCount()))
67  {
68  ISTL::dispatch_vector_allocation(gfs.ordering(),*_container,typename GFS::Ordering::ContainerAllocationTag());
69  }
70 
73  : _gfs(gfs)
74  {}
75 
81  BlockVector (const GFS& gfs, Container& container)
82  : _gfs(gfs)
83  , _container(stackobject_to_shared_ptr(container))
84  {
85  _container->resize(gfs.ordering().blockCount());
86  ISTL::dispatch_vector_allocation(gfs.ordering(),*_container,typename GFS::Ordering::ContainerAllocationTag());
87  }
88 
89  BlockVector (const GFS& gfs, const E& e)
90  : _gfs(gfs)
91  , _container(std::make_shared<Container>(gfs.ordering().blockCount()))
92  {
93  ISTL::dispatch_vector_allocation(gfs.ordering(),*_container,typename GFS::Ordering::ContainerAllocationTag());
94  (*_container)=e;
95  }
96 
97  void detach()
98  {
99  _container.reset();
100  }
101 
102  void attach(std::shared_ptr<Container> container)
103  {
104  _container = container;
105  }
106 
107  bool attached() const
108  {
109  return bool(_container);
110  }
111 
112  const std::shared_ptr<Container>& storage() const
113  {
114  return _container;
115  }
116 
117  size_type N() const
118  {
119  return _container->N();
120  }
121 
123  {
124  if (this == &r)
125  return *this;
126  if (attached())
127  {
128  (*_container) = r.native();
129  }
130  else
131  {
132  _container = std::make_shared<Container>(r.native());
133  }
134  return *this;
135  }
136 
138  {
139  (*_container)=e;
140  return *this;
141  }
142 
144  {
145  (*_container)*=e;
146  return *this;
147  }
148 
149 
151  {
152  (*_container)+=e;
153  return *this;
154  }
155 
157  {
158  (*_container)+= e.native();
159  return *this;
160  }
161 
163  {
164  (*_container)-= e.native();
165  return *this;
166  }
167 
168  block_type& block(std::size_t i)
169  {
170  return (*_container)[i];
171  }
172 
173  const block_type& block(std::size_t i) const
174  {
175  return (*_container)[i];
176  }
177 
178  E& operator[](const ContainerIndex& ci)
179  {
180  return ISTL::access_vector_element(ISTL::container_tag(*_container),*_container,ci,ci.size()-1);
181  }
182 
183  const E& operator[](const ContainerIndex& ci) const
184  {
185  return ISTL::access_vector_element(ISTL::container_tag(*_container),*_container,ci,ci.size()-1);
186  }
187 
188  typename Dune::template FieldTraits<E>::real_type two_norm() const
189  {
190  return _container->two_norm();
191  }
192 
193  typename Dune::template FieldTraits<E>::real_type one_norm() const
194  {
195  return _container->one_norm();
196  }
197 
198  typename Dune::template FieldTraits<E>::real_type infinity_norm() const
199  {
200  return _container->infinity_norm();
201  }
202 
203  E operator*(const BlockVector& y) const
204  {
205  return (*_container)*y.native();
206  }
207 
208  E dot(const BlockVector& y) const
209  {
210  return _container->dot(y.native());
211  }
212 
213  BlockVector& axpy(const E& a, const BlockVector& y)
214  {
215  _container->axpy(a, y.native());
216  return *this;
217  }
218 
219  private:
220 
221  // for debugging and AMG access
222  Container& native ()
223  {
224  return *_container;
225  }
226 
227  const Container& native () const
228  {
229  return *_container;
230  }
231 
232  public:
233 
234  operator Container&()
235  {
236  return *_container;
237  }
238 
239  operator const Container&() const
240  {
241  return *_container;
242  }
243 
244  iterator begin()
245  {
246  return iterator(*_container,false);
247  }
248 
249 
250  const_iterator begin() const
251  {
252  return const_iterator(*_container,false);
253  }
254 
255  iterator end()
256  {
257  return iterator(*_container,true);
258  }
259 
260 
261  const_iterator end() const
262  {
263  return const_iterator(*_container,true);
264  }
265 
266  size_t flatsize() const
267  {
268  return _container->dim();
269  }
270 
271  const GFS& gridFunctionSpace() const
272  {
273  return _gfs;
274  }
275 
276  private:
277  const GFS& _gfs;
278  std::shared_ptr<Container> _container;
279  };
280 
281 #ifndef DOXYGEN
282 
283  // helper struct invoking the GFS tree -> ISTL vector reduction
284  template<typename GFS, typename E>
285  struct BlockVectorSelectorHelper
286  {
287 
288  typedef typename TypeTree::AccumulateType<
289  GFS,
290  ISTL::vector_creation_policy<E>
291  >::type vector_descriptor;
292 
294 
295  };
296 
297 #endif // DOXYGEN
298 
299  // can't have the closing of the namespace inside the #ifndef DOXYGEN block
300  } // namespace ISTL
301 
302 #ifndef DOXYGEN
303 
304  namespace Backend {
305  namespace impl {
306 
307  template<Dune::PDELab::ISTL::Blocking blocking, std::size_t block_size, typename GFS, typename E>
308  struct BackendVectorSelectorHelper<ISTL::VectorBackend<blocking,block_size>, GFS, E>
309  : public ISTL::BlockVectorSelectorHelper<GFS,E>
310  {};
311 
312  } // namespace impl
313  } // namespace Backend
314 
315 #endif // DOXYGEN
316 
317  } // namespace PDELab
318 } // namespace Dune
319 
320 #endif // DUNE_PDELAB_BACKEND_ISTL_VECTOR_HH
Tag for requesting a vector or matrix container without a pre-attached underlying object...
Definition: backend/common/tags.hh:25
const Entity & e
Definition: localfunctionspace.hh:111
E & operator[](const ContainerIndex &ci)
Definition: istl/vector.hh:178
Definition: istl/descriptors.hh:50
Definition: uncachedvectorview.hh:135
BlockVector & operator=(const BlockVector &r)
Definition: istl/vector.hh:122
const GFS & gridFunctionSpace() const
Definition: istl/vector.hh:271
BlockVector(const GFS &gfs, const E &e)
Definition: istl/vector.hh:89
Dune::template FieldTraits< E >::real_type two_norm() const
Definition: istl/vector.hh:188
block_type & block(std::size_t i)
Definition: istl/vector.hh:168
tags::container< T >::type container_tag(const T &)
Gets instance of container tag associated with T.
Definition: backend/istl/tags.hh:249
ISTL::vector_iterator< const C > const_iterator
Definition: istl/vector.hh:46
const_iterator end() const
Definition: istl/vector.hh:261
ElementType E
Definition: istl/vector.hh:36
const block_type & block(std::size_t i) const
Definition: istl/vector.hh:173
const_iterator begin() const
Definition: istl/vector.hh:250
ISTL::vector_iterator< C > iterator
Definition: istl/vector.hh:45
BlockVector(const GFS &gfs, Container &container)
Constructs an BlockVector for an explicitly given vector object.
Definition: istl/vector.hh:81
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
Container::size_type size_type
Definition: istl/vector.hh:41
Various tags for influencing backend behavior.
BlockVector(const GFS &gfs, Backend::attached_container=Backend::attached_container())
Definition: istl/vector.hh:64
Dune::template FieldTraits< E >::real_type one_norm() const
Definition: istl/vector.hh:193
E operator*(const BlockVector &y) const
Definition: istl/vector.hh:203
BlockVector(const GFS &gfs, Backend::unattached_container)
Creates an BlockVector without allocating an underlying ISTL vector.
Definition: istl/vector.hh:72
BlockVector & axpy(const E &a, const BlockVector &y)
Definition: istl/vector.hh:213
Definition: vectoriterator.hh:114
Definition: istl/vector.hh:28
BlockVector(const BlockVector &rhs)
Definition: istl/vector.hh:56
E dot(const BlockVector &y) const
Definition: istl/vector.hh:208
Dune::template FieldTraits< E >::real_type infinity_norm() const
Definition: istl/vector.hh:198
size_type N() const
Definition: istl/vector.hh:117
BlockVector & operator-=(const BlockVector &e)
Definition: istl/vector.hh:162
GFS::Ordering::Traits::ContainerIndex ContainerIndex
Definition: istl/vector.hh:43
GFS GridFunctionSpace
Definition: istl/vector.hh:38
const std::shared_ptr< Container > & storage() const
Definition: istl/vector.hh:112
STL namespace.
Container::field_type field_type
Definition: istl/vector.hh:39
const E & operator[](const ContainerIndex &ci) const
Definition: istl/vector.hh:183
C Container
Definition: istl/vector.hh:37
void attach(std::shared_ptr< Container > container)
Definition: istl/vector.hh:102
bool attached() const
Definition: istl/vector.hh:107
Definition: uncachedvectorview.hh:15
iterator end()
Definition: istl/vector.hh:255
size_t flatsize() const
Definition: istl/vector.hh:266
void detach()
Definition: istl/vector.hh:97
Tag for requesting a vector or matrix container with a pre-attached underlying object.
Definition: backend/common/tags.hh:29
C::field_type ElementType
Definition: istl/vector.hh:35
iterator begin()
Definition: istl/vector.hh:244
BlockVector & operator+=(const E &e)
Definition: istl/vector.hh:150
BlockVector & operator*=(const E &e)
Definition: istl/vector.hh:143
Container::block_type block_type
Definition: istl/vector.hh:40