3#ifndef DUNE_PDELAB_BACKEND_EIGEN_MATRIX_HH
4#define DUNE_PDELAB_BACKEND_EIGEN_MATRIX_HH
15#include <Eigen/Sparse>
25 struct MatrixPatternInserter
27 MatrixPatternInserter(
M & mat)
31 template<
typename RI,
typename CI>
32 void add_link(
const RI& ri,
const CI& ci)
34 _matrix.coeffRef(ri.back(),ci.back()) = 0.0;
46 template<
typename GFSV,
typename GFSU,
typename ET,
int _Options>
48 :
public Backend::impl::Wrapper<::Eigen::SparseMatrix<ET,_Options>>
53 typedef ::Eigen::SparseMatrix<ET,_Options> Container;
57 friend Backend::impl::Wrapper<Container>;
64 typedef typename Container::Index
size_type;
65 typedef typename Container::Index index_type;
67 typedef GFSU TrialGridFunctionSpace;
68 typedef GFSV TestGridFunctionSpace;
70 typedef typename GFSV::Ordering::Traits::ContainerIndex RowIndex;
71 typedef typename GFSU::Ordering::Traits::ContainerIndex ColIndex;
73 template<
typename RowCache,
typename ColCache>
74 using LocalView = UncachedMatrixView<MatrixContainer,RowCache,ColCache>;
76 template<
typename RowCache,
typename ColCache>
77 using ConstLocalView = ConstUncachedMatrixView<const MatrixContainer,RowCache,ColCache>;
80 typename GFSV::Ordering::Traits::DOFIndex,
81 typename GFSV::Ordering::Traits::ContainerIndex
85 typename GFSU::Ordering::Traits::DOFIndex,
86 typename GFSU::Ordering::Traits::ContainerIndex
89 typedef MatrixPatternInserter<Container> Pattern;
92 MatrixContainer(
const GO& go)
99 MatrixContainer(
const GO& go,
const ElementType& e)
102 allocate_matrix(_container, go, e);
106 explicit MatrixContainer(Backend::unattached_container = Backend::unattached_container())
110 explicit MatrixContainer(Backend::attached_container)
114 MatrixContainer(
const MatrixContainer&
rhs)
128 _container = std::make_shared<Container>(
rhs.base());
140 _container = container;
143 bool attached()
const
145 return bool(_container);
155 return _container->rows();
160 return _container->cols();
163 MatrixContainer&
operator=(
const ElementType& e)
165 if(!_container->isCompressed()) _container->makeCompressed();
166 for (
int i=0; i<_container->nonZeros(); i++)
167 _container->valuePtr()[i] = e;
173 MatrixContainer&
operator*=(
const ElementType& e)
180 void mv(
const V& x, V& y)
const
182 y.base() = base() * x.base();
186 void usmv(
const ElementType
alpha,
const V& x, V& y)
const
188 y.base() +=
alpha * (base() * x.base());
193 return _container->coeffRef(ri[0],ci[0]);
198 return _container->coeffRef(ri[0],ci[0]);
201 const Container& base()
const
213 const Container&
native()
const
231 void clear_row(
const RowIndex& ri,
const ElementType& diagonal_entry)
233 _container->middleRows(ri[0],1) *= 0.0;
234 _container->coeffRef(ri[0],ri[0]) = diagonal_entry;
238 template<
typename GO>
242 int rows = go.testGridFunctionSpace().ordering().blockCount();
243 int cols = go.trialGridFunctionSpace().ordering().blockCount();
244 c->resize(rows,cols);
245 size_type nz = go.matrixBackend().avg_nz_per_row;
247 c->reserve(::Eigen::VectorXi::Constant(rows,nz));
250 go.fill_pattern(pattern);
BCRSMatrix< FieldMatrix< T, n, m >, A >::size_type size_type
auto rows(Matrix const &matrix)
auto cols(Matrix const &matrix)
SLList< T, A > & operator=(const SLList< T, A > &other)
bigunsignedint< k > & operator*=(const bigunsignedint< k > &x)
void attach(std::ostream &stream)
static constexpr size_type M()
static constexpr size_type N()
void mv(const X &x, Y &y) const
void usmv(const typename FieldTraits< Y >::field_type &alpha, const X &x, Y &y) const
virtual void operator()()=0
std::enable_if< std::is_base_of< impl::WrapperBase, T >::value, Native< T > & >::type native(T &t)
Definition backend/interface.hh:192
For backward compatibility – Do not use this!
Various tags for influencing backend behavior.