1#ifndef DUNE_FEM_EIGENMATRIX_HH
2#define DUNE_FEM_EIGENMATRIX_HH
23#include <Eigen/Sparse>
35 static constexpr int defaultCol = -1;
36 static constexpr int firstCol = defaultCol + 1;
43 typedef Eigen::SparseMatrix<field_type,Eigen::RowMajor> MatrixStorageType;
44 typedef EigenMatrix<field_type> ThisType;
47 typedef ThisType MatrixBaseType;
49 EigenMatrix(
const ThisType& ) =
delete;
52 explicit EigenMatrix() :
58 EigenMatrix(size_type rows, size_type cols, size_type nz) :
61 reserve(rows,cols,nz);
65 void reserve(size_type rows, size_type cols, size_type nz)
67 matrix_.resize(rows,cols);
68 matrix_.reserve(Eigen::VectorXi::Constant(rows,nz));;
74 return matrix_.rows();
80 return matrix_.cols();
84 void set(size_type row, size_type col, field_type val)
86 matrix_.coeffRef(row,col) = val;
90 void add(size_type row, size_type col, field_type val)
92 matrix_.coeffRef(row,col) += val;
96 template<
class ArgDFType,
class DestDFType>
97 void apply(
const ArgDFType& f, DestDFType& ret)
const
99 ret.dofVector().array().coefficients() =
100 matrix_ * f.dofVector().array().coefficients();
104 field_type
operator()(size_type row, size_type col)
const
106 return matrix_.coeff(row,col);
116 void clearRow (size_type row)
118 matrix_.prune([row](
const size_type& r,
const size_type& c,
const field_type& v)
119 {
return (row != r); });
122 template <
class Vector>
123 void setUnitRows(
const Vector &rows )
136 return matrix_.nonZeros();
155 MatrixStorageType&
data()
160 const MatrixStorageType&
data()
const
166 MatrixStorageType matrix_;
169 template<
class DomainSpace,
class RangeSpace >
170 struct EigenMatrixObject
171 :
public SparseRowMatrixObject< DomainSpace, RangeSpace, EigenMatrix< typename DomainSpace::RangeFieldType> >
173 typedef EigenMatrix< typename DomainSpace::RangeFieldType > MatrixType;
174 typedef SparseRowMatrixObject< DomainSpace, RangeSpace, MatrixType > BaseType;
176 inline EigenMatrixObject(
const DomainSpace &domainSpace,
177 const RangeSpace &rangeSpace,
178 const SolverParameter& param = SolverParameter() )
179 : BaseType( domainSpace, rangeSpace, param )
BCRSMatrix< FieldMatrix< T, n, m >, A >::size_type size_type
void add(const Vertex &vertex)
auto rows(Matrix const &matrix)
auto cols(Matrix const &matrix)
std::ptrdiff_t index() const
virtual void operator()()=0