1 #ifndef DUNE_PDELAB_BACKEND_EIGEN_MATRIX_HH 2 #define DUNE_PDELAB_BACKEND_EIGEN_MATRIX_HH 13 #include <Eigen/Sparse> 23 struct MatrixPatternInserter
25 MatrixPatternInserter(M & mat)
29 template<
typename RI,
typename CI>
30 void add_link(
const RI& ri,
const CI& ci)
32 _matrix.coeffRef(ri.back(),ci.back()) = 0.0;
44 template<
typename GFSV,
typename GFSU,
typename ET,
int _Options>
46 :
public Backend::impl::Wrapper<::Eigen::SparseMatrix<ET,_Options>>
51 typedef ::Eigen::SparseMatrix<ET,_Options> Container;
55 friend Backend::impl::Wrapper<Container>;
59 typedef ET ElementType;
61 typedef ElementType field_type;
62 typedef typename Container::Index size_type;
63 typedef typename Container::Index index_type;
65 typedef GFSU TrialGridFunctionSpace;
66 typedef GFSV TestGridFunctionSpace;
68 typedef typename GFSV::Ordering::Traits::ContainerIndex RowIndex;
69 typedef typename GFSU::Ordering::Traits::ContainerIndex ColIndex;
71 template<
typename RowCache,
typename ColCache>
72 using LocalView = UncachedMatrixView<MatrixContainer,RowCache,ColCache>;
74 template<
typename RowCache,
typename ColCache>
75 using ConstLocalView = ConstUncachedMatrixView<const MatrixContainer,RowCache,ColCache>;
78 typename GFSV::Ordering::Traits::DOFIndex,
79 typename GFSV::Ordering::Traits::ContainerIndex
83 typename GFSU::Ordering::Traits::DOFIndex,
84 typename GFSU::Ordering::Traits::ContainerIndex
87 typedef MatrixPatternInserter<Container> Pattern;
90 MatrixContainer(
const GO& go)
91 : _container(
std::make_shared<Container>())
93 allocate_matrix(_container, go, ElementType(0));
97 MatrixContainer(
const GO& go,
const ElementType&
e)
98 : _container(
std::make_shared<Container>())
100 allocate_matrix(_container, go, e);
104 explicit MatrixContainer(Backend::unattached_container = Backend::unattached_container())
108 explicit MatrixContainer(Backend::attached_container)
109 : _container(
std::make_shared<Container>())
112 MatrixContainer(
const MatrixContainer& rhs)
113 : _container(
std::make_shared<Container>(*(rhs._container)))
116 MatrixContainer& operator=(
const MatrixContainer& rhs)
126 _container = std::make_shared<Container>(rhs.base());
136 void attach(std::shared_ptr<Container> container)
138 _container = container;
141 bool attached()
const 143 return bool(_container);
146 const std::shared_ptr<Container>& storage()
const 153 return _container->rows();
158 return _container->cols();
161 MatrixContainer& operator=(
const ElementType&
e)
163 if(!_container->isCompressed()) _container->makeCompressed();
164 for (
int i=0; i<_container->nonZeros(); i++)
165 _container->valuePtr()[i] =
e;
171 MatrixContainer& operator*=(
const ElementType& e)
178 void mv(
const V& x, V& y)
const 180 y.base() = base() * x.base();
184 void usmv(
const ElementType alpha,
const V& x, V& y)
const 186 y.base() += alpha * (base() * x.base());
189 ElementType& operator()(
const RowIndex& ri,
const ColIndex& ci)
191 return _container->coeffRef(ri[0],ci[0]);
194 const ElementType operator()(
const RowIndex& ri,
const ColIndex& ci)
const 196 return _container->coeffRef(ri[0],ci[0]);
199 const Container& base()
const 211 const Container&
native()
const 229 void clear_row(
const RowIndex& ri,
const ElementType& diagonal_entry)
231 _container->middleRows(ri[0],1) *= 0.0;
232 _container->coeffRef(ri[0],ri[0]) = diagonal_entry;
236 template<
typename GO>
237 static void allocate_matrix(std::shared_ptr<Container> & c,
const GO & go,
const ElementType& e)
240 int rows = go.testGridFunctionSpace().ordering().blockCount();
241 int cols = go.trialGridFunctionSpace().ordering().blockCount();
242 c->resize(rows,cols);
243 size_type nz = go.matrixBackend().avg_nz_per_row;
245 c->reserve(::Eigen::VectorXi::Constant(rows,nz));
248 go.fill_pattern(pattern);
253 std::shared_ptr< Container > _container;
262 #endif // DUNE_PDELAB_BACKEND_EIGEN_MATRIX_HH const Entity & e
Definition: localfunctionspace.hh:111
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!
Definition: adaptivity.hh:27
Various tags for influencing backend behavior.