2#ifndef DUNE_PDELAB_BACKEND_SIMPLE_MATRIX_HH
3#define DUNE_PDELAB_BACKEND_SIMPLE_MATRIX_HH
13#include <dune/pdelab/backend/interface.hh>
14#include <dune/pdelab/backend/common/uncachedmatrixview.hh>
15#include <dune/pdelab/backend/simple/descriptors.hh>
21 template<
typename GFSV,
typename GFSU,
typename C>
23 :
public Backend::impl::Wrapper<C>
26 friend Backend::impl::Wrapper<C>;
31 typedef typename Container::value_type ElementType;
32 typedef ElementType E;
34 typedef ElementType field_type;
35 typedef typename Container::size_type size_type;
37 typedef GFSU TrialGridFunctionSpace;
38 typedef GFSV TestGridFunctionSpace;
40 typedef typename GFSV::Ordering::Traits::ContainerIndex RowIndex;
41 typedef typename GFSU::Ordering::Traits::ContainerIndex ColIndex;
43 template<
typename RowCache,
typename ColCache>
44 using LocalView = UncachedMatrixView<MatrixContainer,RowCache,ColCache>;
46 template<
typename RowCache,
typename ColCache>
47 using ConstLocalView = ConstUncachedMatrixView<const MatrixContainer,RowCache,ColCache>;
51 MatrixContainer(
const GO& go)
52 : _rows(go.testGridFunctionSpace().
size())
53 , _cols(go.trialGridFunctionSpace().
size())
54 , _container(
std::make_shared<Container>(_rows*_cols,E(0)))
58 MatrixContainer(
const GO& go,
const E& e)
59 : _rows(go.testGridFunctionSpace().
size())
60 , _cols(go.trialGridFunctionSpace().
size())
61 , _container(
std::make_shared<Container>(_rows*_cols,e))
65 explicit MatrixContainer(Backend::unattached_container = Backend::unattached_container())
71 explicit MatrixContainer(Backend::attached_container)
74 , _container(
std::make_shared<Container>())
77 MatrixContainer(
const MatrixContainer& rhs)
80 , _container(
std::make_shared<Container>(*(rhs._container)))
83 MatrixContainer& operator=(
const MatrixContainer& rhs)
87 if (_rows == 0 && _cols == 0)
94 (*_container) = (*(rhs._container));
98 _container = std::make_shared<Container>(*(rhs._container));
108 void attach(std::shared_ptr<Container> container)
110 _container = container;
113 bool attached()
const
115 return bool(_container);
118 const std::shared_ptr<Container>& storage()
const
133 MatrixContainer& operator=(
const E& e)
135 std::fill(_container->begin(),_container->end(),e);
139 MatrixContainer& operator*=(
const E& e)
141 using namespace std::placeholders;
142 std::transform(_container->begin(),_container->end(),_container->begin(),std::bind(std::multiplies<E>(),e,
_1));
147 void mv(
const V& x, V& y)
const
149 auto rowit = _container->begin();
152 v = std::inner_product(rowit,rowit + _cols,x.begin(),E(0));
158 void usmv(
const E alpha,
const V& x, V& y)
const
160 auto rowit = _container->begin();
163 v += alpha * std::inner_product(rowit,rowit + _cols,x.begin(),E(0));
168 E& operator()(
const RowIndex& ri,
const ColIndex& ci)
170 return (*_container)[ri[0]*_cols + ci[0]];
173 const E& operator()(
const RowIndex& ri,
const ColIndex& ci)
const
175 return (*_container)[ri[0]*_cols + ci[0]];
178 const Container& base()
const
190 const Container& native()
const
208 void clear_row(
const RowIndex& ri,
const E& diagonal_entry)
210 std::fill(_container->begin() + ri[0]*_cols,_container->begin() + (ri[0]+1)*_cols,E(0));
211 (*this)(ri,ri) = diagonal_entry;
214 void clear_row_block(
const RowIndex& ri,
const E& diagonal_entry)
216 std::fill(_container->begin() + ri[0]*_cols,_container->begin() + (ri[0]+1)*_cols,E(0));
217 (*this)(ri,ri) = diagonal_entry;
224 std::shared_ptr<Container> _container;
Traits for type conversions and type information.
constexpr index_constant< 1 > _1
Compile time index with value 1.
Definition: indices.hh:55
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75