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