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