1#ifndef DUNE_FEM_EIGENMATRIX_HH
2#define DUNE_FEM_EIGENMATRIX_HH
12#include <dune/fem/function/adaptivefunction/adaptivefunction.hh>
13#include <dune/fem/misc/functor.hh>
14#include <dune/fem/operator/common/localmatrix.hh>
15#include <dune/fem/operator/common/localmatrixwrapper.hh>
16#include <dune/fem/io/file/asciiparser.hh>
17#include <dune/fem/io/parameter.hh>
18#include <dune/fem/operator/common/operator.hh>
19#include <dune/fem/operator/matrix/columnobject.hh>
20#include <dune/fem/operator/matrix/spmatrix.hh>
21#include <dune/fem/space/mapper/nonblockmapper.hh>
22#include <dune/fem/storage/objectstack.hh>
23#include <Eigen/Sparse>
35 static constexpr int defaultCol = -1;
36 static constexpr int firstCol = defaultCol + 1;
42 typedef int size_type;
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));;
72 size_type rows()
const
74 return matrix_.rows();
78 size_type cols()
const
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 )
134 size_type numNonZeros()
const
136 return matrix_.nonZeros();
141 size_type numNonZeros(size_type i)
const
143 std::cout <<
"EigenMatrix::numNonZeros not yet implemented" << std::endl;
149 std::pair<const field_type, size_type> realValue(size_type index)
const
151 std::cout <<
"EigenMatrix::realValue not yet implemented" << std::endl;
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 )
Dune namespace.
Definition: alignedallocator.hh:13