3#ifndef DUNE_PDELAB_BACKEND_ISTL_VECTOR_HH
4#define DUNE_PDELAB_BACKEND_ISTL_VECTOR_HH
9#include <dune/typetree/typetree.hh>
10#include <dune/functions/backends/istlvectorbackend.hh>
12#include <dune/pdelab/backend/interface.hh>
14#include <dune/pdelab/backend/common/uncachedvectorview.hh>
15#include <dune/pdelab/backend/common/aliasedvectorview.hh>
16#include <dune/pdelab/backend/istl/descriptors.hh>
17#include <dune/pdelab/backend/istl/vectorhelpers.hh>
18#include <dune/pdelab/backend/istl/vectoriterator.hh>
19#include <dune/pdelab/gridfunctionspace/gridfunctionspace.hh>
20#include <dune/pdelab/gridfunctionspace/lfsindexcache.hh>
21#include <dune/pdelab/gridfunctionspace/tags.hh>
27 template<
typename GFS,
typename C>
29 :
public Backend::impl::Wrapper<C>
32 friend Backend::impl::Wrapper<C>;
35 typedef typename C::field_type ElementType;
36 typedef ElementType E;
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;
45 typedef typename GFS::Ordering::Traits::ContainerIndex ContainerIndex;
47 typedef ISTL::vector_iterator<C> iterator;
48 typedef ISTL::vector_iterator<const C> const_iterator;
51 template<
typename LFSCache>
52 using LocalView = UncachedVectorView<BlockVector,LFSCache>;
54 template<
typename LFSCache>
55 using ConstLocalView = ConstUncachedVectorView<const BlockVector,LFSCache>;
57 template<
typename LFSCache>
58 using AliasedLocalView = AliasedVectorView<BlockVector,LFSCache>;
60 template<
typename LFSCache>
61 using ConstAliasedLocalView = ConstAliasedVectorView<const BlockVector,LFSCache>;
63 BlockVector(
const BlockVector& rhs)
65 , _container(
std::make_shared<Container>(_gfs->ordering().blockCount()))
68 (*_container) = rhs.native();
71 BlockVector(BlockVector&& rhs)
73 , _container(
std::move(rhs._container))
76 BlockVector (std::shared_ptr<const GFS> gfs, Backend::attached_container = Backend::attached_container())
78 , _container(
std::make_shared<Container>())
84 BlockVector(std::shared_ptr<const GFS> gfs, Backend::unattached_container)
93 BlockVector (std::shared_ptr<const GFS> gfs, Container& container)
100 BlockVector (std::shared_ptr<const GFS> gfs,
const E& e)
102 , _container(
std::make_shared<Container>())
108 BlockVector (
const GFS& gfs, Backend::attached_container tag = Backend::attached_container())
113 BlockVector(
const GFS& gfs, Backend::unattached_container tag)
122 BlockVector (
const GFS& gfs, Container& container)
126 BlockVector (
const GFS& gfs,
const E& e)
143 b.resize(size_provider);
151 template<
typename LFSCache>
152 value_type* data(
const LFSCache& lfs_cache)
154 return &((*this)[lfs_cache.containerIndex(0)]);
157 template<
typename LFSCache>
158 const value_type* data(
const LFSCache& lfs_cache)
const
160 return &((*this)[lfs_cache.containerIndex(0)]);
163 void attach(std::shared_ptr<Container> container)
165 _container = container;
168 bool attached()
const
170 return bool(_container);
173 const std::shared_ptr<Container>& storage()
const
180 return _container->N();
183 BlockVector& operator= (
const BlockVector& r)
189 (*_container) = r.native();
193 _container = std::make_shared<Container>(r.native());
198 BlockVector& operator= (
const E& e)
204 BlockVector& operator*= (
const E& e)
211 BlockVector& operator+= (
const E& e)
217 BlockVector& operator+= (
const BlockVector& e)
219 (*_container)+= e.native();
223 BlockVector& operator-= (
const BlockVector& e)
225 (*_container)-= e.native();
229 block_type& block(std::size_t i)
231 return (*_container)[i];
234 const block_type& block(std::size_t i)
const
236 return (*_container)[i];
239 E& operator[](
const ContainerIndex& ci)
241 return ISTL::access_vector_element(ISTL::container_tag(*_container),*_container,ci,ci.size()-1);
244 const E& operator[](
const ContainerIndex& ci)
const
246 return ISTL::access_vector_element(ISTL::container_tag(*_container),*_container,ci,ci.size()-1);
249 typename Dune::template FieldTraits<E>::real_type two_norm2()
const
251 return _container->two_norm2();
254 typename Dune::template FieldTraits<E>::real_type two_norm()
const
256 return _container->two_norm();
259 typename Dune::template FieldTraits<E>::real_type one_norm()
const
261 return _container->one_norm();
264 typename Dune::template FieldTraits<E>::real_type infinity_norm()
const
266 return _container->infinity_norm();
269 E operator*(
const BlockVector& y)
const
271 return (*_container)*y.native();
274 E
dot(
const BlockVector& y)
const
276 return _container->dot(y.native());
279 BlockVector& axpy(
const E& a,
const BlockVector& y)
281 _container->axpy(a, y.native());
293 const Container& native ()
const
300 operator Container&()
305 operator const Container&()
const
312 return iterator(*_container,
false);
316 const_iterator begin()
const
318 return const_iterator(*_container,
false);
323 return iterator(*_container,
true);
327 const_iterator end()
const
329 return const_iterator(*_container,
true);
332 size_t flatsize()
const
334 return _container->dim();
337 const GFS& gridFunctionSpace()
const
342 std::shared_ptr<const GFS> gridFunctionSpaceStorage()
const
348 std::shared_ptr<const GFS> _gfs;
349 std::shared_ptr<Container> _container;
355 template<
typename GFS,
typename E>
356 struct BlockVectorSelectorHelper
359 typedef typename TypeTree::AccumulateType<
361 ISTL::vector_creation_policy<E>
362 >::type vector_descriptor;
364 typedef BlockVector<GFS,typename vector_descriptor::vector_type> Type;
378 template<Dune::PDELab::ISTL::Blocking blocking, std::
size_t block_size,
typename GFS,
typename E>
379 struct BackendVectorSelectorHelper<ISTL::VectorBackend<blocking,block_size>, GFS, E>
380 :
public ISTL::BlockVectorSelectorHelper<GFS,E>
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Implements a vector constructed from a given type representing a field and a compile-time given size.
auto dot(const A &a, const B &b) -> typename std::enable_if< IsNumber< A >::value &&!IsVector< A >::value &&!std::is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type > ::value, decltype(conj(a) *b)>::type
computes the dot product for fundamental data types according to Petsc's VectDot function: dot(a,...
Definition: dotproduct.hh:42
auto istlVectorBackend(Vector &v)
Return a vector backend wrapping non-const ISTL like containers.
Definition: istlvectorbackend.hh:350
SizeProviderAdapter(const std::shared_ptr< const Ordering > &ordering) -> SizeProviderAdapter< typename Ordering::Traits::SizeType, typename Ordering::Traits::ContainerIndex, Ordering::Traits::ContainerIndexOrder >
template deduction guide for orderings
@ Outer2Inner
indices are ordered from outer to inner container: {outer,...,inner}
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
This file implements several utilities related to std::shared_ptr.